| 1 |
import { beforeEach, expect, test } from "@odoo/hoot"; |
| 2 |
import { queryAllTexts, queryFirst, queryRect } from "@odoo/hoot-dom"; |
| 3 |
import { runAllTimers } from "@odoo/hoot-mock"; |
| 4 |
import { mockService, mountWithCleanup, preloadBundle } from "@web/../tests/web_test_helpers"; |
| 5 |
import { |
| 6 |
DEFAULT_DATE, |
| 7 |
FAKE_MODEL, |
| 8 |
clickAllDaySlot, |
| 9 |
clickEvent, |
| 10 |
selectTimeRange, |
| 11 |
} from "./calendar_test_helpers"; |
| 12 |
|
| 13 |
import { CalendarCommonRenderer } from "@web/views/calendar/calendar_common/calendar_common_renderer"; |
| 14 |
import { CallbackRecorder } from "@web/search/action_hook"; |
| 15 |
|
| 16 |
const FAKE_PROPS = { |
| 17 |
model: FAKE_MODEL, |
| 18 |
createRecord() {}, |
| 19 |
deleteRecord() {}, |
| 20 |
editRecord() {}, |
| 21 |
callbackRecorder: new CallbackRecorder(), |
| 22 |
onSquareSelection() {}, |
| 23 |
cleanSquareSelection() {}, |
| 24 |
}; |
| 25 |
|
| 26 |
async function start(props = {}, target) { |
| 27 |
await mountWithCleanup(CalendarCommonRenderer, { |
| 28 |
props: { ...FAKE_PROPS, ...props }, |
| 29 |
target, |
| 30 |
}); |
| 31 |
} |
| 32 |
|
| 33 |
preloadBundle("web.fullcalendar_lib"); |
| 34 |
beforeEach(() => { |
| 35 |
luxon.Settings.defaultZone = "UTC+1"; |
| 36 |
}); |
| 37 |
|
| 38 |
test(`mount a CalendarCommonRenderer`, async () => { |
| 39 |
await start(); |
| 40 |
expect(`.o_calendar_widget.fc`).toHaveCount(1); |
| 41 |
}); |
| 42 |
|
| 43 |
test(`Day: mount a CalendarCommonRenderer`, async () => { |
| 44 |
await start({ model: { ...FAKE_MODEL, scale: "day" } }); |
| 45 |
expect(`.o_calendar_widget.fc .fc-timeGridDay-view`).toHaveCount(1); |
| 46 |
}); |
| 47 |
|
| 48 |
test(`Week: mount a CalendarCommonRenderer`, async () => { |
| 49 |
await start({ model: { ...FAKE_MODEL, scale: "week" } }); |
| 50 |
expect(`.o_calendar_widget.fc .fc-timeGridWeek-view`).toHaveCount(1); |
| 51 |
}); |
| 52 |
|
| 53 |
test(`Month: mount a CalendarCommonRenderer`, async () => { |
| 54 |
await start({ model: { ...FAKE_MODEL, scale: "month" } }); |
| 55 |
expect(`.o_calendar_widget.fc .fc-dayGridMonth-view`).toHaveCount(1); |
| 56 |
}); |
| 57 |
|
| 58 |
test(`Day: check week number`, async () => { |
| 59 |
await start({ model: { ...FAKE_MODEL, scale: "day" } }); |
| 60 |
expect(`[aria-label^="Week "]`).toHaveCount(1); |
| 61 |
expect(`[aria-label^="Week "]`).toHaveText(/(Week )?28/); |
| 62 |
}); |
| 63 |
|
| 64 |
test(`Day: check date`, async () => { |
| 65 |
await start({ model: { ...FAKE_MODEL, scale: "day" } }); |
| 66 |
expect(`.fc-col-header-cell.fc-day`).toHaveCount(1); |
| 67 |
expect(`.fc-col-header-cell.fc-day:eq(0) .o_cw_day_name`).toHaveText("Friday"); |
| 68 |
expect(`.fc-col-header-cell.fc-day:eq(0) .o_cw_day_number`).toHaveText("16"); |
| 69 |
}); |
| 70 |
|
| 71 |
test(`Day: click all day slot`, async () => { |
| 72 |
await start({ |
| 73 |
model: { ...FAKE_MODEL, scale: "day" }, |
| 74 |
createRecord(record) { |
| 75 |
expect.step("create"); |
| 76 |
expect(record.isAllDay).toBe(true); |
| 77 |
expect(record.start.valueOf()).toBe(DEFAULT_DATE.startOf("day").valueOf()); |
| 78 |
}, |
| 79 |
}); |
| 80 |
await clickAllDaySlot("2021-07-16"); |
| 81 |
expect.verifySteps(["create"]); |
| 82 |
}); |
| 83 |
|
| 84 |
test.tags("desktop"); |
| 85 |
test(`Day: select range`, async () => { |
| 86 |
await start({ |
| 87 |
model: { ...FAKE_MODEL, scale: "day" }, |
| 88 |
createRecord(record) { |
| 89 |
expect.step("create"); |
| 90 |
expect(record.isAllDay).toBe(false); |
| 91 |
expect(record.start.valueOf()).toBe(luxon.DateTime.local(2021, 7, 16, 8, 0).valueOf()); |
| 92 |
expect(record.end.valueOf()).toBe(luxon.DateTime.local(2021, 7, 16, 10, 0).valueOf()); |
| 93 |
}, |
| 94 |
}); |
| 95 |
await selectTimeRange("2021-07-16 08:00:00", "2021-07-16 10:00:00"); |
| 96 |
expect.verifySteps(["create"]); |
| 97 |
}); |
| 98 |
|
| 99 |
test(`Day: check event`, async () => { |
| 100 |
await start({ model: { ...FAKE_MODEL, scale: "day" } }); |
| 101 |
expect(`.o_event`).toHaveCount(1); |
| 102 |
expect(`.o_event`).toHaveAttribute("data-event-id", "1"); |
| 103 |
}); |
| 104 |
|
| 105 |
test.tags("desktop"); |
| 106 |
test(`Day: click on event`, async () => { |
| 107 |
mockService("popover", () => ({ |
| 108 |
add(target, component, { record }) { |
| 109 |
expect.step("popover"); |
| 110 |
expect(record.id).toBe(1); |
| 111 |
return () => {}; |
| 112 |
}, |
| 113 |
})); |
| 114 |
await start({ model: { ...FAKE_MODEL, scale: "day" } }); |
| 115 |
await clickEvent(1); |
| 116 |
await runAllTimers(); |
| 117 |
expect.verifySteps(["popover"]); |
| 118 |
}); |
| 119 |
|
| 120 |
test(`Week: check week number`, async () => { |
| 121 |
await start({ model: { ...FAKE_MODEL, scale: "week" } }); |
| 122 |
expect(`.fc-scrollgrid-section-header .fc-timegrid-axis-cushion`).toHaveCount(1); |
| 123 |
expect(`.fc-scrollgrid-section-header .fc-timegrid-axis-cushion`).toHaveText(/(Week )?28/); |
| 124 |
}); |
| 125 |
|
| 126 |
test(`Week: check dates`, async () => { |
| 127 |
await start({ model: { ...FAKE_MODEL, scale: "week" } }); |
| 128 |
expect(`.fc-col-header-cell.fc-day`).toHaveCount(7); |
| 129 |
expect(queryAllTexts(`.fc-col-header-cell .o_cw_day_name`)).toEqual([ |
| 130 |
"Sun", |
| 131 |
"Mon", |
| 132 |
"Tue", |
| 133 |
"Wed", |
| 134 |
"Thu", |
| 135 |
"Fri", |
| 136 |
"Sat", |
| 137 |
]); |
| 138 |
expect(queryAllTexts`.fc-col-header-cell .o_cw_day_number`).toEqual([ |
| 139 |
"11", |
| 140 |
"12", |
| 141 |
"13", |
| 142 |
"14", |
| 143 |
"15", |
| 144 |
"16", |
| 145 |
"17", |
| 146 |
]); |
| 147 |
}); |
| 148 |
|
| 149 |
test(`Day: automatically scroll to 6am`, async () => { |
| 150 |
await mountWithCleanup(`<div class="scrollable" style="height: 500px;"/>`); |
| 151 |
await start({ model: { ...FAKE_MODEL, scale: "day" } }, queryFirst(`.scrollable`)); |
| 152 |
|
| 153 |
const containerDimensions = queryRect(`.fc-scrollgrid-section-liquid .fc-scroller`); |
| 154 |
const dayStartDimensions = queryRect(`.fc-timegrid-slot[data-time="06:00:00"]:eq(0)`); |
| 155 |
expect(Math.abs(dayStartDimensions.y - containerDimensions.y)).toBeLessThan(2); |
| 156 |
}); |
| 157 |
|
| 158 |
test(`Week: automatically scroll to 6am`, async () => { |
| 159 |
await mountWithCleanup(`<div class="scrollable" style="height: 500px;"/>`); |
| 160 |
await start({ model: { ...FAKE_MODEL, scale: "week" } }, queryFirst(`.scrollable`)); |
| 161 |
|
| 162 |
const containerDimensions = queryRect(`.fc-scrollgrid-section-liquid .fc-scroller`); |
| 163 |
const dayStartDimensions = queryRect(`.fc-timegrid-slot[data-time="06:00:00"]:eq(0)`); |
| 164 |
expect(Math.abs(dayStartDimensions.y - containerDimensions.y)).toBeLessThan(2); |
| 165 |
}); |
| 166 |
|
| 167 |
test("Month: remove row when no day of current month", async () => { |
| 168 |
await start({ model: { ...FAKE_MODEL, scale: "month" } }); |
| 169 |
expect(".fc-day-other, .fc-day-disabled").toHaveCount(4); |
| 170 |
}); |