| 1 |
import { expect, test } from "@odoo/hoot"; |
| 2 |
import { queryAllTexts, resize } from "@odoo/hoot-dom"; |
| 3 |
import { mockTimeZone, runAllTimers } from "@odoo/hoot-mock"; |
| 4 |
import { |
| 5 |
mockService, |
| 6 |
mountWithCleanup, |
| 7 |
preloadBundle, |
| 8 |
patchWithCleanup, |
| 9 |
} from "@web/../tests/web_test_helpers"; |
| 10 |
import { FAKE_MODEL, clickDate, selectDateRange } from "./calendar_test_helpers"; |
| 11 |
|
| 12 |
import { CalendarYearRenderer } from "@web/views/calendar/calendar_year/calendar_year_renderer"; |
| 13 |
|
| 14 |
const FAKE_PROPS = { |
| 15 |
model: FAKE_MODEL, |
| 16 |
createRecord() {}, |
| 17 |
deleteRecord() {}, |
| 18 |
editRecord() {}, |
| 19 |
}; |
| 20 |
|
| 21 |
async function start(props = {}) { |
| 22 |
await mountWithCleanup(CalendarYearRenderer, { |
| 23 |
props: { ...FAKE_PROPS, ...props }, |
| 24 |
}); |
| 25 |
} |
| 26 |
|
| 27 |
preloadBundle("web.fullcalendar_lib"); |
| 28 |
|
| 29 |
test(`mount a CalendarYearRenderer`, async () => { |
| 30 |
await start(); |
| 31 |
expect(`.fc-month-container`).toHaveCount(12); |
| 32 |
|
| 33 |
// check "title format" |
| 34 |
expect(`.fc-toolbar-chunk:nth-child(2) .fc-toolbar-title`).toHaveCount(12); |
| 35 |
expect(queryAllTexts`.fc-toolbar-chunk:nth-child(2) .fc-toolbar-title`).toEqual([ |
| 36 |
"January 2021", |
| 37 |
"February 2021", |
| 38 |
"March 2021", |
| 39 |
"April 2021", |
| 40 |
"May 2021", |
| 41 |
"June 2021", |
| 42 |
"July 2021", |
| 43 |
"August 2021", |
| 44 |
"September 2021", |
| 45 |
"October 2021", |
| 46 |
"November 2021", |
| 47 |
"December 2021", |
| 48 |
]); |
| 49 |
|
| 50 |
// check day header format |
| 51 |
expect(`.fc-month:eq(0) .fc-col-header-cell`).toHaveCount(7); |
| 52 |
expect(queryAllTexts`.fc-month:eq(0) .fc-col-header-cell`).toEqual([ |
| 53 |
"S", |
| 54 |
"M", |
| 55 |
"T", |
| 56 |
"W", |
| 57 |
"T", |
| 58 |
"F", |
| 59 |
"S", |
| 60 |
]); |
| 61 |
|
| 62 |
// check showNonCurrentDates |
| 63 |
expect(`:not(.fc-day-disabled) > * > * > .fc-daygrid-day-number`).toHaveCount(365); |
| 64 |
}); |
| 65 |
|
| 66 |
test.tags("desktop"); |
| 67 |
test(`display events`, async () => { |
| 68 |
mockService("popover", () => ({ |
| 69 |
add(target, component, props) { |
| 70 |
expect.step(`${props.date.toISODate()} ${props.records[0].title}`); |
| 71 |
return () => {}; |
| 72 |
}, |
| 73 |
})); |
| 74 |
|
| 75 |
await start({ |
| 76 |
createRecord(record) { |
| 77 |
expect.step(`${record.start.toISODate()} allDay:${record.isAllDay} no event`); |
| 78 |
}, |
| 79 |
}); |
| 80 |
|
| 81 |
await clickDate("2021-07-15"); |
| 82 |
expect.verifySteps(["2021-07-15 allDay:true no event"]); |
| 83 |
await clickDate("2021-07-16"); |
| 84 |
expect.verifySteps(["2021-07-16 1 day, all day in July"]); |
| 85 |
await clickDate("2021-07-17"); |
| 86 |
expect.verifySteps(["2021-07-17 allDay:true no event"]); |
| 87 |
await clickDate("2021-07-18"); |
| 88 |
expect.verifySteps(["2021-07-18 3 days, all day in July"]); |
| 89 |
await clickDate("2021-07-19"); |
| 90 |
expect.verifySteps(["2021-07-19 3 days, all day in July"]); |
| 91 |
await clickDate("2021-07-20"); |
| 92 |
expect.verifySteps(["2021-07-20 3 days, all day in July"]); |
| 93 |
await clickDate("2021-07-21"); |
| 94 |
expect.verifySteps(["2021-07-21 allDay:true no event"]); |
| 95 |
await clickDate("2021-06-28"); |
| 96 |
expect.verifySteps(["2021-06-28 allDay:true no event"]); |
| 97 |
await clickDate("2021-06-29"); |
| 98 |
expect.verifySteps(["2021-06-29 Over June and July"]); |
| 99 |
await clickDate("2021-06-30"); |
| 100 |
expect.verifySteps(["2021-06-30 Over June and July"]); |
| 101 |
await clickDate("2021-07-01"); |
| 102 |
expect.verifySteps(["2021-07-01 Over June and July"]); |
| 103 |
await clickDate("2021-07-02"); |
| 104 |
expect.verifySteps(["2021-07-02 Over June and July"]); |
| 105 |
await clickDate("2021-07-03"); |
| 106 |
expect.verifySteps(["2021-07-03 Over June and July"]); |
| 107 |
await clickDate("2021-07-04"); |
| 108 |
expect.verifySteps(["2021-07-04 allDay:true no event"]); |
| 109 |
}); |
| 110 |
|
| 111 |
test.tags("desktop"); |
| 112 |
test(`select a range of date`, async () => { |
| 113 |
await start({ |
| 114 |
createRecord({ isAllDay, start, end }) { |
| 115 |
expect.step("create"); |
| 116 |
expect(isAllDay).toBe(true); |
| 117 |
expect(start.toSQL()).toBe("2021-07-02 00:00:00.000 +01:00"); |
| 118 |
expect(end.toSQL()).toBe("2021-07-05 00:00:00.000 +01:00"); |
| 119 |
}, |
| 120 |
}); |
| 121 |
await selectDateRange("2021-07-02", "2021-07-05"); |
| 122 |
expect.verifySteps(["create"]); |
| 123 |
}); |
| 124 |
|
| 125 |
test(`display correct column header for days, independent of the timezone`, async () => { |
| 126 |
// Regression test: when the system tz is somewhere in a negative GMT (in our example Alaska) |
| 127 |
// the day headers of a months were incorrectly set. (S S M T W T F) instead of (S M T W T F S) |
| 128 |
// if the first day of the week is Sunday. |
| 129 |
mockTimeZone(-9); |
| 130 |
await start(); |
| 131 |
expect(queryAllTexts`.fc-month:eq(0) .fc-col-header-cell`).toEqual([ |
| 132 |
"S", |
| 133 |
"M", |
| 134 |
"T", |
| 135 |
"W", |
| 136 |
"T", |
| 137 |
"F", |
| 138 |
"S", |
| 139 |
]); |
| 140 |
}); |
| 141 |
|
| 142 |
test("remove row when no day of current month", async () => { |
| 143 |
await start(); |
| 144 |
expect(".fc-day-other, .fc-day-disabled").toHaveCount(76); |
| 145 |
}); |
| 146 |
|
| 147 |
test("resize callback is being called", async () => { |
| 148 |
patchWithCleanup(CalendarYearRenderer.prototype, { |
| 149 |
onWindowResize() { |
| 150 |
expect.step("onWindowResize"); |
| 151 |
}, |
| 152 |
}); |
| 153 |
await start(); |
| 154 |
expect.verifySteps([]); |
| 155 |
await resize({ height: 500 }); |
| 156 |
await runAllTimers(); |
| 157 |
expect.verifySteps(new Array(12).fill("onWindowResize")); // one for each FullCalendar instance |
| 158 |
}); |