Debian Codegraph @

addons/web/static/tests/views/calendar/calendar_multi_create.test.js

raw
1 import { beforeEach, expect, test } from "@odoo/hoot";
2 import { click, edit, keyDown, keyUp, queryAllTexts, queryAll } from "@odoo/hoot-dom";
3 import {
4 advanceTime,
5 animationFrame,
6 disableAnimations,
7 mockTimeZone,
8 runAllTimers,
9 } from "@odoo/hoot-mock";
10 import {
11 contains,
12 defineModels,
13 fields,
14 getService,
15 models,
16 mountView,
17 mountWithCleanup,
18 onRpc,
19 patchWithCleanup,
20 preloadBundle,
21 serverState,
22 } from "@web/../tests/web_test_helpers";
23 import { selectDateRange } from "./calendar_test_helpers";
24
25 import { Domain } from "@web/core/domain";
26 import { notificationService } from "@web/core/notifications/notification_service";
27 import { CalendarModel } from "@web/views/calendar/calendar_model";
28 import { WebClient } from "@web/webclient/webclient";
29
30 class Event extends models.Model {
31 name = fields.Char();
32 date_start = fields.Date();
33 datetime_start = fields.Datetime();
34 datetime_end = fields.Datetime();
35 type = fields.Many2one({ relation: "event.type" });
36 user_id = fields.Many2one({ relation: "calendar.user" });
37 user_ids = fields.Many2many({ relation: "calendar.user" });
38
39 // FIXME: needed for the filter to work
40 filter_user_id = fields.Many2one({ relation: "calendar.user" });
41
42 _records = [
43 {
44 id: 1,
45 name: "event 1",
46 date_start: "2019-02-11",
47 type: 1,
48 user_id: 1,
49 },
50 {
51 id: 2,
52 name: "event 2",
53 date_start: "2019-03-12",
54 type: 1,
55 user_id: 1,
56 },
57 {
58 id: 3,
59 name: "event 3",
60 date_start: "2019-03-12",
61 type: 1,
62 user_id: 1,
63 },
64 {
65 id: 4,
66 name: "event 4",
67 date_start: "2019-03-14",
68 type: 1,
69 user_id: 2,
70 },
71 {
72 id: 5,
73 name: "event 5",
74 date_start: "2019-03-13",
75 type: 1,
76 user_id: 3,
77 },
78 {
79 id: 6,
80 name: "event 6",
81 date_start: "2019-03-18",
82 type: 1,
83 user_id: 3,
84 },
85 {
86 id: 7,
87 name: "event 7",
88 date_start: "2019-04-14",
89 type: 1,
90 user_id: 1,
91 },
92 {
93 id: 8,
94 name: "event 8",
95 datetime_start: "2019-03-03 07:00:00",
96 datetime_end: "2019-03-03 17:00:00",
97 type: 1,
98 user_id: 1,
99 },
100 {
101 id: 9,
102 name: "event 9",
103 datetime_start: "2019-03-04 07:00:00",
104 datetime_end: "2019-03-04 16:00:00",
105 type: 1,
106 user_id: 1,
107 },
108 {
109 id: 10,
110 name: "event 10",
111 datetime_start: "2019-03-04 07:00:00",
112 datetime_end: "2019-03-04 16:00:00",
113 type: 1,
114 user_id: 2,
115 },
116 {
117 id: 11,
118 name: "event 11",
119 datetime_start: "2019-03-04 07:00:00",
120 datetime_end: "2019-03-04 16:00:00",
121 type: 1,
122 user_id: 3,
123 },
124 ];
125
126 _views = {
127 calendar: `
128 <calendar date_start="date_start" scales="month" multi_create_view="multi_create_form" aggregate="id:count">
129 <!-- Popover -->
130 <field name="name"/>
131 <field name="type"/>
132
133 <!-- Filter -->
134 <field name="user_id" write_model="filter.user" write_field="filter_user_id" filter_field="is_checked"/>
135
136 <!-- For filter to work -->
137 <field name="date_start" invisible="1"/>
138 <field name="filter_user_id" invisible="1"/>
139 </calendar>
140 `,
141 "calendar,calendar_state": `
142 <calendar date_start="datetime_start" date_stop="datetime_end" scales="month" multi_create_view="multi_create_form_state" aggregate="id:count">
143 <!-- Popover -->
144 <field name="name"/>
145 </calendar>
146 `,
147 "form,multi_create_form": `
148 <form>
149 <group>
150 <field name="name" required="1"/>
151 <field name="type"/>
152 </group>
153 </form>
154 `,
155 "form,multi_create_form_state": `
156 <form>
157 <group>
158 <field name="name" required="1"/>
159 <field name="type"/>
160 <field name="user_ids" widget="many2many_tags"/>
161 </group>
162 </form>
163 `,
164 };
165 }
166
167 class EventType extends models.Model {
168 name = fields.Char();
169
170 _records = [
171 { id: 1, name: "Event Type 1" },
172 { id: 2, name: "Event Type 2" },
173 { id: 3, name: "Event Type 3" },
174 ];
175 }
176
177 class CalendarUser extends models.Model {
178 name = fields.Char();
179
180 _records = [
181 { id: 1, name: "user 1" },
182 { id: 2, name: "user 2" },
183 { id: 3, name: "user 3" },
184 { id: 7, name: "user 7" },
185 ];
186 }
187
188 class FilterUser extends models.Model {
189 filter_user_id = fields.Many2one({ relation: "calendar.user" });
190 user_id = fields.Many2one({ relation: "calendar.user" });
191 is_checked = fields.Boolean();
192
193 _records = [
194 { id: 1, filter_user_id: 1, user_id: serverState.userId, is_checked: true },
195 { id: 2, filter_user_id: 3, user_id: serverState.userId, is_checked: true },
196 ];
197 }
198
199 defineModels([Event, EventType, CalendarUser, FilterUser]);
200
201 preloadBundle("web.fullcalendar_lib");
202
203 beforeEach(() => {
204 mockTimeZone("Europe/Brussels");
205 disableAnimations();
206 });
207
208 // Utils function
209
210 async function multiCreateClickAddButton() {
211 await click(".o_multi_selection_buttons .btn:contains(Add)");
212 await animationFrame();
213 }
214
215 async function multiCreatePopoverClickAddButton() {
216 await click(".o_multi_create_popover .popover-footer .btn:contains(Add)");
217 await animationFrame();
218 }
219
220 test.tags("desktop");
221 test("multi_create: render and basic creation (simple use case)", async () => {
222 onRpc("event", "create", ({ args: [records] }) => {
223 for (const record of records) {
224 expect.step(`${record.name}_${record.date_start}`);
225 }
226 });
227
228 await mountView({
229 type: "calendar",
230 resModel: "event",
231 arch: `<calendar date_start="date_start" scales="month" multi_create_view="multi_create_form" aggregate="id:count">
232 <!-- Popover -->
233 <field name="name"/>
234 <field name="date_start" invisible="1"/>
235 </calendar>`,
236 });
237
238 expect(".fc .fc-event").toHaveCount(5, {
239 message: "All events of this month should be visible",
240 });
241 expect(".o_calendar_filter_item").toHaveCount(0, {
242 message: "No filters should be visible",
243 });
244
245 const { drop, moveTo } = await contains(".fc-day[data-date='2019-03-04']").drag();
246 await moveTo(".fc-day[data-date='2019-03-14']");
247 await animationFrame();
248 expect(".fc-day.o-highlight").toHaveCount(8);
249 await drop();
250 await animationFrame();
251
252 expect(".o_selection_box").toHaveText("4\nselected");
253
254 await multiCreateClickAddButton();
255 expect(".o_multi_create_popover").toHaveCount(1);
256 await click(".o_multi_create_popover .o_form_view [name='name'] input");
257 await edit("Time off");
258 await multiCreatePopoverClickAddButton();
259
260 expect(".o_multi_create_popover").toHaveCount(0);
261 expect.verifySteps([
262 "Time off_2019-03-04",
263 "Time off_2019-03-05",
264 "Time off_2019-03-06",
265 "Time off_2019-03-07",
266 "Time off_2019-03-11",
267 "Time off_2019-03-12",
268 "Time off_2019-03-13",
269 "Time off_2019-03-14",
270 ]);
271 expect(".fc .fc-event").toHaveCount(13, {
272 message: "All new events should be added",
273 });
274
275 await click(".fc-event[data-event-id='12']");
276 await runAllTimers();
277 await animationFrame();
278 expect(".o_popover").toHaveCount(1);
279 expect(".o_popover .o_field_widget[name='name']").toHaveText("Time off");
280 });
281
282 test.tags("desktop");
283 test("multi_create: render and basic functionalities (complex with filters use case)", async () => {
284 onRpc("event", "create", ({ args: [records] }) => {
285 for (const record of records) {
286 if (record.name !== "Time off" || record.type !== 3) {
287 expect.step("error");
288 }
289 expect.step(`${record.user_id}_${record.date_start}`);
290 }
291 });
292
293 await mountView({
294 resModel: "event",
295 type: "calendar",
296 context: { default_name: "Sick" },
297 });
298
299 expect(".fc .fc-event").toHaveCount(4, { message: "events should be filter" });
300
301 const { drop, moveTo } = await contains(".fc-day[data-date='2019-03-04']").drag();
302 await moveTo(".fc-day[data-date='2019-03-14']");
303 await animationFrame();
304 expect(".fc-day.o-highlight").toHaveCount(8);
305 await drop();
306 await animationFrame();
307
308 await multiCreateClickAddButton();
309
310 expect(".o_multi_create_popover .o_form_view").toBeVisible();
311 expect(".o_multi_create_popover .o_form_view [name='name'] input").toHaveValue("Sick", {
312 message: "should have a default value from the context",
313 });
314 await click(".o_multi_create_popover .o_form_view [name='name'] input");
315 await edit("Time off");
316 await contains(".o_multi_create_popover .o_form_view [name='type'] input").click();
317 await contains(".o-autocomplete--dropdown-item:contains('Event Type 3')").click();
318 await multiCreatePopoverClickAddButton();
319
320 expect.verifySteps([
321 "1_2019-03-04",
322 "3_2019-03-04",
323 "1_2019-03-05",
324 "3_2019-03-05",
325 "1_2019-03-06",
326 "3_2019-03-06",
327 "1_2019-03-07",
328 "3_2019-03-07",
329 "1_2019-03-11",
330 "3_2019-03-11",
331 "1_2019-03-12",
332 "3_2019-03-12",
333 "1_2019-03-13",
334 "3_2019-03-13",
335 "1_2019-03-14",
336 "3_2019-03-14",
337 ]);
338 expect(".fc .fc-event").toHaveCount(20, {
339 message: "events should be added for the two users selected",
340 });
341
342 await click(".fc-event[data-event-id='12']");
343 await runAllTimers();
344 await animationFrame();
345 await expect(".o_popover").toHaveCount(1);
346 await expect(".o_popover .o_field_widget[name='name']").toHaveText("Time off");
347 await expect(".o_popover .o_field_widget[name='type']").toHaveText("Event Type 3");
348 await expect(".o_popover .o_field_widget[name='user_id']").toHaveText("user 1");
349
350 await click(".fc-event[data-event-id='13']");
351 await runAllTimers();
352 await animationFrame();
353 await expect(".o_popover").toHaveCount(1);
354 await expect(".o_popover .o_field_widget[name='user_id']").toHaveText("user 3");
355
356 await click(".o_calendar_filter_item[data-value='3'] input");
357 await animationFrame();
358 await advanceTime(CalendarModel.DEBOUNCED_LOAD_DELAY);
359 expect(".fc .fc-event").toHaveCount(10, { message: "events should be filter" });
360 });
361
362 test.tags("desktop");
363 test("multi_create: basic creation (datetime field)", async () => {
364 onRpc("event", "create", ({ args: [records] }) => {
365 for (const record of records) {
366 if (record.name !== "Time off" || record.type !== 3) {
367 expect.step("error");
368 }
369 expect.step(`${record.user_id}_${record.datetime_start}_${record.datetime_end}`);
370 }
371 });
372
373 await mountView({
374 resModel: "event",
375 type: "calendar",
376 context: { default_name: "Sick" },
377 arch: `
378 <calendar date_start="datetime_start" date_stop="datetime_end" scales="month" multi_create_view="multi_create_form" aggregate="id:count">
379 <!-- Popover -->
380 <field name="name"/>
381 <field name="type"/>
382
383 <!-- Filter -->
384 <field name="user_id" write_model="filter.user" write_field="filter_user_id" filter_field="is_checked"/>
385 </calendar>
386 `,
387 });
388
389 expect(".fc .fc-event").toHaveCount(3, { message: "events should be filter" });
390
391 const { drop, moveTo } = await contains(".fc-day[data-date='2019-03-04']").drag();
392 await moveTo(".fc-day[data-date='2019-03-14']");
393 await animationFrame();
394 expect(".fc-day.o-highlight").toHaveCount(8);
395 await drop();
396 await animationFrame();
397
398 await multiCreateClickAddButton();
399
400 expect(".o_multi_create_popover .o_time_picker_input").toHaveCount(2);
401
402 await click(".o_time_picker_input:eq(0)");
403 await animationFrame();
404 expect(".o-dropdown--menu.o_time_picker_dropdown").toHaveCount(1);
405 await click(".o_time_picker_option:contains(8:00)");
406 await animationFrame();
407
408 await click(".o_time_picker_input:eq(1)");
409 await animationFrame();
410 expect(".o-dropdown--menu.o_time_picker_dropdown").toHaveCount(1);
411 await click(".o_time_picker_option:contains(11:30)");
412 await animationFrame();
413
414 expect(".o_multi_create_popover .o_form_view").toBeVisible();
415 expect(".o_multi_create_popover .o_form_view [name='name'] input").toHaveValue("Sick", {
416 message: "should have a default value from the context",
417 });
418 await click(".o_multi_create_popover .o_form_view [name='name'] input");
419 await edit("Time off");
420 await contains(".o_multi_create_popover .o_form_view [name='type'] input").click();
421 await contains(".o-autocomplete--dropdown-item:contains('Event Type 3')").click();
422
423 await multiCreatePopoverClickAddButton();
424
425 expect.verifySteps([
426 "1_2019-03-04 07:00:00_2019-03-04 10:30:00",
427 "3_2019-03-04 07:00:00_2019-03-04 10:30:00",
428 "1_2019-03-05 07:00:00_2019-03-05 10:30:00",
429 "3_2019-03-05 07:00:00_2019-03-05 10:30:00",
430 "1_2019-03-06 07:00:00_2019-03-06 10:30:00",
431 "3_2019-03-06 07:00:00_2019-03-06 10:30:00",
432 "1_2019-03-07 07:00:00_2019-03-07 10:30:00",
433 "3_2019-03-07 07:00:00_2019-03-07 10:30:00",
434 "1_2019-03-11 07:00:00_2019-03-11 10:30:00",
435 "3_2019-03-11 07:00:00_2019-03-11 10:30:00",
436 "1_2019-03-12 07:00:00_2019-03-12 10:30:00",
437 "3_2019-03-12 07:00:00_2019-03-12 10:30:00",
438 "1_2019-03-13 07:00:00_2019-03-13 10:30:00",
439 "3_2019-03-13 07:00:00_2019-03-13 10:30:00",
440 "1_2019-03-14 07:00:00_2019-03-14 10:30:00",
441 "3_2019-03-14 07:00:00_2019-03-14 10:30:00",
442 ]);
443 expect(".fc .fc-event").toHaveCount(19, {
444 message: "events should be added for the two users selected",
445 });
446
447 await click(".fc-event[data-event-id='12']");
448 await runAllTimers();
449 await animationFrame();
450 await expect(".o_popover").toHaveCount(1);
451 await expect(".o_popover .fa-clock-o").toHaveCount(1);
452 await expect(".o_popover .list-group-item:has(.fa-clock-o)").toHaveText(
453 "08:00 - 11:30 (3 hours, 30 minutes)"
454 );
455 await expect(".o_popover .o_field_widget[name='name']").toHaveText("Time off");
456 await expect(".o_popover .o_field_widget[name='type']").toHaveText("Event Type 3");
457 await expect(".o_popover .o_field_widget[name='user_id']").toHaveText("user 1");
458
459 await click(".fc-event[data-event-id='13']");
460 await runAllTimers();
461 await animationFrame();
462 await expect(".o_popover").toHaveCount(1);
463 await expect(".o_popover .fa-clock-o").toHaveCount(1);
464 await expect(".o_popover .list-group-item:has(.fa-clock-o)").toHaveText(
465 "08:00 - 11:30 (3 hours, 30 minutes)"
466 );
467 await expect(".o_popover .o_field_widget[name='user_id']").toHaveText("user 3");
468
469 await click(".o_calendar_filter_item[data-value='3'] input");
470 await animationFrame();
471 await advanceTime(CalendarModel.DEBOUNCED_LOAD_DELAY);
472 expect(".fc .fc-event").toHaveCount(10, { message: "events should be filter" });
473 });
474
475 test.tags("desktop");
476 test("multi_create: input validation (datetime field)", async () => {
477 patchWithCleanup(notificationService, {
478 start: () => ({
479 add: (message) => {
480 expect.step(message);
481 },
482 }),
483 });
484
485 onRpc("event", "create", ({ args: [records] }) => {
486 for (const record of records) {
487 expect.step(`${record.user_id}_${record.datetime_start}_${record.datetime_end}`);
488 }
489 });
490
491 await mountView({
492 resModel: "event",
493 type: "calendar",
494 context: { default_name: "Sick" },
495 arch: `
496 <calendar date_start="datetime_start" date_stop="datetime_end" scales="month" multi_create_view="multi_create_form" aggregate="id:count">
497 <!-- Popover -->
498 <field name="name"/>
499 <field name="type"/>
500
501 <!-- Filter -->
502 <field name="user_id" write_model="filter.user" write_field="filter_user_id" filter_field="is_checked"/>
503 </calendar>
504 `,
505 });
506
507 const { drop } = await contains(".fc-day[data-date='2019-03-04']").drag();
508 await animationFrame();
509 await drop();
510 await animationFrame();
511
512 await multiCreateClickAddButton();
513
514 // No time range
515 await click(".o_time_picker_input:eq(1)");
516 await edit("", { confirm: "enter" });
517
518 await multiCreatePopoverClickAddButton();
519
520 expect.verifySteps(["Invalid time range"]);
521
522 await multiCreateClickAddButton();
523 // Start time before end time
524 await click(".o_time_picker_input:eq(0)");
525 await animationFrame();
526 await click(".o_time_picker_option:contains(11:30)");
527 await animationFrame();
528
529 await click(".o_time_picker_input:eq(1)");
530 await animationFrame();
531 await click(".o_time_picker_option:contains(8:00)");
532 await animationFrame();
533
534 await multiCreatePopoverClickAddButton();
535
536 expect.verifySteps(["Start time should be before end time"]);
537
538 // Valid input
539 await click(".o_time_picker_input:eq(1)");
540 await animationFrame();
541 await click(".o_time_picker_option:contains(12:00)");
542 await animationFrame();
543
544 await multiCreatePopoverClickAddButton();
545
546 expect.verifySteps([
547 "1_2019-03-04 10:30:00_2019-03-04 11:00:00",
548 "3_2019-03-04 10:30:00_2019-03-04 11:00:00",
549 ]);
550 });
551
552 test.tags("desktop");
553 test("multi_create: use state to keep values of inputs", async () => {
554 onRpc("event.type", "get_formview_action", ({ args, model }) => ({
555 type: "ir.actions.act_window",
556 res_model: model,
557 target: "current",
558 views: [[false, "form"]],
559 res_id: args[0][0],
560 }));
561
562 await mountWithCleanup(WebClient);
563 await getService("action").doAction({
564 name: "Event",
565 res_model: "event",
566 type: "ir.actions.act_window",
567 views: [["calendar_state", "calendar"]],
568 });
569
570 let { drop } = await contains(".fc-day[data-date='2019-03-04']").drag();
571 await animationFrame();
572 await drop();
573 await animationFrame();
574
575 await multiCreateClickAddButton();
576
577 await click(".o_time_picker_input:eq(0)");
578 await animationFrame();
579 await click(".o_time_picker_option:contains(1:30)");
580 await animationFrame();
581
582 await click(".o_time_picker_input:eq(1)");
583 await animationFrame();
584 await click(".o_time_picker_option:contains(8:00)");
585 await animationFrame();
586
587 await click(".o_multi_create_popover .o_form_view [name='name'] input");
588 await animationFrame();
589 await edit("Test state");
590
591 await contains(".o_multi_create_popover .o_form_view [name='type'] input").click();
592 await contains(".o-autocomplete--dropdown-item:contains('Event Type 3')").click();
593
594 await contains(".o_multi_create_popover .o_form_view [name='user_ids'] input").click();
595 await contains(".o-autocomplete--dropdown-item:contains('user 1')").click();
596 await contains(".o_multi_create_popover .o_form_view [name='user_ids'] input").click();
597 await contains(".o-autocomplete--dropdown-item:contains('user 3')").click();
598
599 // Navigate to the many2one record
600 await click(".o_form_view [name='type'] .o_external_button");
601 await animationFrame();
602 await animationFrame();
603
604 // Go back to the calendar view
605 await click(".breadcrumb-item");
606 await animationFrame();
607
608 ({ drop } = await contains(".fc-day[data-date='2019-03-04']").drag());
609 await animationFrame();
610 await drop();
611 await animationFrame();
612
613 await multiCreateClickAddButton();
614
615 expect(".o_time_picker_input:eq(0)").toHaveValue("1:30");
616 expect(".o_time_picker_input:eq(1)").toHaveValue("8:00");
617 expect(".o_form_view [name='name'] input").toHaveValue("Test state");
618 expect(".o_form_view [name='type'] input").toHaveValue("Event Type 3");
619 expect(queryAllTexts(".o_form_view [name='user_ids'] .o_tag")).toEqual(["user 1", "user 3"]);
620 });
621
622 test.tags("desktop");
623 test("multi_create: delete", async () => {
624 onRpc("event", "unlink", ({ args: [ids] }) => {
625 expect.step(ids);
626 });
627
628 await mountView({
629 resModel: "event",
630 type: "calendar",
631 context: { default_name: "Sick" },
632 });
633
634 await click(".fc-event[data-event-id='2']");
635 await runAllTimers();
636 await animationFrame();
637 await expect(".o_popover").toHaveCount(1);
638
639 await click(".o_calendar_header"); // Hide the popover
640 await animationFrame();
641
642 const { drop } = await contains(".fc-day[data-date='2019-02-26']").drag();
643 await drop(".fc-day[data-date='2019-04-03']");
644 await animationFrame();
645
646 await contains(".o_multi_selection_buttons .btn .fa-trash").click();
647 await animationFrame();
648 expect(".o_dialog .modal-body").toHaveText(
649 "Are you sure you want to delete the 3 selected records?"
650 );
651 await contains(".o_dialog footer button:contains(Ok)").click();
652 await animationFrame();
653
654 expect.verifySteps([[2, 3, 5]]);
655 expect(".fc .fc-event").toHaveCount(1, { message: "selected events should be deleted" });
656
657 await click(".o_calendar_filter_item[data-value='3'] input");
658 await animationFrame();
659 await advanceTime(CalendarModel.DEBOUNCED_LOAD_DELAY);
660 expect(".fc .fc-event").toHaveCount(0, { message: "events should be filter" });
661 });
662
663 test.tags("desktop");
664 test("multi_create: test onChange on form with no blur (input text)", async () => {
665 await mountView({
666 resModel: "event",
667 type: "calendar",
668 context: { default_name: "Sick" },
669 });
670
671 await click(".fc-day[data-date='2019-03-04']");
672 await animationFrame();
673
674 await multiCreateClickAddButton();
675
676 await click(".o_multi_create_popover .o_form_view [name='name'] input");
677 await edit("Test onChange");
678
679 await multiCreatePopoverClickAddButton();
680
681 await click(".fc-event[data-event-id='12']");
682 await runAllTimers();
683 await animationFrame();
684 await expect(".o_popover").toHaveCount(1);
685 await expect(".o_popover .o_field_widget[name='name']").toHaveText("Test onChange");
686 });
687
688 test.tags("desktop");
689 test("multi_create: test onChange on TimePicker with no blur (input text)", async () => {
690 patchWithCleanup(notificationService, {
691 start: () => ({
692 add: (message) => {
693 expect.step(message);
694 },
695 }),
696 });
697
698 onRpc("event", "create", ({ args: [records] }) => {
699 for (const record of records) {
700 expect.step(`${record.user_id}_${record.datetime_start}_${record.datetime_end}`);
701 }
702 });
703
704 await mountView({
705 resModel: "event",
706 type: "calendar",
707 context: { default_name: "Sick" },
708 arch: `
709 <calendar date_start="datetime_start" date_stop="datetime_end" scales="month" multi_create_view="multi_create_form" aggregate="id:count">
710 <!-- Popover -->
711 <field name="name"/>
712 <field name="type"/>
713
714 <!-- Filter -->
715 <field name="user_id" write_model="filter.user" write_field="filter_user_id" filter_field="is_checked"/>
716 </calendar>
717 `,
718 });
719
720 const { drop } = await contains(".fc-day[data-date='2019-03-04']").drag();
721 await animationFrame();
722 await drop();
723 await animationFrame();
724
725 await multiCreateClickAddButton();
726
727 await click(".o_multi_create_popover .o_form_view [name='name'] input");
728 await edit("Test onChange");
729
730 await click(".o_time_picker_input:eq(0)");
731 await animationFrame();
732 await click(".o_time_picker_option:contains(1:30)");
733 await animationFrame();
734
735 await click(".o_time_picker_input:eq(1)");
736 await animationFrame();
737 await edit("8:00");
738 await animationFrame();
739
740 await multiCreatePopoverClickAddButton();
741
742 expect.verifySteps([
743 "1_2019-03-04 00:30:00_2019-03-04 07:00:00",
744 "3_2019-03-04 00:30:00_2019-03-04 07:00:00",
745 ]);
746 });
747
748 test.tags("desktop");
749 test("multi_create: test popover", async () => {
750 await mountView({
751 resModel: "event",
752 type: "calendar",
753 });
754
755 expect(".o_popover").toHaveCount(0);
756
757 await click(".fc-event[data-event-id='2']");
758 await runAllTimers();
759 await animationFrame();
760
761 expect(".o_popover").toHaveCount(1);
762 });
763
764 test.tags("desktop");
765 test("multi_create: avoid trigger add/del event on specific element", async () => {
766 function makeEvents(numberOfEvent) {
767 return [...Array(numberOfEvent).keys()].map((i) => ({
768 id: i,
769 name: `event ${i}`,
770 date_start: "2019-03-13",
771 type: 1,
772 user_id: 1,
773 }));
774 }
775 Event._records = makeEvents(6);
776
777 await mountView({
778 resModel: "event",
779 type: "calendar",
780 });
781
782 await click(".fc-event[data-event-id='1']");
783 await runAllTimers();
784 await animationFrame();
785 expect(".o_popover").toHaveCount(1);
786
787 await click(".o_calendar_button_today");
788 await runAllTimers();
789 await animationFrame();
790 expect(".o_popover").toHaveCount(0);
791
792 await click(".fc-more-cell a");
793 await animationFrame();
794 expect(".fc-more-popover").toHaveCount(1);
795 expect(".o_multi_selection_buttons").toHaveCount(0);
796
797 await click(".fc-popover-title");
798 await animationFrame();
799 expect(".fc-more-popover").toHaveCount(1);
800 expect(".o_multi_selection_buttons").toHaveCount(0);
801
802 await click(".fc-popover-close");
803 await animationFrame();
804 expect(".fc-more-popover").toHaveCount(0);
805 expect(".o_multi_selection_buttons").toHaveCount(0);
806 });
807
808 test.tags("desktop");
809 test("multi_create: test required attribute in form", async () => {
810 patchWithCleanup(notificationService, {
811 start: () => ({
812 add: (message) => {
813 expect.step(message);
814 },
815 }),
816 });
817
818 onRpc("event", "create", ({ args: [records] }) => {
819 for (const record of records) {
820 expect.step(`${record.name}_${record.date_start}`);
821 }
822 });
823
824 await mountView({
825 resModel: "event",
826 type: "calendar",
827 });
828
829 const { drop } = await contains(".fc-day[data-date='2019-03-04']").drag();
830 await animationFrame();
831 await drop();
832 await animationFrame();
833 await multiCreateClickAddButton();
834 await multiCreatePopoverClickAddButton();
835 expect(".o_multi_create_popover .o_form_view [name='name']").toHaveClass("o_required_modifier");
836 expect.verifySteps(["Missing required fields"]);
837
838 const { drop: dropOk } = await contains(".fc-day[data-date='2019-03-04']").drag();
839 await animationFrame();
840 await dropOk();
841 await animationFrame();
842 await multiCreateClickAddButton();
843 await click(".o_multi_create_popover .o_form_view [name='name'] input");
844 await edit("Test required");
845 await multiCreatePopoverClickAddButton();
846 expect.verifySteps(["Test required_2019-03-04", "Test required_2019-03-04"]);
847 });
848
849 test.tags("desktop");
850 test(`multi_create: no button "Delete" if no record selected`, async () => {
851 await mountView({
852 resModel: "event",
853 type: "calendar",
854 domain: Domain.FALSE.toList(),
855 });
856 expect("o_multi_selection_buttons").toHaveCount(0);
857
858 await contains(".fc-day[data-date='2019-03-04']").click();
859 expect(".o_multi_selection_buttons").toHaveCount(1);
860 expect(".o_multi_selection_buttons .btn .fa-trash").toHaveCount(0);
861 });
862
863 test.tags("desktop");
864 test("multi_create: selection with ctrl", async () => {
865 onRpc("event", "create", ({ args: [records] }) => {
866 for (const record of records) {
867 if (record.name !== "Time off" || record.type !== 3) {
868 expect.step("error");
869 }
870 expect.step(`${record.user_id}_${record.date_start}`);
871 }
872 });
873
874 await mountView({
875 resModel: "event",
876 type: "calendar",
877 context: { default_name: "Sick" },
878 });
879
880 expect(".fc .fc-event").toHaveCount(4, { message: "events should be filter" });
881
882 await selectDateRange("2019-03-04", "2019-03-14");
883
884 await keyDown("Control");
885 await selectDateRange("2019-02-26", "2019-03-27");
886 await contains(".fc-day[data-date='2019-03-20']").click();
887 await contains(".fc-day[data-date='2019-03-16']").click();
888 await keyUp("Control");
889
890 expect(".fc-day.o-highlight").toHaveCount(14);
891
892 await multiCreateClickAddButton();
893
894 expect(".o_multi_create_popover .o_form_view").toBeVisible();
895 expect(".o_multi_create_popover .o_form_view [name='name'] input").toHaveValue("Sick", {
896 message: "should have a default value from the context",
897 });
898 await click(".o_multi_create_popover .o_form_view [name='name'] input");
899 await edit("Time off");
900 await contains(".o_multi_create_popover .o_form_view [name='type'] input").click();
901 await contains(".o-autocomplete--dropdown-item:contains('Event Type 3')").click();
902 await multiCreatePopoverClickAddButton();
903
904 expect.verifySteps([
905 "1_2019-03-04",
906 "3_2019-03-04",
907 "1_2019-03-05",
908 "3_2019-03-05",
909 "1_2019-03-06",
910 "3_2019-03-06",
911 "1_2019-03-07",
912 "3_2019-03-07",
913 "1_2019-03-11",
914 "3_2019-03-11",
915 "1_2019-03-12",
916 "3_2019-03-12",
917 "1_2019-03-13",
918 "3_2019-03-13",
919 "1_2019-03-14",
920 "3_2019-03-14",
921 "1_2019-02-26",
922 "3_2019-02-26",
923 "1_2019-02-27",
924 "3_2019-02-27",
925 "1_2019-03-19",
926 "3_2019-03-19",
927 "1_2019-03-26",
928 "3_2019-03-26",
929 "1_2019-03-27",
930 "3_2019-03-27",
931 "1_2019-03-16",
932 "3_2019-03-16",
933 ]);
934 expect(".fc .fc-event").toHaveCount(32, {
935 message: "events should be added for the two users selected",
936 });
937 });
938
939 test.tags("desktop");
940 test("multi_create: selection with shift", async () => {
941 onRpc("event", "create", ({ args: [records] }) => {
942 for (const record of records) {
943 if (record.name !== "Time off" || record.type !== 3) {
944 expect.step("error");
945 }
946 expect.step(`${record.user_id}_${record.date_start}`);
947 }
948 });
949
950 await mountView({
951 resModel: "event",
952 type: "calendar",
953 context: { default_name: "Sick" },
954 });
955
956 expect(".fc .fc-event").toHaveCount(4, { message: "events should be filter" });
957
958 await keyDown("Shift");
959 await contains(".fc-day[data-date='2019-03-20']").click();
960 await contains(".fc-day[data-date='2019-03-16']").click();
961 await keyUp("Shift");
962
963 expect(".o_selection_box").toHaveText("1\nselected");
964 expect(queryAll(".fc-day.o-highlight").map((el) => el.dataset.date)).toEqual([
965 "2019-03-16",
966 "2019-03-17",
967 "2019-03-18",
968 "2019-03-19",
969 "2019-03-20",
970 ]);
971
972 await multiCreateClickAddButton();
973
974 expect(".o_multi_create_popover .o_form_view").toBeVisible();
975 expect(".o_multi_create_popover .o_form_view [name='name'] input").toHaveValue("Sick", {
976 message: "should have a default value from the context",
977 });
978 await click(".o_multi_create_popover .o_form_view [name='name'] input");
979 await edit("Time off");
980 await contains(".o_multi_create_popover .o_form_view [name='type'] input").click();
981 await contains(".o-autocomplete--dropdown-item:contains('Event Type 3')").click();
982 await multiCreatePopoverClickAddButton();
983
984 expect.verifySteps([
985 "1_2019-03-16",
986 "3_2019-03-16",
987 "1_2019-03-17",
988 "3_2019-03-17",
989 "1_2019-03-18",
990 "3_2019-03-18",
991 "1_2019-03-19",
992 "3_2019-03-19",
993 "1_2019-03-20",
994 "3_2019-03-20",
995 ]);
996 expect(".fc .fc-event").toHaveCount(14, {
997 message: "events should be added for the two users selected",
998 });
999
1000 await keyDown("Shift");
1001 await contains(".fc-day[data-date='2019-03-16']").click();
1002 await contains(".fc-day[data-date='2019-03-20']").click();
1003 await contains(".fc-day[data-date='2019-03-14']").click();
1004
1005 expect(".o_selection_box").toHaveText("2\nselected");
1006 expect(queryAll(".fc-day.o-highlight").map((el) => el.dataset.date)).toEqual([
1007 "2019-03-14",
1008 "2019-03-15",
1009 "2019-03-16",
1010 ]);
1011
1012 await contains(".fc-day[data-date='2019-03-13']").click();
1013
1014 expect(".o_selection_box").toHaveText("3\nselected");
1015 expect(queryAll(".fc-day.o-highlight").map((el) => el.dataset.date)).toEqual([
1016 "2019-03-13",
1017 "2019-03-14",
1018 "2019-03-15",
1019 "2019-03-16",
1020 ]);
1021
1022 await keyUp("Shift");
1023 await contains(".fc-day[data-date='2019-03-13']").click();
1024 await keyDown("Shift");
1025 await contains(".fc-day[data-date='2019-03-11']").click();
1026 await keyUp("Shift");
1027
1028 expect(".o_selection_box").toHaveText("3\nselected");
1029 expect(queryAll(".fc-day.o-highlight").map((el) => el.dataset.date)).toEqual([
1030 "2019-03-11",
1031 "2019-03-12",
1032 "2019-03-13",
1033 ]);
1034
1035 await contains(".fc-day[data-date='2019-03-20']").click();
1036
1037 await selectDateRange("2019-03-04", "2019-03-14");
1038
1039 await keyUp("Shift");
1040 await contains(".fc-day[data-date='2019-03-13']").click();
1041
1042 expect(".o_selection_box").toHaveText("1\nselected");
1043 expect(queryAll(".fc-day.o-highlight").map((el) => el.dataset.date)).toEqual(["2019-03-13"]);
1044 });