| 1 |
import { expect, test } from "@odoo/hoot"; |
| 2 |
import { waitFor } from "@odoo/hoot-dom"; |
| 3 |
import { |
| 4 |
contains, |
| 5 |
getService, |
| 6 |
mountWithCleanup, |
| 7 |
preloadBundle, |
| 8 |
} from "@web/../tests/web_test_helpers"; |
| 9 |
import { FAKE_MODEL } from "./calendar_test_helpers"; |
| 10 |
|
| 11 |
import { MainComponentsContainer } from "@web/core/main_components_container"; |
| 12 |
import { CalendarQuickCreate } from "@web/views/calendar/quick_create/calendar_quick_create"; |
| 13 |
|
| 14 |
const FAKE_PROPS = { |
| 15 |
model: FAKE_MODEL, |
| 16 |
record: {}, |
| 17 |
editRecord() {}, |
| 18 |
}; |
| 19 |
|
| 20 |
/** |
| 21 |
* @param {{ |
| 22 |
* props?: object; |
| 23 |
* dialogOptions?: import("@web/core/dialog/dialog_service").DialogServiceInterfaceAddOptions; |
| 24 |
* }} [params] |
| 25 |
*/ |
| 26 |
async function start(params = {}) { |
| 27 |
await mountWithCleanup(MainComponentsContainer); |
| 28 |
getService("dialog").add( |
| 29 |
CalendarQuickCreate, |
| 30 |
{ ...FAKE_PROPS, ...params.props }, |
| 31 |
params.dialogOptions |
| 32 |
); |
| 33 |
await waitFor(`.o_dialog`); |
| 34 |
} |
| 35 |
|
| 36 |
preloadBundle("web.fullcalendar_lib"); |
| 37 |
|
| 38 |
test.tags("desktop"); |
| 39 |
test(`mount a CalendarQuickCreate`, async () => { |
| 40 |
await start(); |
| 41 |
expect(`.o-calendar-quick-create`).toHaveCount(1); |
| 42 |
expect(`.o_dialog .modal-sm`).toHaveCount(1); |
| 43 |
expect(`.modal-title`).toHaveText("New Event"); |
| 44 |
expect(`input[name="title"]`).toBeFocused(); |
| 45 |
expect(`.o-calendar-quick-create--create-btn`).toHaveCount(1); |
| 46 |
expect(`.o-calendar-quick-create--edit-btn`).toHaveCount(1); |
| 47 |
expect(`.o-calendar-quick-create--cancel-btn`).toHaveCount(1); |
| 48 |
}); |
| 49 |
|
| 50 |
test(`click on create button`, async () => { |
| 51 |
await start({ |
| 52 |
props: { |
| 53 |
model: { ...FAKE_MODEL, createRecord: () => expect.step("create") }, |
| 54 |
}, |
| 55 |
dialogOptions: { onClose: () => expect.step("close") }, |
| 56 |
}); |
| 57 |
await contains(`.o-calendar-quick-create--create-btn`).click(); |
| 58 |
expect.verifySteps([]); |
| 59 |
expect(`input[name=title]`).toHaveClass("o_field_invalid"); |
| 60 |
}); |
| 61 |
|
| 62 |
test(`click on create button (with name)`, async () => { |
| 63 |
await start({ |
| 64 |
props: { |
| 65 |
model: { |
| 66 |
...FAKE_MODEL, |
| 67 |
createRecord(record) { |
| 68 |
expect.step("create"); |
| 69 |
expect(record.title).toBe("TEST"); |
| 70 |
}, |
| 71 |
}, |
| 72 |
}, |
| 73 |
dialogOptions: { onClose: () => expect.step("close") }, |
| 74 |
}); |
| 75 |
await contains(`.o-calendar-quick-create--input`).edit("TEST", { confirm: "blur" }); |
| 76 |
await contains(`.o-calendar-quick-create--create-btn`).click(); |
| 77 |
expect.verifySteps(["create", "close"]); |
| 78 |
}); |
| 79 |
|
| 80 |
test(`click on edit button`, async () => { |
| 81 |
await start({ |
| 82 |
props: { editRecord: () => expect.step("edit") }, |
| 83 |
dialogOptions: { onClose: () => expect.step("close") }, |
| 84 |
}); |
| 85 |
await contains(`.o-calendar-quick-create--edit-btn`).click(); |
| 86 |
expect.verifySteps(["edit", "close"]); |
| 87 |
}); |
| 88 |
|
| 89 |
test(`click on edit button (with name)`, async () => { |
| 90 |
await start({ |
| 91 |
props: { |
| 92 |
editRecord(record) { |
| 93 |
expect.step("edit"); |
| 94 |
expect(record.title).toBe("TEST"); |
| 95 |
}, |
| 96 |
}, |
| 97 |
dialogOptions: { onClose: () => expect.step("close") }, |
| 98 |
}); |
| 99 |
await contains(`.o-calendar-quick-create--input`).edit("TEST", { confirm: "blur" }); |
| 100 |
await contains(`.o-calendar-quick-create--edit-btn`).click(); |
| 101 |
expect.verifySteps(["edit", "close"]); |
| 102 |
}); |
| 103 |
|
| 104 |
test(`click on cancel button`, async () => { |
| 105 |
await start({ |
| 106 |
dialogOptions: { onClose: () => expect.step("close") }, |
| 107 |
}); |
| 108 |
await contains(`.o-calendar-quick-create--cancel-btn`).click(); |
| 109 |
expect.verifySteps(["close"]); |
| 110 |
}); |
| 111 |
|
| 112 |
test(`check default title`, async () => { |
| 113 |
await start({ |
| 114 |
props: { title: "Example Title" }, |
| 115 |
}); |
| 116 |
expect(`.o-calendar-quick-create--input`).toHaveValue("Example Title"); |
| 117 |
}); |