| 1 |
import { describe, expect, test } from "@odoo/hoot"; |
| 2 |
import { queryAllTexts } from "@odoo/hoot-dom"; |
| 3 |
import { contains, mountWithCleanup, preloadBundle } from "@web/../tests/web_test_helpers"; |
| 4 |
import { DEFAULT_DATE, FAKE_MODEL } from "./calendar_test_helpers"; |
| 5 |
|
| 6 |
import { CalendarYearPopover } from "@web/views/calendar/calendar_year/calendar_year_popover"; |
| 7 |
|
| 8 |
describe.current.tags("desktop"); |
| 9 |
|
| 10 |
const FAKE_RECORDS = [ |
| 11 |
{ |
| 12 |
id: 1, |
| 13 |
start: DEFAULT_DATE, |
| 14 |
end: DEFAULT_DATE, |
| 15 |
isAllDay: true, |
| 16 |
title: "R1", |
| 17 |
}, |
| 18 |
{ |
| 19 |
id: 2, |
| 20 |
start: DEFAULT_DATE.set({ hours: 14 }), |
| 21 |
end: DEFAULT_DATE.set({ hours: 16 }), |
| 22 |
isAllDay: false, |
| 23 |
title: "R2", |
| 24 |
}, |
| 25 |
{ |
| 26 |
id: 3, |
| 27 |
start: DEFAULT_DATE.minus({ days: 1 }), |
| 28 |
end: DEFAULT_DATE.plus({ days: 1 }), |
| 29 |
isAllDay: true, |
| 30 |
title: "R3", |
| 31 |
}, |
| 32 |
{ |
| 33 |
id: 4, |
| 34 |
start: DEFAULT_DATE.minus({ days: 3 }), |
| 35 |
end: DEFAULT_DATE.plus({ days: 1 }), |
| 36 |
isAllDay: true, |
| 37 |
title: "R4", |
| 38 |
}, |
| 39 |
{ |
| 40 |
id: 5, |
| 41 |
start: DEFAULT_DATE.minus({ days: 1 }), |
| 42 |
end: DEFAULT_DATE.plus({ days: 3 }), |
| 43 |
isAllDay: true, |
| 44 |
title: "R5", |
| 45 |
}, |
| 46 |
]; |
| 47 |
|
| 48 |
const FAKE_PROPS = { |
| 49 |
model: FAKE_MODEL, |
| 50 |
date: DEFAULT_DATE, |
| 51 |
records: FAKE_RECORDS, |
| 52 |
createRecord() {}, |
| 53 |
deleteRecord() {}, |
| 54 |
editRecord() {}, |
| 55 |
close() {}, |
| 56 |
}; |
| 57 |
|
| 58 |
async function start(props = {}) { |
| 59 |
await mountWithCleanup(CalendarYearPopover, { |
| 60 |
props: { ...FAKE_PROPS, ...props }, |
| 61 |
}); |
| 62 |
} |
| 63 |
|
| 64 |
preloadBundle("web.fullcalendar_lib"); |
| 65 |
|
| 66 |
test(`canCreate is true`, async () => { |
| 67 |
await start({ |
| 68 |
model: { ...FAKE_MODEL, canCreate: true }, |
| 69 |
}); |
| 70 |
expect(`.o_cw_popover_create`).toHaveCount(1); |
| 71 |
}); |
| 72 |
|
| 73 |
test(`canCreate is false`, async () => { |
| 74 |
await start({ |
| 75 |
model: { ...FAKE_MODEL, canCreate: false }, |
| 76 |
}); |
| 77 |
expect(`.o_cw_popover_create`).toHaveCount(0); |
| 78 |
}); |
| 79 |
|
| 80 |
test(`click on create button`, async () => { |
| 81 |
await start({ |
| 82 |
createRecord: () => expect.step("create"), |
| 83 |
model: { ...FAKE_MODEL, canCreate: true }, |
| 84 |
}); |
| 85 |
expect(`.o_cw_popover_create`).toHaveCount(1); |
| 86 |
|
| 87 |
await contains(`.o_cw_popover_create`).click(); |
| 88 |
expect.verifySteps(["create"]); |
| 89 |
}); |
| 90 |
|
| 91 |
test(`group records`, async () => { |
| 92 |
await start(); |
| 93 |
expect(`.o_cw_body > div`).toHaveCount(4); |
| 94 |
expect(`.o_cw_body > a`).toHaveCount(1); |
| 95 |
expect(queryAllTexts`.o_cw_body > div`).toEqual([ |
| 96 |
"July 16, 2021\nR1\n14:00\nR2", |
| 97 |
"July 13-17, 2021\nR4", |
| 98 |
"July 15-17, 2021\nR3", |
| 99 |
"July 15-19, 2021\nR5", |
| 100 |
]); |
| 101 |
expect(`.o_cw_body`).toHaveText( |
| 102 |
"July 16, 2021\nR1\n14:00\nR2\nJuly 13-17, 2021\nR4\nJuly 15-17, 2021\nR3\nJuly 15-19, 2021\nR5\n Create" |
| 103 |
); |
| 104 |
}); |
| 105 |
|
| 106 |
test(`click on record`, async () => { |
| 107 |
await start({ |
| 108 |
records: [FAKE_RECORDS[3]], |
| 109 |
editRecord: () => expect.step("edit"), |
| 110 |
}); |
| 111 |
expect(`.o_cw_body a.o_cw_popover_link`).toHaveCount(1); |
| 112 |
|
| 113 |
await contains(`.o_cw_body a.o_cw_popover_link`).click(); |
| 114 |
expect.verifySteps(["edit"]); |
| 115 |
}); |