| 1 |
import { describe, expect, test } from "@odoo/hoot"; |
| 2 |
import { click } from "@odoo/hoot-dom"; |
| 3 |
import { mountWithCleanup } from "@web/../tests/web_test_helpers"; |
| 4 |
import { DEFAULT_DATE, FAKE_MODEL } from "./calendar_test_helpers"; |
| 5 |
|
| 6 |
import { CalendarCommonPopover } from "@web/views/calendar/calendar_common/calendar_common_popover"; |
| 7 |
|
| 8 |
describe.current.tags("desktop"); |
| 9 |
|
| 10 |
const FAKE_RECORD = { |
| 11 |
id: 5, |
| 12 |
title: "Meeting", |
| 13 |
isAllDay: false, |
| 14 |
start: DEFAULT_DATE, |
| 15 |
end: DEFAULT_DATE.plus({ hours: 3, minutes: 15 }), |
| 16 |
colorIndex: 0, |
| 17 |
isTimeHidden: false, |
| 18 |
rawRecord: { |
| 19 |
name: "Meeting", |
| 20 |
description: "<p>Test description</p>", |
| 21 |
}, |
| 22 |
}; |
| 23 |
|
| 24 |
const FAKE_PROPS = { |
| 25 |
model: FAKE_MODEL, |
| 26 |
record: FAKE_RECORD, |
| 27 |
createRecord() {}, |
| 28 |
deleteRecord() {}, |
| 29 |
editRecord() {}, |
| 30 |
close() {}, |
| 31 |
}; |
| 32 |
|
| 33 |
async function start(props = {}) { |
| 34 |
await mountWithCleanup(CalendarCommonPopover, { |
| 35 |
props: { ...FAKE_PROPS, ...props }, |
| 36 |
}); |
| 37 |
} |
| 38 |
|
| 39 |
test(`mount a CalendarCommonPopover`, async () => { |
| 40 |
await start(); |
| 41 |
expect(`.popover-header`).toHaveCount(1); |
| 42 |
expect(`.popover-header`).toHaveText("Meeting"); |
| 43 |
expect(`.list-group`).toHaveCount(2); |
| 44 |
expect(`.list-group.o_cw_popover_fields_secondary`).toHaveCount(1); |
| 45 |
expect(`.list-group.o_cw_popover_fields_secondary div[name="description"]`).toHaveClass("text-wrap"); |
| 46 |
expect(`.card-footer .o_cw_popover_edit`).toHaveCount(1); |
| 47 |
expect(`.card-footer .o_cw_popover_delete`).toHaveCount(1); |
| 48 |
}); |
| 49 |
|
| 50 |
test(`date duration: is all day and is same day`, async () => { |
| 51 |
await start({ |
| 52 |
record: { ...FAKE_RECORD, isAllDay: true, isTimeHidden: true }, |
| 53 |
}); |
| 54 |
expect(`.list-group:eq(0)`).toHaveText("July 16, 2021"); |
| 55 |
}); |
| 56 |
|
| 57 |
test(`date duration: is all day and two days duration`, async () => { |
| 58 |
await start({ |
| 59 |
record: { |
| 60 |
...FAKE_RECORD, |
| 61 |
end: DEFAULT_DATE.plus({ days: 1 }), |
| 62 |
isAllDay: true, |
| 63 |
isTimeHidden: true, |
| 64 |
}, |
| 65 |
}); |
| 66 |
expect(`.list-group:eq(0)`).toHaveText("July 16-17, 2021 2 days"); |
| 67 |
}); |
| 68 |
|
| 69 |
test(`time duration: 1 hour diff`, async () => { |
| 70 |
await start({ |
| 71 |
record: { ...FAKE_RECORD, end: DEFAULT_DATE.plus({ hours: 1 }) }, |
| 72 |
model: { ...FAKE_MODEL, isDateHidden: true }, |
| 73 |
}); |
| 74 |
expect(`.list-group:eq(0)`).toHaveText("08:00 - 09:00 (1 hour)"); |
| 75 |
}); |
| 76 |
|
| 77 |
test(`time duration: 2 hours diff`, async () => { |
| 78 |
await start({ |
| 79 |
record: { ...FAKE_RECORD, end: DEFAULT_DATE.plus({ hours: 2 }) }, |
| 80 |
model: { ...FAKE_MODEL, isDateHidden: true }, |
| 81 |
}); |
| 82 |
expect(`.list-group:eq(0)`).toHaveText("08:00 - 10:00 (2 hours)"); |
| 83 |
}); |
| 84 |
|
| 85 |
test(`time duration: 1 minute diff`, async () => { |
| 86 |
await start({ |
| 87 |
record: { ...FAKE_RECORD, end: DEFAULT_DATE.plus({ minutes: 1 }) }, |
| 88 |
model: { ...FAKE_MODEL, isDateHidden: true }, |
| 89 |
}); |
| 90 |
expect(`.list-group:eq(0)`).toHaveText("08:00 - 08:01 (1 minute)"); |
| 91 |
}); |
| 92 |
|
| 93 |
test(`time duration: 2 minutes diff`, async () => { |
| 94 |
await start({ |
| 95 |
record: { ...FAKE_RECORD, end: DEFAULT_DATE.plus({ minutes: 2 }) }, |
| 96 |
model: { ...FAKE_MODEL, isDateHidden: true }, |
| 97 |
}); |
| 98 |
expect(`.list-group:eq(0)`).toHaveText("08:00 - 08:02 (2 minutes)"); |
| 99 |
}); |
| 100 |
|
| 101 |
test(`time duration: 3 hours and 15 minutes diff`, async () => { |
| 102 |
await start({ |
| 103 |
model: { ...FAKE_MODEL, isDateHidden: true }, |
| 104 |
}); |
| 105 |
expect(`.list-group:eq(0)`).toHaveText("08:00 - 11:15 (3 hours, 15 minutes)"); |
| 106 |
}); |
| 107 |
|
| 108 |
test(`isDateHidden is true`, async () => { |
| 109 |
await start({ |
| 110 |
model: { ...FAKE_MODEL, isDateHidden: true }, |
| 111 |
}); |
| 112 |
expect(`.list-group:eq(0)`).toHaveText("08:00 - 11:15 (3 hours, 15 minutes)"); |
| 113 |
}); |
| 114 |
|
| 115 |
test(`isDateHidden is false`, async () => { |
| 116 |
await start({ |
| 117 |
model: { ...FAKE_MODEL, isDateHidden: false }, |
| 118 |
}); |
| 119 |
expect(`.list-group:eq(0)`).toHaveText("July 16, 2021\n08:00 - 11:15 (3 hours, 15 minutes)"); |
| 120 |
}); |
| 121 |
|
| 122 |
test(`isTimeHidden is true`, async () => { |
| 123 |
await start({ |
| 124 |
record: { ...FAKE_RECORD, isTimeHidden: true }, |
| 125 |
}); |
| 126 |
expect(`.list-group:eq(0)`).toHaveText("July 16, 2021"); |
| 127 |
}); |
| 128 |
|
| 129 |
test(`isTimeHidden is false`, async () => { |
| 130 |
await start({ |
| 131 |
record: { ...FAKE_RECORD, isTimeHidden: false }, |
| 132 |
}); |
| 133 |
expect(`.list-group:eq(0)`).toHaveText("July 16, 2021\n08:00 - 11:15 (3 hours, 15 minutes)"); |
| 134 |
}); |
| 135 |
|
| 136 |
test(`canDelete is true`, async () => { |
| 137 |
await start({ |
| 138 |
model: { ...FAKE_MODEL, canDelete: true }, |
| 139 |
}); |
| 140 |
expect(`.o_cw_popover_delete`).toHaveCount(1); |
| 141 |
}); |
| 142 |
|
| 143 |
test(`canDelete is false`, async () => { |
| 144 |
await start({ |
| 145 |
model: { ...FAKE_MODEL, canDelete: false }, |
| 146 |
}); |
| 147 |
expect(`.o_cw_popover_delete`).toHaveCount(0); |
| 148 |
}); |
| 149 |
|
| 150 |
test(`click on delete button`, async () => { |
| 151 |
await start({ |
| 152 |
model: { ...FAKE_MODEL, canDelete: true }, |
| 153 |
deleteRecord: () => expect.step("delete"), |
| 154 |
}); |
| 155 |
await click(`.o_cw_popover_delete`); |
| 156 |
expect.verifySteps(["delete"]); |
| 157 |
}); |
| 158 |
|
| 159 |
test(`click on edit button`, async () => { |
| 160 |
await start({ |
| 161 |
editRecord: () => expect.step("edit"), |
| 162 |
}); |
| 163 |
await click(`.o_cw_popover_edit`); |
| 164 |
expect.verifySteps(["edit"]); |
| 165 |
}); |