Debian Codegraph @

addons/web/static/tests/views/kanban/kanban_view.test.js

raw
1 import { after, beforeEach, expect, getFixture, test } from "@odoo/hoot";
2 import {
3 click,
4 dblclick,
5 drag,
6 edit,
7 hover,
8 keyDown,
9 keyUp,
10 leave,
11 on,
12 pointerDown,
13 press,
14 queryAll,
15 queryAllTexts,
16 queryFirst,
17 queryOne,
18 queryRect,
19 queryText,
20 resize,
21 scroll,
22 setInputFiles,
23 } from "@odoo/hoot-dom";
24 import {
25 Deferred,
26 advanceFrame,
27 advanceTime,
28 animationFrame,
29 disableAnimations,
30 mockTouch,
31 runAllTimers,
32 tick,
33 } from "@odoo/hoot-mock";
34 import { Component, onRendered, onWillRender, xml } from "@odoo/owl";
35 import {
36 MockServer,
37 clickKanbanLoadMore,
38 clickModalButton,
39 contains,
40 createKanbanRecord,
41 defineActions,
42 defineModels,
43 defineParams,
44 discardKanbanRecord,
45 editKanbanColumnName,
46 editKanbanRecord,
47 editKanbanRecordQuickCreateInput,
48 fields,
49 getDropdownMenu,
50 getFacetTexts,
51 getKanbanColumn,
52 getKanbanColumnDropdownMenu,
53 getKanbanColumnTooltips,
54 getKanbanCounters,
55 getKanbanProgressBars,
56 getKanbanRecord,
57 getKanbanRecordTexts,
58 getMockEnv,
59 getPagerLimit,
60 getPagerValue,
61 getService,
62 makeServerError,
63 mockService,
64 models,
65 mountView,
66 mountWithCleanup,
67 onRpc,
68 pagerNext,
69 pagerPrevious,
70 patchWithCleanup,
71 quickCreateKanbanColumn,
72 quickCreateKanbanRecord,
73 removeFacet,
74 serverState,
75 stepAllNetworkCalls,
76 switchView,
77 toggleKanbanColumnActions,
78 toggleKanbanRecordDropdown,
79 toggleMenuItem,
80 toggleMenuItemOption,
81 toggleSearchBarMenu,
82 validateKanbanColumn,
83 validateKanbanRecord,
84 validateSearch,
85 webModels,
86 } from "@web/../tests/web_test_helpers";
87 import { addNewRule } from "@web/../tests/core/tree_editor/condition_tree_editor_test_helpers";
88
89 import { FileInput } from "@web/core/file_input/file_input";
90 import { browser } from "@web/core/browser/browser";
91 import { currencies } from "@web/core/currency";
92 import { registry } from "@web/core/registry";
93 import { user } from "@web/core/user";
94 import { RelationalModel } from "@web/model/relational_model/relational_model";
95 import { SampleServer } from "@web/model/sample_server";
96 import { KanbanCompiler } from "@web/views/kanban/kanban_compiler";
97 import { KanbanController } from "@web/views/kanban/kanban_controller";
98 import { KanbanRecord } from "@web/views/kanban/kanban_record";
99 import { KanbanRenderer } from "@web/views/kanban/kanban_renderer";
100 import { kanbanView } from "@web/views/kanban/kanban_view";
101 import { ViewButton } from "@web/views/view_button/view_button";
102 import { AnimatedNumber } from "@web/views/view_components/animated_number";
103 import { WebClient } from "@web/webclient/webclient";
104
105 const { IrAttachment } = webModels;
106
107 const fieldRegistry = registry.category("fields");
108 const viewRegistry = registry.category("views");
109 const viewWidgetRegistry = registry.category("view_widgets");
110
111 async function createFileInput({ mockPost, mockAdd, props }) {
112 mockService("notification", {
113 add: mockAdd || (() => {}),
114 });
115 mockService("http", {
116 post: mockPost || (() => {}),
117 });
118 await mountWithCleanup(FileInput, { props });
119 }
120
121 async function toggleMultiCurrencyPopover(el) {
122 if (getMockEnv().isSmall) {
123 await contains(el).click();
124 } else {
125 await contains(el).hover();
126 }
127 }
128
129 class Partner extends models.Model {
130 _name = "partner";
131 _rec_name = "foo";
132
133 foo = fields.Char();
134 bar = fields.Boolean();
135 sequence = fields.Integer();
136 int_field = fields.Integer({ aggregator: "sum", sortable: true });
137 float_field = fields.Float({ aggregator: "sum" });
138 product_id = fields.Many2one({ relation: "product" });
139 category_ids = fields.Many2many({ relation: "category" });
140 date = fields.Date();
141 datetime = fields.Datetime();
142 state = fields.Selection({
143 type: "selection",
144 selection: [
145 ["abc", "ABC"],
146 ["def", "DEF"],
147 ["ghi", "GHI"],
148 ],
149 });
150 salary = fields.Monetary({ aggregator: "sum", currency_field: "currency_id" });
151 currency_id = fields.Many2one({ relation: "res.currency" });
152
153 _records = [
154 {
155 id: 1,
156 foo: "yop",
157 bar: true,
158 int_field: 10,
159 float_field: 0.4,
160 product_id: 3,
161 category_ids: [],
162 state: "abc",
163 salary: 1750,
164 currency_id: 1,
165 },
166 {
167 id: 2,
168 foo: "blip",
169 bar: true,
170 int_field: 9,
171 float_field: 13,
172 product_id: 5,
173 category_ids: [6],
174 state: "def",
175 salary: 1500,
176 currency_id: 1,
177 },
178 {
179 id: 3,
180 foo: "gnap",
181 bar: true,
182 int_field: 17,
183 float_field: -3,
184 product_id: 3,
185 category_ids: [7],
186 state: "ghi",
187 salary: 2000,
188 currency_id: 2,
189 },
190 {
191 id: 4,
192 foo: "blip",
193 bar: false,
194 int_field: -4,
195 float_field: 9,
196 product_id: 5,
197 category_ids: [],
198 state: "ghi",
199 salary: 2222,
200 currency_id: 1,
201 },
202 ];
203 }
204
205 class Product extends models.Model {
206 _name = "product";
207
208 name = fields.Char();
209 fold = fields.Boolean({ default: false });
210
211 _records = [
212 { id: 3, name: "hello" },
213 { id: 5, name: "xmo" },
214 ];
215 }
216
217 class Category extends models.Model {
218 _name = "category";
219
220 name = fields.Char();
221 color = fields.Integer();
222
223 _records = [
224 { id: 6, name: "gold", color: 2 },
225 { id: 7, name: "silver", color: 5 },
226 ];
227 }
228
229 class Currency extends models.Model {
230 _name = "res.currency";
231
232 name = fields.Char();
233 symbol = fields.Char();
234 position = fields.Selection({
235 selection: [
236 ["after", "A"],
237 ["before", "B"],
238 ],
239 });
240 inverse_rate = fields.Float();
241
242 _records = [
243 { id: 1, name: "USD", symbol: "$", position: "before", inverse_rate: 1 },
244 { id: 2, name: "EUR", symbol: "€", position: "after", inverse_rate: 0.5 },
245 ];
246 }
247
248 class User extends models.Model {
249 _name = "res.users";
250 has_group() {
251 return true;
252 }
253 }
254
255 defineModels([Partner, Product, Category, Currency, IrAttachment, User]);
256
257 beforeEach(() => {
258 patchWithCleanup(AnimatedNumber, { enableAnimations: false });
259 });
260
261 test("basic ungrouped rendering", async () => {
262 onRpc("web_search_read", ({ kwargs }) => {
263 expect(kwargs.context.bin_size).toBe(true);
264 });
265
266 await mountView({
267 type: "kanban",
268 resModel: "partner",
269 arch: `
270 <kanban class="o_kanban_test">
271 <templates>
272 <t t-name="card">
273 <field name="foo"/>
274 </t>
275 </templates>
276 </kanban>`,
277 });
278
279 expect(".o_kanban_view").toHaveClass("o_kanban_test");
280 expect(".o_kanban_renderer").toHaveClass("o_kanban_ungrouped");
281 expect(".o_control_panel_main_buttons button.o-kanban-button-new").toHaveCount(1);
282 expect(".o_kanban_record:not(.o_kanban_ghost)").toHaveCount(4);
283 expect(".o_kanban_ghost").toHaveCount(6);
284 expect(".o_kanban_record:contains(gnap)").toHaveCount(1);
285 });
286
287 test("kanban rendering with class and style attributes", async () => {
288 await mountView({
289 type: "kanban",
290 resModel: "partner",
291 arch: `
292 <kanban class="myCustomClass" style="border: 1px solid red;">
293 <templates>
294 <t t-name="card">
295 <field name="foo"/>
296 </t>
297 </templates>
298 </kanban>`,
299 });
300 expect("[style*='border: 1px solid red;']").toHaveCount(0, {
301 message: "style attribute should not be copied",
302 });
303 expect(".o_view_controller.o_kanban_view.myCustomClass").toHaveCount(1, {
304 message: "class attribute should be passed to the view controller",
305 });
306 expect(".myCustomClass").toHaveCount(1, {
307 message: "class attribute should ONLY be passed to the view controller",
308 });
309 });
310
311 test("generic tags are case insensitive", async () => {
312 await mountView({
313 type: "kanban",
314 resModel: "partner",
315 arch: `
316 <kanban>
317 <templates>
318 <t t-name="card">
319 <Div class="test">Hello</Div>
320 </t>
321 </templates>
322 </kanban>`,
323 });
324
325 expect("div.test").toHaveCount(4);
326 });
327
328 test("kanban records are clickable by default", async () => {
329 await mountView({
330 type: "kanban",
331 resModel: "partner",
332 arch: `
333 <kanban>
334 <templates>
335 <t t-name="card">
336 <field name="foo"/>
337 </t>
338 </templates>
339 </kanban>`,
340 selectRecord: (resId) => {
341 expect(resId).toBe(1, { message: "should trigger an event to open the form view" });
342 },
343 });
344
345 await contains(".o_kanban_record").click();
346 });
347
348 test("kanban records with global_click='0'", async () => {
349 await mountView({
350 type: "kanban",
351 resModel: "partner",
352 arch: `
353 <kanban can_open="0">
354 <templates>
355 <t t-name="card">
356 <field name="foo"/>
357 </t>
358 </templates>
359 </kanban>`,
360 selectRecord: (resId) => {
361 expect.step("select record");
362 },
363 });
364
365 await contains(".o_kanban_record").click();
366 expect.verifySteps([]);
367 });
368
369 test("float fields are formatted properly without using a widget", async () => {
370 await mountView({
371 type: "kanban",
372 resModel: "partner",
373 arch: `
374 <kanban>
375 <templates>
376 <t t-name="card">
377 <field name="float_field" digits="[0,5]"/>
378 <field name="float_field" digits="[0,3]"/>
379 </t>
380 </templates>
381 </kanban>`,
382 });
383
384 expect(".o_kanban_record:first").toHaveText("0.40000\n0.400");
385 });
386
387 test("field with widget and attributes in kanban", async () => {
388 const myField = {
389 component: class MyField extends Component {
390 static template = xml`<span/>`;
391 static props = ["*"];
392 setup() {
393 if (this.props.record.resId === 1) {
394 expect(this.props.attrs).toEqual({
395 name: "int_field",
396 widget: "my_field",
397 str: "some string",
398 bool: "true",
399 num: "4.5",
400 field_id: "int_field_0",
401 });
402 }
403 }
404 },
405 extractProps: ({ attrs }) => ({ attrs }),
406 };
407 fieldRegistry.add("my_field", myField);
408 after(() => fieldRegistry.remove("my_field"));
409
410 await mountView({
411 type: "kanban",
412 resModel: "partner",
413 arch: `
414 <kanban>
415 <field name="foo"/>
416 <templates>
417 <t t-name="card">
418 <field name="int_field" widget="my_field"
419 str="some string"
420 bool="true"
421 num="4.5"
422 />
423 </t>
424 </templates>
425 </kanban>`,
426 });
427 });
428
429 test("kanban with integer field with human_readable option", async () => {
430 Partner._records[0].int_field = 5 * 1000 * 1000;
431 await mountView({
432 type: "kanban",
433 resModel: "partner",
434 arch: `
435 <kanban>
436 <templates>
437 <t t-name="card">
438 <field name="int_field" options="{'human_readable': true}"/>
439 </t>
440 </templates>
441 </kanban>`,
442 });
443
444 expect(queryAllTexts(".o_kanban_record:not(.o_kanban_ghost)")).toEqual(["5M", "9", "17", "-4"]);
445 expect(".o_field_widget").toHaveCount(0);
446 });
447
448 test.tags("desktop");
449 test("Hide tooltip when user click inside a kanban headers item", async () => {
450 await mountView({
451 type: "kanban",
452 resModel: "partner",
453 arch: `
454 <kanban default_group_by="product_id">
455 <field name="product_id" options='{"group_by_tooltip": {"name": "Name"}}'/>
456 <templates>
457 <t t-name="card"/>
458 </templates>
459 </kanban>`,
460 });
461 expect(".o_kanban_renderer").toHaveClass("o_kanban_grouped");
462 expect(".o_column_title").toHaveCount(2);
463 expect(".o-tooltip").toHaveCount(0);
464
465 await hover(".o_kanban_group:first-child .o_kanban_header_title .o_column_title");
466 await runAllTimers();
467 expect(".o-tooltip").toHaveCount(1);
468
469 await contains(
470 ".o_kanban_group:first-child .o_kanban_header_title .o_kanban_quick_add"
471 ).click();
472 expect(".o-tooltip").toHaveCount(0);
473
474 await hover(".o_kanban_group:first-child .o_kanban_header_title .o_column_title");
475 await runAllTimers();
476 expect(".o-tooltip").toHaveCount(1);
477
478 await contains(".o_kanban_group:first-child .o_kanban_header_title .fa-gear", {
479 visible: false,
480 }).click();
481 expect(".o-tooltip").toHaveCount(0);
482 });
483
484 test.tags("desktop");
485 test("basic grouped rendering", async () => {
486 expect.assertions(14);
487
488 patchWithCleanup(KanbanRenderer.prototype, {
489 setup() {
490 super.setup(...arguments);
491 onRendered(() => {
492 expect.step("rendered");
493 });
494 },
495 });
496
497 await mountView({
498 type: "kanban",
499 resModel: "partner",
500 arch: `
501 <kanban class="o_kanban_test">
502 <templates>
503 <t t-name="card">
504 <field name="foo" />
505 </t>
506 </templates>
507 </kanban>`,
508 groupBy: ["bar"],
509 });
510
511 expect(".o_kanban_view").toHaveClass("o_kanban_test");
512 expect(".o_kanban_renderer").toHaveClass("o_kanban_grouped");
513 expect(".o_control_panel_main_buttons button.o-kanban-button-new").toHaveCount(1);
514 expect(".o_kanban_group").toHaveCount(2);
515 expect(".o_kanban_group:first-child .o_kanban_record").toHaveCount(1);
516 expect(".o_kanban_group:nth-child(2) .o_kanban_record").toHaveCount(3);
517 expect.verifySteps(["rendered"]);
518
519 await toggleKanbanColumnActions(0);
520
521 // check available actions in kanban header's config dropdown
522 expect(".o-dropdown--menu .o_kanban_toggle_fold").toHaveCount(1);
523 expect(".o_kanban_header:first-child .o_group_config .o_group_edit").toHaveCount(0);
524 expect(".o_kanban_header:first-child .o_group_config .o_group_delete").toHaveCount(0);
525 expect(".o_kanban_header:first-child .o_group_config .o_column_archive_records").toHaveCount(0);
526 expect(".o_kanban_header:first-child .o_group_config .o_column_unarchive_records").toHaveCount(
527 0
528 );
529
530 // focuses the search bar and closes the dropdown
531 await click(".o_searchview input");
532
533 // the next line makes sure that reload works properly. It looks useless,
534 // but it actually test that a grouped local record can be reloaded without
535 // changing its result.
536 await validateSearch();
537 expect(".o_kanban_group:nth-child(2) .o_kanban_record").toHaveCount(3);
538 expect.verifySteps(["rendered"]);
539 });
540
541 test("basic grouped rendering with no record", async () => {
542 Partner._records = [];
543
544 await mountView({
545 type: "kanban",
546 resModel: "partner",
547 arch: `
548 <kanban class="o_kanban_test">
549 <templates>
550 <t t-name="card">
551 <field name="foo" />
552 </t>
553 </templates>
554 </kanban>`,
555 groupBy: ["bar"],
556 });
557 expect(".o_kanban_grouped").toHaveCount(1);
558 expect(".o_view_nocontent").toHaveCount(1);
559 expect(".o_control_panel_main_buttons button.o-kanban-button-new").toHaveCount(1, {
560 message:
561 "There should be a 'New' button even though there is no column when groupby is not a many2one",
562 });
563 });
564
565 test.tags("desktop");
566 test("empty group when grouped by date", async () => {
567 Partner._records[0].date = "2017-01-08";
568 Partner._records[1].date = "2017-02-09";
569 Partner._records[2].date = "2017-02-08";
570 Partner._records[3].date = "2017-02-10";
571
572 await mountView({
573 type: "kanban",
574 resModel: "partner",
575 arch: `<kanban>
576 <templates>
577 <t t-name="card">
578 <field name="foo"/>
579 </t>
580 </templates>
581 </kanban>`,
582 groupBy: ["date:month"],
583 });
584
585 expect(queryAllTexts(".o_kanban_header")).toEqual(["January 2017\n(1)", "February 2017\n(3)"]);
586
587 MockServer.env["partner"].shift(); // remove only record of the first group
588
589 await press("Enter"); // reload
590 await animationFrame();
591
592 expect(queryAllTexts(".o_kanban_header")).toEqual(["January 2017\n(0)", "February 2017\n(3)"]);
593
594 expect(queryAll(".o_kanban_record", { root: getKanbanColumn(0) })).toHaveCount(0);
595 expect(queryAll(".o_kanban_record", { root: getKanbanColumn(1) })).toHaveCount(3);
596 });
597
598 test("grouped rendering with active field (archivable false)", async () => {
599 // add active field on partner model and make all records active
600 Partner._fields.active = fields.Boolean({ default: true });
601
602 await mountView({
603 type: "kanban",
604 resModel: "partner",
605 arch: `
606 <kanban archivable="false">
607 <templates>
608 <t t-name="card">
609 <field name="foo"/>
610 </t>
611 </templates>
612 </kanban>`,
613 groupBy: ["bar"],
614 });
615
616 await toggleKanbanColumnActions(0);
617
618 // check archive/restore all actions in kanban header's config dropdown
619 expect(".o_column_archive_records").toHaveCount(0, { root: getKanbanColumnDropdownMenu(0) });
620 expect(".o_column_unarchive_records").toHaveCount(0, { root: getKanbanColumnDropdownMenu(0) });
621 });
622
623 test.tags("desktop");
624 test("m2m grouped rendering with active field (archivable true)", async () => {
625 // add active field on partner model and make all records active
626 Partner._fields.active = fields.Boolean({ default: true });
627
628 // more many2many data
629 Partner._records[0].category_ids = [6, 7];
630 Partner._records[3].foo = "blork";
631
632 await mountView({
633 type: "kanban",
634 resModel: "partner",
635 arch: `
636 <kanban archivable="true">
637 <templates>
638 <t t-name="card">
639 <field name="foo"/>
640 </t>
641 </templates>
642 </kanban>`,
643 groupBy: ["category_ids"],
644 });
645
646 expect(".o_kanban_group").toHaveCount(3);
647 expect(queryAll(".o_kanban_record", { root: getKanbanColumn(1) })).toHaveCount(2);
648 expect(queryAll(".o_kanban_record", { root: getKanbanColumn(2) })).toHaveCount(2);
649
650 expect(queryAllTexts(".o_kanban_group")).toEqual([
651 "None\n(1)",
652 "gold\n(2)\nyop\nblip",
653 "silver\n(2)\nyop\ngnap",
654 ]);
655
656 await click(getKanbanColumn(0));
657 await animationFrame();
658 await toggleKanbanColumnActions(0);
659
660 // check archive/restore all actions in kanban header's config dropdown
661 // despite the fact that the kanban view is configured to be archivable,
662 // the actions should not be there as it is grouped by an m2m field.
663 expect(".o_column_archive_records").toHaveCount(0, { root: getKanbanColumnDropdownMenu(0) });
664 expect(".o_column_unarchive_records").toHaveCount(0, { root: getKanbanColumnDropdownMenu(0) });
665 });
666
667 test("kanban grouped by date field", async () => {
668 Partner._records[0].date = "2007-06-10";
669
670 await mountView({
671 type: "kanban",
672 resModel: "partner",
673 arch: `
674 <kanban>
675 <templates>
676 <t t-name="card">
677 <field name="foo"/>
678 </t>
679 </templates>
680 </kanban>`,
681 groupBy: ["date"],
682 });
683
684 expect(queryAllTexts(".o_column_title")).toEqual(["None\n(3)", "June 2007\n(1)"]);
685 });
686
687 test("context can be used in kanban template", async () => {
688 await mountView({
689 type: "kanban",
690 resModel: "partner",
691 arch: `
692 <kanban>
693 <templates>
694 <t t-name="card">
695 <field t-if="context.some_key" name="foo"/>
696 </t>
697 </templates>
698 </kanban>`,
699 context: { some_key: 1 },
700 domain: [["id", "=", 1]],
701 });
702
703 expect(".o_kanban_record:not(.o_kanban_ghost)").toHaveCount(1);
704 expect(".o_kanban_record span:contains(yop)").toHaveCount(1);
705 });
706
707 test("kanban with sub-template", async () => {
708 await mountView({
709 type: "kanban",
710 resModel: "partner",
711 arch: `
712 <kanban>
713 <templates>
714 <t t-name="card">
715 <t t-call="another-template"/>
716 </t>
717 <t t-name="another-template">
718 <field name="foo"/>
719 </t>
720 </templates>
721 </kanban>`,
722 });
723
724 expect(queryAllTexts(".o_kanban_record:not(.o_kanban_ghost)")).toEqual([
725 "yop",
726 "blip",
727 "gnap",
728 "blip",
729 ]);
730 });
731
732 test("kanban with t-set outside card", async () => {
733 await mountView({
734 type: "kanban",
735 resModel: "partner",
736 arch: `
737 <kanban>
738 <field name="int_field"/>
739 <templates>
740 <t t-name="card">
741 <t t-set="x" t-value="record.int_field.value"/>
742 <div>
743 <t t-esc="x"/>
744 </div>
745 </t>
746 </templates>
747 </kanban>`,
748 });
749
750 expect(queryAllTexts(".o_kanban_record:not(.o_kanban_ghost)")).toEqual(["10", "9", "17", "-4"]);
751 });
752
753 test("kanban with t-if/t-else on field", async () => {
754 await mountView({
755 type: "kanban",
756 resModel: "partner",
757 arch: `
758 <kanban>
759 <templates>
760 <t t-name="card">
761 <field t-if="record.int_field.value > -1" name="int_field"/>
762 <t t-else="">Negative value</t>
763 </t>
764 </templates>
765 </kanban>`,
766 });
767
768 expect(queryAllTexts(".o_kanban_record:not(.o_kanban_ghost)")).toEqual([
769 "10",
770 "9",
771 "17",
772 "Negative value",
773 ]);
774 });
775
776 test("kanban with t-if/t-else on field with widget", async () => {
777 await mountView({
778 type: "kanban",
779 resModel: "partner",
780 arch: `
781 <kanban>
782 <templates>
783 <t t-name="card">
784 <field t-if="record.int_field.value > -1" name="int_field" widget="integer"/>
785 <t t-else="">Negative value</t>
786 </t>
787 </templates>
788 </kanban>`,
789 });
790
791 expect(queryAllTexts(".o_kanban_record:not(.o_kanban_ghost)")).toEqual([
792 "10",
793 "9",
794 "17",
795 "Negative value",
796 ]);
797 });
798
799 test("field with widget and dynamic attributes in kanban", async () => {
800 const myField = {
801 component: class MyField extends Component {
802 static template = xml`<span/>`;
803 static props = ["*"];
804 },
805 extractProps: ({ attrs }) => {
806 expect.step(
807 `${attrs["dyn-bool"]}/${attrs["interp-str"]}/${attrs["interp-str2"]}/${attrs["interp-str3"]}`
808 );
809 },
810 };
811 fieldRegistry.add("my_field", myField);
812 after(() => fieldRegistry.remove("my_field"));
813
814 await mountView({
815 type: "kanban",
816 resModel: "partner",
817 arch: `
818 <kanban>
819 <field name="foo"/>
820 <templates>
821 <t t-name="card">
822 <field name="int_field" widget="my_field"
823 t-att-dyn-bool="record.foo.value.length > 3"
824 t-attf-interp-str="hello {{record.foo.value}}"
825 t-attf-interp-str2="hello #{record.foo.value} !"
826 t-attf-interp-str3="hello {{record.foo.value}} }}"
827 />
828 </t>
829 </templates>
830 </kanban>`,
831 });
832 expect.verifySteps([
833 "false/hello yop/hello yop !/hello yop }}",
834 "true/hello blip/hello blip !/hello blip }}",
835 "true/hello gnap/hello gnap !/hello gnap }}",
836 "true/hello blip/hello blip !/hello blip }}",
837 ]);
838 });
839
840 test("view button and string interpolated attribute in kanban", async () => {
841 patchWithCleanup(ViewButton.prototype, {
842 setup() {
843 super.setup();
844 expect.step(`[${this.props.clickParams["name"]}] className: '${this.props.className}'`);
845 },
846 });
847
848 await mountView({
849 type: "kanban",
850 resModel: "partner",
851 arch: `
852 <kanban>
853 <field name="foo"/>
854 <templates>
855 <t t-name="card">
856 <a name="one" type="object" class="hola"/>
857 <a name="two" type="object" class="hola" t-attf-class="hello"/>
858 <a name="sri" type="object" class="hola" t-attf-class="{{record.foo.value}}"/>
859 <a name="foa" type="object" class="hola" t-attf-class="{{record.foo.value}} olleh"/>
860 <a name="fye" type="object" class="hola" t-attf-class="hello {{record.foo.value}}"/>
861 </t>
862 </templates>
863 </kanban>`,
864 });
865 expect.verifySteps([
866 "[one] className: 'hola oe_kanban_action'",
867 "[two] className: 'hola oe_kanban_action hello'",
868 "[sri] className: 'hola oe_kanban_action yop'",
869 "[foa] className: 'hola oe_kanban_action yop olleh'",
870 "[fye] className: 'hola oe_kanban_action hello yop'",
871 "[one] className: 'hola oe_kanban_action'",
872 "[two] className: 'hola oe_kanban_action hello'",
873 "[sri] className: 'hola oe_kanban_action blip'",
874 "[foa] className: 'hola oe_kanban_action blip olleh'",
875 "[fye] className: 'hola oe_kanban_action hello blip'",
876 "[one] className: 'hola oe_kanban_action'",
877 "[two] className: 'hola oe_kanban_action hello'",
878 "[sri] className: 'hola oe_kanban_action gnap'",
879 "[foa] className: 'hola oe_kanban_action gnap olleh'",
880 "[fye] className: 'hola oe_kanban_action hello gnap'",
881 "[one] className: 'hola oe_kanban_action'",
882 "[two] className: 'hola oe_kanban_action hello'",
883 "[sri] className: 'hola oe_kanban_action blip'",
884 "[foa] className: 'hola oe_kanban_action blip olleh'",
885 "[fye] className: 'hola oe_kanban_action hello blip'",
886 ]);
887 });
888
889 test("pager should be hidden in grouped mode", async () => {
890 await mountView({
891 type: "kanban",
892 resModel: "partner",
893 arch: `
894 <kanban>
895 <templates>
896 <t t-name="card">
897 <field name="foo"/>
898 </t>
899 </templates>
900 </kanban>`,
901 groupBy: ["bar"],
902 });
903
904 expect(".o_pager").toHaveCount(0);
905 });
906
907 test("there should be no limit on the number of fetched groups", async () => {
908 patchWithCleanup(RelationalModel, { DEFAULT_GROUP_LIMIT: 1 });
909
910 await mountView({
911 type: "kanban",
912 resModel: "partner",
913 arch: `
914 <kanban>
915 <templates>
916 <t t-name="card">
917 <field name="foo"/>
918 </t>
919 </templates>
920 </kanban>`,
921 groupBy: ["product_id"],
922 });
923
924 expect(".o_kanban_group").toHaveCount(2);
925 });
926
927 test("pager, ungrouped, with default limit", async () => {
928 expect.assertions(2);
929
930 onRpc("web_search_read", ({ kwargs }) => {
931 expect(kwargs.limit).toBe(40);
932 });
933
934 await mountView({
935 type: "kanban",
936 resModel: "partner",
937 arch: `
938 <kanban>
939 <templates>
940 <t t-name="card">
941 <field name="foo"/>
942 </t>
943 </templates>
944 </kanban>`,
945 });
946
947 expect(".o_pager").toHaveCount(1);
948 });
949
950 test.tags("desktop");
951 test("pager, ungrouped, with default limit on desktop", async () => {
952 await mountView({
953 type: "kanban",
954 resModel: "partner",
955 arch: `
956 <kanban>
957 <templates>
958 <t t-name="card">
959 <field name="foo"/>
960 </t>
961 </templates>
962 </kanban>`,
963 });
964
965 expect(getPagerValue()).toEqual([1, 4]);
966 });
967
968 test("pager, ungrouped, with limit given in options", async () => {
969 expect.assertions(1);
970
971 onRpc("web_search_read", ({ kwargs }) => {
972 expect(kwargs.limit).toBe(2);
973 });
974
975 await mountView({
976 type: "kanban",
977 resModel: "partner",
978 arch: `
979 <kanban>
980 <templates>
981 <t t-name="card">
982 <field name="foo"/>
983 </t>
984 </templates>
985 </kanban>`,
986 limit: 2,
987 });
988 });
989
990 test.tags("desktop");
991 test("pager, ungrouped, with limit given in options on desktop", async () => {
992 await mountView({
993 type: "kanban",
994 resModel: "partner",
995 arch: `
996 <kanban>
997 <templates>
998 <t t-name="card">
999 <field name="foo"/>
1000 </t>
1001 </templates>
1002 </kanban>`,
1003 limit: 2,
1004 });
1005 expect(getPagerValue()).toEqual([1, 2]);
1006 expect(getPagerLimit()).toBe(4);
1007 });
1008
1009 test("pager, ungrouped, with limit set on arch and given in options", async () => {
1010 expect.assertions(1);
1011
1012 onRpc("web_search_read", ({ kwargs }) => {
1013 expect(kwargs.limit).toBe(3);
1014 });
1015
1016 // the limit given in the arch should take the priority over the one given in options
1017 await mountView({
1018 type: "kanban",
1019 resModel: "partner",
1020 arch: `
1021 <kanban limit="3">
1022 <templates>
1023 <t t-name="card">
1024 <field name="foo"/>
1025 </t>
1026 </templates>
1027 </kanban>`,
1028 limit: 2,
1029 });
1030 });
1031
1032 test.tags("desktop");
1033 test("pager, ungrouped, with limit set on arch and given in options on desktop", async () => {
1034 // the limit given in the arch should take the priority over the one given in options
1035 await mountView({
1036 type: "kanban",
1037 resModel: "partner",
1038 arch: `
1039 <kanban limit="3">
1040 <templates>
1041 <t t-name="card">
1042 <field name="foo"/>
1043 </t>
1044 </templates>
1045 </kanban>`,
1046 limit: 2,
1047 });
1048
1049 expect(getPagerValue()).toEqual([1, 3]);
1050 expect(getPagerLimit()).toBe(4);
1051 });
1052
1053 test.tags("desktop");
1054 test("pager, ungrouped, with count limit reached", async () => {
1055 patchWithCleanup(RelationalModel, { DEFAULT_COUNT_LIMIT: 3 });
1056
1057 stepAllNetworkCalls();
1058
1059 await mountView({
1060 type: "kanban",
1061 resModel: "partner",
1062 arch: `
1063 <kanban limit="2">
1064 <templates>
1065 <t t-name="card">
1066 <field name="foo"/>
1067 </t>
1068 </templates>
1069 </kanban>`,
1070 });
1071
1072 expect(".o_kanban_record:not(.o_kanban_ghost)").toHaveCount(2);
1073 expect(".o_pager_value").toHaveText("1-2");
1074 expect(".o_pager_limit").toHaveText("3+");
1075 expect.verifySteps([
1076 "/web/webclient/translations",
1077 "/web/webclient/load_menus",
1078 "get_views",
1079 "web_search_read",
1080 "has_group",
1081 ]);
1082
1083 await contains(".o_pager_limit").click();
1084
1085 expect(".o_kanban_record:not(.o_kanban_ghost)").toHaveCount(2);
1086 expect(".o_pager_value").toHaveText("1-2");
1087 expect(".o_pager_limit").toHaveText("4");
1088 expect.verifySteps(["search_count"]);
1089 });
1090
1091 test("pager, ungrouped, with count limit reached, click next", async () => {
1092 patchWithCleanup(RelationalModel, { DEFAULT_COUNT_LIMIT: 3 });
1093
1094 stepAllNetworkCalls();
1095
1096 await mountView({
1097 type: "kanban",
1098 resModel: "partner",
1099 arch: `
1100 <kanban limit="2">
1101 <templates>
1102 <t t-name="card">
1103 <field name="foo"/>
1104 </t>
1105 </templates>
1106 </kanban>`,
1107 });
1108
1109 expect(".o_kanban_record:not(.o_kanban_ghost)").toHaveCount(2);
1110 expect.verifySteps([
1111 "/web/webclient/translations",
1112 "/web/webclient/load_menus",
1113 "get_views",
1114 "web_search_read",
1115 "has_group",
1116 ]);
1117
1118 await contains(".o_pager_next").click();
1119
1120 expect(".o_kanban_record:not(.o_kanban_ghost)").toHaveCount(2);
1121 expect.verifySteps(["web_search_read"]);
1122 });
1123
1124 test.tags("desktop");
1125 test("pager, ungrouped, with count limit reached, click next on desktop", async () => {
1126 patchWithCleanup(RelationalModel, { DEFAULT_COUNT_LIMIT: 3 });
1127
1128 await mountView({
1129 type: "kanban",
1130 resModel: "partner",
1131 arch: `
1132 <kanban limit="2">
1133 <templates>
1134 <t t-name="card">
1135 <field name="foo"/>
1136 </t>
1137 </templates>
1138 </kanban>`,
1139 });
1140
1141 expect(".o_pager_value").toHaveText("1-2");
1142 expect(".o_pager_limit").toHaveText("3+");
1143
1144 await contains(".o_pager_next").click();
1145
1146 expect(".o_pager_value").toHaveText("3-4");
1147 expect(".o_pager_limit").toHaveText("4");
1148 });
1149
1150 test("pager, ungrouped, with count limit reached, click next (2)", async () => {
1151 patchWithCleanup(RelationalModel, { DEFAULT_COUNT_LIMIT: 3 });
1152
1153 Partner._records.push({ id: 5, foo: "xxx" });
1154
1155 stepAllNetworkCalls();
1156
1157 await mountView({
1158 type: "kanban",
1159 resModel: "partner",
1160 arch: `
1161 <kanban limit="2">
1162 <templates>
1163 <t t-name="card">
1164 <field name="foo"/>
1165 </t>
1166 </templates>
1167 </kanban>`,
1168 });
1169
1170 expect(".o_kanban_record:not(.o_kanban_ghost)").toHaveCount(2);
1171 expect.verifySteps([
1172 "/web/webclient/translations",
1173 "/web/webclient/load_menus",
1174 "get_views",
1175 "web_search_read",
1176 "has_group",
1177 ]);
1178
1179 await contains(".o_pager_next").click();
1180
1181 expect(".o_kanban_record:not(.o_kanban_ghost)").toHaveCount(2);
1182 expect.verifySteps(["web_search_read"]);
1183
1184 await contains(".o_pager_next").click();
1185
1186 expect(".o_kanban_record:not(.o_kanban_ghost)").toHaveCount(1);
1187 expect.verifySteps(["web_search_read"]);
1188 });
1189
1190 test.tags("desktop");
1191 test("pager, ungrouped, with count limit reached, click next (2) on desktop", async () => {
1192 patchWithCleanup(RelationalModel, { DEFAULT_COUNT_LIMIT: 3 });
1193
1194 Partner._records.push({ id: 5, foo: "xxx" });
1195
1196 await mountView({
1197 type: "kanban",
1198 resModel: "partner",
1199 arch: `
1200 <kanban limit="2">
1201 <templates>
1202 <t t-name="card">
1203 <field name="foo"/>
1204 </t>
1205 </templates>
1206 </kanban>`,
1207 });
1208
1209 expect(".o_pager_value").toHaveText("1-2");
1210 expect(".o_pager_limit").toHaveText("3+");
1211
1212 await contains(".o_pager_next").click();
1213
1214 expect(".o_pager_value").toHaveText("3-4");
1215 expect(".o_pager_limit").toHaveText("4+");
1216
1217 await contains(".o_pager_next").click();
1218
1219 expect(".o_pager_value").toHaveText("5-5");
1220 expect(".o_pager_limit").toHaveText("5");
1221 });
1222
1223 test("pager, ungrouped, with count limit reached, click previous", async () => {
1224 patchWithCleanup(RelationalModel, { DEFAULT_COUNT_LIMIT: 3 });
1225
1226 Partner._records.push({ id: 5, foo: "xxx" });
1227
1228 stepAllNetworkCalls();
1229
1230 await mountView({
1231 type: "kanban",
1232 resModel: "partner",
1233 arch: `
1234 <kanban limit="2">
1235 <templates>
1236 <t t-name="card">
1237 <field name="foo"/>
1238 </t>
1239 </templates>
1240 </kanban>`,
1241 });
1242
1243 expect(".o_kanban_record:not(.o_kanban_ghost)").toHaveCount(2);
1244 expect.verifySteps([
1245 "/web/webclient/translations",
1246 "/web/webclient/load_menus",
1247 "get_views",
1248 "web_search_read",
1249 "has_group",
1250 ]);
1251
1252 await contains(".o_pager_previous").click();
1253
1254 expect(".o_kanban_record:not(.o_kanban_ghost)").toHaveCount(1);
1255 expect.verifySteps(["search_count", "web_search_read"]);
1256 });
1257
1258 test.tags("desktop");
1259 test("pager, ungrouped, with count limit reached, click previous on desktop", async () => {
1260 patchWithCleanup(RelationalModel, { DEFAULT_COUNT_LIMIT: 3 });
1261
1262 Partner._records.push({ id: 5, foo: "xxx" });
1263
1264 await mountView({
1265 type: "kanban",
1266 resModel: "partner",
1267 arch: `
1268 <kanban limit="2">
1269 <templates>
1270 <t t-name="card">
1271 <field name="foo"/>
1272 </t>
1273 </templates>
1274 </kanban>`,
1275 });
1276
1277 expect(".o_pager_value").toHaveText("1-2");
1278 expect(".o_pager_limit").toHaveText("3+");
1279
1280 await contains(".o_pager_previous").click();
1281
1282 expect(".o_pager_value").toHaveText("5-5");
1283 expect(".o_pager_limit").toHaveText("5");
1284 });
1285
1286 test.tags("desktop");
1287 test("pager, ungrouped, with count limit reached, edit pager", async () => {
1288 patchWithCleanup(RelationalModel, { DEFAULT_COUNT_LIMIT: 3 });
1289
1290 Partner._records.push({ id: 5, foo: "xxx" });
1291 stepAllNetworkCalls();
1292
1293 await mountView({
1294 type: "kanban",
1295 resModel: "partner",
1296 arch: `
1297 <kanban limit="2">
1298 <templates>
1299 <t t-name="card">
1300 <field name="foo"/>
1301 </t>
1302 </templates>
1303 </kanban>`,
1304 });
1305
1306 expect(".o_kanban_record:not(.o_kanban_ghost)").toHaveCount(2);
1307 expect(".o_pager_value").toHaveText("1-2");
1308 expect(".o_pager_limit").toHaveText("3+");
1309 expect.verifySteps([
1310 "/web/webclient/translations",
1311 "/web/webclient/load_menus",
1312 "get_views",
1313 "web_search_read",
1314 "has_group",
1315 ]);
1316
1317 await contains("span.o_pager_value").click();
1318 // FIXME: we have to click out instead of confirming, because somehow if the
1319 // web_search_read calls come back too fast when pressing "Enter", another
1320 // RPC is triggered right after.
1321 await contains("input.o_pager_value").edit("2-4", { confirm: "blur" });
1322
1323 expect(".o_kanban_record:not(.o_kanban_ghost)").toHaveCount(3);
1324 expect(".o_pager_value").toHaveText("2-4");
1325 expect(".o_pager_limit").toHaveText("4+");
1326 expect.verifySteps(["web_search_read"]);
1327
1328 await contains("span.o_pager_value").click();
1329 await contains("input.o_pager_value").edit("2-14", { confirm: "blur" });
1330
1331 expect(".o_kanban_record:not(.o_kanban_ghost)").toHaveCount(4);
1332 expect(".o_pager_value").toHaveText("2-5");
1333 expect(".o_pager_limit").toHaveText("5");
1334 expect.verifySteps(["web_search_read"]);
1335 });
1336
1337 test.tags("desktop");
1338 test("count_limit attrs set in arch", async () => {
1339 stepAllNetworkCalls();
1340
1341 await mountView({
1342 type: "kanban",
1343 resModel: "partner",
1344 arch: `
1345 <kanban limit="2" count_limit="3">
1346 <templates>
1347 <t t-name="card">
1348 <field name="foo"/>
1349 </t>
1350 </templates>
1351 </kanban>`,
1352 });
1353
1354 expect(".o_kanban_record:not(.o_kanban_ghost)").toHaveCount(2);
1355 expect(".o_pager_value").toHaveText("1-2");
1356 expect(".o_pager_limit").toHaveText("3+");
1357 expect.verifySteps([
1358 "/web/webclient/translations",
1359 "/web/webclient/load_menus",
1360 "get_views",
1361 "web_search_read",
1362 "has_group",
1363 ]);
1364
1365 await contains(".o_pager_limit").click();
1366
1367 expect(".o_kanban_record:not(.o_kanban_ghost)").toHaveCount(2);
1368 expect(".o_pager_value").toHaveText("1-2");
1369 expect(".o_pager_limit").toHaveText("4");
1370 expect.verifySteps(["search_count"]);
1371 });
1372
1373 test.tags("desktop");
1374 test("pager, ungrouped, deleting all records from last page", async () => {
1375 await mountView({
1376 type: "kanban",
1377 resModel: "partner",
1378 arch: `
1379 <kanban limit="3">
1380 <templates>
1381 <t t-name="card">
1382 <a role="menuitem" type="delete" class="dropdown-item">Delete</a>
1383 <field name="foo"/>
1384 </t>
1385 </templates>
1386 </kanban>`,
1387 });
1388
1389 expect(getPagerValue()).toEqual([1, 3]);
1390 expect(getPagerLimit()).toBe(4);
1391
1392 // move to next page
1393 await pagerNext();
1394
1395 expect(getPagerValue()).toEqual([4, 4]);
1396
1397 // delete a record
1398 await contains(".o_kanban_record a").click();
1399
1400 expect(".o_dialog").toHaveCount(1);
1401 await contains(".o_dialog footer .btn-primary").click();
1402
1403 expect(getPagerValue()).toEqual([1, 3]);
1404 expect(getPagerLimit()).toBe(3);
1405 });
1406
1407 test.tags("desktop");
1408 test("pager, update calls onUpdatedPager", async () => {
1409 class TestKanbanController extends KanbanController {
1410 setup() {
1411 super.setup();
1412 onWillRender(() => {
1413 expect.step("render");
1414 });
1415 }
1416
1417 async onUpdatedPager() {
1418 expect.step("onUpdatedPager");
1419 }
1420 }
1421
1422 viewRegistry.add("test_kanban_view", {
1423 ...kanbanView,
1424 Controller: TestKanbanController,
1425 });
1426 after(() => viewRegistry.remove("test_kanban_view"));
1427
1428 await mountView({
1429 type: "kanban",
1430 resModel: "partner",
1431 arch: `
1432 <kanban js_class="test_kanban_view">
1433 <templates>
1434 <t t-name="card">
1435 <field name="foo"/>
1436 </t>
1437 </templates>
1438 </kanban>`,
1439 limit: 3,
1440 });
1441
1442 expect(getPagerValue()).toEqual([1, 3]);
1443 expect(getPagerLimit()).toBe(4);
1444 expect.step("next page");
1445 await contains(".o_pager_next").click();
1446 expect(getPagerValue()).toEqual([4, 4]);
1447 expect.verifySteps(["render", "render", "next page", "render", "onUpdatedPager"]);
1448 });
1449
1450 test("click on a button type='delete' to delete a record in a column", async () => {
1451 await mountView({
1452 type: "kanban",
1453 resModel: "partner",
1454 arch: `
1455 <kanban limit="3">
1456 <templates>
1457 <t t-name="card">
1458 <a role="menuitem" type="delete" class="dropdown-item o_delete">Delete</a>
1459 <field name="foo"/>
1460 </t>
1461 </templates>
1462 </kanban>`,
1463 groupBy: ["product_id"],
1464 });
1465 expect(queryAll(".o_kanban_record", { root: getKanbanColumn(0) })).toHaveCount(2);
1466 expect(queryAll(".o_kanban_load_more", { root: getKanbanColumn(0) })).toHaveCount(0);
1467
1468 await click(queryFirst(".o_kanban_record .o_delete", { root: getKanbanColumn(0) }));
1469 await animationFrame();
1470 expect(".modal").toHaveCount(1);
1471
1472 await contains(".modal .btn-primary").click();
1473
1474 expect(queryAll(".o_kanban_record", { root: getKanbanColumn(0) })).toHaveCount(1);
1475 expect(queryAll(".o_kanban_load_more", { root: getKanbanColumn(0) })).toHaveCount(0);
1476 });
1477
1478 test("click on a button type='archive' to archive a record in a column", async () => {
1479 onRpc("action_archive", ({ args }) => {
1480 expect.step(`archive:${args[0]}`);
1481 return true;
1482 });
1483
1484 await mountView({
1485 type: "kanban",
1486 resModel: "partner",
1487 arch: `
1488 <kanban limit="3">
1489 <templates>
1490 <t t-name="card">
1491 <a role="menuitem" type="archive" class="dropdown-item o_archive">archive</a>
1492 <field name="foo"/>
1493 </t>
1494 </templates>
1495 </kanban>`,
1496 groupBy: ["product_id"],
1497 });
1498
1499 expect(queryAll(".o_kanban_record", { root: getKanbanColumn(0) })).toHaveCount(2);
1500
1501 await contains(".o_kanban_record .o_archive").click();
1502
1503 expect(".modal").toHaveCount(1);
1504 expect.verifySteps([]);
1505
1506 await contains(".modal .btn-primary").click();
1507
1508 expect.verifySteps(["archive:1"]);
1509 });
1510
1511 test("click on a button type='unarchive' to unarchive a record in a column", async () => {
1512 onRpc("action_unarchive", ({ args }) => {
1513 expect.step(`unarchive:${args[0]}`);
1514 return true;
1515 });
1516
1517 await mountView({
1518 type: "kanban",
1519 resModel: "partner",
1520 arch: `
1521 <kanban limit="3">
1522 <templates>
1523 <t t-name="card">
1524 <a role="menuitem" type="unarchive" class="dropdown-item o_unarchive">unarchive</a>
1525 <field name="foo"/>
1526 </t>
1527 </templates>
1528 </kanban>`,
1529 groupBy: ["product_id"],
1530 });
1531
1532 expect(queryAll(".o_kanban_record", { root: getKanbanColumn(0) })).toHaveCount(2);
1533
1534 await contains(".o_kanban_record .o_unarchive").click();
1535
1536 expect.verifySteps(["unarchive:1"]);
1537 });
1538
1539 test.tags("desktop");
1540 test("kanban with an action id as on_create attrs", async () => {
1541 mockService("action", {
1542 doAction(action, options) {
1543 // simplified flow in this test: simulate a target new action which
1544 // creates a record and closes itself
1545 expect.step(`doAction ${action}`);
1546 MockServer.env["partner"].create({ foo: "new" });
1547 options.onClose();
1548 },
1549 });
1550
1551 stepAllNetworkCalls();
1552
1553 await mountView({
1554 type: "kanban",
1555 resModel: "partner",
1556 arch: `
1557 <kanban on_create="some.action">
1558 <templates>
1559 <t t-name="card">
1560 <field name="foo"/>
1561 </t>
1562 </templates>
1563 </kanban>`,
1564 });
1565
1566 expect(".o_kanban_record:not(.o_kanban_ghost)").toHaveCount(4);
1567 await createKanbanRecord();
1568 expect(".o_kanban_record:not(.o_kanban_ghost)").toHaveCount(5);
1569 expect.verifySteps([
1570 "/web/webclient/translations",
1571 "/web/webclient/load_menus",
1572 "get_views",
1573 "web_search_read",
1574 "has_group",
1575 "doAction some.action",
1576 "web_search_read",
1577 ]);
1578 });
1579
1580 test("Open new card in form view, without reloading the kanban view", async () => {
1581 defineActions([
1582 {
1583 id: 1,
1584 res_model: "partner",
1585 type: "ir.actions.act_window",
1586 views: [[false, "kanban"]],
1587 },
1588 {
1589 id: 2,
1590 xml_id: "some.action",
1591 res_model: "partner",
1592 type: "ir.actions.act_window",
1593 target: "new",
1594 views: [["create_view_ref", "form"]],
1595 },
1596 ]);
1597 Partner._views = {
1598 kanban: `
1599 <kanban on_create="some.action">
1600 <templates>
1601 <t t-name="card">
1602 <field name="foo"/>
1603 </t>
1604 </templates>
1605 </kanban>`,
1606 form: `
1607 <form>
1608 <field name="foo"/>
1609 </form>`,
1610 "form,create_view_ref": `
1611 <form>
1612 <field name="foo"/>
1613 <footer>
1614 <button string="Create Card" name="open_new_card" type="object" class="btn-primary"/>
1615 </footer>
1616 </form>`,
1617 search: `<search />`,
1618 };
1619 onRpc("/web/dataset/call_button/partner/open_new_card", () => {
1620 const newId = MockServer.env["partner"].create({ foo: "new" });
1621 return {
1622 type: "ir.actions.act_window",
1623 name: "Open Card",
1624 target: "current",
1625 res_model: "partner",
1626 res_id: newId,
1627 view_mode: "form",
1628 views: [[false, "form"]],
1629 };
1630 });
1631
1632 stepAllNetworkCalls();
1633
1634 await mountWithCleanup(WebClient);
1635 await getService("action").doAction(1);
1636
1637 expect(".o_kanban_record:not(.o_kanban_ghost)").toHaveCount(4);
1638 await createKanbanRecord();
1639 expect(`.modal`).toHaveCount(1);
1640 await contains(`.modal-footer button.btn-primary`).click();
1641 expect(`.modal`).toHaveCount(0);
1642 expect(".o_form_view").toHaveCount(1);
1643 // should not reload the first kanban view
1644 expect.verifySteps([
1645 "/web/webclient/translations",
1646 "/web/webclient/load_menus",
1647 "/web/action/load",
1648 "get_views",
1649 "web_search_read",
1650 "has_group",
1651 "/web/action/load",
1652 "get_views",
1653 "onchange",
1654 "web_save",
1655 "open_new_card",
1656 "get_views",
1657 "web_read",
1658 ]);
1659 });
1660
1661 test.tags("desktop");
1662 test("grouped kanban with quick_create attrs set to false", async () => {
1663 await mountView({
1664 type: "kanban",
1665 resModel: "partner",
1666 arch: `
1667 <kanban quick_create="false" on_create="quick_create">
1668 <templates>
1669 <t t-name="card">
1670 <field name="foo"/>
1671 </t>
1672 </templates>
1673 </kanban>`,
1674 groupBy: ["product_id"],
1675 createRecord: () => expect.step("create record"),
1676 });
1677
1678 expect(".o_kanban_group").toHaveCount(2);
1679 expect(".o_kanban_quick_add").toHaveCount(0);
1680
1681 await createKanbanRecord();
1682
1683 expect(".o_kanban_quick_create").toHaveCount(0);
1684 expect.verifySteps(["create record"]);
1685 });
1686
1687 test.tags("desktop");
1688 test("create in grouped on m2o", async () => {
1689 await mountView({
1690 type: "kanban",
1691 resModel: "partner",
1692 arch: `
1693 <kanban on_create="quick_create">
1694 <templates>
1695 <t t-name="card">
1696 <field name="foo"/>
1697 </t>
1698 </templates>
1699 </kanban>`,
1700 groupBy: ["product_id"],
1701 });
1702
1703 expect(".o_kanban_group.o_group_draggable").toHaveCount(2);
1704 expect(".o_control_panel_main_buttons button.o-kanban-button-new").toHaveCount(1);
1705 expect(".o_column_quick_create").toHaveCount(0, {
1706 message: "no quick create since no default groupby",
1707 });
1708
1709 await createKanbanRecord();
1710
1711 expect(".o_kanban_group:first-child > .o_kanban_quick_create").toHaveCount(1);
1712 expect(queryAllTexts(".o_column_title")).toEqual(["hello\n(2)", "xmo\n(2)"]);
1713 });
1714
1715 test("create in grouped on char", async () => {
1716 await mountView({
1717 type: "kanban",
1718 resModel: "partner",
1719 arch: `
1720 <kanban on_create="quick_create">
1721 <templates>
1722 <t t-name="card">
1723 <field name="foo"/>
1724 </t>
1725 </templates>
1726 </kanban>`,
1727 groupBy: ["foo"],
1728 });
1729
1730 expect(".o_kanban_group.o_group_draggable").toHaveCount(0);
1731 expect(".o_kanban_group").toHaveCount(3);
1732 expect(queryAllTexts(".o_column_title")).toEqual(["blip\n(2)", "gnap\n(1)", "yop\n(1)"]);
1733 expect(".o_kanban_group:first-child > .o_kanban_quick_create").toHaveCount(0);
1734 });
1735
1736 test("prevent deletion when grouped by many2many field", async () => {
1737 Partner._records[0].category_ids = [6, 7];
1738 Partner._records[3].category_ids = [7];
1739
1740 await mountView({
1741 type: "kanban",
1742 resModel: "partner",
1743 arch: `
1744 <kanban>
1745 <templates>
1746 <t t-name="card">
1747 <field name="foo"/>
1748 <t t-if="widget.deletable"><span class="thisisdeletable">delete</span></t>
1749 </t>
1750 </templates>
1751 </kanban>`,
1752 searchViewArch: `
1753 <search>
1754 <filter name="group_by_foo" domain="[]" string="GroupBy Foo" context="{ 'group_by': 'foo' }"/>
1755 </search>`,
1756 groupBy: ["category_ids"],
1757 });
1758
1759 expect(".thisisdeletable").toHaveCount(0, { message: "records should not be deletable" });
1760
1761 await toggleSearchBarMenu();
1762 await toggleMenuItem("GroupBy Foo");
1763
1764 expect(".thisisdeletable").toHaveCount(4, { message: "records should be deletable" });
1765 });
1766
1767 test.tags("desktop");
1768 test("kanban grouped by many2one: false column is folded by default", async () => {
1769 Partner._records[0].product_id = false;
1770
1771 await mountView({
1772 type: "kanban",
1773 resModel: "partner",
1774 arch: `
1775 <kanban>
1776 <templates>
1777 <t t-name="card">
1778 <field name="foo"/>
1779 </t>
1780 </templates>
1781 </kanban>`,
1782 groupBy: ["product_id"],
1783 });
1784
1785 expect(".o_kanban_group").toHaveCount(3);
1786 expect(".o_column_folded").toHaveCount(1);
1787 expect(queryAllTexts(".o_kanban_header")).toEqual(["None\n(1)", "hello\n(1)", "xmo\n(2)"]);
1788
1789 await contains(".o_kanban_header").click();
1790
1791 expect(".o_column_folded").toHaveCount(0);
1792 expect(queryAllTexts(".o_kanban_header")).toEqual(["None\n(1)", "hello\n(1)", "xmo\n(2)"]);
1793
1794 // reload -> None column should remain open
1795 await click(".o_searchview_input");
1796 await press("Enter");
1797 await animationFrame();
1798
1799 expect(".o_column_folded").toHaveCount(0);
1800 expect(queryAllTexts(".o_kanban_header")).toEqual(["None\n(1)", "hello\n(1)", "xmo\n(2)"]);
1801 });
1802
1803 test.tags("desktop");
1804 test("quick created records in grouped kanban are on displayed top", async () => {
1805 await mountView({
1806 type: "kanban",
1807 resModel: "partner",
1808 arch: `
1809 <kanban on_create="quick_create">
1810 <templates>
1811 <t t-name="card">
1812 <field name="display_name"/>
1813 </t>
1814 </templates>
1815 </kanban>`,
1816 groupBy: ["product_id"],
1817 });
1818
1819 expect(".o_kanban_group").toHaveCount(2);
1820 expect(".o_kanban_group:first .o_kanban_record").toHaveCount(2);
1821
1822 await createKanbanRecord();
1823
1824 expect(".o_kanban_group:first .o_kanban_record").toHaveCount(2);
1825 expect(".o_kanban_group:first .o_kanban_quick_create").toHaveCount(1);
1826
1827 await edit("new record");
1828 await validateKanbanRecord();
1829
1830 expect(".o_kanban_group:first .o_kanban_record").toHaveCount(3);
1831 expect(".o_kanban_group:first .o_kanban_quick_create").toHaveCount(1);
1832 // the new record must be the first record of the column
1833 expect(queryAllTexts(" .o_kanban_group:first .o_kanban_record")).toEqual([
1834 "new record",
1835 "yop",
1836 "gnap",
1837 ]);
1838
1839 await click(".o_kanban_quick_create input"); // FIXME: should not be necessary
1840 await edit("another record");
1841 await validateKanbanRecord();
1842
1843 expect(".o_kanban_group:first .o_kanban_record").toHaveCount(4);
1844 expect(".o_kanban_group:first .o_kanban_quick_create").toHaveCount(1);
1845 expect(queryAllTexts(".o_kanban_group:first .o_kanban_record")).toEqual([
1846 "another record",
1847 "new record",
1848 "yop",
1849 "gnap",
1850 ]);
1851 });
1852
1853 test.tags("desktop");
1854 test("quick create record without quick_create_view", async () => {
1855 stepAllNetworkCalls();
1856 onRpc("name_create", ({ args }) => {
1857 expect(args[0]).toBe("new partner");
1858 });
1859
1860 await mountView({
1861 type: "kanban",
1862 resModel: "partner",
1863 arch: `
1864 <kanban on_create="quick_create">
1865 <templates>
1866 <t t-name="card">
1867 <field name="foo"/>
1868 </t>
1869 </templates>
1870 </kanban>`,
1871 groupBy: ["bar"],
1872 });
1873
1874 expect(".o_kanban_group:first-child .o_kanban_record").toHaveCount(1);
1875
1876 // click on 'Create' -> should open the quick create in the first column
1877 await createKanbanRecord();
1878
1879 expect(".o_kanban_group:first-child .o_kanban_quick_create").toHaveCount(1);
1880 expect(".o_kanban_quick_create .o_form_view.o_xxs_form_view").toHaveCount(1);
1881 expect(".o_kanban_quick_create input").toHaveCount(1);
1882 expect(
1883 ".o_kanban_quick_create .o_field_widget.o_required_modifier input[placeholder=Title]"
1884 ).toHaveCount(1);
1885
1886 // fill the quick create and validate
1887 await editKanbanRecordQuickCreateInput("display_name", "new partner");
1888 await validateKanbanRecord();
1889
1890 expect(".o_kanban_group:first-child .o_kanban_record").toHaveCount(2);
1891
1892 expect.verifySteps([
1893 "/web/webclient/translations",
1894 "/web/webclient/load_menus",
1895 "get_views",
1896 "web_read_group", // initial web_read_group
1897 "has_group",
1898 "onchange", // quick create
1899 "name_create", // should perform a name_create to create the record
1900 "onchange", // reopen the quick create automatically
1901 "web_read", // read the created record
1902 ]);
1903 });
1904
1905 test.tags("desktop");
1906 test("quick create record with quick_create_view", async () => {
1907 Partner._views["form,some_view_ref"] = `
1908 <form>
1909 <field name="foo"/>
1910 <field name="int_field"/>
1911 <field name="state" widget="priority"/>
1912 </form>`;
1913
1914 stepAllNetworkCalls();
1915 onRpc("web_save", ({ args }) => {
1916 expect(args[1]).toEqual({
1917 foo: "new partner",
1918 int_field: 4,
1919 state: "def",
1920 });
1921 });
1922
1923 await mountView({
1924 type: "kanban",
1925 resModel: "partner",
1926 arch: `
1927 <kanban on_create="quick_create" quick_create_view="some_view_ref">
1928 <templates>
1929 <t t-name="card">
1930 <field name="foo"/>
1931 </t>
1932 </templates>
1933 </kanban>`,
1934 groupBy: ["bar"],
1935 });
1936
1937 expect(".o_control_panel").toHaveCount(1);
1938 expect(".o_kanban_group:first-child .o_kanban_record").toHaveCount(1);
1939
1940 // click on 'Create' -> should open the quick create in the first column
1941 await createKanbanRecord();
1942
1943 expect(".o_kanban_group:first-child .o_kanban_quick_create").toHaveCount(1);
1944 expect(".o_kanban_quick_create .o_form_view.o_xxs_form_view").toHaveCount(1);
1945 expect(".o_control_panel").toHaveCount(1, {
1946 message: "should not have instantiated another control panel",
1947 });
1948 expect(".o_kanban_quick_create input").toHaveCount(2);
1949 expect(".o_kanban_quick_create .o_field_widget").toHaveCount(3);
1950
1951 // fill the quick create and validate
1952 await editKanbanRecordQuickCreateInput("foo", "new partner");
1953 await editKanbanRecordQuickCreateInput("int_field", "4");
1954 await click(".o_kanban_quick_create .o_field_widget[name=state] .o_priority_star:first-child");
1955 await validateKanbanRecord();
1956 expect(".o_kanban_group:first-child .o_kanban_record").toHaveCount(2);
1957
1958 expect.verifySteps([
1959 "/web/webclient/translations",
1960 "/web/webclient/load_menus",
1961 "get_views",
1962 "web_read_group", // initial web_read_group
1963 "has_group",
1964 "get_views", // form view in quick create
1965 "onchange", // quick create
1966 "web_save", // should perform a web_save to create the record
1967 "onchange", // new quick create
1968 "web_read", // read the created record
1969 ]);
1970 });
1971
1972 test.tags("desktop");
1973 test("quick create record flickering", async () => {
1974 let def;
1975 Partner._views["form,some_view_ref"] = `
1976 <form>
1977 <field name="foo"/>
1978 <field name="int_field"/>
1979 <field name="state" widget="priority"/>
1980 </form>`;
1981
1982 onRpc("web_save", ({ args }) => {
1983 expect(args[1]).toEqual({
1984 foo: "new partner",
1985 int_field: 4,
1986 state: "def",
1987 });
1988 });
1989 onRpc("onchange", () => def);
1990
1991 await mountView({
1992 type: "kanban",
1993 resModel: "partner",
1994 arch: `
1995 <kanban on_create="quick_create" quick_create_view="some_view_ref">
1996 <templates>
1997 <t t-name="card">
1998 <field name="foo"/>
1999 </t>
2000 </templates>
2001 </kanban>`,
2002 groupBy: ["bar"],
2003 });
2004
2005 // click on 'Create' -> should open the quick create in the first column
2006 await createKanbanRecord();
2007
2008 expect(".o_kanban_group:first-child .o_kanban_record").toHaveCount(1);
2009 expect(".o_kanban_group:first-child .o_kanban_quick_create").toHaveCount(1);
2010 expect(".o_kanban_quick_create .o_form_view.o_xxs_form_view").toHaveCount(1);
2011 expect(".o_kanban_quick_create input").toHaveCount(2);
2012 expect(".o_kanban_quick_create .o_field_widget").toHaveCount(3);
2013
2014 // fill the quick create and validate
2015 await editKanbanRecordQuickCreateInput("foo", "new partner");
2016 await editKanbanRecordQuickCreateInput("int_field", "4");
2017
2018 await click(".o_kanban_quick_create .o_field_widget[name=state] .o_priority_star:first-child");
2019 def = new Deferred();
2020 await validateKanbanRecord();
2021
2022 expect(".o_kanban_group:first-child .o_kanban_record").toHaveCount(2);
2023 expect(".o_kanban_group:first-child .o_kanban_quick_create").toHaveCount(1);
2024
2025 def.resolve();
2026 await animationFrame();
2027
2028 expect(".o_kanban_group:first-child .o_kanban_record").toHaveCount(2);
2029 expect(".o_kanban_group:first-child .o_kanban_quick_create").toHaveCount(1);
2030 });
2031
2032 test.tags("desktop");
2033 test("quick create record flickering (load more)", async () => {
2034 let def;
2035 Partner._views["form,some_view_ref"] = `<form><field name="foo"/></form>`;
2036
2037 onRpc("read", () => def);
2038
2039 await mountView({
2040 type: "kanban",
2041 resModel: "partner",
2042 arch: `
2043 <kanban on_create="quick_create" quick_create_view="some_view_ref">
2044 <templates>
2045 <t t-name="card">
2046 <field name="foo"/>
2047 </t>
2048 </templates>
2049 </kanban>`,
2050 groupBy: ["bar"],
2051 });
2052
2053 // click on 'Create' -> should open the quick create in the first column
2054 await createKanbanRecord();
2055
2056 // fill the quick create and validate
2057 await editKanbanRecordQuickCreateInput("foo", "new partner");
2058 def = new Deferred();
2059 await validateKanbanRecord();
2060 expect(".o_kanban_load_more").toHaveCount(0);
2061 def.resolve();
2062 await animationFrame();
2063 expect(".o_kanban_load_more").toHaveCount(0);
2064 });
2065
2066 test.tags("desktop");
2067 test("quick create record should focus default field", async function () {
2068 Partner._views["form,some_view_ref"] = `
2069 <form>
2070 <field name="foo"/>
2071 <field name="int_field" default_focus="1"/>
2072 <field name="state" widget="priority"/>
2073 </form>`;
2074
2075 await mountView({
2076 type: "kanban",
2077 resModel: "partner",
2078 arch: `
2079 <kanban on_create="quick_create" quick_create_view="some_view_ref">
2080 <templates>
2081 <t t-name="card">
2082 <field name="foo"/>
2083 </t>
2084 </templates>
2085 </kanban>`,
2086 groupBy: ["bar"],
2087 });
2088
2089 await createKanbanRecord();
2090
2091 expect(".o_field_widget[name=int_field] input:first").toBeFocused();
2092 });
2093
2094 test.tags("desktop");
2095 test("quick create record should focus first field input", async function () {
2096 Partner._views["form,some_view_ref"] = `
2097 <form>
2098 <field name="foo"/>
2099 <field name="int_field"/>
2100 <field name="state" widget="priority"/>
2101 </form>`;
2102
2103 await mountView({
2104 type: "kanban",
2105 resModel: "partner",
2106 arch: `
2107 <kanban on_create="quick_create" quick_create_view="some_view_ref">
2108 <templates>
2109 <t t-name="card">
2110 <field name="foo"/>
2111 </t>
2112 </templates>
2113 </kanban>`,
2114 groupBy: ["bar"],
2115 });
2116
2117 await createKanbanRecord();
2118
2119 expect(".o_field_widget[name=foo] input:first").toBeFocused();
2120 });
2121
2122 test.tags("desktop");
2123 test("quick_create_view without quick_create option", async () => {
2124 Partner._views["form,some_view_ref"] = `
2125 <form>
2126 <field name="display_name"/>
2127 </form>`;
2128
2129 await mountView({
2130 type: "kanban",
2131 resModel: "partner",
2132 arch: `
2133 <kanban quick_create_view="some_view_ref">
2134 <templates>
2135 <t t-name="card">
2136 <field name="foo"/>
2137 </t>
2138 </templates>
2139 </kanban>`,
2140 groupBy: ["bar"],
2141 createRecord() {
2142 expect.step("create record");
2143 },
2144 });
2145
2146 expect(".o_kanban_group").toHaveCount(2);
2147 expect(".o_kanban_group .o_kanban_quick_add").toHaveCount(2);
2148
2149 // click on 'Create' in control panel -> should not open the quick create
2150 await createKanbanRecord();
2151 expect(".o_kanban_quick_create").toHaveCount(0);
2152 expect.verifySteps(["create record"]);
2153
2154 // click "+" icon in first column -> should open the quick create
2155 await contains(".o_kanban_quick_add").click();
2156 await animationFrame();
2157 expect(".o_kanban_group:first .o_kanban_quick_create").toHaveCount(1);
2158 expect.verifySteps([]);
2159 });
2160
2161 test.tags("desktop");
2162 test("quick create record in grouped on m2o (no quick_create_view)", async () => {
2163 expect.assertions(6);
2164
2165 stepAllNetworkCalls();
2166 onRpc("name_create", ({ args, kwargs }) => {
2167 expect(args[0]).toBe("new partner");
2168 const { default_product_id, default_float_field } = kwargs.context;
2169 expect(default_product_id).toBe(3);
2170 expect(default_float_field).toBe(2.5);
2171 });
2172
2173 await mountView({
2174 type: "kanban",
2175 resModel: "partner",
2176 arch: `
2177 <kanban on_create="quick_create">
2178 <templates>
2179 <t t-name="card">
2180 <field name="foo"/>
2181 </t>
2182 </templates>
2183 </kanban>`,
2184 groupBy: ["product_id"],
2185 context: { default_float_field: 2.5 },
2186 });
2187
2188 expect(".o_kanban_group:first-child .o_kanban_record").toHaveCount(2);
2189
2190 // click on 'Create', fill the quick create and validate
2191 await createKanbanRecord();
2192 await editKanbanRecordQuickCreateInput("display_name", "new partner");
2193 await validateKanbanRecord();
2194
2195 expect(".o_kanban_group:first-child .o_kanban_record").toHaveCount(3);
2196
2197 expect.verifySteps([
2198 "/web/webclient/translations",
2199 "/web/webclient/load_menus",
2200 "get_views",
2201 "web_read_group", // initial web_read_group
2202 "has_group",
2203 "onchange", // quick create
2204 "name_create", // should perform a name_create to create the record
2205 "onchange", // reopen the quick create automatically
2206 "web_read", // read the created record
2207 ]);
2208 });
2209
2210 test.tags("desktop");
2211 test("quick create record in grouped on m2o (with quick_create_view)", async () => {
2212 expect.assertions(6);
2213
2214 Partner._views["form,some_view_ref"] = `
2215 <form>
2216 <field name="foo"/>
2217 <field name="int_field"/>
2218 <field name="state" widget="priority"/>
2219 </form>`;
2220
2221 stepAllNetworkCalls();
2222 onRpc("web_save", ({ method, args, kwargs }) => {
2223 expect(args[1]).toEqual({
2224 foo: "new partner",
2225 int_field: 4,
2226 state: "def",
2227 });
2228 const { default_product_id, default_float_field } = kwargs.context;
2229 expect(default_product_id).toBe(3);
2230 expect(default_float_field).toBe(2.5);
2231 });
2232
2233 await mountView({
2234 type: "kanban",
2235 resModel: "partner",
2236 arch: `
2237 <kanban on_create="quick_create" quick_create_view="some_view_ref">
2238 <templates>
2239 <t t-name="card">
2240 <field name="foo"/>
2241 </t>
2242 </templates>
2243 </kanban>`,
2244 groupBy: ["product_id"],
2245 context: { default_float_field: 2.5 },
2246 });
2247
2248 expect(".o_kanban_group:first-child .o_kanban_record").toHaveCount(2);
2249
2250 // click on 'Create', fill the quick create and validate
2251 await createKanbanRecord();
2252 await editKanbanRecordQuickCreateInput("foo", "new partner");
2253 await animationFrame();
2254 await editKanbanRecordQuickCreateInput("int_field", 4);
2255 await animationFrame();
2256 await contains(
2257 ".o_kanban_quick_create .o_field_widget[name=state] .o_priority_star:first-child"
2258 ).click();
2259 await validateKanbanRecord();
2260
2261 expect(".o_kanban_group:first-child .o_kanban_record").toHaveCount(3);
2262 expect.verifySteps([
2263 "/web/webclient/translations",
2264 "/web/webclient/load_menus",
2265 "get_views",
2266 "web_read_group", // initial web_read_group
2267 "has_group",
2268 "get_views", // form view in quick create
2269 "onchange", // quick create
2270 "web_save", // should perform a web_save to create the record
2271 "onchange", // reopen the quick create automatically
2272 "web_read", // read the created record
2273 ]);
2274 });
2275
2276 test("quick create record in grouped on m2m (no quick_create_view)", async () => {
2277 stepAllNetworkCalls();
2278 onRpc("name_create", ({ args, kwargs }) => {
2279 expect(args[0]).toBe("new partner");
2280 expect(kwargs.context.default_category_ids).toEqual([6]);
2281 });
2282
2283 await mountView({
2284 type: "kanban",
2285 resModel: "partner",
2286 arch: `
2287 <kanban on_create="quick_create">
2288 <templates>
2289 <t t-name="card">
2290 <field name="foo"/>
2291 </t>
2292 </templates>
2293 </kanban>`,
2294 groupBy: ["category_ids"],
2295 });
2296
2297 expect(".o_kanban_group:nth-child(2) .o_kanban_record").toHaveCount(1);
2298
2299 // click on 'Create', fill the quick create and validate
2300 await quickCreateKanbanRecord(1);
2301 await editKanbanRecordQuickCreateInput("display_name", "new partner");
2302 await animationFrame();
2303 await validateKanbanRecord();
2304
2305 expect(".o_kanban_group:nth-child(2) .o_kanban_record").toHaveCount(2);
2306 expect.verifySteps([
2307 "/web/webclient/translations",
2308 "/web/webclient/load_menus",
2309 "get_views",
2310 "web_read_group", // initial web_read_group
2311 "has_group",
2312 "onchange", // quick create
2313 "name_create", // should perform a name_create to create the record
2314 "onchange", // reopen the quick create automatically
2315 "web_read", // read the created record
2316 ]);
2317 });
2318
2319 test.tags("desktop");
2320 test("quick create record in grouped on m2m in the None column", async () => {
2321 stepAllNetworkCalls();
2322 onRpc("name_create", ({ args, kwargs }) => {
2323 expect(args[0]).toBe("new partner");
2324 expect(kwargs.context.default_category_ids).toBe(false);
2325 });
2326
2327 await mountView({
2328 type: "kanban",
2329 resModel: "partner",
2330 arch: `
2331 <kanban on_create="quick_create">
2332 <templates>
2333 <t t-name="card">
2334 <field name="foo"/>
2335 </t>
2336 </templates>
2337 </kanban>`,
2338 groupBy: ["category_ids"],
2339 });
2340
2341 await contains(".o_kanban_group:nth-child(1)").click();
2342
2343 expect(".o_kanban_group:nth-child(1) .o_kanban_record").toHaveCount(2);
2344
2345 // click on 'Create', fill the quick create and validate
2346 await quickCreateKanbanRecord(0);
2347 await editKanbanRecordQuickCreateInput("display_name", "new partner");
2348 await animationFrame();
2349 await validateKanbanRecord();
2350
2351 expect(".o_kanban_group:nth-child(1) .o_kanban_record").toHaveCount(3);
2352 expect.verifySteps([
2353 "/web/webclient/translations",
2354 "/web/webclient/load_menus",
2355 "get_views",
2356 "web_read_group", // initial web_read_group
2357 "has_group",
2358 "web_search_read", // read records when unfolding 'None'
2359 "onchange", // quick create
2360 "name_create", // should perform a name_create to create the record
2361 "onchange", // reopen the quick create automatically
2362 "web_read", // read the created record
2363 ]);
2364 });
2365
2366 test("quick create record in grouped on m2m (field not in template)", async () => {
2367 Partner._views["form,some_view_ref"] = `<form><field name="foo"/></form>`;
2368
2369 onRpc("web_save", ({ args, kwargs }) => {
2370 expect(args[1]).toEqual({ foo: "new partner" });
2371 expect(kwargs.context.default_category_ids).toEqual([6]);
2372 return [{ id: 5 }];
2373 });
2374 onRpc("web_read", ({ args }) => {
2375 if (args[0][0] === 5) {
2376 return [{ id: 5, foo: "new partner", category_ids: [6] }];
2377 }
2378 });
2379 stepAllNetworkCalls();
2380
2381 await mountView({
2382 type: "kanban",
2383 resModel: "partner",
2384 arch: `
2385 <kanban on_create="quick_create" quick_create_view="some_view_ref">
2386 <templates>
2387 <t t-name="card">
2388 <field name="foo"/>
2389 </t>
2390 </templates>
2391 </kanban>`,
2392 groupBy: ["category_ids"],
2393 });
2394
2395 expect(".o_kanban_group:nth-child(2) .o_kanban_record").toHaveCount(1);
2396
2397 // click on 'Create', fill the quick create and validate
2398 await quickCreateKanbanRecord(1);
2399 await editKanbanRecordQuickCreateInput("foo", "new partner");
2400 await validateKanbanRecord();
2401
2402 expect(".o_kanban_group:nth-child(2) .o_kanban_record").toHaveCount(2);
2403
2404 expect.verifySteps([
2405 "/web/webclient/translations",
2406 "/web/webclient/load_menus",
2407 "get_views",
2408 "web_read_group", // initial web_read_group
2409 "has_group",
2410 "get_views", // get form view
2411 "onchange", // quick create
2412 "web_save", // should perform a web_save to create the record
2413 "onchange", // reopen the quick create automatically
2414 "web_read", // read the created record
2415 ]);
2416 });
2417
2418 test("quick create record in grouped on m2m (field in the form view)", async () => {
2419 Partner._views["form,some_view_ref"] = `
2420 <form>
2421 <field name="foo"/>
2422 <field name="category_ids" widget="many2many_tags"/>
2423 </form>`;
2424
2425 stepAllNetworkCalls();
2426 onRpc("web_save", ({ method, args, kwargs }) => {
2427 expect(args[1]).toEqual({
2428 category_ids: [[4, 6]],
2429 foo: "new partner",
2430 });
2431 expect(kwargs.context.default_category_ids).toEqual([6]);
2432 });
2433
2434 await mountView({
2435 type: "kanban",
2436 resModel: "partner",
2437 arch: `
2438 <kanban on_create="quick_create" quick_create_view="some_view_ref">
2439 <templates>
2440 <t t-name="card">
2441 <field name="foo"/>
2442 </t>
2443 </templates>
2444 </kanban>`,
2445 groupBy: ["category_ids"],
2446 });
2447
2448 expect(".o_kanban_group:nth-child(2) .o_kanban_record").toHaveCount(1);
2449
2450 // click on 'Create', fill the quick create and validate
2451 await quickCreateKanbanRecord(1);
2452
2453 // verify that the quick create m2m field contains the column value
2454 expect(".o_tag_badge_text").toHaveCount(1);
2455 expect(".o_tag_badge_text").toHaveText("gold");
2456
2457 await editKanbanRecordQuickCreateInput("foo", "new partner");
2458 await validateKanbanRecord();
2459
2460 expect(".o_kanban_group:nth-child(2) .o_kanban_record").toHaveCount(2);
2461
2462 expect.verifySteps([
2463 "/web/webclient/translations",
2464 "/web/webclient/load_menus",
2465 "get_views",
2466 "web_read_group", // initial web_read_group
2467 "has_group",
2468 "get_views", // get form view
2469 "onchange", // quick create
2470 "web_save", // should perform a web_save to create the record
2471 "onchange",
2472 "web_read",
2473 ]);
2474 });
2475
2476 test.tags("desktop");
2477 test("quick create record validation: stays open when invalid", async () => {
2478 stepAllNetworkCalls();
2479
2480 await mountView({
2481 type: "kanban",
2482 resModel: "partner",
2483 arch: `
2484 <kanban on_create="quick_create">
2485 <templates>
2486 <t t-name="card">
2487 <field name="foo"/>
2488 </t>
2489 </templates>
2490 </kanban>`,
2491 groupBy: ["bar"],
2492 });
2493
2494 expect.verifySteps([
2495 "/web/webclient/translations",
2496 "/web/webclient/load_menus",
2497 "get_views",
2498 "web_read_group",
2499 "has_group",
2500 ]);
2501
2502 await createKanbanRecord();
2503 expect.verifySteps(["onchange"]);
2504
2505 // do not fill anything and validate
2506 await validateKanbanRecord();
2507
2508 expect.verifySteps([]);
2509 expect(".o_kanban_group:first-child .o_kanban_quick_create").toHaveCount(1);
2510 expect("[name=display_name]").toHaveClass("o_field_invalid");
2511 expect(".o_notification_manager .o_notification").toHaveCount(1);
2512 expect(".o_notification").toHaveText("Invalid Display Name");
2513 });
2514
2515 test.tags("desktop");
2516 test("quick create record with default values and onchanges", async () => {
2517 Partner._fields.int_field = fields.Integer({ default: 4 });
2518 Partner._fields.foo = fields.Char({
2519 onChange: (obj) => {
2520 if (obj.foo) {
2521 obj.int_field = 8;
2522 }
2523 },
2524 });
2525 Partner._views["form,some_view_ref"] = `
2526 <form>
2527 <field name="foo"/>
2528 <field name="int_field"/>
2529 </form>`;
2530
2531 stepAllNetworkCalls();
2532
2533 await mountView({
2534 type: "kanban",
2535 resModel: "partner",
2536 arch: `
2537 <kanban on_create="quick_create" quick_create_view="some_view_ref">
2538 <templates>
2539 <t t-name="card">
2540 <field name="foo"/>
2541 </t>
2542 </templates>
2543 </kanban>`,
2544 groupBy: ["bar"],
2545 });
2546
2547 // click on 'Create' -> should open the quick create in the first column
2548 await createKanbanRecord();
2549
2550 expect(".o_kanban_group:first-child .o_kanban_quick_create").toHaveCount(1);
2551 expect(".o_field_widget[name=int_field] input").toHaveValue("4", {
2552 message: "default value should be set",
2553 });
2554
2555 // fill the 'foo' field -> should trigger the onchange
2556 // await fieldInput("foo").edit("new partner");
2557 await editKanbanRecordQuickCreateInput("foo", "new partner");
2558
2559 expect(".o_field_widget[name=int_field] input").toHaveValue("8", {
2560 message: "onchange should have been triggered",
2561 });
2562 expect.verifySteps([
2563 "/web/webclient/translations",
2564 "/web/webclient/load_menus",
2565 "get_views",
2566 "web_read_group", // initial web_read_group
2567 "has_group",
2568 "get_views", // form view in quick create
2569 "onchange", // quick create
2570 "onchange", // onchange due to 'foo' field change
2571 ]);
2572 });
2573
2574 test("quick create record with quick_create_view: modifiers", async () => {
2575 Partner._views["form,some_view_ref"] = `
2576 <form>
2577 <field name="foo" required="1"/>
2578 <field name="int_field" invisible="not foo"/>
2579 </form>`;
2580
2581 await mountView({
2582 type: "kanban",
2583 resModel: "partner",
2584 arch: `
2585 <kanban quick_create_view="some_view_ref">
2586 <templates>
2587 <t t-name="card">
2588 <field name="foo"/>
2589 </t>
2590 </templates>
2591 </kanban>`,
2592 groupBy: ["bar"],
2593 });
2594
2595 // create a new record
2596 await quickCreateKanbanRecord();
2597
2598 expect(".o_kanban_quick_create .o_field_widget[name=foo]").toHaveClass("o_required_modifier");
2599 expect(".o_kanban_quick_create .o_field_widget[name=int_field]").toHaveCount(0);
2600
2601 // fill 'foo' field
2602 await editKanbanRecordQuickCreateInput("foo", "new partner");
2603 await animationFrame();
2604
2605 expect(".o_kanban_quick_create .o_field_widget[name=int_field]").toHaveCount(1);
2606 });
2607
2608 test("quick create record with onchange of field marked readonly", async () => {
2609 Partner._fields.foo = fields.Char({
2610 onChange: (obj) => {
2611 obj.int_field = 8;
2612 },
2613 });
2614 Partner._views["form,some_view_ref"] = `
2615 <form>
2616 <field name="foo"/>
2617 <field name="int_field" readonly="true"/>
2618 </form>`;
2619
2620 stepAllNetworkCalls();
2621 onRpc("web_save", ({ method, args }) => {
2622 expect(args[1].int_field).toBe(undefined, {
2623 message: "readonly field shouldn't be sent in create",
2624 });
2625 });
2626
2627 await mountView({
2628 type: "kanban",
2629 resModel: "partner",
2630 arch: `
2631 <kanban on_create="quick_create" quick_create_view="some_view_ref">
2632 <templates>
2633 <t t-name="card">
2634 <field name="foo"/>
2635 </t>
2636 </templates>
2637 </kanban>`,
2638 groupBy: ["bar"],
2639 });
2640 expect.verifySteps([
2641 "/web/webclient/translations",
2642 "/web/webclient/load_menus",
2643 "get_views",
2644 "web_read_group", // initial web_read_group
2645 "has_group",
2646 ]);
2647
2648 // click on 'Create' -> should open the quick create in the first column
2649 await quickCreateKanbanRecord();
2650 expect.verifySteps(["get_views", "onchange"]);
2651
2652 // fill the 'foo' field -> should trigger the onchange
2653 await editKanbanRecordQuickCreateInput("foo", "new partner");
2654 expect.verifySteps(["onchange"]);
2655
2656 await validateKanbanRecord();
2657 expect.verifySteps(["web_save", "onchange", "web_read"]);
2658 });
2659
2660 test("quick create record and change state in grouped mode", async () => {
2661 Partner._fields.kanban_state = fields.Selection({
2662 selection: [
2663 ["normal", "Grey"],
2664 ["done", "Green"],
2665 ["blocked", "Red"],
2666 ],
2667 });
2668
2669 await mountView({
2670 type: "kanban",
2671 resModel: "partner",
2672 arch: `
2673 <kanban on_create="quick_create">
2674 <templates>
2675 <div t-name="card">
2676 <field name="foo"/>
2677 <footer>
2678 <field name="kanban_state" widget="state_selection"/>
2679 </footer>
2680 </div>
2681 </templates>
2682 </kanban>`,
2683 groupBy: ["foo"],
2684 });
2685
2686 // Quick create kanban record
2687 await quickCreateKanbanRecord();
2688 await editKanbanRecordQuickCreateInput("display_name", "Test");
2689 await validateKanbanRecord();
2690
2691 // Select state in kanban
2692 await click(".o_status", { root: getKanbanRecord({ index: 0 }) });
2693 await animationFrame();
2694 await contains(".dropdown-item:nth-child(2)").click();
2695
2696 expect(".o_status:first").toHaveClass("o_status_green");
2697 });
2698
2699 test("window resize should not change quick create form size", async () => {
2700 await mountView({
2701 type: "kanban",
2702 resModel: "partner",
2703 arch: `
2704 <kanban on_create="quick_create">
2705 <templates>
2706 <t t-name="card">
2707 <field name="foo"/>
2708 </t>
2709 </templates>
2710 </kanban>`,
2711 groupBy: ["bar"],
2712 });
2713
2714 await quickCreateKanbanRecord();
2715
2716 expect(".o_kanban_quick_create .o_form_view").toHaveClass("o_xxs_form_view");
2717
2718 await resize({ width: 800, height: 400 });
2719
2720 expect(".o_kanban_quick_create .o_form_view").toHaveClass("o_xxs_form_view");
2721 });
2722
2723 test("quick create record: cancel and validate without using the buttons", async () => {
2724 Partner._views["form,some_view_ref"] = `<form><field name="foo"/></form>`;
2725
2726 await mountView({
2727 type: "kanban",
2728 resModel: "partner",
2729 arch: `
2730 <kanban quick_create_view="some_view_ref" on_create="quick_create">
2731 <templates>
2732 <t t-name="card">
2733 <field name="foo"/>
2734 </t>
2735 </templates>
2736 </kanban>`,
2737 groupBy: ["bar"],
2738 });
2739
2740 expect(".o_kanban_record:not(.o_kanban_ghost)").toHaveCount(4);
2741
2742 // click to add an element and cancel the quick creation by pressing ESC
2743 await quickCreateKanbanRecord();
2744
2745 expect(".o_kanban_quick_create").toHaveCount(1);
2746
2747 await press("Escape");
2748 await animationFrame();
2749
2750 expect(".o_kanban_quick_create").toHaveCount(0);
2751
2752 // click to add and element and click outside, should cancel the quick creation
2753 await quickCreateKanbanRecord();
2754 await contains(".o_kanban_group:first-child .o_kanban_record:last-of-type").click();
2755 expect(".o_kanban_quick_create").toHaveCount(0);
2756
2757 // click to input and drag the mouse outside, should not cancel the quick creation
2758 await quickCreateKanbanRecord();
2759 await (
2760 await drag(".o_kanban_quick_create input")
2761 ).drop(".o_kanban_group:first-child .o_kanban_record:last-of-type");
2762 await animationFrame();
2763 expect(".o_kanban_quick_create").toHaveCount(1, {
2764 message: "the quick create should not have been destroyed after clicking outside",
2765 });
2766
2767 // click to really add an element
2768 await quickCreateKanbanRecord();
2769 await editKanbanRecordQuickCreateInput("foo", "new partner");
2770
2771 // clicking outside should no longer destroy the quick create as it is dirty
2772 await contains(".o_kanban_group:first-child .o_kanban_record:last-of-type").click();
2773 expect(".o_kanban_quick_create").toHaveCount(1, {
2774 message: "the quick create should not have been destroyed",
2775 });
2776
2777 // confirm by pressing ENTER
2778 await press("Enter");
2779 await animationFrame();
2780
2781 expect(".o_kanban_record:not(.o_kanban_ghost)").toHaveCount(5);
2782 expect(getKanbanRecordTexts(0)).toEqual(["new partner", "blip"]);
2783 });
2784
2785 test("quick create record: validate with ENTER", async () => {
2786 Partner._views["form,some_view_ref"] = `
2787 <form>
2788 <field name="foo"/>
2789 <field name="int_field"/>
2790 </form>`;
2791
2792 await mountView({
2793 type: "kanban",
2794 resModel: "partner",
2795 arch: `
2796 <kanban on_create="quick_create" quick_create_view="some_view_ref">
2797 <templates>
2798 <t t-name="card">
2799 <field name="foo"/>
2800 </t>
2801 </templates>
2802 </kanban>`,
2803 groupBy: ["bar"],
2804 });
2805
2806 expect(".o_kanban_record").toHaveCount(4);
2807
2808 // add an element and confirm by pressing ENTER
2809 await quickCreateKanbanRecord();
2810 await editKanbanRecordQuickCreateInput("foo", "new partner");
2811 await validateKanbanRecord();
2812
2813 expect(".o_kanban_record").toHaveCount(5);
2814 expect(".o_kanban_quick_create .o_field_widget[name=foo] input").toHaveValue("");
2815 });
2816
2817 test("quick create record: prevent multiple adds with ENTER", async () => {
2818 Partner._views["form,some_view_ref"] = `
2819 <form>
2820 <field name="foo"/>
2821 <field name="int_field"/>
2822 </form>`;
2823
2824 const def = new Deferred();
2825 onRpc("web_save", () => {
2826 expect.step("web_save");
2827 return def;
2828 });
2829
2830 await mountView({
2831 type: "kanban",
2832 resModel: "partner",
2833 arch: `
2834 <kanban on_create="quick_create" quick_create_view="some_view_ref">
2835 <templates>
2836 <t t-name="card">
2837 <field name="foo"/>
2838 </t>
2839 </templates>
2840 </kanban>`,
2841 groupBy: ["bar"],
2842 });
2843
2844 expect(".o_kanban_record").toHaveCount(4);
2845
2846 // add an element and press ENTER twice
2847 await quickCreateKanbanRecord();
2848 await editKanbanRecordQuickCreateInput("foo", "new partner");
2849 await press("Enter");
2850 await animationFrame();
2851
2852 expect(".o_kanban_record").toHaveCount(4);
2853 expect(".o_kanban_quick_create .o_field_widget[name=foo] input").toHaveValue("new partner");
2854 expect(".o_kanban_quick_create").toHaveClass("o_disabled");
2855
2856 def.resolve();
2857 await animationFrame();
2858
2859 expect(".o_kanban_record").toHaveCount(5);
2860 expect(".o_kanban_quick_create .o_field_widget[name=foo] input").toHaveValue("");
2861 expect(".o_kanban_quick_create").not.toHaveClass("o_disabled");
2862
2863 expect.verifySteps(["web_save"]);
2864 });
2865
2866 test("quick create record: prevent multiple adds with Add clicked", async () => {
2867 Partner._views["form,some_view_ref"] = `
2868 <form>
2869 <field name="foo"/>
2870 <field name="int_field"/>
2871 </form>`;
2872
2873 const def = new Deferred();
2874 onRpc("web_save", () => {
2875 expect.step("web_save");
2876 return def;
2877 });
2878
2879 await mountView({
2880 type: "kanban",
2881 resModel: "partner",
2882 arch: `
2883 <kanban on_create="quick_create" quick_create_view="some_view_ref">
2884 <templates>
2885 <t t-name="card">
2886 <field name="foo"/>
2887 </t>
2888 </templates>
2889 </kanban>`,
2890 groupBy: ["bar"],
2891 });
2892
2893 expect(".o_kanban_record").toHaveCount(4);
2894
2895 // add an element and click 'Add' twice
2896 await quickCreateKanbanRecord();
2897 await editKanbanRecordQuickCreateInput("foo", "new partner");
2898 await validateKanbanRecord();
2899 await validateKanbanRecord();
2900
2901 expect(".o_kanban_record").toHaveCount(4);
2902 expect(".o_kanban_quick_create .o_field_widget[name=foo] input").toHaveValue("new partner");
2903 expect(".o_kanban_quick_create").toHaveClass("o_disabled");
2904
2905 def.resolve();
2906 await animationFrame();
2907
2908 expect(".o_kanban_record").toHaveCount(5);
2909 expect(".o_kanban_quick_create .o_field_widget[name=foo] input").toHaveValue("");
2910 expect(".o_kanban_quick_create").not.toHaveClass("o_disabled");
2911
2912 expect.verifySteps(["web_save"]);
2913 });
2914
2915 test.tags("desktop");
2916 test("save a quick create record and create a new one simultaneously", async () => {
2917 const def = new Deferred();
2918
2919 onRpc("name_create", () => {
2920 expect.step("name_create");
2921 return def;
2922 });
2923
2924 await mountView({
2925 type: "kanban",
2926 resModel: "partner",
2927 arch: `
2928 <kanban on_create="quick_create">
2929 <templates>
2930 <t t-name="card">
2931 <field name="display_name"/>
2932 </t>
2933 </templates>
2934 </kanban>`,
2935 groupBy: ["bar"],
2936 });
2937
2938 expect(".o_kanban_record").toHaveCount(4);
2939
2940 // Create and save a record
2941 await quickCreateKanbanRecord();
2942 await editKanbanRecordQuickCreateInput("display_name", "new partner");
2943 await validateKanbanRecord();
2944 expect(".o_kanban_record").toHaveCount(4);
2945 expect(".o_kanban_quick_create [name=display_name] input").toHaveValue("new partner");
2946 expect(".o_kanban_quick_create").toHaveClass("o_disabled");
2947
2948 // Create a new record during the save of the first one
2949 await createKanbanRecord();
2950 expect(".o_kanban_record").toHaveCount(4);
2951 expect(".o_kanban_quick_create [name=display_name] input").toHaveValue("new partner");
2952 expect(".o_kanban_quick_create").toHaveClass("o_disabled");
2953
2954 def.resolve();
2955 await animationFrame();
2956 expect(".o_kanban_record").toHaveCount(5);
2957 expect(".o_kanban_quick_create [name=display_name] input").toHaveValue("");
2958 expect(".o_kanban_quick_create").not.toHaveClass("o_disabled");
2959 expect.verifySteps(["name_create"]);
2960 });
2961
2962 test("quick create record: prevent multiple adds with ENTER, with onchange", async () => {
2963 Partner._fields.foo = fields.Char({
2964 onChange: (obj) => {
2965 obj.int_field += obj.foo ? 3 : 0;
2966 },
2967 });
2968 Partner._views["form,some_view_ref"] = `
2969 <form>
2970 <field name="foo"/>
2971 <field name="int_field"/>
2972 </form>`;
2973
2974 onRpc("onchange", () => {
2975 expect.step("onchange");
2976 if (shouldDelayOnchange) {
2977 return def;
2978 }
2979 });
2980 onRpc("web_save", ({ args }) => {
2981 expect.step("web_save");
2982 const values = args[1];
2983 expect(values.foo).toBe("new partner");
2984 expect(values.int_field).toBe(3);
2985 });
2986
2987 let shouldDelayOnchange = false;
2988 const def = new Deferred();
2989 await mountView({
2990 type: "kanban",
2991 resModel: "partner",
2992 arch: `
2993 <kanban on_create="quick_create" quick_create_view="some_view_ref">
2994 <templates>
2995 <t t-name="card">
2996 <field name="foo"/>
2997 </t>
2998 </templates>
2999 </kanban>`,
3000 groupBy: ["bar"],
3001 });
3002
3003 expect(".o_kanban_record").toHaveCount(4, {
3004 message: "should have 4 records at the beginning",
3005 });
3006
3007 // add an element and press ENTER twice
3008 await quickCreateKanbanRecord();
3009 shouldDelayOnchange = true;
3010 await editKanbanRecordQuickCreateInput("foo", "new partner");
3011 await press("Enter");
3012 await animationFrame();
3013 await press("Enter");
3014 await animationFrame();
3015
3016 expect(".o_kanban_record").toHaveCount(4, {
3017 message: "should not have created the record yet",
3018 });
3019 expect(".o_kanban_quick_create .o_field_widget[name=foo] input").toHaveValue("new partner", {
3020 message: "quick create should not be empty yet",
3021 });
3022 expect(".o_kanban_quick_create").toHaveClass("o_disabled");
3023
3024 def.resolve();
3025 await animationFrame();
3026
3027 expect(".o_kanban_record").toHaveCount(5, { message: "should have created a new record" });
3028 expect(".o_kanban_quick_create .o_field_widget[name=foo] input").toHaveValue("", {
3029 message: "quick create should now be empty",
3030 });
3031 expect(".o_kanban_quick_create").not.toHaveClass("o_disabled");
3032
3033 expect.verifySteps([
3034 "onchange", // default_get
3035 "onchange", // new partner
3036 "web_save",
3037 "onchange", // default_get
3038 ]);
3039 });
3040
3041 test("quick create record: click Add to create, with delayed onchange", async () => {
3042 Partner._fields.foo = fields.Char({
3043 onChange: (obj) => {
3044 obj.int_field += obj.foo ? 3 : 0;
3045 },
3046 });
3047 Partner._views["form,some_view_ref"] = `
3048 <form>
3049 <field name="foo"/>
3050 <field name="int_field"/>
3051 </form>`;
3052
3053 onRpc("onchange", () => {
3054 expect.step("onchange");
3055 if (shouldDelayOnchange) {
3056 return def;
3057 }
3058 });
3059 onRpc("web_save", ({ args }) => {
3060 expect.step("web_save");
3061 expect(args[1]).toEqual({
3062 foo: "new partner",
3063 int_field: 3,
3064 });
3065 });
3066
3067 let shouldDelayOnchange = false;
3068 const def = new Deferred();
3069 await mountView({
3070 type: "kanban",
3071 resModel: "partner",
3072 arch: `
3073 <kanban on_create="quick_create" quick_create_view="some_view_ref">
3074 <templates>
3075 <t t-name="card">
3076 <field name="foo"/>
3077 <field name="int_field"/>
3078 </t>
3079 </templates>
3080 </kanban>`,
3081 groupBy: ["bar"],
3082 });
3083
3084 expect(".o_kanban_record").toHaveCount(4, {
3085 message: "should have 4 records at the beginning",
3086 });
3087
3088 // add an element and click 'add'
3089 await quickCreateKanbanRecord();
3090 shouldDelayOnchange = true;
3091 await editKanbanRecordQuickCreateInput("foo", "new partner");
3092 await validateKanbanRecord();
3093
3094 expect(".o_kanban_record").toHaveCount(4, {
3095 message: "should not have created the record yet",
3096 });
3097 expect(".o_kanban_quick_create .o_field_widget[name=foo] input").toHaveValue("new partner", {
3098 message: "quick create should not be empty yet",
3099 });
3100 expect(".o_kanban_quick_create").toHaveClass("o_disabled");
3101
3102 def.resolve(); // the onchange returns
3103
3104 await animationFrame();
3105 expect(".o_kanban_record").toHaveCount(5, { message: "should have created a new record" });
3106 expect(".o_kanban_quick_create .o_field_widget[name=foo] input").toHaveValue("", {
3107 message: "quick create should now be empty",
3108 });
3109 expect(".o_kanban_quick_create").not.toHaveClass("o_disabled");
3110
3111 expect.verifySteps([
3112 "onchange", // default_get
3113 "onchange", // new partner
3114 "web_save",
3115 "onchange", // default_get
3116 ]);
3117 });
3118
3119 test.tags("desktop");
3120 test("quick create when first column is folded", async () => {
3121 await mountView({
3122 type: "kanban",
3123 resModel: "partner",
3124 arch: `
3125 <kanban on_create="quick_create">
3126 <templates>
3127 <t t-name="card">
3128 <field name="foo"/>
3129 </t>
3130 </templates>
3131 </kanban>`,
3132 groupBy: ["bar"],
3133 });
3134
3135 expect(".o_kanban_group:first-child").not.toHaveClass("o_column_folded");
3136 expect(".o_kanban_group:nth-child(2)").not.toHaveClass("o_column_folded");
3137
3138 // fold the first column
3139 let clickColumnAction = await toggleKanbanColumnActions(0);
3140 await clickColumnAction("Fold");
3141
3142 expect(".o_kanban_group:first-child").toHaveClass("o_column_folded");
3143 expect(".o_kanban_group:nth-child(2)").not.toHaveClass("o_column_folded");
3144
3145 expect(".o_kanban_quick_create").toHaveCount(0);
3146
3147 // click on 'Create' to open the quick create in the first non-folded column (second column)
3148 await createKanbanRecord();
3149
3150 expect(".o_kanban_group:first-child").toHaveClass("o_column_folded");
3151 expect(".o_kanban_group:nth-child(2)").not.toHaveClass("o_column_folded");
3152
3153 expect(".o_kanban_group:nth-child(2) .o_kanban_quick_create").toHaveCount(1);
3154
3155 // fold again the second column
3156 clickColumnAction = await toggleKanbanColumnActions(1);
3157 await clickColumnAction("Fold");
3158
3159 expect(".o_kanban_group:first-child").toHaveClass("o_column_folded");
3160 expect(".o_kanban_group:nth-child(2)").toHaveClass("o_column_folded");
3161
3162 expect(".o_kanban_quick_create").toHaveCount(0);
3163
3164 // click on 'Create' to open the quick create in the first column since all columns are folded
3165 await createKanbanRecord();
3166
3167 expect(".o_kanban_group:first-child").not.toHaveClass("o_column_folded");
3168 expect(".o_kanban_group:nth-child(2)").toHaveClass("o_column_folded");
3169
3170 expect(".o_kanban_group:first-child .o_kanban_quick_create").toHaveCount(1);
3171 });
3172
3173 test("quick create record: cancel when not dirty", async () => {
3174 await mountView({
3175 type: "kanban",
3176 resModel: "partner",
3177 arch: `
3178 <kanban>
3179 <templates>
3180 <t t-name="card">
3181 <field name="foo"/>
3182 </t>
3183 </templates>
3184 </kanban>`,
3185 groupBy: ["bar"],
3186 });
3187
3188 expect(".o_kanban_group:first-child .o_kanban_record").toHaveCount(1, {
3189 message: "first column should contain one record",
3190 });
3191
3192 // click to add an element
3193 await quickCreateKanbanRecord();
3194 expect(".o_kanban_quick_create").toHaveCount(1, {
3195 message: "should have open the quick create widget",
3196 });
3197
3198 // click again to add an element -> should have kept the quick create open
3199 await quickCreateKanbanRecord();
3200 expect(".o_kanban_quick_create").toHaveCount(1, {
3201 message: "should have kept the quick create open",
3202 });
3203
3204 // click outside: should remove the quick create
3205 await contains(".o_kanban_group:first-child .o_kanban_record:last-of-type").click();
3206 expect(".o_kanban_quick_create").toHaveCount(0, {
3207 message: "the quick create should not have been destroyed",
3208 });
3209
3210 // click to reopen the quick create
3211 await quickCreateKanbanRecord();
3212 expect(".o_kanban_quick_create").toHaveCount(1, {
3213 message: "should have open the quick create widget",
3214 });
3215
3216 // press ESC: should remove the quick create
3217 await press("Escape");
3218 await animationFrame();
3219
3220 expect(".o_kanban_quick_create").toHaveCount(0, {
3221 message: "quick create widget should have been removed",
3222 });
3223
3224 // click to reopen the quick create
3225 await quickCreateKanbanRecord();
3226 expect(".o_kanban_quick_create").toHaveCount(1, {
3227 message: "should have open the quick create widget",
3228 });
3229
3230 // click on 'Discard': should remove the quick create
3231 await quickCreateKanbanRecord();
3232 await discardKanbanRecord();
3233 expect(".o_kanban_quick_create").toHaveCount(0, {
3234 message: "the quick create should be destroyed when the user clicks outside",
3235 });
3236
3237 expect(".o_kanban_group:first-child .o_kanban_record").toHaveCount(1, {
3238 message: "first column should still contain one record",
3239 });
3240
3241 // click to reopen the quick create
3242 await quickCreateKanbanRecord();
3243 expect(".o_kanban_quick_create").toHaveCount(1, {
3244 message: "should have open the quick create widget",
3245 });
3246
3247 // clicking on the quick create itself should keep it open
3248 await contains(".o_kanban_quick_create").click();
3249 expect(".o_kanban_quick_create").toHaveCount(1, {
3250 message: "the quick create should not have been destroyed when clicked on itself",
3251 });
3252 });
3253
3254 test.tags("desktop");
3255 test("quick create record: cancel when modal is opened", async () => {
3256 Partner._views["form,some_view_ref"] = `
3257 <form>
3258 <field name="product_id"/>
3259 <field name="foo"/>
3260 </form>
3261 `;
3262 Product._views.form = '<form><field name="name"/></form>';
3263
3264 await mountView({
3265 type: "kanban",
3266 resModel: "partner",
3267 groupBy: ["bar"],
3268 arch: `
3269 <kanban on_create="quick_create" quick_create_view="some_view_ref">
3270 <templates>
3271 <t t-name="card">
3272 <field name="foo"/>
3273 </t>
3274 </templates>
3275 </kanban>`,
3276 });
3277
3278 // click to add an element
3279 await quickCreateKanbanRecord();
3280 expect(".o_kanban_quick_create").toHaveCount(1);
3281
3282 await press("t");
3283 await press("e");
3284 await press("s");
3285 await press("t");
3286 await runAllTimers();
3287 await click(".o_m2o_dropdown_option_create_edit"); // open create and edit dialog
3288 await animationFrame();
3289
3290 // When focusing out of the many2one, a modal to add a 'product' will appear.
3291 // The following assertions ensures that a click on the body element that has 'modal-open'
3292 // will NOT close the quick create.
3293 // This can happen when the user clicks out of the input because of a race condition between
3294 // the focusout of the m2o and the global 'click' handler of the quick create.
3295 // Check odoo/odoo#61981 for more details.
3296 expect(".o_dialog").toHaveCount(1, { message: "modal should be opening after m2o focusout" });
3297 expect(document.body).toHaveClass("modal-open");
3298 await click(document.body);
3299 await animationFrame();
3300 expect(".o_kanban_quick_create").toHaveCount(1, {
3301 message: "quick create should stay open while modal is opening",
3302 });
3303 });
3304
3305 test("quick create record: cancel when dirty", async () => {
3306 await mountView({
3307 type: "kanban",
3308 resModel: "partner",
3309 arch: `
3310 <kanban>
3311 <templates>
3312 <t t-name="card">
3313 <field name="foo"/>
3314 </t>
3315 </templates>
3316 </kanban>`,
3317 groupBy: ["bar"],
3318 });
3319
3320 expect(".o_kanban_group:first-child .o_kanban_record").toHaveCount(1, {
3321 message: "first column should contain one record",
3322 });
3323
3324 // click to add an element and edit it
3325 await quickCreateKanbanRecord();
3326
3327 expect(".o_kanban_quick_create").toHaveCount(1, {
3328 message: "should have open the quick create widget",
3329 });
3330
3331 await editKanbanRecordQuickCreateInput("display_name", "some value");
3332
3333 // click outside: should not remove the quick create
3334 await contains(".o_kanban_group:first-child .o_kanban_record").click();
3335
3336 expect(".o_kanban_quick_create").toHaveCount(1, {
3337 message: "the quick create should not have been destroyed",
3338 });
3339
3340 // press ESC: should remove the quick create
3341 await press("Escape");
3342 await animationFrame();
3343
3344 expect(".o_kanban_quick_create").toHaveCount(0, {
3345 message: "quick create widget should have been removed",
3346 });
3347
3348 // click to reopen quick create and edit it
3349 await quickCreateKanbanRecord();
3350
3351 expect(".o_kanban_quick_create").toHaveCount(1, {
3352 message: "should have open the quick create widget",
3353 });
3354
3355 await editKanbanRecordQuickCreateInput("display_name", "some value");
3356
3357 // click on 'Discard': should remove the quick create
3358 await discardKanbanRecord();
3359
3360 expect(".o_kanban_quick_create").toHaveCount(0, {
3361 message: "the quick create should be destroyed when the user discard quick creation",
3362 });
3363 expect(".o_kanban_group:first-child .o_kanban_record").toHaveCount(1, {
3364 message: "first column should still contain one record",
3365 });
3366 });
3367
3368 test("quick create record and edit in grouped mode", async () => {
3369 expect.assertions(4);
3370
3371 onRpc("web_read", ({ args }) => {
3372 newRecordID = args[0][0];
3373 });
3374
3375 let newRecordID;
3376 await mountView({
3377 type: "kanban",
3378 resModel: "partner",
3379 arch: `
3380 <kanban on_create="quick_create">
3381 <templates>
3382 <t t-name="card">
3383 <field name="foo"/>
3384 </t>
3385 </templates>
3386 </kanban>`,
3387 groupBy: ["bar"],
3388 selectRecord: (resId) => {
3389 expect(resId).toBe(newRecordID);
3390 },
3391 });
3392
3393 expect(".o_kanban_group:first-child .o_kanban_record").toHaveCount(1, {
3394 message: "first column should contain one record",
3395 });
3396
3397 // click to add and edit a record
3398 await quickCreateKanbanRecord();
3399 await editKanbanRecordQuickCreateInput("display_name", "new partner");
3400 await editKanbanRecord();
3401
3402 expect(".o_kanban_group:first-child .o_kanban_record").toHaveCount(2, {
3403 message: "first column should now contain two records",
3404 });
3405 expect(queryAllTexts(".o_kanban_group:first-child .o_kanban_record")).toEqual([
3406 "new partner",
3407 "blip",
3408 ]);
3409 });
3410
3411 test.tags("desktop");
3412 test("quick create several records in a row", async () => {
3413 await mountView({
3414 type: "kanban",
3415 resModel: "partner",
3416 arch: `
3417 <kanban on_create="quick_create">
3418 <templates>
3419 <t t-name="card">
3420 <field name="foo"/>
3421 </t>
3422 </templates>
3423 </kanban>`,
3424 groupBy: ["bar"],
3425 });
3426
3427 expect(".o_kanban_group:first-child .o_kanban_record").toHaveCount(1, {
3428 message: "first column should contain one record",
3429 });
3430
3431 // click to add an element, fill the input and press ENTER
3432 await quickCreateKanbanRecord();
3433
3434 expect(".o_kanban_quick_create").toHaveCount(1, { message: "the quick create should be open" });
3435
3436 await editKanbanRecordQuickCreateInput("display_name", "new partner 1");
3437 await validateKanbanRecord();
3438
3439 expect(".o_kanban_group:first-child .o_kanban_record").toHaveCount(2, {
3440 message: "first column should now contain two records",
3441 });
3442 expect(".o_kanban_quick_create").toHaveCount(1, {
3443 message: "the quick create should still be open",
3444 });
3445
3446 // create a second element in a row
3447 await createKanbanRecord();
3448 await editKanbanRecordQuickCreateInput("display_name", "new partner 2");
3449 await validateKanbanRecord();
3450
3451 expect(".o_kanban_group:first-child .o_kanban_record").toHaveCount(3, {
3452 message: "first column should now contain three records",
3453 });
3454 expect(".o_kanban_quick_create").toHaveCount(1, {
3455 message: "the quick create should still be open",
3456 });
3457 });
3458
3459 test("quick create is re-enabled directly after the validation", async () => {
3460 let webSaveDef;
3461 let webReadDef;
3462 onRpc("web_save", () => webSaveDef);
3463 onRpc("web_read", () => webReadDef);
3464
3465 await mountView({
3466 type: "kanban",
3467 resModel: "partner",
3468 arch: `
3469 <kanban on_create="quick_create">
3470 <templates>
3471 <t t-name="card">
3472 <field name="foo"/>
3473 </t>
3474 </templates>
3475 </kanban>`,
3476 groupBy: ["bar"],
3477 });
3478
3479 expect(".o_kanban_group:first-child .o_kanban_record").toHaveCount(1, {
3480 message: "first column should contain one record",
3481 });
3482
3483 // click to add a record, and add two in a row (first one will be delayed)
3484 await quickCreateKanbanRecord();
3485
3486 expect(".o_kanban_quick_create").toHaveCount(1, { message: "the quick create should be open" });
3487
3488 await editKanbanRecordQuickCreateInput("display_name", "new partner 1");
3489 webSaveDef = new Deferred();
3490 webReadDef = new Deferred();
3491 await validateKanbanRecord();
3492
3493 expect(".o_kanban_group:first-child .o_kanban_record").toHaveCount(1, {
3494 message: "first column should still contain one record",
3495 });
3496 expect(".o_kanban_quick_create.o_disabled").toHaveCount(0, {
3497 message: "quick create should be enabled",
3498 });
3499
3500 webSaveDef.resolve();
3501 await animationFrame();
3502
3503 expect(".o_kanban_group:first-child .o_kanban_record").toHaveCount(1, {
3504 message: "first column should still contain one record",
3505 });
3506 expect(".o_kanban_quick_create.o_disabled").toHaveCount(0, {
3507 message: "quick create should be enabled",
3508 });
3509
3510 webReadDef.resolve();
3511 await animationFrame();
3512
3513 expect(".o_kanban_group:first-child .o_kanban_record").toHaveCount(2, {
3514 message: "first column should now contain two records",
3515 });
3516 expect(".o_kanban_quick_create.o_disabled").toHaveCount(0, {
3517 message: "quick create should be enabled",
3518 });
3519 });
3520
3521 test.tags("desktop");
3522 test("kanban grouped by stage_id: move record from to the None column", async () => {
3523 // Fake model: partner.stage (only for group headers)
3524 const Stage = class extends models.Model {
3525 _name = "partner.stage";
3526 name = fields.Char();
3527 _records = [{ id: 10, name: "New" }];
3528 };
3529 defineModels([Stage]);
3530
3531 // Set up a record with no stage initially
3532 Partner._records = [
3533 { id: 1, foo: "Task A", stage_id: false },
3534 { id: 2, foo: "Task B", stage_id: 10 },
3535 ];
3536 Partner._fields.stage_id = fields.Many2one({ relation: "partner.stage" });
3537
3538 await mountView({
3539 type: "kanban",
3540 resModel: "partner",
3541 arch: `
3542 <kanban>
3543 <templates>
3544 <t t-name="card">
3545 <field name="foo"/>
3546 </t>
3547 </templates>
3548 </kanban>`,
3549 groupBy: ["stage_id"],
3550 });
3551
3552 expect(queryAll(".o_kanban_group")).toHaveCount(2); // None and New
3553
3554 await click(".o_kanban_group:first .o_kanban_header");
3555
3556 // Drag a record to the "None" column
3557 const dragActions = await contains(".o_kanban_record:contains(Task B)").drag();
3558 await dragActions.moveTo(".o_kanban_group:nth-child(1) .o_kanban_header");
3559 await dragActions.drop();
3560
3561 // Reload
3562 await validateSearch();
3563
3564 // Assert it's back in "None"
3565 expect(queryAll(".o_kanban_record", { root: getKanbanColumn(0) })).toHaveCount(2);
3566 expect(queryAllTexts(".o_kanban_record", { root: getKanbanColumn(0) })[1]).toBe("Task B");
3567 });
3568
3569 test.tags("desktop");
3570 test("quick create record fail in grouped by many2one", async () => {
3571 Partner._views["form"] = `
3572 <form>
3573 <field name="product_id"/>
3574 <field name="foo"/>
3575 </form>`;
3576
3577 onRpc("name_create", () => {
3578 throw makeServerError({ message: "This is a user error" });
3579 });
3580
3581 await mountView({
3582 type: "kanban",
3583 resModel: "partner",
3584 arch: `
3585 <kanban on_create="quick_create">
3586 <templates>
3587 <t t-name="card">
3588 <field name="foo"/>
3589 </t>
3590 </templates>
3591 </kanban>`,
3592 groupBy: ["product_id"],
3593 });
3594
3595 expect(".o_kanban_group:first .o_kanban_record").toHaveCount(2);
3596
3597 await createKanbanRecord();
3598 expect(".o_kanban_group:first .o_kanban_quick_create").toHaveCount(1);
3599
3600 await editKanbanRecordQuickCreateInput("display_name", "test");
3601 await validateKanbanRecord();
3602 expect(".modal .o_form_view .o_form_editable").toHaveCount(1);
3603 expect(".modal .o_field_many2one input:first").toHaveValue("hello");
3604
3605 // specify a name and save
3606 await contains(".modal .o_field_widget[name=foo] input").edit("test");
3607 await contains(".modal .o_form_button_save").click();
3608 expect(".modal").toHaveCount(0);
3609 expect(".o_kanban_group:first .o_kanban_record").toHaveCount(3);
3610 expect(".o_kanban_group .o_kanban_record:first").toHaveText("test");
3611 expect(".o_kanban_quick_create:not(.o_disabled)").toHaveCount(1);
3612 });
3613
3614 test("quick create record and click Edit, name_create fails", async () => {
3615 Partner._views["kanban"] = `
3616 <kanban sample="1">
3617 <templates>
3618 <t t-name="card">
3619 <field name="foo"/>
3620 </t>
3621 </templates>
3622 </kanban>`;
3623 Partner._views["list"] = '<list><field name="foo"/></list>';
3624 Partner._views["form"] = `
3625 <form>
3626 <field name="product_id"/>
3627 <field name="foo"/>
3628 </form>`;
3629
3630 onRpc("name_create", () => {
3631 throw makeServerError({ message: "This is a user error" });
3632 });
3633
3634 await mountWithCleanup(WebClient);
3635 await getService("action").doAction({
3636 res_model: "partner",
3637 type: "ir.actions.act_window",
3638 views: [
3639 [false, "kanban"],
3640 [false, "form"],
3641 ],
3642 context: {
3643 group_by: ["product_id"],
3644 },
3645 });
3646
3647 expect(".o_kanban_group:first .o_kanban_record").toHaveCount(2);
3648
3649 await quickCreateKanbanRecord(0);
3650 expect(".o_kanban_group:first .o_kanban_quick_create").toHaveCount(1);
3651
3652 await editKanbanRecordQuickCreateInput("display_name", "test");
3653 await editKanbanRecord();
3654 expect(".modal .o_form_view .o_form_editable").toHaveCount(1);
3655 expect(".modal .o_field_many2one input:first").toHaveValue("hello");
3656
3657 // specify a name and save
3658 await contains(".modal .o_field_widget[name=foo] input").edit("test");
3659 await contains(".modal .o_form_button_save").click();
3660 expect(".modal").toHaveCount(0);
3661 expect(".o_kanban_group:first .o_kanban_record").toHaveCount(3);
3662 expect(".o_kanban_group .o_kanban_record:first").toHaveText("test");
3663 expect(".o_kanban_quick_create:not(.o_disabled)").toHaveCount(1);
3664 });
3665
3666 test.tags("desktop");
3667 test("quick create record is re-enabled after discard on failure", async () => {
3668 Partner._views["form"] = `
3669 <form>
3670 <field name="product_id"/>
3671 <field name="foo"/>
3672 </form>`;
3673
3674 onRpc("name_create", () => {
3675 throw makeServerError({ message: "This is a user error" });
3676 });
3677
3678 await mountView({
3679 type: "kanban",
3680 resModel: "partner",
3681 arch: `
3682 <kanban on_create="quick_create">
3683 <templates>
3684 <t t-name="card">
3685 <field name="foo"/>
3686 </t>
3687 </templates>
3688 </kanban>`,
3689 groupBy: ["product_id"],
3690 });
3691
3692 expect(".o_kanban_group:first .o_kanban_record").toHaveCount(2);
3693
3694 await createKanbanRecord();
3695 expect(".o_kanban_group:first .o_kanban_quick_create").toHaveCount(1);
3696
3697 await editKanbanRecordQuickCreateInput("display_name", "test");
3698 await validateKanbanRecord();
3699 expect(".modal .o_form_view .o_form_editable").toHaveCount(1);
3700
3701 await contains(".modal .o_form_button_cancel").click();
3702 expect(".modal .o_form_view .o_form_editable").toHaveCount(0);
3703 expect(".o_kanban_group:first .o_kanban_quick_create").toHaveCount(1);
3704 expect(".o_kanban_group:first .o_kanban_record").toHaveCount(2);
3705 });
3706
3707 test("quick create record fails in grouped by char", async () => {
3708 expect.assertions(7);
3709
3710 Partner._views["form"] = '<form><field name="foo"/></form>';
3711
3712 onRpc("name_create", () => {
3713 throw makeServerError({ message: "This is a user error" });
3714 });
3715 onRpc("web_save", ({ args, kwargs }) => {
3716 expect(args[1]).toEqual({ foo: "blip" });
3717 expect(kwargs.context).toEqual({
3718 allowed_company_ids: [1],
3719 default_foo: "blip",
3720 default_name: "test",
3721 lang: "en",
3722 tz: "taht",
3723 uid: 7,
3724 });
3725 });
3726
3727 await mountView({
3728 type: "kanban",
3729 resModel: "partner",
3730 groupBy: ["foo"],
3731 arch: `
3732 <kanban on_create="quick_create">
3733 <templates>
3734 <t t-name="card">
3735 <field name="foo"/>
3736 </t>
3737 </templates>
3738 </kanban>`,
3739 });
3740
3741 expect(".o_kanban_group:first .o_kanban_record").toHaveCount(2);
3742
3743 await quickCreateKanbanRecord();
3744 await editKanbanRecordQuickCreateInput("display_name", "test");
3745 await validateKanbanRecord();
3746
3747 expect(".modal .o_form_view .o_form_editable").toHaveCount(1);
3748 expect(".modal .o_field_widget[name=foo] input").toHaveValue("blip");
3749 await contains(".modal .o_form_button_save").click();
3750
3751 expect(".modal .o_form_view .o_form_editable").toHaveCount(0);
3752 expect(".o_kanban_group:first .o_kanban_record").toHaveCount(3);
3753 });
3754
3755 test("quick create record fails in grouped by selection", async () => {
3756 expect.assertions(7);
3757
3758 Partner._views["form"] = '<form><field name="state"/></form>';
3759
3760 onRpc("name_create", () => {
3761 throw makeServerError({ message: "This is a user error" });
3762 });
3763 onRpc("web_save", ({ args, kwargs }) => {
3764 expect(args[1]).toEqual({ state: "abc" });
3765 expect(kwargs.context).toEqual({
3766 allowed_company_ids: [1],
3767 default_state: "abc",
3768 default_name: "test",
3769 lang: "en",
3770 tz: "taht",
3771 uid: 7,
3772 });
3773 });
3774
3775 await mountView({
3776 type: "kanban",
3777 resModel: "partner",
3778 groupBy: ["state"],
3779 arch: `
3780 <kanban on_create="quick_create">
3781 <templates>
3782 <t t-name="card">
3783 <field name="state"/>
3784 </t>
3785 </templates>
3786 </kanban>`,
3787 });
3788
3789 expect(".o_kanban_group:first .o_kanban_record").toHaveCount(1);
3790
3791 await quickCreateKanbanRecord();
3792 await editKanbanRecordQuickCreateInput("display_name", "test");
3793 await validateKanbanRecord();
3794
3795 expect(".modal .o_form_view .o_form_editable").toHaveCount(1);
3796 expect(".modal .o_field_widget[name=state] input").toHaveValue("ABC");
3797
3798 await contains(".modal .o_form_button_save").click();
3799
3800 expect(".modal .o_form_view .o_form_editable").toHaveCount(0);
3801 expect(".o_kanban_group:first .o_kanban_record").toHaveCount(2);
3802 });
3803
3804 test.tags("desktop");
3805 test("quick create record in empty grouped kanban", async () => {
3806 onRpc("web_read_group", () =>
3807 // override web_read_group to return empty groups, as this is
3808 // the case for several models (e.g. project.task grouped
3809 // by stage_id)
3810 ({
3811 groups: [
3812 {
3813 __extra_domain: [["product_id", "=", 3]],
3814 __count: 0,
3815 product_id: [3, "xplone"],
3816 },
3817 {
3818 __extra_domain: [["product_id", "=", 5]],
3819 __count: 0,
3820 product_id: [5, "xplan"],
3821 },
3822 ],
3823 length: 2,
3824 })
3825 );
3826
3827 await mountView({
3828 type: "kanban",
3829 resModel: "partner",
3830 arch: `
3831 <kanban on_create="quick_create">
3832 <templates>
3833 <t t-name="card">
3834 <field name="foo"/>
3835 </t>
3836 </templates>
3837 </kanban>`,
3838 groupBy: ["product_id"],
3839 });
3840
3841 expect(".o_kanban_group").toHaveCount(2, { message: "there should be 2 columns" });
3842 expect(".o_kanban_record").toHaveCount(0, { message: "both columns should be empty" });
3843
3844 await createKanbanRecord();
3845
3846 expect(".o_kanban_group:first-child .o_kanban_quick_create").toHaveCount(1, {
3847 message: "should have opened the quick create in the first column",
3848 });
3849 });
3850
3851 test.tags("desktop");
3852 test("quick create record in grouped on date(time) field", async () => {
3853 await mountView({
3854 type: "kanban",
3855 resModel: "partner",
3856 arch: `
3857 <kanban on_create="quick_create">
3858 <templates>
3859 <t t-name="card">
3860 <field name="display_name"/>
3861 </t>
3862 </templates>
3863 </kanban>`,
3864 searchViewArch: `
3865 <search>
3866 <filter name="group_by_datetime" domain="[]" string="GroupBy Datetime" context="{ 'group_by': 'datetime' }"/>
3867 </search>`,
3868 groupBy: ["date"],
3869 createRecord: () => {
3870 expect.step("createKanbanRecord");
3871 },
3872 });
3873
3874 expect(".o_kanban_header .o_kanban_quick_add i").toHaveCount(0, {
3875 message: "quick create should be disabled when grouped on a date field",
3876 });
3877
3878 // clicking on CREATE in control panel should not open a quick create
3879 await createKanbanRecord();
3880 expect(".o_kanban_quick_create").toHaveCount(0, {
3881 message: "should not have opened the quick create widget",
3882 });
3883
3884 await toggleSearchBarMenu();
3885 await toggleMenuItem("GroupBy Datetime");
3886
3887 expect(".o_kanban_header .o_kanban_quick_add i").toHaveCount(0, {
3888 message: "quick create should be disabled when grouped on a datetime field",
3889 });
3890
3891 // clicking on CREATE in control panel should not open a quick create
3892 await createKanbanRecord();
3893 expect(".o_kanban_quick_create").toHaveCount(0, {
3894 message: "should not have opened the quick create widget",
3895 });
3896
3897 expect.verifySteps(["createKanbanRecord", "createKanbanRecord"]);
3898 });
3899
3900 test("quick create record feature is properly enabled/disabled at reload", async () => {
3901 await mountView({
3902 type: "kanban",
3903 resModel: "partner",
3904 arch: `
3905 <kanban on_create="quick_create">
3906 <templates>
3907 <t t-name="card">
3908 <field name="display_name"/>
3909 </t>
3910 </templates>
3911 </kanban>`,
3912 searchViewArch: `
3913 <search>
3914 <filter name="group_by_date" domain="[]" string="GroupBy Date" context="{ 'group_by': 'date' }"/>
3915 <filter name="group_by_bar" domain="[]" string="GroupBy Bar" context="{ 'group_by': 'bar' }"/>
3916 </search>`,
3917 groupBy: ["foo"],
3918 });
3919
3920 expect(".o_kanban_header .o_kanban_quick_add i").toHaveCount(3, {
3921 message: "quick create should be enabled when grouped on a char field",
3922 });
3923
3924 await toggleSearchBarMenu();
3925 await toggleMenuItem("GroupBy Date");
3926 await toggleMenuItemOption("GroupBy Date", "Month");
3927
3928 expect(".o_kanban_header .o_kanban_quick_add i").toHaveCount(0, {
3929 message: "quick create should now be disabled (grouped on date field)",
3930 });
3931
3932 await toggleMenuItemOption("GroupBy Date", "Month");
3933 await toggleMenuItem("GroupBy Bar");
3934
3935 expect(".o_kanban_header .o_kanban_quick_add i").toHaveCount(2, {
3936 message: "quick create should be enabled again (grouped on boolean field)",
3937 });
3938 });
3939
3940 test("quick create record in grouped by char field", async () => {
3941 expect.assertions(4);
3942
3943 onRpc("name_create", ({ kwargs }) => {
3944 expect(kwargs.context.default_foo).toBe("blip");
3945 });
3946
3947 await mountView({
3948 type: "kanban",
3949 resModel: "partner",
3950 arch: `
3951 <kanban on_create="quick_create">
3952 <templates>
3953 <t t-name="card">
3954 <field name="display_name"/>
3955 </t>
3956 </templates>
3957 </kanban>`,
3958 groupBy: ["foo"],
3959 });
3960
3961 expect(".o_kanban_header .o_kanban_quick_add i").toHaveCount(3);
3962 expect(".o_kanban_group:first-child .o_kanban_record").toHaveCount(2);
3963
3964 await quickCreateKanbanRecord();
3965 await editKanbanRecordQuickCreateInput("display_name", "new record");
3966 await validateKanbanRecord();
3967
3968 expect(".o_kanban_group:first-child .o_kanban_record").toHaveCount(3);
3969 });
3970
3971 test("quick create record in grouped by boolean field", async () => {
3972 expect.assertions(4);
3973
3974 onRpc("name_create", ({ kwargs }) => {
3975 expect(kwargs.context.default_bar).toBe(true);
3976 });
3977
3978 await mountView({
3979 type: "kanban",
3980 resModel: "partner",
3981 arch: `
3982 <kanban on_create="quick_create">
3983 <templates>
3984 <t t-name="card">
3985 <field name="display_name"/>
3986 </t>
3987 </templates>
3988 </kanban>`,
3989 groupBy: ["bar"],
3990 });
3991
3992 expect(".o_kanban_header .o_kanban_quick_add i").toHaveCount(2);
3993 expect(".o_kanban_group:last-child .o_kanban_record").toHaveCount(3);
3994
3995 await quickCreateKanbanRecord(1);
3996 await editKanbanRecordQuickCreateInput("display_name", "new record");
3997 await validateKanbanRecord();
3998
3999 expect(".o_kanban_group:last-child .o_kanban_record").toHaveCount(4);
4000 });
4001
4002 test("quick create record in grouped on selection field", async () => {
4003 expect.assertions(4);
4004
4005 onRpc("name_create", ({ kwargs }) => {
4006 expect(kwargs.context.default_state).toBe("abc");
4007 });
4008
4009 await mountView({
4010 type: "kanban",
4011 resModel: "partner",
4012 arch: `
4013 <kanban on_create="quick_create">
4014 <templates>
4015 <t t-name="card">
4016 <field name="display_name"/>
4017 </t>
4018 </templates>
4019 </kanban>`,
4020 groupBy: ["state"],
4021 });
4022
4023 expect(".o_kanban_header .o_kanban_quick_add i").toHaveCount(3, {
4024 message: "quick create should be enabled when grouped on a selection field",
4025 });
4026 expect(".o_kanban_group:first-child .o_kanban_record").toHaveCount(1, {
4027 message: "first column (abc) should contain 1 record",
4028 });
4029
4030 await quickCreateKanbanRecord();
4031 await editKanbanRecordQuickCreateInput("display_name", "new record");
4032 await validateKanbanRecord();
4033
4034 expect(".o_kanban_group:first-child .o_kanban_record").toHaveCount(2, {
4035 message: "first column (abc) should contain 2 records",
4036 });
4037 });
4038
4039 test("quick create record in grouped by char field (within quick_create_view)", async () => {
4040 expect.assertions(6);
4041
4042 Partner._views["form,some_view_ref"] = `<form><field name="foo"/></form>`;
4043
4044 onRpc("web_save", ({ args, kwargs }) => {
4045 expect(args[1]).toEqual({ foo: "blip" });
4046 expect(kwargs.context.default_foo).toBe("blip");
4047 });
4048
4049 await mountView({
4050 type: "kanban",
4051 resModel: "partner",
4052 arch: `
4053 <kanban on_create="quick_create" quick_create_view="some_view_ref">
4054 <templates>
4055 <t t-name="card">
4056 <field name="foo"/>
4057 </t>
4058 </templates>
4059 </kanban>`,
4060 groupBy: ["foo"],
4061 });
4062
4063 expect(".o_kanban_header .o_kanban_quick_add i").toHaveCount(3);
4064 expect(".o_kanban_group:first-child .o_kanban_record").toHaveCount(2);
4065
4066 await quickCreateKanbanRecord();
4067 expect(".o_kanban_quick_create input:first").toHaveValue("blip", {
4068 message: "should have set the correct foo value by default",
4069 });
4070 await validateKanbanRecord();
4071
4072 expect(".o_kanban_group:first-child .o_kanban_record").toHaveCount(3);
4073 });
4074
4075 test("quick create record in grouped by boolean field (within quick_create_view)", async () => {
4076 expect.assertions(6);
4077
4078 Partner._views["form,some_view_ref"] = `<form><field name="bar"/></form>`;
4079
4080 onRpc("web_save", ({ args, kwargs }) => {
4081 expect(args[1]).toEqual({ bar: true });
4082 expect(kwargs.context.default_bar).toBe(true);
4083 });
4084
4085 await mountView({
4086 type: "kanban",
4087 resModel: "partner",
4088 arch: `
4089 <kanban on_create="quick_create" quick_create_view="some_view_ref">
4090 <templates>
4091 <t t-name="card">
4092 <field name="bar"/>
4093 </t>
4094 </templates>
4095 </kanban>`,
4096 groupBy: ["bar"],
4097 });
4098
4099 expect(".o_kanban_header .o_kanban_quick_add i").toHaveCount(2, {
4100 message: "quick create should be enabled when grouped on a boolean field",
4101 });
4102 expect(".o_kanban_group:last-child .o_kanban_record").toHaveCount(3);
4103
4104 await quickCreateKanbanRecord(1);
4105 expect(".o_kanban_quick_create .o_field_boolean input").toBeChecked();
4106
4107 await contains(".o_kanban_quick_create .o_kanban_add").click();
4108 await animationFrame();
4109 expect(".o_kanban_group:last-child .o_kanban_record").toHaveCount(4);
4110 });
4111
4112 test("quick create record in grouped by selection field (within quick_create_view)", async () => {
4113 expect.assertions(6);
4114
4115 Partner._views["form,some_view_ref"] = `<form><field name="state"/></form>`;
4116
4117 onRpc("web_save", ({ args, kwargs }) => {
4118 expect(args[1]).toEqual({ state: "abc" });
4119 expect(kwargs.context.default_state).toBe("abc");
4120 });
4121
4122 await mountView({
4123 type: "kanban",
4124 resModel: "partner",
4125 arch: `
4126 <kanban on_create="quick_create" quick_create_view="some_view_ref">
4127 <templates>
4128 <t t-name="card">
4129 <field name="state"/>
4130 </t>
4131 </templates>
4132 </kanban>`,
4133 groupBy: ["state"],
4134 });
4135
4136 expect(".o_kanban_header .o_kanban_quick_add i").toHaveCount(3, {
4137 message: "quick create should be enabled when grouped on a selection field",
4138 });
4139 expect(".o_kanban_group:first-child .o_kanban_record").toHaveCount(1, {
4140 message: "first column (abc) should contain 1 record",
4141 });
4142
4143 await quickCreateKanbanRecord();
4144 expect(".o_kanban_quick_create input").toHaveValue("ABC", {
4145 message: "should have set the correct state value by default",
4146 });
4147
4148 await contains(".o_kanban_quick_create .o_kanban_add").click();
4149 await animationFrame();
4150 expect(".o_kanban_group:first-child .o_kanban_record").toHaveCount(2, {
4151 message: "first column (abc) should now contain 2 records",
4152 });
4153 });
4154
4155 test.tags("desktop");
4156 test("quick create record while adding a new column", async () => {
4157 const def = new Deferred();
4158 onRpc("product", "name_create", () => def);
4159
4160 await mountView({
4161 type: "kanban",
4162 resModel: "partner",
4163 arch: `
4164 <kanban default_group_by="product_id" on_create="quick_create">
4165 <templates>
4166 <t t-name="card">
4167 <field name="foo"/>
4168 </t>
4169 </templates>
4170 </kanban>`,
4171 });
4172
4173 expect(".o_kanban_group").toHaveCount(2);
4174 expect(".o_kanban_group:first-child .o_kanban_record").toHaveCount(2);
4175
4176 // add a new column
4177 expect(".o_column_quick_create.o_quick_create_folded").toHaveCount(1);
4178
4179 await quickCreateKanbanColumn();
4180
4181 expect(".o_column_quick_create.o_quick_create_unfolded").toHaveCount(1);
4182
4183 await editKanbanColumnName("new column");
4184 await validateKanbanColumn();
4185
4186 await animationFrame();
4187
4188 expect(".o_column_quick_create input:first").toHaveValue("");
4189 expect(".o_kanban_group").toHaveCount(2);
4190
4191 // click to add a new record
4192 await createKanbanRecord();
4193
4194 expect(".o_kanban_quick_create").toHaveCount(1);
4195
4196 // unlock column creation
4197 def.resolve();
4198 await animationFrame();
4199
4200 expect(".o_kanban_group").toHaveCount(3);
4201 expect(".o_kanban_quick_create").toHaveCount(1);
4202
4203 // quick create record in first column
4204 await editKanbanRecordQuickCreateInput("display_name", "new record");
4205 await validateKanbanRecord();
4206
4207 expect(".o_kanban_group:first-child .o_kanban_record").toHaveCount(3);
4208 });
4209
4210 test.tags("desktop");
4211 test("close a column while quick creating a record", async () => {
4212 Partner._views["form,some_view_ref"] = '<form><field name="int_field"/></form>';
4213
4214 let def;
4215 onRpc("get_views", () => {
4216 if (def) {
4217 expect.step("get_views");
4218 return def;
4219 }
4220 });
4221 await mountView({
4222 type: "kanban",
4223 resModel: "partner",
4224 arch: `
4225 <kanban on_create="quick_create" quick_create_view="some_view_ref">
4226 <templates>
4227 <t t-name="card">
4228 <field name="foo"/>
4229 </t>
4230 </templates>
4231 </kanban>`,
4232 groupBy: ["product_id"],
4233 });
4234
4235 def = new Deferred();
4236
4237 expect.verifySteps([]);
4238 expect(".o_kanban_group").toHaveCount(2);
4239 expect(".o_column_folded").toHaveCount(0);
4240
4241 // click to quick create a new record in the first column (this operation is delayed)
4242 await quickCreateKanbanRecord();
4243
4244 expect.verifySteps(["get_views"]);
4245 expect(".o_form_view").toHaveCount(0);
4246
4247 // click to fold the first column
4248 const clickColumnAction = await toggleKanbanColumnActions(0);
4249 await clickColumnAction("Fold");
4250
4251 expect(".o_column_folded").toHaveCount(1);
4252
4253 def.resolve();
4254 await animationFrame();
4255
4256 expect.verifySteps([]);
4257 expect(".o_form_view").toHaveCount(0);
4258 expect(".o_column_folded").toHaveCount(1);
4259
4260 await createKanbanRecord();
4261
4262 expect.verifySteps([]); // "get_views" should have already be done
4263 expect(".o_form_view").toHaveCount(1);
4264 expect(".o_column_folded").toHaveCount(1);
4265 });
4266
4267 test("quick create record: open on a column while another column has already one", async () => {
4268 await mountView({
4269 type: "kanban",
4270 resModel: "partner",
4271 arch: `
4272 <kanban on_create="quick_create">
4273 <templates>
4274 <t t-name="card">
4275 <field name="foo"/>
4276 </t>
4277 </templates>
4278 </kanban>`,
4279 groupBy: ["product_id"],
4280 });
4281
4282 // Click on quick create in first column
4283 await quickCreateKanbanRecord();
4284 expect(".o_kanban_quick_create").toHaveCount(1);
4285 expect(queryAll(".o_kanban_quick_create", { root: getKanbanColumn(0) })).toHaveCount(1);
4286
4287 // Click on quick create in second column
4288 await quickCreateKanbanRecord(1);
4289 expect(".o_kanban_quick_create").toHaveCount(1);
4290 expect(queryAll(".o_kanban_quick_create", { root: getKanbanColumn(2) })).toHaveCount(1);
4291
4292 // Click on quick create in first column once again
4293 await quickCreateKanbanRecord();
4294 expect(".o_kanban_quick_create").toHaveCount(1);
4295 expect(queryAll(".o_kanban_quick_create", { root: getKanbanColumn(0) })).toHaveCount(1);
4296 });
4297
4298 test("many2many_tags in kanban views", async () => {
4299 Partner._records[0].category_ids = [6, 7];
4300 Partner._records[1].category_ids = [7, 8];
4301 Category._records.push({
4302 id: 8,
4303 name: "hello",
4304 color: 0,
4305 });
4306
4307 stepAllNetworkCalls();
4308
4309 await mountView({
4310 type: "kanban",
4311 resModel: "partner",
4312 arch: `
4313 <kanban>
4314 <templates>
4315 <t t-name="card">
4316 <field name="category_ids" widget="many2many_tags" options="{'color_field': 'color'}"/>
4317 <field name="foo"/>
4318 <field name="state" widget="priority"/>
4319 </t>
4320 </templates>
4321 </kanban>`,
4322 selectRecord: (resId) => {
4323 expect(resId).toBe(1, {
4324 message: "should trigger an event to open the clicked record in a form view",
4325 });
4326 },
4327 });
4328
4329 expect(
4330 queryAll(".o_field_many2many_tags .o_tag", { root: getKanbanRecord({ index: 0 }) })
4331 ).toHaveCount(2, {
4332 message: "first record should contain 2 tags",
4333 });
4334 expect(queryAll(".o_tag.o_tag_color_2", { root: getKanbanRecord({ index: 0 }) })).toHaveCount(
4335 1,
4336 {
4337 message: "first tag should have color 2",
4338 }
4339 );
4340 expect.verifySteps([
4341 "/web/webclient/translations",
4342 "/web/webclient/load_menus",
4343 "get_views",
4344 "web_search_read",
4345 "has_group",
4346 ]);
4347
4348 // Checks that second records has only one tag as one should be hidden (color 0)
4349 expect(".o_kanban_record:nth-child(2) .o_tag").toHaveCount(1, {
4350 message: "there should be only one tag in second record",
4351 });
4352 expect(".o_kanban_record:nth-child(2) .o_tag:first").toHaveText("silver");
4353
4354 // Write on the record using the priority widget to trigger a re-render in readonly
4355 await contains(".o_kanban_record:first-child .o_priority_star:first-child").click();
4356
4357 expect.verifySteps(["web_save"]);
4358 expect(".o_kanban_record:first-child .o_field_many2many_tags .o_tag").toHaveCount(2, {
4359 message: "first record should still contain only 2 tags",
4360 });
4361 const tags = queryAll(".o_kanban_record:first-child .o_tag");
4362 expect(tags[0]).toHaveText("gold");
4363 expect(tags[1]).toHaveText("silver");
4364
4365 // click on a tag (should trigger switch_view)
4366 await contains(".o_kanban_record:first-child .o_tag:first-child").click();
4367 });
4368
4369 test("priority field should not be editable when missing access rights", async () => {
4370 await mountView({
4371 type: "kanban",
4372 resModel: "partner",
4373 arch: `
4374 <kanban edit="0">
4375 <templates>
4376 <t t-name="card">
4377 <field name="foo"/>
4378 <field name="state" widget="priority"/>
4379 </t>
4380 </templates>
4381 </kanban>`,
4382 });
4383 // Try to fill one star in the priority field of the first record
4384 await contains(".o_kanban_record:first-child .o_priority_star:first-child").click();
4385 expect(".o_kanban_record:first-child .o_priority .fa-star-o").toHaveCount(2, {
4386 message: "first record should still contain 2 empty stars",
4387 });
4388 });
4389
4390 test("Do not open record when clicking on `a` with `href`", async () => {
4391 expect.assertions(6);
4392
4393 Partner._records = [{ id: 1, foo: "yop" }];
4394
4395 mockService("action", {
4396 async switchView() {
4397 // when clicking on a record in kanban view,
4398 // it switches to form view.
4399 expect.step("switchView");
4400 },
4401 });
4402
4403 await mountView({
4404 type: "kanban",
4405 resModel: "partner",
4406 arch: `
4407 <kanban>
4408 <templates>
4409 <t t-name="card">
4410 <field name="foo"/>
4411 <a class="o_test_link" href="#">test link</a>
4412 </t>
4413 </templates>
4414 </kanban>`,
4415 });
4416
4417 expect(".o_kanban_record:not(.o_kanban_ghost)").toHaveCount(1);
4418 expect(".o_kanban_record a").toHaveCount(1);
4419
4420 expect(".o_kanban_record a").toHaveAttribute("href", null, {
4421 message: "link inside kanban record should have non-empty href",
4422 });
4423
4424 // Prevent the browser default behaviour when clicking on anything.
4425 // This includes clicking on a `<a>` with `href`, so that it does not
4426 // change the URL in the address bar.
4427 // Note that we should not specify a click listener on 'a', otherwise
4428 // it may influence the kanban record global click handler to not open
4429 // the record.
4430 const testLink = queryFirst(".o_kanban_record a");
4431 testLink.addEventListener("click", (ev) => {
4432 expect(ev.defaultPrevented).toBe(false, {
4433 message: "should not prevented browser default behaviour beforehand",
4434 });
4435 expect(ev.target).toBe(testLink, {
4436 message: "should have clicked on the test link in the kanban record",
4437 });
4438 ev.preventDefault();
4439 });
4440
4441 await click(".o_kanban_record a");
4442
4443 expect.verifySteps([]);
4444 });
4445
4446 test("Open record when clicking on widget field", async function (assert) {
4447 expect.assertions(2);
4448
4449 Product._views["form"] = `<form string="Product"><field name="display_name"/></form>`;
4450
4451 await mountView({
4452 type: "kanban",
4453 resModel: "partner",
4454 arch: `
4455 <kanban>
4456 <templates>
4457 <t t-name="card">
4458 <field name="salary" widget="monetary"/>
4459 </t>
4460 </templates>
4461 </kanban>`,
4462 selectRecord: (resId) => {
4463 expect(resId).toBe(1, { message: "should trigger an event to open the form view" });
4464 },
4465 });
4466
4467 expect(".o_kanban_record:not(.o_kanban_ghost)").toHaveCount(4);
4468
4469 await click(".o_field_monetary[name=salary]");
4470 });
4471
4472 test("o2m loaded in only one batch", async () => {
4473 class Subtask extends models.Model {
4474 _name = "subtask";
4475
4476 name = fields.Char();
4477
4478 _records = [
4479 { id: 1, name: "subtask #1" },
4480 { id: 2, name: "subtask #2" },
4481 ];
4482 }
4483 defineModels([Subtask]);
4484 Partner._fields.subtask_ids = fields.One2many({ relation: "subtask" });
4485 Partner._records[0].subtask_ids = [1];
4486 Partner._records[1].subtask_ids = [2];
4487
4488 stepAllNetworkCalls();
4489
4490 await mountView({
4491 type: "kanban",
4492 resModel: "partner",
4493 arch: `
4494 <kanban>
4495 <templates>
4496 <t t-name="card">
4497 <field name="subtask_ids" widget="many2many_tags"/>
4498 </t>
4499 </templates>
4500 </kanban>`,
4501 groupBy: ["product_id"],
4502 });
4503
4504 await validateSearch();
4505 expect.verifySteps([
4506 "/web/webclient/translations",
4507 "/web/webclient/load_menus",
4508 "get_views",
4509 "web_read_group",
4510 "has_group",
4511 "web_read_group",
4512 ]);
4513 });
4514
4515 test.tags("desktop");
4516 test("kanban with many2many, load and reload", async () => {
4517 stepAllNetworkCalls();
4518
4519 await mountView({
4520 type: "kanban",
4521 resModel: "partner",
4522 arch: `
4523 <kanban>
4524 <templates>
4525 <t t-name="card">
4526 <field name="category_ids" widget="many2many_tags"/>
4527 </t>
4528 </templates>
4529 </kanban>`,
4530 groupBy: ["product_id"],
4531 });
4532
4533 await press("Enter"); // reload
4534 await animationFrame();
4535
4536 expect.verifySteps([
4537 "/web/webclient/translations",
4538 "/web/webclient/load_menus",
4539 "get_views",
4540 "web_read_group",
4541 "has_group",
4542 "web_read_group",
4543 ]);
4544 });
4545
4546 test.tags("desktop");
4547 test("kanban with reference field", async () => {
4548 Partner._fields.ref_product = fields.Reference({ selection: [["product", "Product"]] });
4549 Partner._records[0].ref_product = "product,3";
4550 Partner._records[1].ref_product = "product,5";
4551
4552 stepAllNetworkCalls();
4553
4554 await mountView({
4555 type: "kanban",
4556 resModel: "partner",
4557 groupBy: ["product_id"],
4558 arch: `
4559 <kanban>
4560 <templates>
4561 <t t-name="card">
4562 <field name="ref_product"/>
4563 </t>
4564 </templates>
4565 </kanban>`,
4566 });
4567
4568 await press("Enter"); // reload
4569 await animationFrame();
4570
4571 expect.verifySteps([
4572 "/web/webclient/translations",
4573 "/web/webclient/load_menus",
4574 "get_views",
4575 "web_read_group",
4576 "has_group",
4577 "web_read_group",
4578 ]);
4579 expect(queryAllTexts(".o_kanban_record span")).toEqual(["hello", "", "xmo", ""]);
4580 });
4581
4582 test.tags("desktop");
4583 test("drag and drop a record with load more", async () => {
4584 await mountView({
4585 type: "kanban",
4586 resModel: "partner",
4587 arch: `
4588 <kanban limit="1">
4589 <templates>
4590 <t t-name="card">
4591 <field name="id"/>
4592 </t>
4593 </templates>
4594 </kanban>`,
4595 groupBy: ["bar"],
4596 });
4597
4598 expect(queryAllTexts(".o_kanban_group:eq(0) .o_kanban_record")).toEqual(["4"]);
4599 expect(queryAllTexts(".o_kanban_group:eq(1) .o_kanban_record")).toEqual(["1"]);
4600
4601 await contains(".o_kanban_group:eq(1) .o_kanban_record").dragAndDrop(".o_kanban_group:eq(0)");
4602 expect(queryAllTexts(".o_kanban_group:eq(0) .o_kanban_record")).toEqual(["4", "1"]);
4603 expect(queryAllTexts(".o_kanban_group:eq(1) .o_kanban_record")).toEqual(["2"]);
4604 });
4605
4606 test.tags("desktop");
4607 test("can drag and drop a record from one column to the next", async () => {
4608 onRpc("web_resequence", () => {
4609 expect.step("resequence");
4610 });
4611
4612 await mountView({
4613 type: "kanban",
4614 resModel: "partner",
4615 arch: `
4616 <kanban on_create="quick_create">
4617 <templates>
4618 <t t-name="card">
4619 <field name="foo"/>
4620 <t t-if="widget.editable">
4621 <span class="thisiseditable">edit</span>
4622 </t>
4623 </t>
4624 </templates>
4625 </kanban>`,
4626 groupBy: ["product_id"],
4627 });
4628 expect(".o_kanban_group:first-child .o_kanban_record").toHaveCount(2);
4629 expect(".o_kanban_group:nth-child(2) .o_kanban_record").toHaveCount(2);
4630 expect(".thisiseditable").toHaveCount(4);
4631
4632 expect.verifySteps([]);
4633
4634 // first record of first column moved to the bottom of second column
4635 await contains(".o_kanban_group:first-child .o_kanban_record").dragAndDrop(
4636 ".o_kanban_group:nth-child(2)"
4637 );
4638
4639 expect(".o_kanban_group:first-child .o_kanban_record").toHaveCount(1);
4640 expect(".o_kanban_group:nth-child(2) .o_kanban_record").toHaveCount(3);
4641 expect(".thisiseditable").toHaveCount(4);
4642
4643 expect.verifySteps(["resequence"]);
4644 });
4645
4646 test.tags("desktop");
4647 test("user without permission cannot drag and drop a column thus sequence remains unchanged on drag and drop attempt", async () => {
4648 expect.errors(1);
4649
4650 onRpc("web_resequence", () => {
4651 throw makeServerError({ message: "No Permission" }); // Simulate user without permission
4652 });
4653
4654 await mountView({
4655 type: "kanban",
4656 resModel: "partner",
4657 arch: `
4658 <kanban>
4659 <templates>
4660 <t t-name="card">
4661 <field name="foo"/>
4662 </t>
4663 </templates>
4664 </kanban>`,
4665 groupBy: ["product_id"],
4666 });
4667
4668 expect(queryAllTexts(".o_column_title")).toEqual(["hello\n(2)", "xmo\n(2)"]);
4669
4670 const groups = queryAll(".o_column_title");
4671 await contains(groups[0]).dragAndDrop(groups[1]);
4672
4673 expect(queryAllTexts(".o_column_title")).toEqual(["hello\n(2)", "xmo\n(2)"]);
4674
4675 expect.verifyErrors(["No Permission"]);
4676 });
4677
4678 test.tags("desktop");
4679 test("user without permission cannot drag and drop a record thus sequence remains unchanged on drag and drop attempt", async () => {
4680 expect.errors(1);
4681
4682 onRpc("partner", "web_save", () => {
4683 throw makeServerError({ message: "No Permission" }); // Simulate user without permission
4684 });
4685
4686 await mountView({
4687 type: "kanban",
4688 resModel: "partner",
4689 arch: `
4690 <kanban>
4691 <templates>
4692 <t t-name="card">
4693 <field name="foo"/>
4694 </t>
4695 </templates>
4696 </kanban>`,
4697 groupBy: ["product_id"],
4698 });
4699
4700 expect(".o_kanban_record:first").toHaveText("yop", {
4701 message: "Checking the initial state of the view",
4702 });
4703
4704 await contains(".o_kanban_record").dragAndDrop(".o_kanban_group:nth-child(2)");
4705
4706 expect(".o_kanban_record:first").toHaveText("yop", {
4707 message: "Do not let the user d&d the record without permission",
4708 });
4709
4710 await contains(".o_kanban_record").dragAndDrop(".o_kanban_record:nth-child(3)");
4711
4712 expect(".o_kanban_record:first").toHaveText("gnap", {
4713 message: "Check that the record does not become static after d&d",
4714 });
4715
4716 expect.verifyErrors(["No Permission"]);
4717 });
4718
4719 test.tags("desktop");
4720 test("drag and drop highlight on hover and has visible placeholder", async () => {
4721 await mountView({
4722 type: "kanban",
4723 resModel: "partner",
4724 arch: `
4725 <kanban on_create="quick_create">
4726 <templates>
4727 <t t-name="card">
4728 <field name="foo"/>
4729 </t>
4730 </templates>
4731 </kanban>`,
4732 groupBy: ["product_id"],
4733 });
4734 expect(".o_kanban_group:first-child .o_kanban_record").toHaveCount(2);
4735 expect(".o_kanban_group:nth-child(2) .o_kanban_record").toHaveCount(2);
4736
4737 // first record of first column moved to the bottom of second column
4738 const { drop, moveTo } = await contains(".o_kanban_group:first-child .o_kanban_record").drag();
4739 await moveTo(".o_kanban_group:nth-child(2)");
4740 expect(".o_kanban_group:first-child .o_kanban_record").toHaveCount(2);
4741 expect(".o_kanban_group:nth-child(2) .o_kanban_record").toHaveCount(3); // includes the placeholder
4742 expect(".o_kanban_group:nth-child(2) .o_kanban_record:eq(2)").toBeVisible();
4743
4744 expect(getKanbanColumn(1)).toHaveClass("o_kanban_hover");
4745
4746 await drop();
4747
4748 expect(".o_kanban_group:first-child .o_kanban_record").toHaveCount(1);
4749 expect(".o_kanban_group:nth-child(2) .o_kanban_record").toHaveCount(3);
4750 expect(".o_kanban_group:nth-child(2).o_kanban_hover").toHaveCount(0);
4751 });
4752
4753 test("drag and drop outside of a column", async () => {
4754 await mountView({
4755 type: "kanban",
4756 resModel: "partner",
4757 arch: `
4758 <kanban default_group_by="product_id" on_create="quick_create">
4759 <templates>
4760 <t t-name="card">
4761 <field name="foo"/>
4762 </t>
4763 </templates>
4764 </kanban>`,
4765 });
4766 expect(".o_kanban_group:first-child .o_kanban_record").toHaveCount(2);
4767 expect(".o_kanban_group:nth-child(2) .o_kanban_record").toHaveCount(2);
4768
4769 // first record of first column moved to the right of a column
4770 await contains(".o_kanban_group:first-child .o_kanban_record").dragAndDrop(
4771 ".o_column_quick_create"
4772 );
4773 expect(".o_kanban_group:first-child .o_kanban_record").toHaveCount(2);
4774 });
4775
4776 test.tags("desktop");
4777 test("drag and drop a record, grouped by selection", async () => {
4778 onRpc("web_resequence", () => {
4779 expect.step("resequence");
4780 });
4781 onRpc("partner", "web_save", ({ args }) => {
4782 expect.step(args[1]);
4783 });
4784
4785 await mountView({
4786 type: "kanban",
4787 resModel: "partner",
4788 arch: `
4789 <kanban on_create="quick_create">
4790 <templates>
4791 <t t-name="card">
4792 <field name="state"/>
4793 </t>
4794 </templates>
4795 </kanban>`,
4796 groupBy: ["state"],
4797 });
4798 expect(".o_kanban_group:first-child .o_kanban_record").toHaveCount(1);
4799 expect(".o_kanban_group:nth-child(2) .o_kanban_record").toHaveCount(1);
4800 expect.verifySteps([]);
4801
4802 // first record of second column moved to the bottom of first column
4803 await contains(".o_kanban_group:nth-child(2) .o_kanban_record").dragAndDrop(
4804 ".o_kanban_group:first-child"
4805 );
4806
4807 expect(".o_kanban_group:first-child .o_kanban_record").toHaveCount(2);
4808 expect(".o_kanban_group:nth-child(2) .o_kanban_record").toHaveCount(0);
4809 expect.verifySteps([{ state: "abc" }, "resequence"]);
4810 });
4811
4812 test.tags("desktop");
4813 test("prevent drag and drop of record if grouped by readonly", async () => {
4814 // Whether the kanban is grouped by state, foo, bar or product_id
4815 // the user must not be able to drag and drop from one group to another,
4816 // as state, foo bar, product_id are made readonly one way or another.
4817 // state must not be draggable:
4818 // state is not readonly in the model. state is passed in the arch specifying readonly="1".
4819 // foo must not be draggable:
4820 // foo is readonly in the model fields. foo is passed in the arch but without specifying readonly.
4821 // bar must not be draggable:
4822 // bar is readonly in the model fields. bar is not passed in the arch.
4823 // product_id must not be draggable:
4824 // product_id is readonly in the model fields. product_id is passed in the arch specifying readonly="0",
4825 // but the readonly in the model takes over.
4826 Partner._fields.foo = fields.Char({ readonly: true });
4827 Partner._fields.bar = fields.Boolean({ readonly: true });
4828 Partner._fields.product_id = fields.Many2one({ relation: "product", readonly: true });
4829
4830 onRpc("partner", "write", () => {
4831 expect.step("should not be called");
4832 });
4833
4834 await mountView({
4835 type: "kanban",
4836 resModel: "partner",
4837 arch: `
4838 <kanban>
4839 <templates>
4840 <t t-name="card">
4841 <div>
4842 <field name="foo"/>
4843 <field name="product_id" readonly="0" invisible="1"/>
4844 <field name="state" readonly="1"/>
4845 </div>
4846 </t>
4847 </templates>
4848 </kanban>`,
4849 searchViewArch: `
4850 <search>
4851 <filter name="group_by_foo" domain="[]" string="GroupBy Foo" context="{ 'group_by': 'foo' }"/>
4852 <filter name="group_by_bar" domain="[]" string="GroupBy Bar" context="{ 'group_by': 'bar' }"/>
4853 <filter name="group_by_product" domain="[]" string="GroupBy Product" context="{ 'group_by': 'product_id' }"/>
4854 </search>`,
4855 groupBy: ["state"],
4856 });
4857
4858 expect(".o_kanban_group:first-child .o_kanban_record").toHaveCount(1);
4859 expect(".o_kanban_group:nth-child(2) .o_kanban_record").toHaveCount(1);
4860 expect(".o_kanban_group:nth-child(3) .o_kanban_record").toHaveCount(2);
4861
4862 // first record of first column moved to the bottom of second column
4863 await contains(".o_kanban_group:first-child .o_kanban_record").dragAndDrop(
4864 ".o_kanban_group:nth-child(2)"
4865 );
4866
4867 // should not be draggable
4868 expect(".o_kanban_group:first-child .o_kanban_record").toHaveCount(1);
4869 expect(".o_kanban_group:nth-child(2) .o_kanban_record").toHaveCount(1);
4870 expect(".o_kanban_group:nth-child(3) .o_kanban_record").toHaveCount(2);
4871
4872 await toggleSearchBarMenu();
4873 await toggleMenuItem("GroupBy Foo");
4874
4875 expect(".o_kanban_group:first-child .o_kanban_record").toHaveCount(2);
4876 expect(".o_kanban_group:nth-child(2) .o_kanban_record").toHaveCount(1);
4877 expect(".o_kanban_group:nth-child(3) .o_kanban_record").toHaveCount(1);
4878
4879 // first record of first column moved to the bottom of second column
4880 await contains(".o_kanban_group:first-child .o_kanban_record").dragAndDrop(
4881 ".o_kanban_group:nth-child(2)"
4882 );
4883
4884 // should not be draggable
4885 expect(".o_kanban_group:first-child .o_kanban_record").toHaveCount(2);
4886 expect(".o_kanban_group:nth-child(2) .o_kanban_record").toHaveCount(1);
4887 expect(".o_kanban_group:nth-child(3) .o_kanban_record").toHaveCount(1);
4888
4889 expect(getKanbanRecordTexts(0)).toEqual(["blipDEF", "blipGHI"]);
4890
4891 // second record of first column moved at first place
4892 await contains(".o_kanban_group:first-child .o_kanban_record:last-of-type").dragAndDrop(
4893 ".o_kanban_group:first-child .o_kanban_record"
4894 );
4895
4896 // should still be able to resequence
4897 expect(getKanbanRecordTexts(0)).toEqual(["blipGHI", "blipDEF"]);
4898
4899 await toggleSearchBarMenu();
4900 await toggleMenuItem("GroupBy Foo");
4901 await toggleMenuItem("GroupBy Bar");
4902
4903 expect(".o_kanban_group:first-child .o_kanban_record").toHaveCount(1);
4904 expect(".o_kanban_group:nth-child(2) .o_kanban_record").toHaveCount(3);
4905 expect(".o_kanban_group:nth-child(3) .o_kanban_record").toHaveCount(0);
4906
4907 expect(getKanbanRecordTexts(0)).toEqual(["blipGHI"]);
4908
4909 // first record of first column moved to the bottom of second column
4910 await contains(".o_kanban_group:first-child .o_kanban_record").dragAndDrop(
4911 ".o_kanban_group:nth-child(2)"
4912 );
4913
4914 // should not be draggable
4915 expect(".o_kanban_group:first-child .o_kanban_record").toHaveCount(1);
4916 expect(".o_kanban_group:nth-child(2) .o_kanban_record").toHaveCount(3);
4917 expect(".o_kanban_group:nth-child(3) .o_kanban_record").toHaveCount(0);
4918
4919 expect(getKanbanRecordTexts(0)).toEqual(["blipGHI"]);
4920
4921 await toggleSearchBarMenu();
4922 await toggleMenuItem("GroupBy Bar");
4923 await toggleMenuItem("GroupBy Product");
4924
4925 expect(".o_kanban_group:first-child .o_kanban_record").toHaveCount(2);
4926 expect(".o_kanban_group:nth-child(2) .o_kanban_record").toHaveCount(2);
4927 expect(".o_kanban_group:nth-child(3) .o_kanban_record").toHaveCount(0);
4928
4929 expect(getKanbanRecordTexts(0)).toEqual(["yopABC", "gnapGHI"]);
4930
4931 // first record of first column moved to the bottom of second column
4932 await contains(".o_kanban_group:first-child .o_kanban_record").dragAndDrop(
4933 ".o_kanban_group:nth-child(2)"
4934 );
4935
4936 // should not be draggable
4937 expect(".o_kanban_group:first-child .o_kanban_record").toHaveCount(2);
4938 expect(".o_kanban_group:nth-child(2) .o_kanban_record").toHaveCount(2);
4939 expect(".o_kanban_group:nth-child(3) .o_kanban_record").toHaveCount(0);
4940
4941 expect(getKanbanRecordTexts(0)).toEqual(["yopABC", "gnapGHI"]);
4942 expect.verifySteps([]);
4943 });
4944
4945 test("prevent drag and drop if grouped by date/datetime field", async () => {
4946 Partner._records[0].date = "2017-01-08";
4947 Partner._records[1].date = "2017-01-09";
4948 Partner._records[2].date = "2017-02-08";
4949 Partner._records[3].date = "2017-02-10";
4950 Partner._records[0].datetime = "2017-01-08 10:55:05";
4951 Partner._records[1].datetime = "2017-01-09 11:31:10";
4952 Partner._records[2].datetime = "2017-02-08 09:20:25";
4953 Partner._records[3].datetime = "2017-02-10 08:05:51";
4954
4955 await mountView({
4956 type: "kanban",
4957 resModel: "partner",
4958 arch: `
4959 <kanban>
4960 <templates>
4961 <t t-name="card">
4962 <field name="foo"/>
4963 </t>
4964 </templates>
4965 </kanban>`,
4966 searchViewArch: `
4967 <search>
4968 <filter name="group_by_datetime" domain="[]" string="GroupBy Datetime" context="{ 'group_by': 'datetime' }"/>
4969 </search>`,
4970 groupBy: ["date:month"],
4971 });
4972
4973 expect(".o_kanban_group").toHaveCount(2);
4974 expect(".o_kanban_group:nth-child(2) .o_kanban_record").toHaveCount(2, {
4975 message: "1st column should contain 2 records of January month",
4976 });
4977 expect(".o_kanban_group:nth-child(2) .o_kanban_record").toHaveCount(2, {
4978 message: "2nd column should contain 2 records of February month",
4979 });
4980
4981 // drag&drop a record in another column
4982 await contains(".o_kanban_group:first-child .o_kanban_record").dragAndDrop(
4983 ".o_kanban_group:nth-child(2)"
4984 );
4985
4986 // should not drag&drop record
4987 expect(".o_kanban_group:first-child .o_kanban_record").toHaveCount(2, {
4988 message: "Should remain same records in first column (2 records)",
4989 });
4990 expect(".o_kanban_group:nth-child(2) .o_kanban_record").toHaveCount(2, {
4991 message: "Should remain same records in 2nd column (2 record)",
4992 });
4993
4994 await toggleSearchBarMenu();
4995 await toggleMenuItem("GroupBy Datetime");
4996 await toggleMenuItemOption("GroupBy Datetime", "Month");
4997
4998 expect(".o_kanban_group").toHaveCount(2);
4999 expect(".o_kanban_group:first-child .o_kanban_record").toHaveCount(2, {
5000 message: "1st column should contain 2 records of January month",
5001 });
5002 expect(".o_kanban_group:nth-child(2) .o_kanban_record").toHaveCount(2, {
5003 message: "2nd column should contain 2 records of February month",
5004 });
5005
5006 // drag&drop a record in another column
5007 await contains(".o_kanban_group:first-child .o_kanban_record").dragAndDrop(
5008 ".o_kanban_group:nth-child(2)"
5009 );
5010
5011 // should not drag&drop record
5012 expect(".o_kanban_group:first-child .o_kanban_record").toHaveCount(2, {
5013 message: "Should remain same records in first column(2 records)",
5014 });
5015 expect(".o_kanban_group:nth-child(2) .o_kanban_record").toHaveCount(2, {
5016 message: "Should remain same records in 2nd column(2 record)",
5017 });
5018 });
5019
5020 test.tags("desktop");
5021 test("prevent drag and drop if grouped by many2many field", async () => {
5022 Partner._records[0].category_ids = [6, 7];
5023 Partner._records[3].category_ids = [7];
5024
5025 await mountView({
5026 type: "kanban",
5027 resModel: "partner",
5028 arch: `
5029 <kanban>
5030 <templates>
5031 <t t-name="card">
5032 <field name="foo"/>
5033 </t>
5034 </templates>
5035 </kanban>`,
5036 searchViewArch: `
5037 <search>
5038 <filter name="group_by_state" domain="[]" string="GroupBy State" context="{ 'group_by': 'state' }"/>
5039 </search>`,
5040 groupBy: ["category_ids"],
5041 });
5042
5043 expect(".o_kanban_group").toHaveCount(2);
5044 expect(".o_kanban_group:first-child .o_column_title:first").toHaveText("gold\n(2)", {
5045 message: "first column should have correct title",
5046 });
5047 expect(".o_kanban_group:last-child .o_column_title:first").toHaveText("silver\n(3)", {
5048 message: "second column should have correct title",
5049 });
5050 expect(".o_kanban_group:first-child .o_kanban_record").toHaveCount(2);
5051 expect(".o_kanban_group:last-child .o_kanban_record").toHaveCount(3);
5052
5053 // drag&drop a record in another column
5054 await contains(".o_kanban_group:first-child .o_kanban_record").dragAndDrop(
5055 ".o_kanban_group:nth-child(2)"
5056 );
5057
5058 expect(".o_kanban_group:first-child .o_kanban_record").toHaveCount(2);
5059 expect(".o_kanban_group:last-child .o_kanban_record").toHaveCount(3);
5060
5061 // Sanity check: groupby a non m2m field and check dragdrop is working
5062 await toggleSearchBarMenu();
5063 await toggleMenuItem("GroupBy State");
5064
5065 expect(".o_kanban_group").toHaveCount(3);
5066 expect(queryAllTexts(".o_kanban_group .o_column_title")).toEqual([
5067 "ABC\n(1)",
5068 "DEF\n(1)",
5069 "GHI\n(2)",
5070 ]);
5071 expect(".o_kanban_group:first-child .o_kanban_record").toHaveCount(1, {
5072 message: "first column should have 1 record",
5073 });
5074 expect(".o_kanban_group:last-child .o_kanban_record").toHaveCount(2, {
5075 message: "last column should have 2 records",
5076 });
5077
5078 await contains(".o_kanban_group:first-child .o_kanban_record").dragAndDrop(
5079 ".o_kanban_group:last-child"
5080 );
5081
5082 expect(".o_kanban_group:first-child .o_kanban_record").toHaveCount(0, {
5083 message: "first column should not contain records",
5084 });
5085 expect(".o_kanban_group:last-child .o_kanban_record").toHaveCount(3, {
5086 message: "last column should contain 3 records",
5087 });
5088 });
5089
5090 test("Ensuring each progress bar has some space", async () => {
5091 Partner._records = [
5092 {
5093 id: 1,
5094 foo: "blip",
5095 state: "def",
5096 },
5097 {
5098 id: 2,
5099 foo: "blip",
5100 state: "abc",
5101 },
5102 ];
5103
5104 for (let i = 0; i < 20; i++) {
5105 Partner._records.push({
5106 id: 3 + i,
5107 foo: "blip",
5108 state: "ghi",
5109 });
5110 }
5111
5112 await mountView({
5113 type: "kanban",
5114 resModel: "partner",
5115 arch: `
5116 <kanban>
5117 <progressbar field="state" colors='{"abc": "success", "def": "warning", "ghi": "danger"}' />
5118 <templates>
5119 <div t-name="card">
5120 <field name="state" widget="state_selection" />
5121 <field name="foo" />
5122 </div>
5123 </templates>
5124 </kanban>`,
5125 groupBy: ["foo"],
5126 });
5127
5128 expect(getKanbanProgressBars(0).map((pb) => pb.style.width)).toEqual(["5%", "5%", "90%"]);
5129 });
5130
5131 test("completely prevent drag and drop if records_draggable set to false", async () => {
5132 await mountView({
5133 type: "kanban",
5134 resModel: "partner",
5135 arch: `
5136 <kanban records_draggable="false">
5137 <templates>
5138 <t t-name="card">
5139 <field name="foo"/>
5140 </t>
5141 </templates>
5142 </kanban>`,
5143 groupBy: ["product_id"],
5144 });
5145
5146 // testing initial state
5147 expect(".o_kanban_group:first-child .o_kanban_record").toHaveCount(2);
5148 expect(".o_kanban_group:nth-child(2) .o_kanban_record").toHaveCount(2);
5149 expect(getKanbanRecordTexts()).toEqual(["yop", "gnap", "blip", "blip"]);
5150 expect(".o_draggable").toHaveCount(0);
5151
5152 // attempt to drag&drop a record in another column
5153 await contains(".o_kanban_group:first-child .o_kanban_record").dragAndDrop(
5154 ".o_kanban_group:nth-child(2)"
5155 );
5156
5157 // should not drag&drop record
5158 expect(".o_kanban_group:first-child .o_kanban_record").toHaveCount(2, {
5159 message: "First column should still contain 2 records",
5160 });
5161 expect(".o_kanban_group:nth-child(2) .o_kanban_record").toHaveCount(2, {
5162 message: "Second column should still contain 2 records",
5163 });
5164 expect(getKanbanRecordTexts()).toEqual(["yop", "gnap", "blip", "blip"], {
5165 message: "Records should not have moved",
5166 });
5167
5168 // attempt to drag&drop a record in the same column
5169 await contains(".o_kanban_group:first-child .o_kanban_record").dragAndDrop(
5170 ".o_kanban_group:first-child .o_kanban_record:last-of-type"
5171 );
5172
5173 expect(getKanbanRecordTexts()).toEqual(["yop", "gnap", "blip", "blip"], {
5174 message: "Records should not have moved",
5175 });
5176 });
5177
5178 test.tags("desktop");
5179 test("prevent drag and drop of record if save fails", async () => {
5180 expect.errors(1);
5181
5182 onRpc("partner", "web_save", () => {
5183 throw new Error("Save failed");
5184 });
5185 await mountView({
5186 type: "kanban",
5187 resModel: "partner",
5188 arch: `
5189 <kanban>
5190 <templates>
5191 <t t-name="card">
5192 <field name="foo"/>
5193 <field name="product_id"/>
5194 </t>
5195 </templates>
5196 </kanban>`,
5197 groupBy: ["product_id"],
5198 });
5199
5200 expect(".o_kanban_group:first-child .o_kanban_record").toHaveCount(2);
5201 expect(".o_kanban_group:nth-child(2) .o_kanban_record").toHaveCount(2);
5202
5203 // drag&drop a record in another column
5204 await contains(".o_kanban_group:first-child .o_kanban_record").dragAndDrop(
5205 ".o_kanban_group:nth-child(2)"
5206 );
5207
5208 // should not be dropped, card should reset back to first column
5209 expect(".o_kanban_group:first-child .o_kanban_record").toHaveCount(2);
5210 expect(".o_kanban_group:nth-child(2) .o_kanban_record").toHaveCount(2);
5211
5212 expect.verifyErrors(["Save failed"]);
5213 });
5214
5215 test("kanban view with default_group_by", async () => {
5216 expect.assertions(11);
5217
5218 Partner._records[0].product_id = 1;
5219 Product._records.push({ id: 1, display_name: "third product" });
5220
5221 let readGroupCount = 0;
5222 onRpc("web_read_group", ({ kwargs }) => {
5223 readGroupCount++;
5224 switch (readGroupCount) {
5225 case 1: {
5226 expect(kwargs.groupby).toEqual(["bar"]);
5227 break;
5228 }
5229 case 2: {
5230 expect(kwargs.groupby).toEqual(["product_id"]);
5231 break;
5232 }
5233 case 3: {
5234 expect(kwargs.groupby).toEqual(["bar"]);
5235 break;
5236 }
5237 }
5238 });
5239 await mountView({
5240 type: "kanban",
5241 resModel: "partner",
5242 arch: `
5243 <kanban default_group_by="bar">
5244 <templates>
5245 <t t-name="card">
5246 <field name="foo"/>
5247 </t>
5248 </templates>
5249 </kanban>`,
5250 searchViewArch: `
5251 <search>
5252 <filter name="group_by_product_id" domain="[]" string="GroupBy Product" context="{ 'group_by': 'product_id' }"/>
5253 </search>`,
5254 });
5255
5256 expect(".o_kanban_renderer").toHaveClass("o_kanban_grouped");
5257 expect(".o_kanban_group").toHaveCount(2);
5258 // open search bar in mobile
5259 if (queryAll(".o_control_panel_navigation > button").length) {
5260 await contains(".o_control_panel_navigation > button").click();
5261 }
5262 expect(`.o_searchview_facet`).toHaveCount(0);
5263
5264 // simulate an update coming from the searchview, with another groupby given
5265 await toggleSearchBarMenu();
5266 await toggleMenuItem("GroupBy Product");
5267 expect(".o_kanban_group").toHaveCount(3);
5268 expect(`.o_searchview_facet`).toHaveCount(1);
5269 expect(`.o_searchview_facet`).toHaveText("GroupBy Product");
5270
5271 // simulate an update coming from the searchview, removing the previously set groupby
5272 await contains(".o_searchview_facet .o_facet_remove").click();
5273 expect(".o_kanban_group").toHaveCount(2);
5274 expect(`.o_searchview_facet`).toHaveCount(0);
5275 });
5276
5277 test.tags("desktop");
5278 test("edit a favorite: group by = default_group_by", async () => {
5279 expect.assertions(4);
5280
5281 const irFilters = [
5282 {
5283 context: "{ 'group_by': ['bar'] }",
5284 domain: "[]",
5285 id: 1,
5286 is_default: true,
5287 name: "My favorite",
5288 sort: "[]",
5289 user_ids: [2],
5290 },
5291 ];
5292
5293 onRpc("web_read_group", ({ kwargs }) => {
5294 expect(kwargs.groupby).toEqual(["bar"]);
5295 });
5296 onRpc("/web/domain/validate", () => true);
5297
5298 await mountView({
5299 type: "kanban",
5300 resModel: "partner",
5301 arch: `
5302 <kanban default_group_by="bar">
5303 <templates>
5304 <t t-name="card">
5305 <field name="foo"/>
5306 </t>
5307 </templates>
5308 </kanban>`,
5309 irFilters,
5310 });
5311
5312 expect(getFacetTexts()).toEqual(["My favorite"]);
5313
5314 await contains(".o_searchview_facet_label").click();
5315 await addNewRule();
5316 await contains("button:contains('Search')").click();
5317 expect(getFacetTexts()).toEqual(["Id = 1"]);
5318 });
5319
5320 test.tags("desktop");
5321 test("edit a favorite: group by != default_group_by", async () => {
5322 expect.assertions(4);
5323
5324 const irFilters = [
5325 {
5326 context: "{ 'group_by': ['product_id'] }",
5327 domain: "[]",
5328 id: 1,
5329 is_default: true,
5330 name: "My favorite",
5331 sort: "[]",
5332 user_ids: [2],
5333 },
5334 ];
5335
5336 onRpc("web_read_group", ({ kwargs }) => {
5337 expect(kwargs.groupby).toEqual(["product_id"]);
5338 });
5339 onRpc("/web/domain/validate", () => true);
5340
5341 await mountView({
5342 type: "kanban",
5343 resModel: "partner",
5344 arch: `
5345 <kanban default_group_by="bar">
5346 <templates>
5347 <t t-name="card">
5348 <field name="foo"/>
5349 </t>
5350 </templates>
5351 </kanban>`,
5352 irFilters,
5353 });
5354
5355 expect(getFacetTexts()).toEqual(["My favorite"]);
5356
5357 await contains(".o_searchview_facet_label").click();
5358 await addNewRule();
5359 await contains("button:contains('Search')").click();
5360 expect(getFacetTexts()).toEqual(["Id = 1", "Product"]);
5361 });
5362
5363 test.tags("desktop");
5364 test("kanban view not groupable", async () => {
5365 patchWithCleanup(kanbanView, { searchMenuTypes: ["filter", "favorite"] });
5366
5367 onRpc("web_read_group", () => {
5368 expect.step("web_read_group");
5369 });
5370
5371 await mountView({
5372 type: "kanban",
5373 resModel: "partner",
5374 arch: `
5375 <kanban default_group_by="bar">
5376 <templates>
5377 <t t-name="card">
5378 <field name="foo"/>
5379 </t>
5380 </templates>
5381 </kanban>`,
5382 searchViewArch: `
5383 <search>
5384 <filter string="Filter" name="filter" domain="[]"/>
5385 <filter string="candle" name="itsName" context="{'group_by': 'foo'}"/>
5386 </search>`,
5387 context: { search_default_itsName: 1 },
5388 });
5389
5390 expect(".o_kanban_renderer").not.toHaveClass("o_kanban_grouped");
5391 expect(".o_control_panel div.o_search_options div.o_group_by_menu").toHaveCount(0);
5392 expect(getFacetTexts()).toEqual([]);
5393
5394 // validate presence of the search arch info
5395 await toggleSearchBarMenu();
5396 expect(".o_filter_menu .o_menu_item").toHaveCount(2);
5397 expect.verifySteps([]);
5398 });
5399
5400 test("kanban view with create=False", async () => {
5401 await mountView({
5402 type: "kanban",
5403 resModel: "partner",
5404 arch: `
5405 <kanban create="0">
5406 <templates>
5407 <t t-name="card">
5408 <field name="foo"/>
5409 </t>
5410 </templates>
5411 </kanban>`,
5412 });
5413
5414 expect(".o-kanban-button-new").toHaveCount(0);
5415 });
5416
5417 test("kanban view with create=False and groupby", async () => {
5418 await mountView({
5419 type: "kanban",
5420 resModel: "partner",
5421 arch: `
5422 <kanban create="0">
5423 <templates>
5424 <t t-name="card">
5425 <field name="foo"/>
5426 </t>
5427 </templates>
5428 </kanban>`,
5429 groupBy: ["product_id"],
5430 });
5431
5432 expect(".o-kanban-button-new").toHaveCount(0);
5433 expect(".o_kanban_group").toHaveCount(2);
5434 expect(".o_kanban_quick_add").toHaveCount(0);
5435 });
5436
5437 test("clicking on a link triggers correct event", async () => {
5438 await mountView({
5439 type: "kanban",
5440 resModel: "partner",
5441 arch: `
5442 <kanban>
5443 <templates>
5444 <t t-name="card">
5445 <a type="open">Edit</a>
5446 </t>
5447 </templates>
5448 </kanban>`,
5449 selectRecord: (resId) => {
5450 expect(resId).toBe(1);
5451 },
5452 });
5453 await contains("a", { root: getKanbanRecord({ index: 0 }) }).click();
5454 });
5455
5456 test.tags("desktop");
5457 test("environment is updated when (un)folding groups", async () => {
5458 await mountView({
5459 type: "kanban",
5460 resModel: "partner",
5461 arch: `
5462 <kanban>
5463 <templates>
5464 <t t-name="card">
5465 <field name="id"/>
5466 </t>
5467 </templates>
5468 </kanban>`,
5469 groupBy: ["product_id"],
5470 });
5471
5472 expect(getKanbanRecordTexts()).toEqual(["1", "3", "2", "4"]);
5473
5474 // fold the second group and check that the res_ids it contains are no
5475 // longer in the environment
5476 const clickColumnAction = await toggleKanbanColumnActions(1);
5477 await clickColumnAction("Fold");
5478
5479 expect(getKanbanRecordTexts()).toEqual(["1", "3"]);
5480
5481 // re-open the second group and check that the res_ids it contains are
5482 // back in the environment
5483 await contains(getKanbanColumn(1)).click();
5484
5485 expect(getKanbanRecordTexts()).toEqual(["1", "3", "2", "4"]);
5486 });
5487
5488 test.tags("desktop");
5489 test("create a column in default grouped on m2o", async () => {
5490 onRpc("web_resequence", ({ args, method }) => {
5491 expect.step([method, args[0]]);
5492 });
5493 onRpc("name_create", ({ method }) => {
5494 expect.step(method);
5495 });
5496
5497 await mountView({
5498 type: "kanban",
5499 resModel: "partner",
5500 arch: `
5501 <kanban default_group_by="product_id" on_create="quick_create">
5502 <templates>
5503 <t t-name="card">
5504 <field name="foo"/>
5505 </t>
5506 </templates>
5507 </kanban>`,
5508 });
5509
5510 expect(".o_kanban_group").toHaveCount(2);
5511 expect(".o_column_quick_create").toHaveCount(1, {
5512 message: "should have a quick create column",
5513 });
5514 expect(".o_column_quick_create input").toHaveCount(0, {
5515 message: "the input should not be visible",
5516 });
5517
5518 await quickCreateKanbanColumn();
5519
5520 expect(".o_column_quick_create input").toHaveCount(1, {
5521 message: "the input should be visible",
5522 });
5523
5524 // discard the column creation and click it again
5525 await press("Escape");
5526 await animationFrame();
5527
5528 expect(".o_column_quick_create input").toHaveCount(0, {
5529 message: "the input should not be visible",
5530 });
5531
5532 await quickCreateKanbanColumn();
5533
5534 expect(".o_column_quick_create input").toHaveCount(1, {
5535 message: "the input should be visible",
5536 });
5537
5538 await editKanbanColumnName("new value");
5539 await validateKanbanColumn();
5540
5541 expect(".o_kanban_group").toHaveCount(3);
5542 expect(
5543 queryAll(".o_column_title:contains(new value)", { root: getKanbanColumn(2) })
5544 ).toHaveCount(1, {
5545 message: "the last column should be the newly created one",
5546 });
5547 expect(!!getKanbanColumn(2).dataset.id).toBe(true, {
5548 message: "the created column should have an associated id",
5549 });
5550 expect(getKanbanColumn(2)).not.toHaveClass("o_column_folded", {
5551 message: "the created column should not be folded",
5552 });
5553 expect.verifySteps(["name_create", ["web_resequence", [3, 5, 6]]]);
5554
5555 // fold and unfold the created column, and check that no RPCs are done (as there are no records)
5556 const clickColumnAction = await toggleKanbanColumnActions(2);
5557 await clickColumnAction("Fold");
5558
5559 expect(getKanbanColumn(2)).toHaveClass("o_column_folded");
5560
5561 await click(getKanbanColumn(2));
5562 await animationFrame();
5563
5564 expect(getKanbanColumn(1)).not.toHaveClass("o_column_folded");
5565 // no rpc should have been done when folding/unfolding
5566 expect.verifySteps([]);
5567
5568 // quick create a record
5569 await createKanbanRecord();
5570
5571 expect(queryOne(".o_kanban_quick_create", { root: getKanbanColumn(0) })).toHaveCount(1);
5572 });
5573
5574 test("create a column in grouped on m2o without sequence field on view model", async () => {
5575 delete Partner._fields.sequence;
5576
5577 onRpc("name_create", () => {
5578 expect.step("name_create");
5579 });
5580 onRpc("web_resequence", ({ args }) => {
5581 expect.step(["resequence", args[0]]);
5582 return [];
5583 });
5584
5585 await mountView({
5586 type: "kanban",
5587 resModel: "partner",
5588 arch: `
5589 <kanban default_group_by="product_id" on_create="quick_create">
5590 <templates>
5591 <t t-name="card">
5592 <field name="foo"/>
5593 </t>
5594 </templates>
5595 </kanban>`,
5596 });
5597
5598 expect(".o_kanban_group").toHaveCount(2);
5599 expect(".o_column_quick_create").toHaveCount(1, {
5600 message: "should have a quick create column",
5601 });
5602 expect(".o_column_quick_create input").toHaveCount(0, {
5603 message: "the input should not be visible",
5604 });
5605
5606 await quickCreateKanbanColumn();
5607 await editKanbanColumnName("new value");
5608 await validateKanbanColumn();
5609
5610 expect.verifySteps(["name_create", ["resequence", [3, 5, 6]]]);
5611 });
5612
5613 test.tags("desktop");
5614 test("delete a column in grouped on m2o", async () => {
5615 stepAllNetworkCalls();
5616 let resequencedIDs = [];
5617 onRpc("web_resequence", ({ args }) => {
5618 resequencedIDs = args[0];
5619 expect(resequencedIDs.filter(isNaN)).toHaveLength(0, {
5620 message: "column resequenced should be existing records with IDs",
5621 });
5622 });
5623
5624 await mountView({
5625 type: "kanban",
5626 resModel: "partner",
5627 arch: `
5628 <kanban default_group_by="product_id" class="o_kanban_test" on_create="quick_create">
5629 <templates>
5630 <t t-name="card">
5631 <field name="foo"/>
5632 </t>
5633 </templates>
5634 </kanban>`,
5635 });
5636
5637 // check the initial rendering
5638 expect(".o_kanban_group").toHaveCount(2, { message: "should have two columns" });
5639 expect(queryText(".o_column_title", { root: getKanbanColumn(0) })).toBe("hello\n(2)");
5640 expect(queryText(".o_column_title", { root: getKanbanColumn(1) })).toBe("xmo\n(2)");
5641 expect(queryAll(".o_kanban_record", { root: getKanbanColumn(1) })).toHaveCount(2, {
5642 message: "second column should have two records",
5643 });
5644
5645 // check available actions in kanban header's config dropdown
5646 await toggleKanbanColumnActions(0);
5647 expect(queryAll(".o_kanban_toggle_fold", { root: getKanbanColumnDropdownMenu(0) })).toHaveCount(
5648 1,
5649 {
5650 message: "should be able to fold the column",
5651 }
5652 );
5653 expect(queryAll(".o_group_edit", { root: getKanbanColumnDropdownMenu(0) })).toHaveCount(1, {
5654 message: "should be able to edit the column",
5655 });
5656 expect(queryAll(".o_group_delete", { root: getKanbanColumnDropdownMenu(0) })).toHaveCount(1, {
5657 message: "should be able to delete the column",
5658 });
5659 expect(
5660 queryAll(".o_column_archive_records", { root: getKanbanColumnDropdownMenu(0) })
5661 ).toHaveCount(0, { message: "should not be able to archive all the records" });
5662 expect(queryAll(".o_column_unarchive_records", { root: getKanbanColumn(0) })).toHaveCount(0, {
5663 message: "should not be able to restore all the records",
5664 });
5665
5666 // delete second column (first cancel the confirm request, then confirm)
5667 let clickColumnAction = await toggleKanbanColumnActions(1);
5668 await clickColumnAction("Delete");
5669
5670 expect(".o_dialog").toHaveCount(1);
5671 await contains(".o_dialog footer .btn-secondary").click();
5672
5673 expect(queryText(".o_column_title", { root: getKanbanColumn(1) })).toBe("xmo\n(2)");
5674
5675 clickColumnAction = await toggleKanbanColumnActions(1);
5676 await clickColumnAction("Delete");
5677
5678 expect(".o_dialog").toHaveCount(1);
5679 await contains(".o_dialog footer .btn-primary").click();
5680
5681 expect(queryText(".o_column_title", { root: getKanbanColumn(1) })).toBe("hello\n(2)");
5682 expect(".o_kanban_group").toHaveCount(2, { message: "should still have two columns" });
5683 expect(getKanbanColumn(0).querySelector(".o_column_title")).toHaveText("None\n(2)", {
5684 message: "first column should have no id (Undefined column)",
5685 });
5686
5687 // check available actions on 'Undefined' column
5688 await click(getKanbanColumn(0));
5689 await animationFrame();
5690 await toggleKanbanColumnActions(0);
5691
5692 expect(queryAll(".o_kanban_toggle_fold", { root: getKanbanColumnDropdownMenu(0) })).toHaveCount(
5693 1,
5694 {
5695 message: "should be able to fold the column",
5696 }
5697 );
5698 expect(queryAll(".o_group_edit", { root: getKanbanColumnDropdownMenu(0) })).toHaveCount(0, {
5699 message: "should be able to edit the column",
5700 });
5701 expect(queryAll(".o_group_delete", { root: getKanbanColumnDropdownMenu(0) })).toHaveCount(0, {
5702 message: "should not be able to delete the column",
5703 });
5704 expect(
5705 queryAll(".o_column_archive_records", { root: getKanbanColumnDropdownMenu(0) })
5706 ).toHaveCount(0, { message: "should not be able to archive all the records" });
5707 expect(
5708 queryAll(".o_column_unarchive_records", { root: getKanbanColumnDropdownMenu(0) })
5709 ).toHaveCount(0, { message: "should not be able to restore all the records" });
5710 expect.verifySteps([
5711 "/web/webclient/translations",
5712 "/web/webclient/load_menus",
5713 "get_views",
5714 "web_read_group",
5715 "has_group",
5716 "unlink",
5717 "web_read_group",
5718 "web_search_read",
5719 ]);
5720 expect(".o_kanban_group").toHaveCount(2, {
5721 message: "the old groups should have been correctly deleted",
5722 });
5723
5724 // test column drag and drop having an 'Undefined' column
5725 expect(getKanbanColumn(0)).not.toHaveClass("o_group_draggable");
5726 await contains(".o_kanban_group:first-child .o_column_title").dragAndDrop(
5727 queryAll(".o_kanban_group")[1]
5728 );
5729
5730 expect(resequencedIDs).toEqual([], {
5731 message: "resequencing require at least 2 not Undefined columns",
5732 });
5733
5734 await quickCreateKanbanColumn();
5735 await editKanbanColumnName("once third column");
5736 await validateKanbanColumn();
5737
5738 expect.verifySteps(["name_create", "web_resequence"]);
5739 expect(resequencedIDs).toEqual([3, 4], {
5740 message: "creating a column should trigger a resequence",
5741 });
5742
5743 await contains(".o_kanban_group:first-child .o_column_title").dragAndDrop(
5744 queryAll(".o_kanban_group")[2]
5745 );
5746
5747 expect(resequencedIDs).toEqual([3, 4], {
5748 message: "moving the Undefined column should not affect order of other columns",
5749 });
5750
5751 expect(getKanbanColumn(1)).toHaveClass("o_group_draggable");
5752 await contains(".o_kanban_group:nth-child(2) .o_column_title").dragAndDrop(
5753 queryAll(".o_kanban_group")[2]
5754 );
5755 expect.verifySteps(["web_resequence"]);
5756 expect(resequencedIDs).toEqual([4, 3], {
5757 message: "moved column should be resequenced accordingly",
5758 });
5759 });
5760
5761 test("create a column, delete it and create another one", async () => {
5762 await mountView({
5763 type: "kanban",
5764 resModel: "partner",
5765 arch: `
5766 <kanban default_group_by="product_id" on_create="quick_create">
5767 <templates>
5768 <t t-name="card">
5769 <field name="foo"/>
5770 </t>
5771 </templates>
5772 </kanban>`,
5773 });
5774
5775 expect(".o_kanban_group").toHaveCount(2);
5776
5777 await quickCreateKanbanColumn();
5778 await editKanbanColumnName("new column 1");
5779 await validateKanbanColumn();
5780
5781 expect(".o_kanban_group").toHaveCount(3);
5782
5783 const clickColumnAction = await toggleKanbanColumnActions(2);
5784 await clickColumnAction("Delete");
5785
5786 expect(".o_dialog").toHaveCount(1);
5787 await contains(".o_dialog footer .btn-primary").click();
5788
5789 expect(".o_kanban_group").toHaveCount(2);
5790
5791 await quickCreateKanbanColumn();
5792 await editKanbanColumnName("new column 2");
5793 await validateKanbanColumn();
5794
5795 expect(".o_kanban_group").toHaveCount(3);
5796 expect(getKanbanColumn(2).querySelector("div")).toHaveText("new column 2\n(0)", {
5797 message: "the last column should be the newly created one",
5798 });
5799 });
5800
5801 test("delete an empty column, then a column with records.", async () => {
5802 let firstLoad = true;
5803
5804 onRpc("web_read_group", function ({ parent }) {
5805 // override web_read_group to return an extra empty groups
5806 const result = parent();
5807 if (firstLoad) {
5808 result.groups.unshift({
5809 __extra_domain: [["product_id", "=", 7]],
5810 product_id: [7, "empty group"],
5811 __count: 0,
5812 __records: [],
5813 });
5814 result.length = 3;
5815 firstLoad = false;
5816 }
5817 return result;
5818 });
5819
5820 await mountView({
5821 type: "kanban",
5822 resModel: "partner",
5823 arch: `
5824 <kanban on_create="quick_create">
5825 <templates>
5826 <t t-name="card">
5827 <field name="foo"/>
5828 </t>
5829 </templates>
5830 </kanban>`,
5831 groupBy: ["product_id"],
5832 });
5833
5834 expect(".o_kanban_header .o_column_title:contains('empty group')").toHaveCount(1);
5835 expect(".o_kanban_header .o_column_title:contains('hello')").toHaveCount(1);
5836 expect(".o_kanban_header .o_column_title:contains('None')").toHaveCount(0);
5837
5838 // Delete the empty group
5839 let clickColumnAction = await toggleKanbanColumnActions();
5840 await clickColumnAction("Delete");
5841
5842 expect(".o_dialog").toHaveCount(1);
5843 await contains(".o_dialog footer .btn-primary").click();
5844
5845 // Delete the group 'hello'
5846 clickColumnAction = await toggleKanbanColumnActions();
5847 await clickColumnAction("Delete");
5848
5849 expect(".o_dialog").toHaveCount(1);
5850 await contains(".o_dialog footer .btn-primary").click();
5851
5852 // None of the previous groups should be present inside the view. Instead, a 'none' column should be displayed.
5853 expect(".o_kanban_header span:contains('empty group')").toHaveCount(0);
5854 expect(".o_kanban_header span:contains('hello')").toHaveCount(0);
5855 expect(".o_kanban_header .o_column_title:contains('None')").toHaveCount(1);
5856 });
5857
5858 test.tags("desktop");
5859 test("edit a column in grouped on m2o", async () => {
5860 Product._views["form"] = `
5861 <form string="Product">
5862 <field name="name"/>
5863 </form>`;
5864
5865 onRpc(() => {
5866 nbRPCs++;
5867 });
5868
5869 let nbRPCs = 0;
5870 await mountView({
5871 type: "kanban",
5872 resModel: "partner",
5873 arch: `
5874 <kanban on_create="quick_create">
5875 <templates>
5876 <t t-name="card">
5877 <field name="foo"/>
5878 </t>
5879 </templates>
5880 </kanban>`,
5881 groupBy: ["product_id"],
5882 });
5883
5884 expect(queryText(".o_column_title", { root: getKanbanColumn(1) })).toBe("xmo\n(2)");
5885
5886 // edit the title of column [5, 'xmo'] and close without saving
5887 let clickColumnAction = await toggleKanbanColumnActions(1);
5888 await clickColumnAction("Edit");
5889
5890 expect(".modal .o_form_editable").toHaveCount(1);
5891 expect(".modal .o_form_editable input").toHaveValue("xmo");
5892
5893 await contains(".modal .o_form_editable input").edit("ged");
5894 nbRPCs = 0;
5895 await contains(".modal-header .btn-close").click();
5896
5897 expect(".modal").toHaveCount(0);
5898 expect(queryText(".o_column_title", { root: getKanbanColumn(1) })).toBe("xmo\n(2)");
5899 expect(nbRPCs).toBe(0, { message: "no RPC should have been done" });
5900
5901 // edit the title of column [5, 'xmo'] and discard
5902 clickColumnAction = await toggleKanbanColumnActions(1);
5903 await clickColumnAction("Edit");
5904 await contains(".modal .o_form_editable input").edit("ged");
5905 nbRPCs = 0;
5906 await contains(".modal button.o_form_button_cancel").click();
5907
5908 expect(".modal").toHaveCount(0);
5909 expect(queryText(".o_column_title", { root: getKanbanColumn(1) })).toBe("xmo\n(2)");
5910 expect(nbRPCs).toBe(0, { message: "no RPC should have been done" });
5911
5912 // edit the title of column [5, 'xmo'] and save
5913 clickColumnAction = await toggleKanbanColumnActions(1);
5914 await clickColumnAction("Edit");
5915 await contains(".modal .o_form_editable input").edit("ged");
5916 nbRPCs = 0;
5917 await click(".modal .o_form_button_save"); // click on save
5918 await animationFrame();
5919
5920 expect(".modal").toHaveCount(0, { message: "the modal should be closed" });
5921 expect(queryText(".o_column_title", { root: getKanbanColumn(1) })).toBe("ged\n(2)");
5922 expect(nbRPCs).toBe(2, {
5923 message: "should have done 1 write, 1 web_read_group",
5924 });
5925 });
5926
5927 test("edit a column propagates right context", async () => {
5928 expect.assertions(3);
5929
5930 Product._views["form"] = `
5931 <form string="Product">
5932 <field name="display_name"/>
5933 </form>`;
5934
5935 serverState.lang = "nb_NO";
5936
5937 onRpc(({ method, model, kwargs }) => {
5938 if (model === "partner" && method === "web_read_group") {
5939 expect(kwargs.context.lang).toBe("nb_NO", {
5940 message: "lang is present in context for partner operations",
5941 });
5942 } else if (model === "product") {
5943 expect(kwargs.context.lang).toBe("nb_NO", {
5944 message: "lang is present in context for product operations",
5945 });
5946 }
5947 });
5948
5949 await mountView({
5950 type: "kanban",
5951 resModel: "partner",
5952 arch: `
5953 <kanban on_create="quick_create">
5954 <templates>
5955 <t t-name="card">
5956 <field name="foo"/>
5957 </t>
5958 </templates>
5959 </kanban>`,
5960 groupBy: ["product_id"],
5961 });
5962
5963 const clickColumnAction = await toggleKanbanColumnActions(1);
5964 await clickColumnAction("Edit");
5965 });
5966
5967 test("quick create column should be opened if there is no column", async () => {
5968 await mountView({
5969 type: "kanban",
5970 resModel: "partner",
5971 arch: `
5972 <kanban default_group_by="product_id">
5973 <templates>
5974 <t t-name="card">
5975 <field name="foo"/>
5976 </t>
5977 </templates>
5978 </kanban>`,
5979 domain: [["foo", "=", "norecord"]],
5980 });
5981
5982 expect(".o_kanban_group").toHaveCount(0);
5983 expect(".o_column_quick_create").toHaveCount(1);
5984 expect(".o_column_quick_create input").toHaveCount(1, {
5985 message: "the quick create should be opened",
5986 });
5987 });
5988
5989 test("quick create column should close on window click if there is no column", async () => {
5990 await mountView({
5991 type: "kanban",
5992 resModel: "partner",
5993 arch: `
5994 <kanban default_group_by="product_id">
5995 <templates>
5996 <t t-name="card">
5997 <field name="foo"/>
5998 </t>
5999 </templates>
6000 </kanban>`,
6001 domain: [["foo", "=", "norecord"]],
6002 });
6003
6004 expect(".o_kanban_group").toHaveCount(0);
6005 expect(".o_column_quick_create").toHaveCount(1);
6006 expect(".o_column_quick_create input").toHaveCount(1, {
6007 message: "the quick create should be opened",
6008 });
6009 // click outside should discard quick create column
6010 await contains(getFixture()).click();
6011 expect(".o_column_quick_create input").toHaveCount(0, {
6012 message: "the quick create should be closed",
6013 });
6014 });
6015
6016 test("quick create several columns in a row", async () => {
6017 await mountView({
6018 type: "kanban",
6019 resModel: "partner",
6020 arch: `
6021 <kanban default_group_by="product_id">
6022 <templates>
6023 <t t-name="card">
6024 <field name="foo"/>
6025 </t>
6026 </templates>
6027 </kanban>`,
6028 });
6029
6030 expect(".o_kanban_group").toHaveCount(2, { message: "should have two columns" });
6031 expect(".o_column_quick_create").toHaveCount(1, {
6032 message: "should have a ColumnQuickCreate widget",
6033 });
6034 expect(".o_column_quick_create.o_quick_create_folded:visible").toHaveCount(1, {
6035 message: "the ColumnQuickCreate should be folded",
6036 });
6037 expect(".o_column_quick_create.o_quick_create_unfolded:visible").toHaveCount(0, {
6038 message: "the ColumnQuickCreate should be folded",
6039 });
6040
6041 // add a new column
6042 await quickCreateKanbanColumn();
6043 expect(".o_column_quick_create.o_quick_create_folded:visible").toHaveCount(0, {
6044 message: "the ColumnQuickCreate should be unfolded",
6045 });
6046 expect(".o_column_quick_create.o_quick_create_unfolded:visible").toHaveCount(1, {
6047 message: "the ColumnQuickCreate should be unfolded",
6048 });
6049 await editKanbanColumnName("New Column 1");
6050 await validateKanbanColumn();
6051 expect(".o_kanban_group").toHaveCount(3, { message: "should now have three columns" });
6052
6053 // add another column
6054 expect(".o_column_quick_create.o_quick_create_folded:visible").toHaveCount(0, {
6055 message: "the ColumnQuickCreate should still be unfolded",
6056 });
6057 expect(".o_column_quick_create.o_quick_create_unfolded:visible").toHaveCount(1, {
6058 message: "the ColumnQuickCreate should still be unfolded",
6059 });
6060 await editKanbanColumnName("New Column 2");
6061 await validateKanbanColumn();
6062 expect(".o_kanban_group").toHaveCount(4);
6063 });
6064
6065 test.tags("desktop");
6066 test("quick create column with enter", async () => {
6067 await mountView({
6068 type: "kanban",
6069 resModel: "partner",
6070 arch: `
6071 <kanban default_group_by="product_id">
6072 <templates>
6073 <t t-name="card">
6074 <field name="foo"/>
6075 </t>
6076 </templates>
6077 </kanban>`,
6078 });
6079
6080 await quickCreateKanbanColumn();
6081 await edit("New Column 1");
6082 await animationFrame();
6083 expect(".o_kanban_group").toHaveCount(2);
6084
6085 await press("Enter");
6086 await animationFrame();
6087 expect(".o_kanban_group").toHaveCount(3);
6088 });
6089
6090 test.tags("desktop");
6091 test("empty stages kanban examples", async () => {
6092 Partner._records = [];
6093 registry.category("kanban_examples").add("test", {
6094 allowedGroupBys: ["product_id"],
6095 examples: [
6096 {
6097 name: "A first example",
6098 columns: ["Column 1", "Column 2", "Column 3"],
6099 description: "A weak description.",
6100 },
6101 {
6102 name: "A second example",
6103 columns: ["Col 1", "Col 2"],
6104 description: `A fantastic description.`,
6105 },
6106 ],
6107 });
6108 after(() => registry.category("kanban_examples").remove("test"));
6109
6110 await mountView({
6111 type: "kanban",
6112 resModel: "partner",
6113 arch: `
6114 <kanban default_group_by="product_id" examples="test">
6115 <templates>
6116 <t t-name="card">
6117 <field name="foo"/>
6118 </t>
6119 </templates>
6120 </kanban>`,
6121 });
6122
6123 expect(".o_kanban_stages_nocontent").toHaveCount(1, {
6124 message: "should show the empty stages kanban helper",
6125 });
6126
6127 expect(".o_kanban_stages_nocontent .o_kanban_examples").toHaveCount(1, {
6128 message: "should have a link to see examples",
6129 });
6130
6131 // click to see the examples
6132 await contains(".o_kanban_stages_nocontent .o_kanban_examples").click();
6133
6134 expect(".modal .o_kanban_examples_dialog").toHaveCount(1, {
6135 message: "should have open the examples dialog",
6136 });
6137 expect(".modal .o_notebook_headers li").toHaveCount(2, {
6138 message: "should have two examples (in the menu)",
6139 });
6140 expect(".modal .o_notebook_headers").toHaveText("A first example\nA second example", {
6141 message: "example names should be correct",
6142 });
6143 expect(".modal .o_notebook_content .tab-pane").toHaveCount(1, {
6144 message: "should have only rendered one page",
6145 });
6146
6147 const firstPane = queryFirst(".modal .o_notebook_content .tab-pane");
6148 expect(queryAll(".o_kanban_examples_group", { root: firstPane })).toHaveCount(3);
6149 expect(queryAllTexts("h6", { root: firstPane })).toEqual(["Column 1", "Column 2", "Column 3"], {
6150 message: "column titles should be correct",
6151 });
6152 expect(queryFirst(".o_kanban_examples_description", { root: firstPane })).toHaveInnerHTML(
6153 "A weak description.",
6154 { message: "An escaped description should be displayed" }
6155 );
6156
6157 await contains(".nav-item:nth-child(2) .nav-link").click();
6158 const secondPane = queryFirst(".o_notebook_content");
6159 expect(queryAll(".o_kanban_examples_group", { root: firstPane })).toHaveCount(2);
6160 expect(queryAllTexts("h6", { root: secondPane })).toEqual(["Col 1", "Col 2"], {
6161 message: "column titles should be correct",
6162 });
6163 expect(secondPane.querySelector(".o_kanban_examples_description").innerHTML).toBe(
6164 "A fantastic description.",
6165 { message: "A formatted description should be displayed." }
6166 );
6167 });
6168
6169 test("quick create column with x_name as _rec_name", async () => {
6170 Product._rec_name = "x_name";
6171 Product._fields.x_name = fields.Char();
6172 Product._records = [
6173 { id: 3, x_name: "hello" },
6174 { id: 5, x_name: "xmo" },
6175 ];
6176
6177 await mountView({
6178 type: "kanban",
6179 resModel: "partner",
6180 arch: `
6181 <kanban default_group_by="product_id">
6182 <templates>
6183 <t t-name="card">
6184 <field name="foo"/>
6185 </t>
6186 </templates>
6187 </kanban>`,
6188 });
6189 await quickCreateKanbanColumn();
6190 await editKanbanColumnName("New Column 1");
6191 await validateKanbanColumn();
6192 expect(".o_kanban_group").toHaveCount(3, { message: "should now have three columns" });
6193 });
6194
6195 test.tags("desktop");
6196 test("count of folded groups in empty kanban with sample data", async () => {
6197 onRpc("web_read_group", () => ({
6198 groups: [
6199 {
6200 product_id: [1, "New"],
6201 __count: 0,
6202 __extra_domain: [],
6203 __records: [],
6204 },
6205 {
6206 product_id: [2, "In Progress"],
6207 __count: 0,
6208 __extra_domain: [],
6209 },
6210 ],
6211 length: 2,
6212 }));
6213
6214 await mountView({
6215 resModel: "partner",
6216 type: "kanban",
6217 arch: `
6218 <kanban sample="1">
6219 <templates>
6220 <div t-name="card">
6221 <field name="foo"/>
6222 </div>
6223 </templates>
6224 </kanban>`,
6225 groupBy: ["product_id"],
6226 domain: [["id", "<", 0]],
6227 });
6228
6229 expect(queryFirst(".o_content")).toHaveClass("o_view_sample_data");
6230 expect(".o_kanban_group").toHaveCount(2);
6231 expect(queryAll(".o_kanban_record").length > 0).toBe(true, {
6232 message: "should contain sample records",
6233 });
6234 expect(getKanbanColumn(1)).toHaveClass("o_column_folded");
6235 expect(queryAllTexts(".o_kanban_group")).toEqual(["New", "In Progress"]);
6236 });
6237
6238 test.tags("desktop");
6239 test("empty stages kanban examples: with folded columns", async () => {
6240 registry.category("kanban_examples").add("test", {
6241 allowedGroupBys: ["product_id"],
6242 foldField: "folded",
6243 examples: [
6244 {
6245 name: "A first example",
6246 columns: ["not folded"],
6247 foldedColumns: ["folded"],
6248 description: "A weak description.",
6249 },
6250 ],
6251 });
6252 after(() => registry.category("kanban_examples").remove("test"));
6253
6254 Partner._records = [];
6255 Product._fields.folded = fields.Boolean();
6256
6257 onRpc(["name_create", "write"], ({ model, method, args }) => {
6258 expect.step(`${method} (model: ${model}):${JSON.stringify(args)}`);
6259 });
6260
6261 await mountView({
6262 type: "kanban",
6263 resModel: "partner",
6264 arch: `
6265 <kanban default_group_by="product_id" examples="test">
6266 <templates>
6267 <t t-name="card">
6268 <field name="foo"/>
6269 </t>
6270 </templates>
6271 </kanban>`,
6272 });
6273
6274 // click to see the examples
6275 await contains(".o_kanban_stages_nocontent .o_kanban_examples").click();
6276
6277 // apply the examples
6278 expect.verifySteps([]);
6279 await contains(".modal .modal-footer .btn.btn-primary").click();
6280 expect.verifySteps([
6281 'name_create (model: product):["not folded"]',
6282 'name_create (model: product):["folded"]',
6283 'write (model: product):[[7],{"folded":true}]',
6284 ]);
6285
6286 // the applied examples should be visible
6287 expect(".o_kanban_group").toHaveCount(2);
6288 expect(".o_kanban_group:not(.o_column_folded)").toHaveCount(1);
6289 expect(".o_kanban_group.o_column_folded").toHaveCount(1);
6290 expect(queryAllTexts(".o_kanban_group")).toEqual(["not folded\n(0)", "folded"]);
6291 });
6292
6293 test.tags("desktop");
6294 test("empty stages kanban examples: apply button's display text", async () => {
6295 Partner._records = [];
6296 const applyExamplesText = "Use This For My Test";
6297 registry.category("kanban_examples").add("test", {
6298 allowedGroupBys: ["product_id"],
6299 applyExamplesText: applyExamplesText,
6300 examples: [
6301 {
6302 name: "A first example",
6303 columns: ["Column 1", "Column 2", "Column 3"],
6304 },
6305 {
6306 name: "A second example",
6307 columns: ["Col 1", "Col 2"],
6308 },
6309 ],
6310 });
6311 after(() => registry.category("kanban_examples").remove("test"));
6312
6313 await mountView({
6314 type: "kanban",
6315 resModel: "partner",
6316 arch: `
6317 <kanban default_group_by="product_id" examples="test">
6318 <templates>
6319 <t t-name="card">
6320 <field name="foo"/>
6321 </t>
6322 </templates>
6323 </kanban>`,
6324 });
6325
6326 // click to see the examples
6327 await contains(".o_kanban_stages_nocontent .o_kanban_examples").click();
6328
6329 expect(".modal footer.modal-footer button.btn-primary").toHaveText(applyExamplesText, {
6330 message: "the primary button should display the value of applyExamplesText",
6331 });
6332 });
6333
6334 test("nocontent helper after adding a record (kanban with progressbar)", async () => {
6335 onRpc("web_read_group", () => ({
6336 groups: [
6337 {
6338 __extra_domain: [["product_id", "=", 3]],
6339 __count: 0,
6340 product_id: [3, "hello"],
6341 __records: [],
6342 },
6343 ],
6344 }));
6345 stepAllNetworkCalls();
6346
6347 await mountView({
6348 type: "kanban",
6349 resModel: "partner",
6350 arch: `
6351 <kanban >
6352 <progressbar field="foo" colors='{"yop": "success", "gnap": "warning", "blip": "danger"}' sum_field="int_field"/>
6353 <templates>
6354 <t t-name="card">
6355 <field name="foo"/>
6356 </t>
6357 </templates>
6358 </kanban>`,
6359 groupBy: ["product_id"],
6360 domain: [["foo", "=", "abcd"]],
6361 noContentHelp: "No content helper",
6362 });
6363
6364 expect(".o_view_nocontent").toHaveCount(1, { message: "the nocontent helper is displayed" });
6365
6366 // add a record
6367 await quickCreateKanbanRecord();
6368 await editKanbanRecordQuickCreateInput("display_name", "twilight sparkle");
6369 await validateKanbanRecord();
6370
6371 expect(".o_view_nocontent").toHaveCount(0, {
6372 message: "the nocontent helper is not displayed after quick create",
6373 });
6374
6375 // cancel quick create
6376 await discardKanbanRecord();
6377 expect(".o_view_nocontent").toHaveCount(0, {
6378 message: "the nocontent helper is not displayed after cancelling the quick create",
6379 });
6380 expect.verifySteps([
6381 "/web/webclient/translations",
6382 "/web/webclient/load_menus",
6383 "get_views",
6384 "read_progress_bar",
6385 "web_read_group",
6386 "has_group",
6387 "onchange",
6388 "name_create",
6389 "onchange",
6390 "web_read",
6391 "read_progress_bar",
6392 "formatted_read_group",
6393 ]);
6394 });
6395
6396 test.tags("desktop");
6397 test("ungrouped kanban view can be grouped, then ungrouped", async () => {
6398 await mountView({
6399 type: "kanban",
6400 resModel: "partner",
6401 arch: `
6402 <kanban on_create="quick_create">
6403 <templates>
6404 <t t-name="card">
6405 <field name="foo"/>
6406 </t>
6407 </templates>
6408 </kanban>`,
6409 searchViewArch: `
6410 <search>
6411 <filter name="group_by_product" domain="[]" string="GroupBy Product" context="{ 'group_by': 'product_id' }"/>
6412 </search>`,
6413 });
6414
6415 expect(".o_kanban_renderer").not.toHaveClass("o_kanban_grouped");
6416
6417 await toggleSearchBarMenu();
6418 await toggleMenuItem("GroupBy Product");
6419
6420 expect(".o_kanban_renderer").toHaveClass("o_kanban_grouped");
6421
6422 await toggleMenuItem("GroupBy Product");
6423
6424 expect(".o_kanban_renderer").not.toHaveClass("o_kanban_grouped");
6425 });
6426
6427 test.tags("desktop");
6428 test("no content helper when no data", async () => {
6429 Partner._records = [];
6430
6431 await mountView({
6432 type: "kanban",
6433 resModel: "partner",
6434 arch: `
6435 <kanban>
6436 <templates>
6437 <t t-name="card">
6438 <field name="foo"/>
6439 </t>
6440 </templates>
6441 </kanban>`,
6442 noContentHelp: '<p class="hello">click to add a partner</p>',
6443 });
6444
6445 expect(".o_view_nocontent").toHaveCount(1, { message: "should display the no content helper" });
6446
6447 expect(".o_view_nocontent").toHaveText('<p class="hello">click to add a partner</p>', {
6448 message: "should have rendered no content helper from action",
6449 });
6450
6451 MockServer.env["partner"].create([{ foo: "new record" }]);
6452 await press("Enter");
6453 await animationFrame();
6454
6455 expect(".o_view_nocontent").toHaveCount(0, {
6456 message: "should not display the no content helper",
6457 });
6458 });
6459
6460 test("no nocontent helper for grouped kanban with empty groups", async () => {
6461 onRpc("web_read_group", function ({ kwargs, parent }) {
6462 // override web_read_group to return empty groups, as this is
6463 // the case for several models (e.g. project.task grouped
6464 // by stage_id)
6465 const result = parent();
6466 for (const group of result.groups) {
6467 group.__count = 0;
6468 group.__records = [];
6469 }
6470 return result;
6471 });
6472
6473 await mountView({
6474 type: "kanban",
6475 resModel: "partner",
6476 arch: `
6477 <kanban>
6478 <templates>
6479 <t t-name="card">
6480 <field name="foo"/>
6481 </t>
6482 </templates>
6483 </kanban>`,
6484 groupBy: ["product_id"],
6485 noContentHelp: "No content helper",
6486 });
6487
6488 expect(".o_kanban_group").toHaveCount(2, { message: "there should be two columns" });
6489 expect(".o_kanban_record").toHaveCount(0, { message: "there should be no records" });
6490 });
6491
6492 test("stages nocontent helper for grouped kanban with no records", async () => {
6493 Partner._records = [];
6494
6495 await mountView({
6496 type: "kanban",
6497 resModel: "partner",
6498 arch: `
6499 <kanban default_group_by="product_id">
6500 <templates>
6501 <t t-name="card">
6502 <field name="foo"/>
6503 </t>
6504 </templates>
6505 </kanban>`,
6506 noContentHelp: "No content helper",
6507 });
6508
6509 expect(".o_kanban_group").toHaveCount(0, { message: "there should be no columns" });
6510 expect(".o_kanban_record").toHaveCount(0, { message: "there should be no records" });
6511 expect(".o_view_nocontent.o_kanban_stages_nocontent").toHaveCount(1);
6512 expect(".o_column_quick_create").toHaveCount(1);
6513 });
6514
6515 test("basic nocontent helper is shown when no longer creating column", async () => {
6516 Partner._records = [];
6517
6518 await mountView({
6519 type: "kanban",
6520 resModel: "partner",
6521 arch: `
6522 <kanban default_group_by="product_id">
6523 <templates>
6524 <t t-name="card">
6525 <field name="foo"/>
6526 </t>
6527 </templates>
6528 </kanban>`,
6529 noContentHelp: "No content helper",
6530 });
6531
6532 expect(".o_view_nocontent.o_kanban_stages_nocontent").toHaveCount(1, {
6533 message: "there should be no nocontent helper (we are in 'column creation mode')",
6534 });
6535
6536 // creating a new column
6537 await editKanbanColumnName("applejack");
6538 await validateKanbanColumn();
6539
6540 expect(".o_view_nocontent").toHaveCount(0, {
6541 message: "there should be no nocontent helper (still in 'column creation mode')",
6542 });
6543
6544 // leaving column creation mode
6545 await press("Escape");
6546 await animationFrame();
6547
6548 expect(".o_view_nocontent:not(.o_kanban_stages_nocontent)").toHaveCount(1);
6549 });
6550
6551 test("no nocontent helper is hidden when quick creating a column", async () => {
6552 Partner._records = [];
6553
6554 onRpc("web_read_group", () => ({
6555 groups: [
6556 {
6557 __extra_domain: [["product_id", "=", 3]],
6558 __count: 0,
6559 product_id: [3, "hello"],
6560 },
6561 ],
6562 length: 1,
6563 }));
6564
6565 await mountView({
6566 type: "kanban",
6567 resModel: "partner",
6568 arch: `
6569 <kanban default_group_by="product_id">
6570 <templates>
6571 <t t-name="card">
6572 <field name="foo"/>
6573 </t>
6574 </templates>
6575 </kanban>`,
6576 noContentHelp: "No content helper",
6577 });
6578
6579 expect(".o_view_nocontent").toHaveCount(1, { message: "there should be a nocontent helper" });
6580
6581 await quickCreateKanbanColumn();
6582
6583 expect(".o_view_nocontent").toHaveCount(0, {
6584 message: "there should be no nocontent helper (we are in 'column creation mode')",
6585 });
6586 });
6587
6588 test("remove nocontent helper after adding a record", async () => {
6589 Partner._records = [];
6590
6591 onRpc("web_read_group", () => ({
6592 groups: [
6593 {
6594 __extra_domain: [["product_id", "=", 3]],
6595 __count: 0,
6596 product_id: [3, "hello"],
6597 __records: [],
6598 },
6599 ],
6600 length: 1,
6601 }));
6602
6603 await mountView({
6604 type: "kanban",
6605 resModel: "partner",
6606 arch: `
6607 <kanban>
6608 <templates>
6609 <t t-name="card">
6610 <field name="foo"/>
6611 </t>
6612 </templates>
6613 </kanban>`,
6614 groupBy: ["product_id"],
6615 noContentHelp: "No content helper",
6616 });
6617
6618 expect(".o_view_nocontent").toHaveCount(1, { message: "there should be a nocontent helper" });
6619
6620 await quickCreateKanbanRecord();
6621 await editKanbanRecordQuickCreateInput("display_name", "twilight sparkle");
6622 await validateKanbanRecord();
6623
6624 expect(".o_view_nocontent").toHaveCount(0, {
6625 message: "there should be no nocontent helper (there is now one record)",
6626 });
6627 });
6628
6629 test("remove nocontent helper when adding a record", async () => {
6630 Partner._records = [];
6631
6632 onRpc("web_read_group", () => ({
6633 groups: [
6634 {
6635 __extra_domain: [["product_id", "=", 3]],
6636 __count: 0,
6637 product_id: [3, "hello"],
6638 __records: [],
6639 },
6640 ],
6641 length: 1,
6642 }));
6643
6644 await mountView({
6645 type: "kanban",
6646 resModel: "partner",
6647 arch: `
6648 <kanban>
6649 <templates>
6650 <t t-name="card">
6651 <field name="foo"/>
6652 </t>
6653 </templates>
6654 </kanban>`,
6655 groupBy: ["product_id"],
6656 noContentHelp: "No content helper",
6657 });
6658
6659 expect(".o_view_nocontent").toHaveCount(1, { message: "there should be a nocontent helper" });
6660
6661 await quickCreateKanbanRecord();
6662 await editKanbanRecordQuickCreateInput("display_name", "twilight sparkle");
6663
6664 expect(".o_view_nocontent").toHaveCount(0, {
6665 message: "there should be no nocontent helper (there is now one record)",
6666 });
6667 });
6668
6669 test("nocontent helper is displayed again after canceling quick create", async () => {
6670 Partner._records = [];
6671
6672 onRpc("web_read_group", () => ({
6673 groups: [
6674 {
6675 __extra_domain: [["product_id", "=", 3]],
6676 __count: 0,
6677 product_id: [3, "hello"],
6678 __records: [],
6679 },
6680 ],
6681 length: 1,
6682 }));
6683
6684 await mountView({
6685 type: "kanban",
6686 resModel: "partner",
6687 arch: `
6688 <kanban>
6689 <templates>
6690 <t t-name="card">
6691 <field name="foo"/>
6692 </t>
6693 </templates>
6694 </kanban>`,
6695 groupBy: ["product_id"],
6696 noContentHelp: "No content helper",
6697 });
6698
6699 await quickCreateKanbanRecord();
6700 await press("Escape");
6701 await animationFrame();
6702
6703 expect(".o_view_nocontent").toHaveCount(1, {
6704 message: "there should be again a nocontent helper",
6705 });
6706 });
6707
6708 test("nocontent helper for grouped kanban (on m2o field) with no records with no group_create", async () => {
6709 Partner._records = [];
6710
6711 await mountView({
6712 type: "kanban",
6713 resModel: "partner",
6714 arch: `
6715 <kanban default_group_by="product_id" group_create="false">
6716 <templates>
6717 <t t-name="card">
6718 <field name="foo"/>
6719 </t>
6720 </templates>
6721 </kanban>`,
6722 noContentHelp: "No content helper",
6723 });
6724
6725 expect(".o_kanban_group").toHaveCount(0, { message: "there should be no columns" });
6726 expect(".o_kanban_record").toHaveCount(0, { message: "there should be no records" });
6727 expect(".o_view_nocontent").toHaveCount(0, {
6728 message: "there should not be a nocontent helper",
6729 });
6730 expect(".o_column_quick_create").toHaveCount(0, {
6731 message: "there should not be a column quick create",
6732 });
6733 });
6734
6735 test("nocontent helper for grouped kanban (on date field) with no records with no group_create", async () => {
6736 Partner._records = [];
6737
6738 await mountView({
6739 type: "kanban",
6740 resModel: "partner",
6741 arch: `
6742 <kanban default_group_by="date" group_create="false">
6743 <templates>
6744 <t t-name="card">
6745 <field name="foo"/>
6746 </t>
6747 </templates>
6748 </kanban>`,
6749 noContentHelp: "No content helper",
6750 });
6751
6752 expect(".o_kanban_group").toHaveCount(0);
6753 expect(".o_kanban_record").toHaveCount(0);
6754 expect(".o_view_nocontent").toHaveCount(1);
6755 expect(".o_column_quick_create").toHaveCount(0);
6756 expect(".o_kanban_example_background").toHaveCount(0);
6757 });
6758
6759 test("empty grouped kanban with sample data and no columns", async () => {
6760 Partner._records = [];
6761
6762 await mountView({
6763 arch: `
6764 <kanban default_group_by="product_id" sample="1">
6765 <templates>
6766 <div t-name="card">
6767 <field name="foo"/>
6768 </div>
6769 </templates>
6770 </kanban>`,
6771 resModel: "partner",
6772 type: "kanban",
6773 noContentHelp: "No content helper",
6774 });
6775
6776 expect(".o_kanban_stages_nocontent").toHaveCount(1);
6777 expect(".o_quick_create_unfolded").toHaveCount(1);
6778 });
6779
6780 test("empty kanban with sample data grouped by date range (fill temporal)", async () => {
6781 Partner._records = [];
6782
6783 onRpc("web_read_group", () =>
6784 // Simulate fill temporal
6785 ({
6786 groups: [
6787 {
6788 __count: 0,
6789 state: false,
6790 "date:month": ["2022-12-01", "December 2022"],
6791 __extra_domain: [
6792 ["date", ">=", "2022-12-01"],
6793 ["date", "<", "2023-01-01"],
6794 ],
6795 __records: [],
6796 },
6797 ],
6798 length: 1,
6799 })
6800 );
6801 await mountView({
6802 arch: `
6803 <kanban sample="1">
6804 <progressbar field="state" sum_field="int_field" help="progress" colors="{}"/>
6805 <templates>
6806 <div t-name="card">
6807 <field name="foo"/>
6808 <field name="int_field"/>
6809 </div>
6810 </templates>
6811 </kanban>`,
6812 groupBy: ["date:month"],
6813 resModel: "partner",
6814 type: "kanban",
6815 noContentHelp: "No content helper",
6816 });
6817
6818 expect(".o_view_nocontent").toHaveCount(1);
6819 expect(".o_kanban_group .o_column_title").toHaveText("December 2022");
6820 expect(".o_kanban_group").toHaveCount(1);
6821 expect(".o_kanban_group .o_kanban_record").toHaveCount(16);
6822 });
6823
6824 test("empty grouped kanban with sample data and click quick create", async () => {
6825 onRpc("web_read_group", function ({ kwargs, parent }) {
6826 // override web_read_group to return empty groups, as this is
6827 // the case for several models (e.g. project.task grouped
6828 // by stage_id)
6829 const result = parent();
6830 result.groups.forEach((group) => {
6831 group.__count = 0;
6832 });
6833 return result;
6834 });
6835
6836 await mountView({
6837 type: "kanban",
6838 resModel: "partner",
6839 arch: `
6840 <kanban sample="1">
6841 <templates>
6842 <t t-name="card">
6843 <field name="foo"/>
6844 </t>
6845 </templates>
6846 </kanban>`,
6847 groupBy: ["product_id"],
6848 noContentHelp: "No content helper",
6849 });
6850
6851 expect(".o_kanban_group").toHaveCount(2, { message: "there should be two columns" });
6852 expect(".o_content").toHaveClass("o_view_sample_data");
6853 expect(".o_view_nocontent").toHaveCount(1);
6854 expect(".o_kanban_record").toHaveCount(16, {
6855 message: "there should be 8 sample records by column",
6856 });
6857 expect(queryAllTexts(".o_column_title")).toEqual(["hello", "xmo"]);
6858
6859 await quickCreateKanbanRecord();
6860 expect(".o_content").not.toHaveClass("o_view_sample_data");
6861 expect(".o_kanban_record").toHaveCount(0);
6862 expect(".o_view_nocontent").toHaveCount(0);
6863 expect(queryAll(".o_kanban_quick_create", { root: getKanbanColumn(0) })).toHaveCount(1);
6864 expect(queryAllTexts(".o_column_title")).toEqual(["hello\n(0)", "xmo\n(0)"]);
6865
6866 await editKanbanRecordQuickCreateInput("display_name", "twilight sparkle");
6867 await validateKanbanRecord();
6868
6869 expect(".o_content").not.toHaveClass("o_view_sample_data");
6870 expect(queryAll(".o_kanban_record", { root: getKanbanColumn(0) })).toHaveCount(1);
6871 expect(".o_view_nocontent").toHaveCount(0);
6872 expect(queryAllTexts(".o_column_title")).toEqual(["hello\n(1)", "xmo\n(0)"]);
6873 });
6874
6875 test.tags("desktop");
6876 test("quick create record in grouped kanban with sample data", async () => {
6877 onRpc("web_read_group", function ({ kwargs, parent }) {
6878 // override web_read_group to return empty groups, as this is
6879 // the case for several models (e.g. project.task grouped
6880 // by stage_id)
6881 const result = parent();
6882 result.groups.forEach((group) => {
6883 group.__count = 0;
6884 });
6885 return result;
6886 });
6887
6888 await mountView({
6889 type: "kanban",
6890 resModel: "partner",
6891 arch: `
6892 <kanban sample="1" on_create="quick_create">
6893 <templates>
6894 <t t-name="card">
6895 <field name="foo"/>
6896 </t>
6897 </templates>
6898 </kanban>`,
6899 groupBy: ["product_id"],
6900 noContentHelp: "No content helper",
6901 });
6902
6903 expect(".o_kanban_group").toHaveCount(2, { message: "there should be two columns" });
6904 expect(".o_content").toHaveClass("o_view_sample_data");
6905 expect(".o_view_nocontent").toHaveCount(1);
6906 expect(".o_kanban_record").toHaveCount(16, {
6907 message: "there should be 8 sample records by column",
6908 });
6909
6910 await createKanbanRecord();
6911 expect(".o_content").not.toHaveClass("o_view_sample_data");
6912 expect(".o_kanban_record").toHaveCount(0);
6913 expect(".o_kanban_load_more").toHaveCount(0);
6914 expect(".o_view_nocontent").toHaveCount(0);
6915 expect(queryAll(".o_kanban_quick_create", { root: getKanbanColumn(0) })).toHaveCount(1);
6916 });
6917
6918 test("empty grouped kanban with sample data and cancel quick create", async () => {
6919 onRpc("web_read_group", function ({ kwargs, parent }) {
6920 // override web_read_group to return empty groups, as this is
6921 // the case for several models (e.g. project.task grouped
6922 // by stage_id)
6923 const result = parent();
6924 result.groups.forEach((group) => {
6925 group.__count = 0;
6926 });
6927 return result;
6928 });
6929
6930 await mountView({
6931 type: "kanban",
6932 resModel: "partner",
6933 arch: `
6934 <kanban sample="1">
6935 <templates>
6936 <t t-name="card">
6937 <field name="foo"/>
6938 </t>
6939 </templates>
6940 </kanban>`,
6941 groupBy: ["product_id"],
6942 noContentHelp: "No content helper",
6943 });
6944 expect(".o_kanban_group").toHaveCount(2, { message: "there should be two columns" });
6945 expect(".o_content").toHaveClass("o_view_sample_data");
6946 expect(".o_view_nocontent").toHaveCount(1);
6947 expect(".o_kanban_record").toHaveCount(16, {
6948 message: "there should be 8 sample records by column",
6949 });
6950
6951 await quickCreateKanbanRecord();
6952 expect(".o_content").not.toHaveClass("o_view_sample_data");
6953 expect(".o_kanban_record").toHaveCount(0);
6954 expect(".o_view_nocontent").toHaveCount(0);
6955 expect(queryAll(".o_kanban_quick_create", { root: getKanbanColumn(0) })).toHaveCount(1);
6956
6957 await contains(".o_kanban_view").click();
6958 expect(".o_content").not.toHaveClass("o_view_sample_data");
6959 expect(".o_kanban_quick_create").toHaveCount(0);
6960 expect(".o_kanban_record").toHaveCount(0);
6961 expect(".o_view_nocontent").toHaveCount(1);
6962 });
6963
6964 test.tags("desktop");
6965 test("empty grouped kanban with sample data: keynav", async () => {
6966 onRpc("web_read_group", function ({ parent }) {
6967 const result = parent();
6968 result.groups.forEach((g) => (g.__count = 0));
6969 return result;
6970 });
6971
6972 await mountView({
6973 resModel: "partner",
6974 type: "kanban",
6975 arch: `
6976 <kanban sample="1">
6977 <templates>
6978 <div t-name="card">
6979 <field name="foo"/>
6980 <field name="state" widget="priority"/>
6981 </div>
6982 </templates>
6983 </kanban>`,
6984 groupBy: ["product_id"],
6985 });
6986
6987 expect(".o_kanban_record").toHaveCount(16);
6988 expect(document.activeElement).toHaveClass("o_searchview_input");
6989
6990 await press("ArrowDown");
6991 await animationFrame();
6992
6993 expect(document.activeElement).toHaveClass("o_searchview_input");
6994 });
6995
6996 test.tags("desktop");
6997 test("empty kanban with sample data", async () => {
6998 Partner._records = [];
6999
7000 await mountView({
7001 type: "kanban",
7002 resModel: "partner",
7003 arch: `
7004 <kanban sample="1">
7005 <templates>
7006 <t t-name="card">
7007 <field name="foo"/>
7008 </t>
7009 </templates>
7010 </kanban>`,
7011 searchViewArch: `
7012 <search>
7013 <filter name="no_match" string="Match nothing" domain="[['id', '=', 0]]"/>
7014 </search>`,
7015 noContentHelp: "No content helper",
7016 });
7017
7018 expect(".o_content").toHaveClass("o_view_sample_data");
7019 expect(".o_kanban_record:not(.o_kanban_ghost)").toHaveCount(10, {
7020 message: "there should be 10 sample records",
7021 });
7022 expect(".o_view_nocontent").toHaveCount(1);
7023
7024 await toggleSearchBarMenu();
7025 await toggleMenuItem("Match nothing");
7026
7027 expect(".o_content").not.toHaveClass("o_view_sample_data");
7028 expect(".o_kanban_record:not(.o_kanban_ghost)").toHaveCount(0);
7029 expect(".o_view_nocontent").toHaveCount(1);
7030 });
7031
7032 test("empty grouped kanban with sample data and many2many_tags", async () => {
7033 onRpc("web_read_group", function ({ kwargs, parent }) {
7034 const result = parent();
7035 // override web_read_group to return empty groups, as this is
7036 // the case for several models (e.g. project.task grouped
7037 // by stage_id)
7038 result.groups.forEach((group) => {
7039 group.__count = 0;
7040 });
7041 return result;
7042 });
7043 stepAllNetworkCalls();
7044
7045 await mountView({
7046 type: "kanban",
7047 resModel: "partner",
7048 arch: `
7049 <kanban sample="1">
7050 <templates>
7051 <t t-name="card">
7052 <field name="int_field"/>
7053 <field name="category_ids" widget="many2many_tags"/>
7054 </t>
7055 </templates>
7056 </kanban>`,
7057 groupBy: ["product_id"],
7058 });
7059
7060 expect(".o_kanban_group").toHaveCount(2, { message: "there should be 2 'real' columns" });
7061 expect(".o_content").toHaveClass("o_view_sample_data");
7062 expect(queryAll(".o_kanban_record").length >= 1).toBe(true, {
7063 message: "there should be sample records",
7064 });
7065 expect(queryAll(".o_field_many2many_tags .o_tag").length >= 1).toBe(true, {
7066 message: "there should be tags",
7067 });
7068 // should not read the tags
7069 expect.verifySteps([
7070 "/web/webclient/translations",
7071 "/web/webclient/load_menus",
7072 "get_views",
7073 "web_read_group",
7074 "has_group",
7075 ]);
7076 });
7077
7078 test.tags("desktop");
7079 test("sample data does not change after reload with sample data", async () => {
7080 Partner._views["kanban"] = `
7081 <kanban sample="1">
7082 <templates>
7083 <t t-name="card">
7084 <field name="int_field"/>
7085 </t>
7086 </templates>
7087 </kanban>`;
7088 // list-view so that there is a view switcher, unused
7089 Partner._views["list"] = '<list><field name="foo"/></list>';
7090
7091 onRpc("web_read_group", function ({ kwargs, parent }) {
7092 const result = parent();
7093 // override web_read_group to return empty groups, as this is
7094 // the case for several models (e.g. project.task grouped
7095 // by stage_id)
7096 result.groups.forEach((group) => {
7097 group.__count = 0;
7098 });
7099 return result;
7100 });
7101 await mountWithCleanup(WebClient);
7102 await getService("action").doAction({
7103 res_model: "partner",
7104 type: "ir.actions.act_window",
7105 views: [
7106 [false, "kanban"],
7107 [false, "list"],
7108 ],
7109 context: {
7110 group_by: ["product_id"],
7111 },
7112 });
7113
7114 expect(".o_kanban_group").toHaveCount();
7115 expect(".o_content").toHaveClass("o_view_sample_data");
7116 expect(".o_kanban_record").toHaveCount(16);
7117
7118 const kanbanText = queryText(".o_kanban_view");
7119 await contains(".o_control_panel .o_switch_view.o_kanban").click();
7120
7121 expect(".o_kanban_view").toHaveText(kanbanText, {
7122 message: "the content should be the same after reloading the view",
7123 });
7124 });
7125
7126 test.tags("desktop");
7127 test("non empty kanban with sample data", async () => {
7128 await mountView({
7129 type: "kanban",
7130 resModel: "partner",
7131 arch: `
7132 <kanban sample="1">
7133 <templates>
7134 <t t-name="card">
7135 <field name="foo"/>
7136 </t>
7137 </templates>
7138 </kanban>`,
7139 searchViewArch: `
7140 <search>
7141 <filter name="no_match" string="Match nothing" domain="[['id', '=', 0]]"/>
7142 </search>`,
7143 noContentHelp: "No content helper",
7144 });
7145
7146 expect(".o_content").not.toHaveClass("o_view_sample_data");
7147 expect(".o_kanban_record:not(.o_kanban_ghost)").toHaveCount(4);
7148 expect(".o_view_nocontent").toHaveCount(0);
7149
7150 await toggleSearchBarMenu();
7151 await toggleMenuItem("Match nothing");
7152
7153 expect(".o_content").not.toHaveClass("o_view_sample_data");
7154 expect(".o_kanban_record:not(.o_kanban_ghost)").toHaveCount(0);
7155 });
7156
7157 test("empty grouped kanban with sample data: add a column", async () => {
7158 onRpc("web_read_group", function ({ parent }) {
7159 const result = parent();
7160 result.groups = this.env["product"].map((r) => ({
7161 product_id: [r.id, r.display_name],
7162 __count: 0,
7163 __records: [], // Open group by default
7164 __extra_domain: [["product_id", "=", r.id]],
7165 }));
7166 result.length = result.groups.length;
7167 return result;
7168 });
7169
7170 await mountView({
7171 arch: `
7172 <kanban default_group_by="product_id" sample="1">
7173 <templates>
7174 <div t-name="card">
7175 <field name="foo"/>
7176 </div>
7177 </templates>
7178 </kanban>`,
7179 resModel: "partner",
7180 type: "kanban",
7181 });
7182
7183 expect(".o_content").toHaveClass("o_view_sample_data");
7184 expect(".o_kanban_group").toHaveCount(2);
7185 expect(queryAll(".o_kanban_record").length > 0).toBe(true, {
7186 message: "should contain sample records",
7187 });
7188
7189 await quickCreateKanbanColumn();
7190 await editKanbanColumnName("Yoohoo");
7191 await validateKanbanColumn();
7192
7193 expect(".o_content").toHaveClass("o_view_sample_data");
7194 expect(".o_kanban_group").toHaveCount(3);
7195 expect(queryAll(".o_kanban_record").length > 0).toBe(true, {
7196 message: "should contain sample records",
7197 });
7198 });
7199
7200 test.tags("desktop");
7201 test("empty grouped kanban with sample data: cannot fold a column", async () => {
7202 // folding a column in grouped kanban with sample data is disabled, for the sake of simplicity
7203 onRpc("web_read_group", function ({ kwargs, parent }) {
7204 const result = parent();
7205 // override web_read_group to return a single, empty group
7206 result.groups = result.groups.slice(0, 1);
7207 result.groups[0]["__count"] = 0;
7208 result.length = 1;
7209 return result;
7210 });
7211
7212 await mountView({
7213 resModel: "partner",
7214 type: "kanban",
7215 arch: `
7216 <kanban sample="1">
7217 <templates>
7218 <div t-name="card">
7219 <field name="foo"/>
7220 </div>
7221 </templates>
7222 </kanban>`,
7223 groupBy: ["product_id"],
7224 });
7225
7226 expect(".o_content").toHaveClass("o_view_sample_data");
7227 expect(".o_kanban_group").toHaveCount(1);
7228 expect(queryAll(".o_kanban_record").length > 0).toBe(true, {
7229 message: "should contain sample records",
7230 });
7231
7232 await toggleKanbanColumnActions(0);
7233
7234 expect(getDropdownMenu(".o_group_config").querySelector(".o_kanban_toggle_fold")).toHaveClass(
7235 "disabled"
7236 );
7237 });
7238
7239 test("empty grouped kanban with sample data: delete a column", async () => {
7240 Partner._records = [];
7241
7242 let groups = [
7243 {
7244 product_id: [1, "New"],
7245 __count: 0,
7246 __extra_domain: [],
7247 __records: [],
7248 },
7249 ];
7250
7251 onRpc("web_read_group", () =>
7252 // override read_group to return a single, empty group
7253 ({
7254 groups,
7255 length: groups.length,
7256 })
7257 );
7258
7259 await mountView({
7260 resModel: "partner",
7261 type: "kanban",
7262 arch: `
7263 <kanban default_group_by="product_id" sample="1">
7264 <templates>
7265 <div t-name="card">
7266 <field name="foo"/>
7267 </div>
7268 </templates>
7269 </kanban>`,
7270 });
7271
7272 expect(".o_content").toHaveClass("o_view_sample_data");
7273 expect(".o_kanban_group").toHaveCount(1);
7274 expect(queryAll(".o_kanban_record").length > 0).toBe(true, {
7275 message: "should contain sample records",
7276 });
7277
7278 // Delete the first column
7279 groups = [];
7280 const clickColumnAction = await toggleKanbanColumnActions(0);
7281 await clickColumnAction("Delete");
7282 await contains(".o_dialog footer .btn-primary").click();
7283
7284 expect(".o_kanban_group").toHaveCount(0);
7285 expect(".o_column_quick_create.o_quick_create_unfolded").toHaveCount(1);
7286 });
7287
7288 test("empty grouped kanban with sample data: add a column and delete it right away", async () => {
7289 onRpc("web_read_group", function ({ parent }) {
7290 const result = parent();
7291 result.groups = this.env["product"].map((r) => ({
7292 product_id: [r.id, r.display_name],
7293 __count: 0,
7294 __records: [], // Open group by default
7295 __extra_domain: [["product_id", "=", r.id]],
7296 }));
7297 result.length = result.groups.length;
7298 return result;
7299 });
7300
7301 await mountView({
7302 resModel: "partner",
7303 type: "kanban",
7304 arch: `
7305 <kanban default_group_by="product_id" sample="1">
7306 <templates>
7307 <div t-name="card">
7308 <field name="foo"/>
7309 </div>
7310 </templates>
7311 </kanban>`,
7312 });
7313
7314 expect(".o_content").toHaveClass("o_view_sample_data");
7315 expect(".o_kanban_group").toHaveCount(2);
7316 expect(queryAll(".o_kanban_record").length > 0).toBe(true, {
7317 message: "should contain sample records",
7318 });
7319
7320 // add a new column
7321 await quickCreateKanbanColumn();
7322 await editKanbanColumnName("Yoohoo");
7323 await validateKanbanColumn();
7324
7325 expect(".o_content").toHaveClass("o_view_sample_data");
7326 expect(".o_kanban_group").toHaveCount(3);
7327 expect(queryAll(".o_kanban_record").length > 0).toBe(true, {
7328 message: "should contain sample records",
7329 });
7330
7331 // delete the column we just created
7332 const clickColumnAction = await toggleKanbanColumnActions(2);
7333 await clickColumnAction("Delete");
7334 await contains(".o_dialog footer .btn-primary").click();
7335
7336 expect(".o_content").toHaveClass("o_view_sample_data");
7337 expect(".o_kanban_group").toHaveCount(2);
7338 expect(queryAll(".o_kanban_record").length > 0).toBe(true, {
7339 message: "should contain sample records",
7340 });
7341 });
7342
7343 test.tags("desktop");
7344 test("kanban with sample data: do an on_create action", async () => {
7345 Partner._records = [];
7346 Partner._views["form,some_view_ref"] = `<form><field name="foo"/></form>`;
7347
7348 onRpc("/web/action/load", () => ({
7349 type: "ir.actions.act_window",
7350 name: "Archive Action",
7351 res_model: "partner",
7352 view_mode: "form",
7353 target: "new",
7354 views: [[false, "form"]],
7355 }));
7356
7357 await mountView({
7358 resModel: "partner",
7359 type: "kanban",
7360 arch: `
7361 <kanban sample="1" on_create="myCreateAction">
7362 <templates>
7363 <div t-name="card">
7364 <field name="foo"/>
7365 </div>
7366 </templates>
7367 </kanban>`,
7368 });
7369
7370 expect(".o_content").toHaveClass("o_view_sample_data");
7371 expect(".o_kanban_record:not(.o_kanban_ghost)").toHaveCount(10, {
7372 message: "there should be 10 sample records",
7373 });
7374 expect(".o_view_nocontent").toHaveCount(1);
7375
7376 await createKanbanRecord();
7377 expect(".modal").toHaveCount(1);
7378
7379 await contains(".modal .o_form_button_save").click();
7380 expect(".o_content").not.toHaveClass("o_view_sample_data");
7381 expect(".o_kanban_record:not(.o_kanban_ghost)").toHaveCount(1);
7382 expect(".o_view_nocontent").toHaveCount(0);
7383 });
7384
7385 test("kanban with sample data grouped by m2o and existing groups", async () => {
7386 Partner._records = [];
7387
7388 onRpc("web_read_group", () => ({
7389 groups: [
7390 {
7391 __count: 0,
7392 __records: [],
7393 product_id: [3, "hello"],
7394 __extra_domain: [["product_id", "=", "3"]],
7395 },
7396 ],
7397 length: 1,
7398 }));
7399
7400 await mountView({
7401 resModel: "partner",
7402 type: "kanban",
7403 arch: `
7404 <kanban sample="1">
7405 <templates>
7406 <div t-name="card">
7407 <field name="product_id"/>
7408 </div>
7409 </templates>
7410 </kanban>`,
7411 groupBy: ["product_id"],
7412 });
7413
7414 expect(".o_content").toHaveClass("o_view_sample_data");
7415 expect(".o_view_nocontent").toHaveCount(1);
7416 expect(".o_kanban_group:first .o_column_title").toHaveText("hello");
7417 expect(".o_kanban_record:not(.o_kanban_ghost)").toHaveCount(16);
7418 expect(".o_kanban_record").toHaveText("hello");
7419 });
7420
7421 test(`kanban grouped by m2o with sample data with more than 5 real groups`, async () => {
7422 Partner._records = [];
7423 onRpc("web_read_group", () => ({
7424 // simulate 6, empty, real groups
7425 groups: [1, 2, 3, 4, 5, 6].map((id) => ({
7426 __count: 0,
7427 __records: [],
7428 product_id: [id, `Value ${id}`],
7429 __extra_domain: [["product_id", "=", id]],
7430 })),
7431 length: 6,
7432 }));
7433
7434 await mountView({
7435 resModel: "partner",
7436 type: "kanban",
7437 arch: `
7438 <kanban sample="1">
7439 <templates>
7440 <div t-name="card">
7441 <field name="product_id"/>
7442 </div>
7443 </templates>
7444 </kanban>`,
7445 groupBy: ["product_id"],
7446 });
7447 expect(".o_content").toHaveClass("o_view_sample_data");
7448 expect(queryAllTexts(`.o_kanban_group .o_column_title`)).toEqual([
7449 "Value 1",
7450 "Value 2",
7451 "Value 3",
7452 "Value 4",
7453 "Value 5",
7454 "Value 6",
7455 ]);
7456 });
7457
7458 test.tags("desktop");
7459 test("bounce create button when no data and click on empty area", async () => {
7460 await mountView({
7461 type: "kanban",
7462 resModel: "partner",
7463 arch: `
7464 <kanban>
7465 <templates>
7466 <t t-name="card">
7467 <field name="foo"/>
7468 </t>
7469 </templates>
7470 </kanban>`,
7471 searchViewArch: `
7472 <search>
7473 <filter name="no_match" string="Match nothing" domain="[['id', '=', 0]]"/>
7474 </search>`,
7475 noContentHelp: "click to add a partner",
7476 });
7477
7478 await contains(".o_kanban_view").click();
7479 expect(".o-kanban-button-new").not.toHaveClass("o_catch_attention");
7480
7481 await toggleSearchBarMenu();
7482 await toggleMenuItem("Match nothing");
7483
7484 await contains(".o_kanban_renderer").click();
7485 expect(".o-kanban-button-new").toHaveClass("o_catch_attention");
7486 });
7487
7488 test("buttons with modifiers", async () => {
7489 Partner._records[1].bar = false; // so that test is more complete
7490
7491 await mountView({
7492 type: "kanban",
7493 resModel: "partner",
7494 arch: `
7495 <kanban>
7496 <field name="foo"/>
7497 <field name="bar"/>
7498 <field name="state"/>
7499 <templates>
7500 <div t-name="card">
7501 <button class="o_btn_test_1" type="object" name="a1" invisible="foo != 'yop'"/>
7502 <button class="o_btn_test_2" type="object" name="a2" invisible="bar and state not in ['abc', 'def']"/>
7503 </div>
7504 </templates>
7505 </kanban>`,
7506 });
7507
7508 expect(".o_btn_test_1").toHaveCount(1, { message: "kanban should have one buttons of type 1" });
7509 expect(".o_btn_test_2").toHaveCount(3, {
7510 message: "kanban should have three buttons of type 2",
7511 });
7512 });
7513
7514 test("support styling of anchor tags with action type", async function (assert) {
7515 expect.assertions(3);
7516
7517 mockService("action", {
7518 doActionButton(action) {
7519 expect(action.name).toBe("42");
7520 },
7521 });
7522
7523 await mountView({
7524 type: "kanban",
7525 resModel: "partner",
7526 arch: `
7527 <kanban>
7528 <templates>
7529 <div t-name="card">
7530 <field name="foo"/>
7531 <a type="action" name="42" class="btn-primary" style="margin-left: 10px"><i class="oi oi-arrow-right"/> Click me !</a>
7532 </div>
7533 </templates>
7534 </kanban>`,
7535 });
7536
7537 await click("a[type='action']");
7538 expect("a[type='action']:first").toHaveClass("btn-primary");
7539 expect(queryFirst("a[type='action']").style.marginLeft).toBe("10px");
7540 });
7541
7542 test("button executes action and reloads", async () => {
7543 stepAllNetworkCalls();
7544
7545 let count = 0;
7546 mockService("action", {
7547 async doActionButton({ onClose }) {
7548 count++;
7549 await animationFrame();
7550 onClose();
7551 },
7552 });
7553
7554 await mountView({
7555 type: "kanban",
7556 resModel: "partner",
7557 arch: `
7558 <kanban>
7559 <templates>
7560 <div t-name="card">
7561 <field name="foo"/>
7562 <button type="object" name="a1" class="a1">
7563 A1
7564 </button>
7565 </div>
7566 </templates>
7567 </kanban>`,
7568 });
7569
7570 expect.verifySteps([
7571 "/web/webclient/translations",
7572 "/web/webclient/load_menus",
7573 "get_views",
7574 "web_search_read",
7575 "has_group",
7576 ]);
7577 expect("button.a1").toHaveCount(4);
7578 expect("button.a1:first").not.toHaveAttribute("disabled");
7579
7580 await click("button.a1");
7581
7582 expect("button.a1:first").toHaveAttribute("disabled");
7583
7584 await animationFrame();
7585
7586 expect("button.a1:first").not.toHaveAttribute("disabled");
7587 expect(count).toBe(1, { message: "should have triggered an execute action only once" });
7588 // the records should be reloaded after executing a button action
7589 expect.verifySteps(["web_search_read"]);
7590 });
7591
7592 test("button executes action and check domain", async () => {
7593 Partner._fields.active = fields.Boolean({ default: true });
7594 for (let i = 0; i < Partner._records.length; i++) {
7595 Partner._records[i].active = true;
7596 }
7597
7598 mockService("action", {
7599 doActionButton({ onClose }) {
7600 MockServer.env["partner"][0].active = false;
7601 onClose();
7602 },
7603 });
7604
7605 await mountView({
7606 type: "kanban",
7607 resModel: "partner",
7608 arch: `
7609 <kanban>
7610 <templates>
7611 <div t-name="card">
7612 <field name="foo"/>
7613 <button type="object" name="a1" />
7614 <button type="object" name="action_archive" class="action-archive" />
7615 </div>
7616 </templates>
7617 </kanban>`,
7618 });
7619
7620 expect(queryText("span", { root: getKanbanRecord({ index: 0 }) })).toBe("yop", {
7621 message: "should display 'yop' record",
7622 });
7623 await contains("button.action-archive", { root: getKanbanRecord({ index: 0 }) }).click();
7624 expect(queryText("span", { root: getKanbanRecord({ index: 0 }) })).not.toBe("yop", {
7625 message: "should have removed 'yop' record from the view",
7626 });
7627 });
7628
7629 test("field tag with modifiers but no widget", async () => {
7630 await mountView({
7631 type: "kanban",
7632 resModel: "partner",
7633 arch: `
7634 <kanban>
7635 <templates>
7636 <t t-name="card">
7637 <field name="foo" invisible="id == 1"/>
7638 </t>
7639 </templates>
7640 </kanban>`,
7641 });
7642
7643 expect(".o_kanban_record:first").toHaveText("");
7644 expect(".o_kanban_record:eq(1)").toHaveText("blip");
7645 });
7646
7647 test("field tag with widget and class attributes", async () => {
7648 await mountView({
7649 type: "kanban",
7650 resModel: "partner",
7651 arch: `
7652 <kanban>
7653 <templates>
7654 <t t-name="card">
7655 <field name="foo" widget="char" class="hi"/>
7656 </t>
7657 </templates>
7658 </kanban>`,
7659 });
7660
7661 expect(".o_field_widget.hi").toHaveCount(4);
7662 });
7663
7664 test("rendering date and datetime (value)", async () => {
7665 Partner._records[0].date = "2017-01-25";
7666 Partner._records[1].datetime = "2016-12-12 10:55:05";
7667
7668 await mountView({
7669 type: "kanban",
7670 resModel: "partner",
7671 arch: `
7672 <kanban>
7673 <templates>
7674 <t t-name="card">
7675 <field class="date" name="date"/>
7676 <field class="datetime" name="datetime"/>
7677 </t>
7678 </templates>
7679 </kanban>`,
7680 });
7681
7682 expect(getKanbanRecord({ index: 0 }).querySelector(".date")).toHaveText("Jan 25, 2017");
7683 expect(getKanbanRecord({ index: 1 }).querySelector(".datetime")).toHaveText(
7684 "Dec 12, 2016, 11:55 AM"
7685 );
7686 });
7687
7688 test("rendering date and datetime (raw value)", async () => {
7689 Partner._records[0].date = "2017-01-25";
7690 Partner._records[1].datetime = "2016-12-12 10:55:05";
7691
7692 await mountView({
7693 type: "kanban",
7694 resModel: "partner",
7695 arch: `
7696 <kanban>
7697 <field name="date"/>
7698 <field name="datetime"/>
7699 <templates>
7700 <t t-name="card">
7701 <span class="date" t-esc="record.date.raw_value"/>
7702 <span class="datetime" t-esc="record.datetime.raw_value"/>
7703 </t>
7704 </templates>
7705 </kanban>`,
7706 });
7707
7708 expect(getKanbanRecord({ index: 0 }).querySelector(".date")).toHaveText(
7709 "2017-01-25T00:00:00.000+01:00"
7710 );
7711 expect(getKanbanRecord({ index: 1 }).querySelector(".datetime")).toHaveText(
7712 "2016-12-12T11:55:05.000+01:00"
7713 );
7714 });
7715
7716 test("rendering many2one (value)", async () => {
7717 Partner._records[1].product_id = false;
7718
7719 await mountView({
7720 type: "kanban",
7721 resModel: "partner",
7722 arch: `
7723 <kanban>
7724 <templates>
7725 <t t-name="card">
7726 <field name="product_id" class="product_id"/>
7727 </t>
7728 </templates>
7729 </kanban>`,
7730 });
7731
7732 expect(getKanbanRecordTexts()).toEqual(["hello", "", "hello", "xmo"]);
7733 });
7734
7735 test("rendering many2one (raw value)", async () => {
7736 Partner._records[1].product_id = false;
7737
7738 await mountView({
7739 type: "kanban",
7740 resModel: "partner",
7741 arch: `
7742 <kanban>
7743 <field name="product_id"/>
7744 <templates>
7745 <t t-name="card">
7746 <span class="product_id" t-esc="record.product_id.raw_value"/>
7747 </t>
7748 </templates>
7749 </kanban>`,
7750 });
7751
7752 expect(getKanbanRecordTexts()).toEqual(["3", "false", "3", "5"]);
7753 });
7754
7755 test("evaluate conditions on relational fields", async () => {
7756 Partner._records[0].product_id = false;
7757
7758 await mountView({
7759 type: "kanban",
7760 resModel: "partner",
7761 arch: `
7762 <kanban>
7763 <field name="product_id"/>
7764 <field name="category_ids"/>
7765 <templates>
7766 <t t-name="card">
7767 <button t-if="!record.product_id.raw_value" class="btn_a">A</button>
7768 <button t-if="!record.category_ids.raw_value.length" class="btn_b">B</button>
7769 </t>
7770 </templates>
7771 </kanban>`,
7772 });
7773
7774 expect(".o_kanban_record:not(.o_kanban_ghost)").toHaveCount(4, {
7775 message: "there should be 4 records",
7776 });
7777 expect(".o_kanban_record:not(.o_kanban_ghost) .btn_a").toHaveCount(1, {
7778 message: "only 1 of them should have the 'Action' button",
7779 });
7780 expect(".o_kanban_record:not(.o_kanban_ghost) .btn_b").toHaveCount(2, {
7781 message: "only 2 of them should have the 'Action' button",
7782 });
7783 });
7784
7785 test.tags("desktop");
7786 test("resequence columns in grouped by m2o", async () => {
7787 Product._fields.sequence = fields.Integer();
7788
7789 await mountView({
7790 type: "kanban",
7791 resModel: "partner",
7792 arch: `
7793 <kanban>
7794 <templates>
7795 <t t-name="card">
7796 <field name="id"/>
7797 </t>
7798 </templates>
7799 </kanban>`,
7800 groupBy: ["product_id"],
7801 });
7802
7803 expect(".o_kanban_group").toHaveCount(2);
7804 expect(getKanbanColumn(0).querySelector(".o_column_title")).toHaveText("hello\n(2)");
7805 expect(getKanbanRecordTexts()).toEqual(["1", "3", "2", "4"]);
7806
7807 await contains(".o_kanban_group:first-child").dragAndDrop(".o_kanban_group:nth-child(2)");
7808
7809 // Drag & drop on column (not title) should not work
7810 expect(getKanbanColumn(0).querySelector(".o_column_title")).toHaveText("hello\n(2)");
7811 expect(getKanbanRecordTexts()).toEqual(["1", "3", "2", "4"]);
7812
7813 await contains(".o_kanban_group:first-child .o_column_title").dragAndDrop(
7814 ".o_kanban_group:nth-child(2)"
7815 );
7816
7817 expect(getKanbanColumn(0).querySelector(".o_column_title")).toHaveText("xmo\n(2)");
7818 expect(getKanbanRecordTexts()).toEqual(["2", "4", "1", "3"]);
7819 });
7820
7821 test.tags("desktop");
7822 test("resequence all when creating new record + partial resequencing", async () => {
7823 onRpc("web_resequence", ({ args, kwargs }) => {
7824 const [ids] = args;
7825 const { field_name: fieldName, offset } = kwargs;
7826 expect.step({ ids, ...(offset ? { offset } : {}) });
7827 const resequenceOffset = offset || 0;
7828
7829 return ids.map((id, index) => ({
7830 id,
7831 [fieldName]: resequenceOffset + index,
7832 }));
7833 });
7834
7835 await mountView({
7836 type: "kanban",
7837 resModel: "partner",
7838 arch: `
7839 <kanban default_group_by="product_id">
7840 <templates>
7841 <t t-name="card">
7842 <field name="id"/>
7843 </t>
7844 </templates>
7845 </kanban>`,
7846 });
7847
7848 await quickCreateKanbanColumn();
7849 await editKanbanColumnName("foo");
7850 await validateKanbanColumn();
7851 expect.verifySteps([{ ids: [3, 5, 6] }]);
7852
7853 await editKanbanColumnName("bar");
7854 await validateKanbanColumn();
7855 expect.verifySteps([{ ids: [3, 5, 6, 7] }]);
7856
7857 await editKanbanColumnName("baz");
7858 await validateKanbanColumn();
7859 expect.verifySteps([{ ids: [3, 5, 6, 7, 8] }]);
7860
7861 await editKanbanColumnName("boo");
7862 await validateKanbanColumn();
7863 expect.verifySteps([{ ids: [3, 5, 6, 7, 8, 9] }]);
7864
7865 // When rearranging, only resequence the affected records. In this example,
7866 // dragging column 2 to column 4 should only resequence [5, 6, 7] to [6, 7, 5]
7867 // with offset 1.
7868 await contains(".o_kanban_group:nth-child(2) .o_column_title").dragAndDrop(
7869 ".o_kanban_group:nth-child(4)"
7870 );
7871 expect.verifySteps([{ ids: [6, 7, 5], offset: 1 }]);
7872 });
7873
7874 test("prevent resequence columns if groups_draggable=false", async () => {
7875 Product._fields.sequence = fields.Integer();
7876
7877 await mountView({
7878 type: "kanban",
7879 resModel: "partner",
7880 arch: `
7881 <kanban groups_draggable='0'>
7882 <templates>
7883 <t t-name="card">
7884 <field name="id"/>
7885 </t>
7886 </templates>
7887 </kanban>`,
7888 groupBy: ["product_id"],
7889 });
7890
7891 expect(".o_kanban_group").toHaveCount(2);
7892 expect(getKanbanColumn(0).querySelector(".o_column_title")).toHaveText("hello\n(2)");
7893 expect(getKanbanRecordTexts()).toEqual(["1", "3", "2", "4"]);
7894
7895 await contains(".o_kanban_group:first-child").dragAndDrop(".o_kanban_group:nth-child(2)");
7896
7897 // Drag & drop on column (not title) should not work
7898 expect(getKanbanColumn(0).querySelector(".o_column_title")).toHaveText("hello\n(2)");
7899 expect(getKanbanRecordTexts()).toEqual(["1", "3", "2", "4"]);
7900
7901 await contains(".o_kanban_group:first-child .o_column_title").dragAndDrop(
7902 ".o_kanban_group:nth-child(2)"
7903 );
7904
7905 expect(getKanbanColumn(0).querySelector(".o_column_title")).toHaveText("hello\n(2)");
7906 expect(getKanbanRecordTexts()).toEqual(["1", "3", "2", "4"]);
7907 });
7908
7909 test("open config dropdown on kanban with records and groups draggable off", async () => {
7910 await mountView({
7911 type: "kanban",
7912 resModel: "partner",
7913 arch: `
7914 <kanban groups_draggable='0' records_draggable='0'>
7915 <templates>
7916 <t t-name="card">
7917 <field name="id"/>
7918 </t>
7919 </templates>
7920 </kanban>`,
7921 groupBy: ["product_id"],
7922 });
7923
7924 expect(".o_kanban_group .o_group_config").toHaveCount(2);
7925 expect(".o-dropdown--menu").toHaveCount(0);
7926
7927 await toggleKanbanColumnActions(0);
7928
7929 expect(".o-dropdown--menu").toHaveCount(1);
7930 });
7931
7932 test("properly evaluate more complex domains", async () => {
7933 await mountView({
7934 type: "kanban",
7935 resModel: "partner",
7936 arch: `
7937 <kanban>
7938 <field name="bar"/>
7939 <field name="category_ids"/>
7940 <templates>
7941 <t t-name="card">
7942 <field name="foo"/>
7943 <button type="object" invisible="bar or category_ids" class="btn btn-primary float-end" name="arbitrary">Join</button>
7944 </t>
7945 </templates>
7946 </kanban>`,
7947 });
7948
7949 expect("button.float-end.oe_kanban_action").toHaveCount(1, {
7950 message: "only one button should be visible",
7951 });
7952 });
7953
7954 test("kanban with color attribute", async () => {
7955 Category._records[0].color = 5;
7956 Category._records[1].color = 6;
7957
7958 await mountView({
7959 type: "kanban",
7960 resModel: "category",
7961 arch: `
7962 <kanban highlight_color="color">
7963 <templates>
7964 <t t-name="card">
7965 <field name="name"/>
7966 </t>
7967 </templates>
7968 </kanban>`,
7969 });
7970
7971 expect(getKanbanRecord({ index: 0 })).toHaveClass("o_kanban_color_5");
7972 expect(getKanbanRecord({ index: 1 })).toHaveClass("o_kanban_color_6");
7973 });
7974
7975 test("edit the kanban color with the colorpicker", async () => {
7976 Category._records[0].color = 12;
7977
7978 onRpc("web_save", ({ args }) => {
7979 expect.step(`write-color-${args[1].color}`);
7980 });
7981
7982 await mountView({
7983 type: "kanban",
7984 resModel: "category",
7985 arch: `
7986 <kanban highlight_color="color">
7987 <templates>
7988 <t t-name="menu">
7989 <field name="color" widget="kanban_color_picker"/>
7990 </t>
7991 <t t-name="card">
7992 <field name="name"/>
7993 </t>
7994 </templates>
7995 </kanban>`,
7996 });
7997
7998 await toggleKanbanRecordDropdown(0);
7999
8000 expect(".o_kanban_record.o_kanban_color_12").toHaveCount(0, {
8001 message: "no record should have the color 12",
8002 });
8003 expect(
8004 queryAll(".o_kanban_colorpicker", { root: getDropdownMenu(getKanbanRecord({ index: 0 })) })
8005 ).toHaveCount(1);
8006 expect(
8007 queryAll(".o_kanban_colorpicker > *", {
8008 root: getDropdownMenu(getKanbanRecord({ index: 0 })),
8009 })
8010 ).toHaveCount(12, { message: "the color picker should have 12 children (the colors)" });
8011
8012 await contains(".o_kanban_colorpicker .o_colorlist_item_color_9").click();
8013
8014 // should write on the color field
8015 expect.verifySteps(["write-color-9"]);
8016 expect(getKanbanRecord({ index: 0 })).toHaveClass("o_kanban_color_9");
8017 });
8018
8019 test("kanban with colorpicker and node with color attribute", async () => {
8020 Category._fields.colorpickerField = fields.Integer();
8021 Category._records[0].colorpickerField = 3;
8022
8023 onRpc("web_save", ({ args }) => {
8024 expect.step(`write-color-${args[1].colorpickerField}`);
8025 });
8026
8027 await mountView({
8028 type: "kanban",
8029 resModel: "category",
8030 arch: `
8031 <kanban highlight_color="colorpickerField">
8032 <templates>
8033 <t t-name="menu">
8034 <field name="colorpickerField" widget="kanban_color_picker"/>
8035 </t>
8036 <t t-name="card">
8037 <field name="name"/>
8038 </t>
8039 </templates>
8040 </kanban>`,
8041 });
8042 expect(getKanbanRecord({ index: 0 })).toHaveClass("o_kanban_color_3");
8043 await toggleKanbanRecordDropdown(0);
8044 await contains(`.o_kanban_colorpicker .o_colorlist_item_color_9[title="Raspberry"]`).click();
8045 // should write on the color field
8046 expect.verifySteps(["write-color-9"]);
8047 expect(getKanbanRecord({ index: 0 })).toHaveClass("o_kanban_color_9");
8048 });
8049
8050 test("edit the kanban color with translated colors resulting in the same terms", async () => {
8051 Category._records[0].color = 12;
8052
8053 const translations = {
8054 Purple: "Violet",
8055 Violet: "Violet",
8056 };
8057 defineParams({ translations });
8058
8059 await mountView({
8060 type: "kanban",
8061 resModel: "category",
8062 arch: `
8063 <kanban highlight_color="color">
8064 <templates>
8065 <t t-name="menu">
8066 <field name="color" widget="kanban_color_picker"/>
8067 </t>
8068 <t t-name="card">
8069 <field name="name"/>
8070 </t>
8071 </templates>
8072 </kanban>`,
8073 });
8074
8075 await toggleKanbanRecordDropdown(0);
8076 await contains(".o_kanban_colorpicker .o_colorlist_item_color_9").click();
8077 expect(getKanbanRecord({ index: 0 })).toHaveClass("o_kanban_color_9");
8078 });
8079
8080 test("colorpicker doesn't appear when missing access rights", async () => {
8081 await mountView({
8082 type: "kanban",
8083 resModel: "category",
8084 arch: `
8085 <kanban edit="0">
8086 <templates>
8087 <t t-name="menu">
8088 <field name="color" widget="kanban_color_picker"/>
8089 </t>
8090 <t t-name="card">
8091 <field name="name"/>
8092 </t>
8093 </templates>
8094 </kanban>`,
8095 });
8096
8097 await toggleKanbanRecordDropdown(0);
8098 expect(".o_kanban_colorpicker").toHaveCount(0);
8099 });
8100
8101 test("load more records in column", async () => {
8102 onRpc("web_search_read", ({ kwargs }) => {
8103 expect.step(`web_search_read ${kwargs.limit} - ${kwargs.offset}`);
8104 });
8105 await mountView({
8106 type: "kanban",
8107 resModel: "partner",
8108 arch: `
8109 <kanban>
8110 <templates>
8111 <t t-name="card">
8112 <field name="id"/>
8113 </t>
8114 </templates>
8115 </kanban>`,
8116 groupBy: ["bar"],
8117 limit: 2,
8118 });
8119
8120 expect(queryAll(".o_kanban_record", { root: getKanbanColumn(1) })).toHaveCount(2, {
8121 message: "there should be 2 records in the column",
8122 });
8123 expect(getKanbanRecordTexts(1)).toEqual(["1", "2"]);
8124
8125 // load more
8126 await clickKanbanLoadMore(1);
8127
8128 expect(queryAll(".o_kanban_record", { root: getKanbanColumn(1) })).toHaveCount(3, {
8129 message: "there should now be 3 records in the column",
8130 });
8131 // the records should be correctly fetched
8132 expect(getKanbanRecordTexts(1)).toEqual(["1", "2", "3"]);
8133 expect.verifySteps(["web_search_read 4 - 0"]);
8134
8135 // reload
8136 await validateSearch();
8137
8138 expect(queryAll(".o_kanban_record", { root: getKanbanColumn(1) })).toHaveCount(3, {
8139 message: "there should still be 3 records in the column after reload",
8140 });
8141 expect(getKanbanRecordTexts(1)).toEqual(["1", "2", "3"]);
8142 expect.verifySteps([]); // managed by web_read_group
8143 });
8144
8145 test("load more records in column with x2many", async () => {
8146 Partner._records[0].category_ids = [7];
8147 Partner._records[1].category_ids = [];
8148 Partner._records[2].category_ids = [6];
8149 Partner._records[3].category_ids = [];
8150 // record [2] will be loaded after
8151
8152 onRpc("web_search_read", ({ kwargs }) => {
8153 expect.step(`web_search_read ${kwargs.limit} - ${kwargs.offset}`);
8154 });
8155 await mountView({
8156 type: "kanban",
8157 resModel: "partner",
8158 arch: `
8159 <kanban>
8160 <templates>
8161 <t t-name="card">
8162 <field name="category_ids"/>
8163 <field name="foo"/>
8164 </t>
8165 </templates>
8166 </kanban>`,
8167 groupBy: ["bar"],
8168 limit: 2,
8169 });
8170
8171 expect(queryAll(".o_kanban_record", { root: getKanbanColumn(1) })).toHaveCount(2);
8172 expect(queryAllTexts("[name='category_ids']", { root: getKanbanColumn(1) })).toEqual([
8173 "silver",
8174 "",
8175 ]);
8176
8177 // load more
8178 await clickKanbanLoadMore(1);
8179
8180 expect(queryAll(".o_kanban_record", { root: getKanbanColumn(1) })).toHaveCount(3);
8181 expect(queryAllTexts("[name='category_ids']", { root: getKanbanColumn(1) })).toEqual([
8182 "silver",
8183 "",
8184 "gold",
8185 ]);
8186 expect.verifySteps(["web_search_read 4 - 0"]);
8187 });
8188
8189 test("update buttons after column creation", async () => {
8190 Partner._records = [];
8191
8192 await mountView({
8193 type: "kanban",
8194 resModel: "partner",
8195 arch: `
8196 <kanban default_group_by="product_id">
8197 <templates>
8198 <t t-name="card">
8199 <field name="foo"/>
8200 </t>
8201 </templates>
8202 </kanban>`,
8203 groupBy: ["product_id"],
8204 });
8205
8206 expect(".o-kanban-button-new").not.toBeEnabled();
8207 await editKanbanColumnName("new column");
8208 await validateKanbanColumn();
8209 expect(".o-kanban-button-new").toBeEnabled();
8210 });
8211
8212 test.tags("desktop");
8213 test("group_by_tooltip option when grouping on a many2one", async () => {
8214 Partner._records[3].product_id = false;
8215
8216 onRpc("read", ({ args }) => {
8217 expect.step("read: product");
8218 expect(args[1]).toEqual(["display_name", "name"], {
8219 message: "should read on specified fields on the group by relation",
8220 });
8221 });
8222
8223 await mountView({
8224 type: "kanban",
8225 resModel: "partner",
8226 arch: `
8227 <kanban default_group_by="bar">
8228 <field name="product_id" options='{"group_by_tooltip": {"name": "Kikou"}}'/>
8229 <templates>
8230 <t t-name="card">
8231 <field name="foo"/>
8232 </t>
8233 </templates>
8234 </kanban>`,
8235 searchViewArch: `
8236 <search>
8237 <filter name="group_by_product_id" domain="[]" string="GroupBy Product" context="{ 'group_by': 'product_id' }"/>
8238 </search>`,
8239 });
8240
8241 expect(".o_kanban_renderer").toHaveClass("o_kanban_grouped");
8242 expect(".o_kanban_group").toHaveCount(2, { message: "should have 2 columns" });
8243
8244 // simulate an update coming from the searchview, with another groupby given
8245 await toggleSearchBarMenu();
8246 await toggleMenuItem("GroupBy Product");
8247
8248 expect(".o_kanban_group").toHaveCount(3, { message: "should have 3 columns" });
8249 expect(".o_kanban_group:first").toHaveClass("o_column_folded");
8250
8251 await contains(".o_kanban_group").click();
8252 expect(".o_kanban_group").toHaveCount(3, { message: "should have 3 columns" });
8253 expect(".o_kanban_group:first").not.toHaveClass("o_column_folded");
8254 expect(queryAll(".o_kanban_record", { root: getKanbanColumn(0) })).toHaveCount(1);
8255 expect(queryAll(".o_kanban_record", { root: getKanbanColumn(1) })).toHaveCount(2);
8256 expect(queryAll(".o_kanban_record", { root: getKanbanColumn(2) })).toHaveCount(1);
8257 expect(queryText(".o_column_title", { root: getKanbanColumn(0) })).toBe("None\n(1)", {
8258 message: "first column should have a default title for when no value is provided",
8259 });
8260
8261 await hover(".o_column_title");
8262 await runAllTimers();
8263 expect(".o-tooltip").toHaveCount(0, {
8264 message:
8265 "tooltip of first column should not defined, since group_by_tooltip title and the many2one field has no value",
8266 });
8267 // should not have done any read on product because no value
8268 expect.verifySteps([]);
8269
8270 await hover(".o_column_title:eq(1)");
8271 await runAllTimers();
8272 expect(".o-tooltip").toHaveCount(1, {
8273 message:
8274 "second column should have a tooltip with the group_by_tooltip title and many2one field value",
8275 });
8276 expect(".o-tooltip:first").toHaveText("Kikou\nhello");
8277 expect(".o_kanban_group:nth-child(2) .o_column_title").toHaveText("hello\n(2)", {
8278 message: "second column should have a title with a value from the many2one",
8279 });
8280 // should have done one read on product for the second column tooltip
8281 expect.verifySteps(["read: product"]);
8282 });
8283
8284 test.tags("desktop");
8285 test("asynchronous tooltips when grouped", async () => {
8286 const def = new Deferred();
8287 onRpc("read", () => {
8288 expect.step("read: product");
8289 return def;
8290 });
8291 await mountView({
8292 type: "kanban",
8293 resModel: "partner",
8294 arch: `
8295 <kanban default_group_by="product_id">
8296 <field name="product_id" options='{"group_by_tooltip": {"name": "Name"}}'/>
8297 <templates>
8298 <t t-name="card">
8299 <field name="foo"/>
8300 </t>
8301 </templates>
8302 </kanban>`,
8303 });
8304
8305 expect(".o_kanban_renderer").toHaveClass("o_kanban_grouped");
8306 expect(".o_column_title").toHaveCount(2);
8307
8308 await hover(".o_kanban_group .o_kanban_header_title .o_column_title");
8309 await runAllTimers();
8310 expect(".o-tooltip").toHaveCount(0);
8311
8312 await leave();
8313 await runAllTimers();
8314 expect(".o-tooltip").toHaveCount(0);
8315
8316 await hover(".o_kanban_group .o_kanban_header_title .o_column_title");
8317 await runAllTimers();
8318 expect(".o-tooltip").toHaveCount(0);
8319
8320 def.resolve();
8321 await animationFrame();
8322
8323 expect(".o-tooltip").toHaveCount(1);
8324 expect(".o-tooltip").toHaveText("Name\nhello");
8325 expect.verifySteps(["read: product"]);
8326 });
8327
8328 test.tags("desktop");
8329 test("loads data tooltips only when first opening", async () => {
8330 onRpc("read", () => {
8331 expect.step("read: product");
8332 });
8333
8334 await mountView({
8335 type: "kanban",
8336 resModel: "partner",
8337 arch: `
8338 <kanban default_group_by="product_id">
8339 <field name="product_id" options='{"group_by_tooltip": {"name": "Name"}}'/>
8340 <templates>
8341 <t t-name="card">
8342 <field name="foo"/>
8343 </t>
8344 </templates>
8345 </kanban>`,
8346 });
8347
8348 await hover(".o_kanban_group .o_kanban_header_title .o_column_title");
8349 await await runAllTimers();
8350 expect(".o-tooltip").toHaveCount(1);
8351 expect(".o-tooltip").toHaveText("Name\nhello");
8352 expect.verifySteps(["read: product"]);
8353
8354 await leave();
8355 await animationFrame();
8356 expect(".o-tooltip").toHaveCount(0, { message: "tooltip should be closed" });
8357
8358 await hover(".o_kanban_group .o_kanban_header_title .o_column_title");
8359 await runAllTimers();
8360 expect(".o-tooltip").toHaveCount(1);
8361 expect(".o-tooltip").toHaveText("Name\nhello");
8362 expect.verifySteps([]);
8363 });
8364
8365 test.tags("desktop");
8366 test("move a record then put it again in the same column", async () => {
8367 Partner._records = [];
8368
8369 await mountView({
8370 type: "kanban",
8371 resModel: "partner",
8372 arch: `
8373 <kanban default_group_by="product_id">
8374 <templates>
8375 <t t-name="card">
8376 <field name="display_name"/>
8377 </t>
8378 </templates>
8379 </kanban>`,
8380 });
8381
8382 await editKanbanColumnName("column1");
8383 await validateKanbanColumn();
8384
8385 await editKanbanColumnName("column2");
8386 await validateKanbanColumn();
8387
8388 await quickCreateKanbanRecord(1);
8389 await editKanbanRecordQuickCreateInput("display_name", "new partner");
8390 await validateKanbanRecord();
8391
8392 expect(".o_kanban_group:first-child .o_kanban_record").toHaveCount(0);
8393 expect(".o_kanban_group:nth-child(2) .o_kanban_record").toHaveCount(1);
8394
8395 await contains(".o_kanban_group:nth-child(2) .o_kanban_record").dragAndDrop(
8396 ".o_kanban_group:first-child"
8397 );
8398
8399 expect(".o_kanban_group:first-child .o_kanban_record").toHaveCount(1);
8400 expect(".o_kanban_group:nth-child(2) .o_kanban_record").toHaveCount(0);
8401
8402 await contains(".o_kanban_group:first-child .o_kanban_record").dragAndDrop(
8403 ".o_kanban_group:nth-child(2)"
8404 );
8405
8406 expect(".o_kanban_group:first-child .o_kanban_record").toHaveCount(0);
8407 expect(".o_kanban_group:nth-child(2) .o_kanban_record").toHaveCount(1);
8408 });
8409
8410 test.tags("desktop");
8411 test("resequence a record twice", async () => {
8412 Partner._records = [];
8413
8414 const def = new Deferred();
8415 onRpc("web_resequence", () => {
8416 expect.step("resequence");
8417 return def;
8418 });
8419 await mountView({
8420 type: "kanban",
8421 resModel: "partner",
8422 arch: `
8423 <kanban default_group_by="product_id">
8424 <templates>
8425 <t t-name="card">
8426 <field name="display_name"/>
8427 </t>
8428 </templates>
8429 </kanban>`,
8430 });
8431
8432 await editKanbanColumnName("column1");
8433 await validateKanbanColumn();
8434
8435 await quickCreateKanbanRecord();
8436 await editKanbanRecordQuickCreateInput("display_name", "record1");
8437 await validateKanbanRecord();
8438
8439 await quickCreateKanbanRecord();
8440 await editKanbanRecordQuickCreateInput("display_name", "record2");
8441 await validateKanbanRecord();
8442 await discardKanbanRecord(); // close quick create
8443
8444 expect(".o_kanban_group:first-child .o_kanban_record").toHaveCount(2);
8445 expect(getKanbanRecordTexts()).toEqual(["record2", "record1"], {
8446 message: "records should be correctly ordered",
8447 });
8448
8449 await contains(".o_kanban_record:nth-child(2)").dragAndDrop(".o_kanban_record:nth-child(3)");
8450 def.resolve();
8451 await animationFrame();
8452
8453 expect(".o_kanban_group:first-child .o_kanban_record").toHaveCount(2);
8454 expect(getKanbanRecordTexts()).toEqual(["record1", "record2"], {
8455 message: "records should be correctly ordered",
8456 });
8457
8458 await contains(".o_kanban_record:nth-child(3)").dragAndDrop(".o_kanban_record:nth-child(2)");
8459
8460 expect(".o_kanban_group:first-child .o_kanban_record").toHaveCount(2);
8461 expect(getKanbanRecordTexts()).toEqual(["record2", "record1"], {
8462 message: "records should be correctly ordered",
8463 });
8464 // should have resequenced twice
8465 expect.verifySteps(["resequence", "resequence"]);
8466 });
8467
8468 test("basic support for widgets (being Owl Components)", async () => {
8469 class MyComponent extends Component {
8470 static template = xml`<div t-att-class="props.class" t-esc="value"/>`;
8471 static props = ["*"];
8472 get value() {
8473 return JSON.stringify(this.props.record.data);
8474 }
8475 }
8476 const myComponent = {
8477 component: MyComponent,
8478 };
8479 viewWidgetRegistry.add("test", myComponent);
8480 after(() => viewWidgetRegistry.remove("test"));
8481
8482 await mountView({
8483 type: "kanban",
8484 resModel: "partner",
8485 arch: `
8486 <kanban>
8487 <templates>
8488 <t t-name="card">
8489 <field name="foo"/>
8490 <widget name="test"/>
8491 </t>
8492 </templates>
8493 </kanban>`,
8494 });
8495
8496 expect(getKanbanRecord({ index: 2 }).querySelector(".o_widget")).toHaveText('{"foo":"gnap"}');
8497 });
8498
8499 test("kanban card: record value should be updated", async () => {
8500 class MyComponent extends Component {
8501 static template = xml`<div><button t-on-click="onClick">CLick</button></div>`;
8502 static props = ["*"];
8503 onClick() {
8504 this.props.record.update({ foo: "yolo" });
8505 }
8506 }
8507 const myComponent = {
8508 component: MyComponent,
8509 };
8510 viewWidgetRegistry.add("test", myComponent);
8511 after(() => viewWidgetRegistry.remove("test"));
8512
8513 await mountView({
8514 type: "kanban",
8515 resModel: "partner",
8516 arch: `
8517 <kanban>
8518 <templates>
8519 <t t-name="card">
8520 <field name="foo" class="foo"/>
8521 <widget name="test"/>
8522 </t>
8523 </templates>
8524 </kanban>`,
8525 });
8526
8527 expect(queryText(".foo", { root: getKanbanRecord({ index: 0 }) })).toBe("yop");
8528
8529 await click(queryOne("button", { root: getKanbanRecord({ index: 0 }) }));
8530 await animationFrame();
8531 await animationFrame();
8532
8533 expect(queryText(".foo", { root: getKanbanRecord({ index: 0 }) })).toBe("yolo");
8534 });
8535
8536 test("column progressbars properly work", async () => {
8537 stepAllNetworkCalls();
8538
8539 await mountView({
8540 type: "kanban",
8541 resModel: "partner",
8542 arch: `
8543 <kanban>
8544 <progressbar field="foo" colors='{"yop": "success", "gnap": "warning", "blip": "danger"}' sum_field="int_field"/>
8545 <templates>
8546 <t t-name="card">
8547 <field name="foo"/>
8548 </t>
8549 </templates>
8550 </kanban>`,
8551 groupBy: ["bar"],
8552 });
8553
8554 expect(".o_kanban_counter").toHaveCount(2, {
8555 message: "kanban counters should have been created",
8556 });
8557
8558 expect(getKanbanCounters()).toEqual(["-4", "36"], {
8559 message: "counter should display the sum of int_field values",
8560 });
8561 expect.verifySteps([
8562 "/web/webclient/translations",
8563 "/web/webclient/load_menus",
8564 "get_views",
8565 "read_progress_bar",
8566 "web_read_group",
8567 "has_group",
8568 ]);
8569 });
8570
8571 test("filter on progressbar in new groups", async () => {
8572 Partner._views["form,some_view_ref"] = `<form><field name="foo"/></form>`;
8573
8574 await mountView({
8575 type: "kanban",
8576 resModel: "partner",
8577 arch: `
8578 <kanban default_group_by="product_id" on_create="quick_create" quick_create_view="some_view_ref">
8579 <progressbar field="foo" colors='{"yop": "success", "gnap": "warning", "blip": "danger"}'/>
8580 <templates>
8581 <t t-name="card">
8582 <field name="foo"/>
8583 </t>
8584 </templates>
8585 </kanban>`,
8586 });
8587
8588 expect(".o_kanban_group").toHaveCount(2);
8589
8590 await quickCreateKanbanColumn();
8591 await editKanbanColumnName("new column 1");
8592 await validateKanbanColumn();
8593 await editKanbanColumnName("new column 2");
8594 await validateKanbanColumn();
8595 expect(".o_kanban_group").toHaveCount(4);
8596 expect(queryAll(".o_kanban_record", { root: getKanbanColumn(2) })).toHaveCount(0);
8597 expect(queryAll(".o_kanban_record", { root: getKanbanColumn(3) })).toHaveCount(0);
8598
8599 await quickCreateKanbanRecord(2);
8600 await contains(".o_field_widget[name=foo] input").edit("new record 1");
8601 await quickCreateKanbanRecord(3);
8602 await contains(".o_field_widget[name=foo] input").edit("new record 2");
8603 expect(queryAll(".o_kanban_record", { root: getKanbanColumn(2) })).toHaveCount(1);
8604 expect(queryAll(".o_kanban_record", { root: getKanbanColumn(3) })).toHaveCount(1);
8605
8606 expect(".o_kanban_group_show_200").toHaveCount(0);
8607
8608 await contains(".o_column_progress .progress-bar", { root: getKanbanColumn(2) }).click();
8609 expect(".o_kanban_group_show_200").toHaveCount(1);
8610 expect(getKanbanColumn(2)).toHaveClass("o_kanban_group_show_200");
8611 });
8612
8613 test('column progressbars: "false" bar is clickable', async () => {
8614 Partner._records.push({
8615 id: 5,
8616 bar: true,
8617 foo: false,
8618 product_id: 5,
8619 state: "ghi",
8620 });
8621
8622 stepAllNetworkCalls();
8623
8624 await mountView({
8625 type: "kanban",
8626 resModel: "partner",
8627 arch: `
8628 <kanban>
8629 <progressbar field="foo" colors='{"yop": "success", "gnap": "warning", "blip": "danger"}'/>
8630 <templates>
8631 <t t-name="card">
8632 <field name="foo"/>
8633 </t>
8634 </templates>
8635 </kanban>`,
8636 groupBy: ["bar"],
8637 });
8638
8639 expect(".o_kanban_group").toHaveCount(2);
8640 expect(getKanbanCounters()).toEqual(["1", "4"]);
8641 expect(".o_kanban_group:last-child .o_column_progress .progress-bar").toHaveCount(4);
8642 expect(".o_kanban_group:last-child .o_column_progress .progress-bar.bg-200").toHaveCount(1, {
8643 message: "should have false kanban color",
8644 });
8645 expect(".o_kanban_group:last-child .o_column_progress .progress-bar.bg-200:first").toHaveClass(
8646 "bg-200"
8647 );
8648
8649 await contains(".o_kanban_group:last-child .o_column_progress .progress-bar.bg-200").click();
8650
8651 expect(".o_kanban_group:last-child .o_column_progress .progress-bar.bg-200:first").toHaveClass(
8652 "progress-bar-animated"
8653 );
8654 expect(".o_kanban_group:last-child").toHaveClass("o_kanban_group_show_200");
8655 expect(getKanbanCounters()).toEqual(["1", "1"]);
8656 expect.verifySteps([
8657 "/web/webclient/translations",
8658 "/web/webclient/load_menus",
8659 "get_views",
8660 "read_progress_bar",
8661 "web_read_group",
8662 "has_group",
8663 "web_search_read",
8664 "read_progress_bar",
8665 ]);
8666 });
8667
8668 test('column progressbars: "false" bar with sum_field', async () => {
8669 Partner._records.push({
8670 id: 5,
8671 bar: true,
8672 foo: false,
8673 int_field: 15,
8674 product_id: 5,
8675 state: "ghi",
8676 });
8677
8678 stepAllNetworkCalls();
8679
8680 await mountView({
8681 type: "kanban",
8682 resModel: "partner",
8683 arch: `
8684 <kanban>
8685 <progressbar field="foo" colors='{"yop": "success", "gnap": "warning", "blip": "danger"}' sum_field="int_field"/>
8686 <templates>
8687 <t t-name="card">
8688 <field name="foo"/>
8689 </t>
8690 </templates>
8691 </kanban>`,
8692 groupBy: ["bar"],
8693 });
8694
8695 expect(".o_kanban_group").toHaveCount(2);
8696 expect(getKanbanCounters()).toEqual(["-4", "51"]);
8697
8698 await contains(".o_kanban_group:last-child .o_column_progress .progress-bar.bg-200").click();
8699
8700 expect(".o_kanban_group:last-child .o_column_progress .progress-bar.bg-200:first").toHaveClass(
8701 "progress-bar-animated"
8702 );
8703 expect(getKanbanCounters()).toEqual(["-4", "15"]);
8704 expect.verifySteps([
8705 "/web/webclient/translations",
8706 "/web/webclient/load_menus",
8707 "get_views",
8708 "read_progress_bar",
8709 "web_read_group",
8710 "has_group",
8711 "formatted_read_group",
8712 "web_search_read",
8713 "read_progress_bar",
8714 "formatted_read_group",
8715 "formatted_read_group",
8716 ]);
8717 });
8718
8719 test("column progressbars should not crash in non grouped views", async () => {
8720 stepAllNetworkCalls();
8721
8722 await mountView({
8723 type: "kanban",
8724 resModel: "partner",
8725 arch: `
8726 <kanban>
8727 <progressbar field="foo" colors='{"yop": "success", "gnap": "warning", "blip": "danger"}' sum_field="int_field"/>
8728 <templates>
8729 <t t-name="card">
8730 <field name="foo"/>
8731 </t>
8732 </templates>
8733 </kanban>`,
8734 });
8735
8736 expect(getKanbanRecordTexts()).toEqual(["yop", "blip", "gnap", "blip"]);
8737 // no read on progress bar data is done
8738 expect.verifySteps([
8739 "/web/webclient/translations",
8740 "/web/webclient/load_menus",
8741 "get_views",
8742 "web_search_read",
8743 "has_group",
8744 ]);
8745 });
8746
8747 test("column progressbars: creating a new column should create a new progressbar", async () => {
8748 stepAllNetworkCalls();
8749
8750 await mountView({
8751 type: "kanban",
8752 resModel: "partner",
8753 arch: `
8754 <kanban default_group_by="product_id">
8755 <progressbar field="foo" colors='{"yop": "success", "gnap": "warning", "blip": "danger"}'/>
8756 <templates>
8757 <t t-name="card">
8758 <field name="foo"/>
8759 </t>
8760 </templates>
8761 </kanban>`,
8762 });
8763
8764 expect(".o_kanban_counter").toHaveCount(2);
8765
8766 // Create a new column: this should create an empty progressbar
8767 await quickCreateKanbanColumn();
8768 await editKanbanColumnName("test");
8769 await validateKanbanColumn();
8770
8771 expect(".o_kanban_counter").toHaveCount(3, {
8772 message: "a new column with a new column progressbar should have been created",
8773 });
8774 expect.verifySteps([
8775 "/web/webclient/translations",
8776 "/web/webclient/load_menus",
8777 "get_views",
8778 "read_progress_bar",
8779 "web_read_group",
8780 "has_group",
8781 "name_create",
8782 "web_resequence",
8783 ]);
8784 });
8785
8786 test("column progressbars on quick create properly update counter", async () => {
8787 stepAllNetworkCalls();
8788
8789 await mountView({
8790 type: "kanban",
8791 resModel: "partner",
8792 arch: `
8793 <kanban>
8794 <progressbar field="foo" colors='{"yop": "success", "gnap": "warning", "blip": "danger"}'/>
8795 <templates>
8796 <t t-name="card">
8797 <field name="foo"/>
8798 </t>
8799 </templates>
8800 </kanban>`,
8801 groupBy: ["bar"],
8802 });
8803
8804 expect(getKanbanCounters()).toEqual(["1", "3"]);
8805
8806 await quickCreateKanbanRecord();
8807 await editKanbanRecordQuickCreateInput("display_name", "Test");
8808
8809 expect(getKanbanCounters()).toEqual(["1", "3"]);
8810
8811 await validateKanbanRecord();
8812
8813 expect(getKanbanCounters()).toEqual(["2", "3"], {
8814 message: "kanban counters should have updated on quick create",
8815 });
8816 expect.verifySteps([
8817 "/web/webclient/translations",
8818 "/web/webclient/load_menus",
8819 "get_views",
8820 "read_progress_bar",
8821 "web_read_group",
8822 "has_group",
8823 "onchange",
8824 "name_create",
8825 "onchange",
8826 "web_read",
8827 "read_progress_bar",
8828 ]);
8829 });
8830
8831 test("column progressbars are working with load more", async () => {
8832 stepAllNetworkCalls();
8833
8834 await mountView({
8835 type: "kanban",
8836 resModel: "partner",
8837 domain: [["bar", "=", true]],
8838 arch: `
8839 <kanban limit="1">
8840 <progressbar field="foo" colors='{"yop": "success", "gnap": "warning", "blip": "danger"}'/>
8841 <templates>
8842 <t t-name="card">
8843 <field name="id"/>
8844 </t>
8845 </templates>
8846 </kanban>`,
8847 groupBy: ["bar"],
8848 });
8849
8850 expect(getKanbanRecordTexts(0)).toEqual(["1"]);
8851
8852 await clickKanbanLoadMore(0);
8853 await clickKanbanLoadMore(0);
8854
8855 expect(getKanbanRecordTexts(0)).toEqual(["1", "2", "3"]);
8856 expect.verifySteps([
8857 "/web/webclient/translations",
8858 "/web/webclient/load_menus",
8859 "get_views",
8860 "read_progress_bar",
8861 "web_read_group",
8862 "has_group",
8863 "web_search_read",
8864 "web_search_read",
8865 ]);
8866 });
8867
8868 test("column progressbars with an active filter are working with load more", async () => {
8869 Partner._records.push(
8870 { id: 5, bar: true, foo: "blork" },
8871 { id: 6, bar: true, foo: "blork" },
8872 { id: 7, bar: true, foo: "blork" }
8873 );
8874
8875 stepAllNetworkCalls();
8876
8877 await mountView({
8878 type: "kanban",
8879 resModel: "partner",
8880 domain: [["bar", "=", true]],
8881 arch: `
8882 <kanban limit="1">
8883 <progressbar field="foo" colors='{"blork": "success"}'/>
8884 <templates>
8885 <t t-name="card">
8886 <field name="id"/>
8887 </t>
8888 </templates>
8889 </kanban>`,
8890 groupBy: ["bar"],
8891 });
8892
8893 await contains(".o_column_progress .progress-bar.bg-success").click();
8894
8895 expect(getKanbanRecordTexts()).toEqual(["5"]);
8896
8897 await clickKanbanLoadMore(0);
8898 await clickKanbanLoadMore(0);
8899
8900 expect(getKanbanRecordTexts()).toEqual(["5", "6", "7"]);
8901 expect.verifySteps([
8902 "/web/webclient/translations",
8903 "/web/webclient/load_menus",
8904 "get_views",
8905 "read_progress_bar",
8906 "web_read_group",
8907 "has_group",
8908 "web_search_read",
8909 "read_progress_bar",
8910 "web_search_read",
8911 "web_search_read",
8912 ]);
8913 });
8914
8915 test("column progressbars on archiving records update counter", async () => {
8916 // add active field on partner model and make all records active
8917 Partner._fields.active = fields.Boolean({ default: true });
8918
8919 stepAllNetworkCalls();
8920
8921 await mountView({
8922 type: "kanban",
8923 resModel: "partner",
8924 arch: `
8925 <kanban>
8926 <progressbar field="foo" colors='{"yop": "success", "gnap": "warning", "blip": "danger"}' sum_field="int_field"/>
8927 <templates>
8928 <t t-name="card">
8929 <field name="foo"/>
8930 </t>
8931 </templates>
8932 </kanban>`,
8933 groupBy: ["bar"],
8934 loadActionMenus: true,
8935 });
8936
8937 expect(getKanbanCounters()).toEqual(["-4", "36"]);
8938 expect(getKanbanColumnTooltips(1)).toEqual(["1 yop", "1 gnap", "1 blip"], {
8939 message: "the counter progressbars should be correctly displayed",
8940 });
8941
8942 // archive all records of the second columns
8943 await keyDown("alt");
8944 await animationFrame();
8945 await contains(".o_kanban_group:nth-of-type(2) .o_kanban_record:nth-of-type(1)").click();
8946 await keyUp("alt");
8947 await contains(".o_kanban_group:nth-of-type(2) .o_kanban_record:nth-of-type(2)").click();
8948 await contains(".o_kanban_group:nth-of-type(2) .o_kanban_record:nth-of-type(3)").click();
8949 await contains(".o_cp_action_menus button").click();
8950 await contains(".o_menu_item:contains(Archive)").click();
8951 await contains(".modal-footer .btn-primary").click();
8952
8953 expect(getKanbanCounters()).toEqual(["-4", "0"]);
8954 expect(queryAll(".progress-bar", { root: getKanbanColumn(1) })).toHaveCount(0, {
8955 message: "the counter progressbars should have been correctly updated",
8956 });
8957 expect.verifySteps([
8958 "/web/webclient/translations",
8959 "/web/webclient/load_menus",
8960 "get_views",
8961 "read_progress_bar",
8962 "web_read_group",
8963 "has_group",
8964 "action_archive",
8965 "read_progress_bar",
8966 "web_read_group",
8967 ]);
8968 });
8969
8970 test("kanban with progressbars: correctly update env when archiving records", async () => {
8971 // add active field on partner model and make all records active
8972 Partner._fields.active = fields.Boolean({ default: true });
8973
8974 stepAllNetworkCalls();
8975
8976 await mountView({
8977 type: "kanban",
8978 resModel: "partner",
8979 arch: `
8980 <kanban>
8981 <progressbar field="foo" colors='{"yop": "success", "gnap": "warning", "blip": "danger"}' sum_field="int_field"/>
8982 <templates>
8983 <t t-name="card">
8984 <field name="id"/>
8985 </t>
8986 </templates>
8987 </kanban>`,
8988 groupBy: ["bar"],
8989 loadActionMenus: true,
8990 });
8991
8992 expect(getKanbanRecordTexts()).toEqual(["4", "1", "2", "3"]);
8993
8994 // archive all records of the first column
8995 await keyDown("alt");
8996 await animationFrame();
8997 await contains(".o_kanban_group:nth-of-type(1) .o_kanban_record:nth-of-type(1)").click();
8998 await keyUp("alt");
8999 await contains(".o_cp_action_menus button").click();
9000 await contains(".o_menu_item:contains(Archive)").click();
9001 await contains(".modal-footer .btn-primary").click();
9002
9003 expect(getKanbanRecordTexts()).toEqual(["1", "2", "3"]);
9004 expect.verifySteps([
9005 "/web/webclient/translations",
9006 "/web/webclient/load_menus",
9007 "get_views",
9008 "read_progress_bar",
9009 "web_read_group",
9010 "has_group",
9011 "action_archive",
9012 "read_progress_bar",
9013 "web_read_group",
9014 ]);
9015 });
9016
9017 test("kanban with progressbars: slow read_progress_bar", async () => {
9018 const def = new Deferred();
9019 onRpc("read_progress_bar", () => def);
9020
9021 await mountView({
9022 type: "kanban",
9023 resModel: "partner",
9024 arch: `
9025 <kanban>
9026 <progressbar field="foo" colors='{"yop": "success", "gnap": "warning", "blip": "danger"}' sum_field="int_field"/>
9027 <templates>
9028 <t t-name="card">
9029 <field name="foo"/>
9030 </t>
9031 </templates>
9032 </kanban>`,
9033 groupBy: ["bar"],
9034 });
9035
9036 expect(".o_kanban_view").toHaveCount(1);
9037 expect(".o_kanban_group").toHaveCount(2);
9038 expect(".o_kanban_group:nth-child(2) .o_column_progress").toHaveCount(1);
9039 expect(".o_kanban_group:nth-child(2) .o_column_progress .progress-bar").toHaveCount(0);
9040 expect(".o_kanban_group:nth-child(2) .o_kanban_header").toHaveText("Yes");
9041
9042 def.resolve();
9043 await animationFrame();
9044 expect(".o_kanban_view").toHaveCount(1);
9045 expect(".o_kanban_group").toHaveCount(2);
9046 expect(".o_kanban_group:nth-child(2) .o_column_progress").toHaveCount(1);
9047 expect(".o_kanban_group:nth-child(2) .o_column_progress .progress-bar").toHaveCount(3);
9048 expect(".o_kanban_group:nth-child(2) .o_kanban_header").toHaveText("Yes\n36");
9049 });
9050
9051 test("RPCs when (re)loading kanban view progressbars", async () => {
9052 stepAllNetworkCalls();
9053
9054 await mountView({
9055 type: "kanban",
9056 resModel: "partner",
9057 arch: `
9058 <kanban>
9059 <progressbar field="foo" colors='{"yop": "success", "gnap": "warning", "blip": "danger"}' sum_field="int_field"/>
9060 <templates>
9061 <t t-name="card">
9062 <field name="foo"/>
9063 </t>
9064 </templates>
9065 </kanban>`,
9066 groupBy: ["bar"],
9067 });
9068
9069 await validateSearch();
9070
9071 expect.verifySteps([
9072 "/web/webclient/translations",
9073 "/web/webclient/load_menus",
9074 // initial load
9075 "get_views",
9076 "read_progress_bar",
9077 "web_read_group",
9078 "has_group",
9079 // reload
9080 "read_progress_bar",
9081 "web_read_group",
9082 ]);
9083 });
9084
9085 test("RPCs when (de)activating kanban view progressbar filters", async () => {
9086 stepAllNetworkCalls();
9087 onRpc("web_read_group", ({ kwargs }) => {
9088 expect.step(`web_read_group domain ${JSON.stringify(kwargs.domain)}`);
9089 });
9090 onRpc("formatted_read_group", ({ kwargs }) => {
9091 expect.step(`formatted_read_group domain ${JSON.stringify(kwargs.domain)}`);
9092 });
9093
9094 await mountView({
9095 type: "kanban",
9096 resModel: "partner",
9097 arch: `
9098 <kanban>
9099 <progressbar field="foo" colors='{"yop": "success", "gnap": "warning", "blip": "danger"}' sum_field="int_field"/>
9100 <templates>
9101 <t t-name="card">
9102 <field name="foo"/>
9103 </t>
9104 </templates>
9105 </kanban>`,
9106 groupBy: ["bar"],
9107 });
9108
9109 // Activate "yop" on second column
9110 await contains(".progress-bar.bg-success", { root: getKanbanColumn(1) }).click();
9111 // Activate "gnap" on second column
9112 await contains(".progress-bar.bg-warning", { root: getKanbanColumn(1) }).click();
9113 // Deactivate "gnap" on second column
9114 await contains(".progress-bar.bg-warning", { root: getKanbanColumn(1) }).click();
9115
9116 expect.verifySteps([
9117 "/web/webclient/translations",
9118 "/web/webclient/load_menus",
9119 // initial load
9120 "get_views",
9121 "read_progress_bar",
9122 "web_read_group",
9123 "has_group",
9124 "web_read_group domain []",
9125 "formatted_read_group", // recomputes aggregates
9126 "web_search_read",
9127 'formatted_read_group domain ["&",["bar","=",true],["foo","=","yop"]]', // perform formatted_read_group only on second column (bar=true)
9128 "read_progress_bar",
9129 "formatted_read_group",
9130 "formatted_read_group",
9131 "formatted_read_group domain []",
9132 'formatted_read_group domain ["&",["bar","=",true],["foo","=","yop"]]',
9133 // activate filter
9134 "formatted_read_group", // recomputes aggregates
9135 "web_search_read",
9136 'formatted_read_group domain ["&",["bar","=",true],["foo","=","gnap"]]', // perform formatted_read_group only on second column (bar=true)
9137 "read_progress_bar",
9138 "formatted_read_group",
9139 "formatted_read_group",
9140 "formatted_read_group domain []",
9141 'formatted_read_group domain ["&",["bar","=",true],["foo","=","gnap"]]',
9142 // activate another filter (switching)
9143 "web_search_read",
9144 ]);
9145 });
9146
9147 test.tags("desktop");
9148 test("drag & drop records grouped by m2o with progressbar", async () => {
9149 Partner._records[0].product_id = false;
9150
9151 stepAllNetworkCalls();
9152
9153 await mountView({
9154 type: "kanban",
9155 resModel: "partner",
9156 arch: `
9157 <kanban>
9158 <progressbar field="foo" colors='{"yop": "success", "gnap": "warning", "blip": "danger"}'/>
9159 <templates>
9160 <t t-name="card">
9161 <field name="int_field"/>
9162 </t>
9163 </templates>
9164 </kanban>`,
9165 groupBy: ["product_id"],
9166 });
9167
9168 // Unfold first column
9169 await contains(getKanbanColumn(0)).click();
9170
9171 expect(getKanbanCounters()).toEqual(["1", "1", "2"]);
9172
9173 await contains(".o_kanban_group:first-child .o_kanban_record").dragAndDrop(
9174 ".o_kanban_group:nth-child(2)"
9175 );
9176
9177 expect(getKanbanCounters()).toEqual(["0", "2", "2"]);
9178
9179 await contains(".o_kanban_group:nth-child(2) .o_kanban_record").dragAndDrop(
9180 ".o_kanban_group:first-child"
9181 );
9182
9183 expect(getKanbanCounters()).toEqual(["1", "1", "2"]);
9184
9185 await contains(".o_kanban_group:first-child .o_kanban_record").dragAndDrop(
9186 ".o_kanban_group:nth-child(3)"
9187 );
9188
9189 expect(getKanbanCounters()).toEqual(["0", "1", "3"]);
9190 expect.verifySteps([
9191 "/web/webclient/translations",
9192 "/web/webclient/load_menus",
9193 "get_views",
9194 "read_progress_bar",
9195 "web_read_group",
9196 "has_group",
9197 "web_search_read",
9198 "web_save",
9199 "read_progress_bar",
9200 "web_resequence",
9201 "web_save",
9202 "read_progress_bar",
9203 "web_resequence",
9204 "web_save",
9205 "read_progress_bar",
9206 "web_resequence",
9207 ]);
9208 });
9209
9210 test.tags("desktop");
9211 test("d&d records grouped by date with progressbar with aggregates", async () => {
9212 Partner._records[0].date = "2010-11-30";
9213 Partner._records[1].date = "2010-11-30";
9214 Partner._records[2].date = "2010-10-30";
9215 Partner._records[3].date = "2010-10-30";
9216
9217 // Usually kanban views grouped by a date, cannot drag and drop.
9218 // There are some overrides that allow the drag and drop of dates (CRM forecast for instance).
9219 // This patch is done to simulate these overrides.
9220 patchWithCleanup(KanbanRenderer.prototype, {
9221 isMovableField() {
9222 return true;
9223 },
9224 });
9225
9226 stepAllNetworkCalls();
9227
9228 await mountView({
9229 type: "kanban",
9230 resModel: "partner",
9231 arch: `
9232 <kanban>
9233 <progressbar field="foo" colors='{"yop": "success", "gnap": "warning", "blip": "danger"}' sum_field="int_field"/>
9234 <templates>
9235 <t t-name="card">
9236 <field name="int_field"/>
9237 </t>
9238 </templates>
9239 </kanban>`,
9240 groupBy: ["date:month"],
9241 });
9242
9243 expect(getKanbanCounters()).toEqual(["13", "19"]);
9244
9245 await contains(".o_kanban_group:first-child .o_kanban_record").dragAndDrop(
9246 ".o_kanban_group:nth-child(2)"
9247 );
9248
9249 expect(getKanbanCounters()).toEqual(["-4", "36"]);
9250
9251 expect.verifySteps([
9252 "/web/webclient/translations",
9253 "/web/webclient/load_menus",
9254 "get_views",
9255 "read_progress_bar",
9256 "web_read_group",
9257 "has_group",
9258 "web_save",
9259 "read_progress_bar",
9260 "formatted_read_group",
9261 "web_resequence",
9262 ]);
9263 });
9264
9265 test("progress bar subgroup count recompute", async () => {
9266 stepAllNetworkCalls();
9267
9268 await mountView({
9269 type: "kanban",
9270 resModel: "partner",
9271 arch: `
9272 <kanban>
9273 <progressbar field="foo" colors='{"yop": "success", "gnap": "warning", "blip": "danger"}'/>
9274 <templates>
9275 <t t-name="card">
9276 <field name="foo"/>
9277 </t>
9278 </templates>
9279 </kanban>`,
9280 groupBy: ["bar"],
9281 });
9282
9283 expect(getKanbanCounters()).toEqual(["1", "3"]);
9284
9285 await contains(".o_kanban_group:nth-child(2) .bg-success").click();
9286
9287 expect(getKanbanCounters()).toEqual(["1", "1"]);
9288 expect.verifySteps([
9289 "/web/webclient/translations",
9290 "/web/webclient/load_menus",
9291 "get_views",
9292 "read_progress_bar",
9293 "web_read_group",
9294 "has_group",
9295 "web_search_read",
9296 "read_progress_bar",
9297 ]);
9298 });
9299
9300 test.tags("desktop");
9301 test("progress bar recompute after d&d to and from other column", async () => {
9302 stepAllNetworkCalls();
9303
9304 await mountView({
9305 type: "kanban",
9306 resModel: "partner",
9307 arch: `
9308 <kanban>
9309 <progressbar field="foo" colors='{"yop": "success", "gnap": "warning", "blip": "danger"}'/>
9310 <templates>
9311 <t t-name="card">
9312 <field name="foo"/>
9313 </t>
9314 </templates>
9315 </kanban>`,
9316 groupBy: ["bar"],
9317 });
9318
9319 expect(getKanbanColumnTooltips()).toEqual(["1 blip", "1 yop", "1 gnap", "1 blip"]);
9320 expect(getKanbanCounters()).toEqual(["1", "3"]);
9321
9322 // Drag the last kanban record to the first column
9323 await contains(".o_kanban_group:last-child .o_kanban_record:nth-child(4)").dragAndDrop(
9324 ".o_kanban_group:first-child"
9325 );
9326
9327 expect(getKanbanColumnTooltips()).toEqual(["1 gnap", "1 blip", "1 yop", "1 blip"]);
9328 expect(getKanbanCounters()).toEqual(["2", "2"]);
9329 expect.verifySteps([
9330 "/web/webclient/translations",
9331 "/web/webclient/load_menus",
9332 "get_views",
9333 "read_progress_bar",
9334 "web_read_group",
9335 "has_group",
9336 "web_save",
9337 "read_progress_bar",
9338 "web_resequence",
9339 ]);
9340 });
9341
9342 test("progress bar recompute after filter selection", async () => {
9343 Partner._records.push({ foo: "yop", bar: true, float_field: 100 });
9344 Partner._records.push({ foo: "yop", bar: true, float_field: 100 });
9345 Partner._records.push({ foo: "yop", bar: true, float_field: 100 });
9346
9347 stepAllNetworkCalls();
9348
9349 await mountView({
9350 type: "kanban",
9351 resModel: "partner",
9352 arch: `
9353 <kanban>
9354 <progressbar field="foo" colors='{"yop": "success", "gnap": "warning", "blip": "danger"}'/>
9355 <templates>
9356 <t t-name="card">
9357 <field name="foo"/>
9358 </t>
9359 </templates>
9360 </kanban>`,
9361 searchViewArch: `
9362 <search>
9363 <filter name="my_filter" string="My filter" domain="[['float_field', '=', 100]]"/>
9364 </search>`,
9365 groupBy: ["bar"],
9366 });
9367
9368 expect(getKanbanColumnTooltips()).toEqual(["1 blip", "4 yop", "1 gnap", "1 blip"]);
9369 expect(getKanbanCounters()).toEqual(["1", "6"]);
9370 expect.verifySteps([
9371 "/web/webclient/translations",
9372 "/web/webclient/load_menus",
9373 "get_views",
9374 "read_progress_bar",
9375 "web_read_group",
9376 "has_group",
9377 ]);
9378
9379 await contains(".progress-bar.bg-success", { root: getKanbanColumn(1) }).click();
9380
9381 expect(getKanbanColumnTooltips()).toEqual(["1 blip", "4 yop", "1 gnap", "1 blip"]);
9382 expect(getKanbanCounters()).toEqual(["1", "4"]);
9383 expect.verifySteps(["web_search_read", "read_progress_bar"]);
9384
9385 // Add search domain to something restricting progressbars' values (records still in filtered group)
9386 await toggleSearchBarMenu();
9387 await toggleMenuItem("My filter");
9388
9389 expect(getKanbanColumnTooltips()).toEqual(["3 yop"]);
9390 expect(getKanbanCounters()).toEqual(["3"]);
9391 expect.verifySteps(["read_progress_bar", "web_read_group"]);
9392 });
9393
9394 test("progress bar recompute after filter selection (aggregates)", async () => {
9395 Partner._records.push({ foo: "yop", bar: true, float_field: 100, int_field: 100 });
9396 Partner._records.push({ foo: "yop", bar: true, float_field: 100, int_field: 200 });
9397 Partner._records.push({ foo: "yop", bar: true, float_field: 100, int_field: 300 });
9398
9399 stepAllNetworkCalls();
9400
9401 await mountView({
9402 type: "kanban",
9403 resModel: "partner",
9404 arch: `
9405 <kanban>
9406 <progressbar field="foo" colors='{"yop": "success", "gnap": "warning", "blip": "danger"}' sum_field="int_field"/>
9407 <templates>
9408 <t t-name="card">
9409 <field name="foo"/>
9410 </t>
9411 </templates>
9412 </kanban>`,
9413 searchViewArch: `
9414 <search>
9415 <filter name="my_filter" string="My filter" domain="[['float_field', '=', 100]]"/>
9416 </search>`,
9417 groupBy: ["bar"],
9418 });
9419
9420 expect(getKanbanColumnTooltips()).toEqual(["1 blip", "4 yop", "1 gnap", "1 blip"]);
9421 expect(getKanbanCounters()).toEqual(["-4", "636"]);
9422 expect.verifySteps([
9423 "/web/webclient/translations",
9424 "/web/webclient/load_menus",
9425 "get_views",
9426 "read_progress_bar",
9427 "web_read_group",
9428 "has_group",
9429 ]);
9430
9431 await contains(".progress-bar.bg-success", { root: getKanbanColumn(1) }).click();
9432
9433 expect(getKanbanColumnTooltips()).toEqual(["1 blip", "4 yop", "1 gnap", "1 blip"]);
9434 expect(getKanbanCounters()).toEqual(["-4", "610"]);
9435 expect.verifySteps([
9436 "formatted_read_group", // recomputes aggregates
9437 "web_search_read",
9438 "read_progress_bar",
9439 "formatted_read_group",
9440 "formatted_read_group",
9441 ]);
9442
9443 // Add searchdomain to something restricting progressbars' values (records still in filtered group)
9444 await toggleSearchBarMenu();
9445 await toggleMenuItem("My filter");
9446
9447 expect(getKanbanColumnTooltips()).toEqual(["3 yop"]);
9448 expect(getKanbanCounters()).toEqual(["600"]);
9449 expect.verifySteps(["read_progress_bar", "web_read_group"]);
9450 });
9451
9452 test("progress bar with monetary aggregate and multi currencies", async () => {
9453 const aed = { id: 3, name: "AED", symbol: "AED", position: "after", inverse_rate: 0.25 };
9454 serverState.currencies = serverState.currencies.concat([aed]);
9455 Currency._records.push(aed);
9456 Partner._records.push({ id: 99, foo: "bar", salary: 300, currency_id: 3, product_id: 3 });
9457 await mountView({
9458 type: "kanban",
9459 resModel: "partner",
9460 arch: `
9461 <kanban>
9462 <progressbar field="foo" colors='{"yop": "success", "gnap": "warning", "blip": "danger"}' sum_field="salary"/>
9463 <field name="currency_id"/>
9464 <templates>
9465 <t t-name="card">
9466 <field name="foo"/>
9467 <field name="salary"/>
9468 </t>
9469 </templates>
9470 </kanban>`,
9471 groupBy: ["product_id"],
9472 });
9473
9474 expect(".o_kanban_counter .o_animated_number").toHaveCount(2);
9475 expect(".o_kanban_counter:last .o_animated_number").toHaveText("$ 3,722");
9476 expect(".o_kanban_counter:first .o_animated_number").toHaveText("$ 4,050?");
9477
9478 await toggleMultiCurrencyPopover(".o_kanban_counter:first .o_animated_number sup");
9479 expect(".o_multi_currency_popover").toHaveCount(1);
9480 expect(".o_multi_currency_popover").toHaveText("8,100.00 € at $ 0.50\n16,200.00 AED at $ 0.25");
9481 });
9482
9483 test("progress bar with monetary aggregate and multi currencies: quick create record", async () => {
9484 Partner._views["form,some_view_ref"] = `
9485 <form>
9486 <field name="salary"/>
9487 <field name="currency_id"/>
9488 </form>`;
9489 Partner._fields.currency_id.default = 1; // create new records in dollars by default
9490 Partner._records = [{ id: 99, foo: "bar", salary: 300, currency_id: 2, product_id: 3 }];
9491 await mountView({
9492 type: "kanban",
9493 resModel: "partner",
9494 arch: `
9495 <kanban quick_create_view="some_view_ref">
9496 <progressbar field="foo" colors='{"yop": "success", "gnap": "warning", "blip": "danger"}' sum_field="salary"/>
9497 <field name="currency_id"/>
9498 <templates>
9499 <t t-name="card">
9500 <field name="foo"/>
9501 <field name="salary"/>
9502 </t>
9503 </templates>
9504 </kanban>`,
9505 groupBy: ["product_id"],
9506 });
9507
9508 expect(".o_kanban_counter .o_animated_number").toHaveCount(1);
9509 expect(".o_kanban_counter:last .o_animated_number").toHaveText("300 €");
9510
9511 await quickCreateKanbanRecord();
9512 expect(".o_kanban_quick_create").toHaveCount(1);
9513 expect(".o_kanban_quick_create .o_field_widget[name=currency_id] input").toHaveValue("USD");
9514
9515 await editKanbanRecordQuickCreateInput("salary", 1000);
9516 await validateKanbanRecord();
9517 expect(".o_kanban_counter:last .o_animated_number").toHaveText("$ 1,300?");
9518 });
9519
9520 test("progress bar with aggregates: activate bars (grouped by boolean)", async () => {
9521 Partner._records = [
9522 { foo: "yop", bar: true, int_field: 1 },
9523 { foo: "yop", bar: true, int_field: 2 },
9524 { foo: "blip", bar: true, int_field: 4 },
9525 { foo: "gnap", bar: true, int_field: 8 },
9526 ];
9527
9528 await mountView({
9529 type: "kanban",
9530 resModel: "partner",
9531 arch: `
9532 <kanban>
9533 <progressbar field="foo" colors='{"yop": "success", "gnap": "warning", "blip": "danger"}' sum_field="int_field"/>
9534 <templates>
9535 <t t-name="card">
9536 <field name="foo"/>
9537 </t>
9538 </templates>
9539 </kanban>`,
9540 groupBy: ["bar"],
9541 });
9542
9543 expect(getKanbanColumnTooltips(0)).toEqual(["2 yop", "1 gnap", "1 blip"]);
9544 expect(getKanbanCounters()).toEqual(["15"]);
9545
9546 await contains(getKanbanProgressBars(0)[0]).click();
9547 expect(getKanbanCounters()).toEqual(["3"]);
9548
9549 await contains(getKanbanProgressBars(0)[2]).click();
9550 expect(getKanbanCounters()).toEqual(["4"]);
9551
9552 await contains(getKanbanProgressBars(0)[2]).click();
9553 expect(getKanbanCounters()).toEqual(["15"]);
9554 });
9555
9556 test("progress bar with aggregates: activate bars (grouped by many2one)", async () => {
9557 Partner._records = [
9558 { foo: "yop", product_id: 3, int_field: 1 },
9559 { foo: "yop", product_id: 3, int_field: 2 },
9560 { foo: "blip", product_id: 3, int_field: 4 },
9561 { foo: "gnap", product_id: 3, int_field: 8 },
9562 ];
9563
9564 await mountView({
9565 type: "kanban",
9566 resModel: "partner",
9567 arch: `
9568 <kanban>
9569 <progressbar field="foo" colors='{"yop": "success", "gnap": "warning", "blip": "danger"}' sum_field="int_field"/>
9570 <templates>
9571 <t t-name="card">
9572 <field name="foo"/>
9573 <field name="float_field"/>
9574 </t>
9575 </templates>
9576 </kanban>`,
9577 groupBy: ["product_id"],
9578 });
9579
9580 onRpc("partner", "web_read_group", ({ kwargs }) => {
9581 // float_field is not in the progressbar, then never ask his aggregation
9582 expect(kwargs.aggregates).not.toInclude("float_field:sum");
9583 });
9584
9585 expect(getKanbanColumnTooltips(0)).toEqual(["2 yop", "1 gnap", "1 blip"]);
9586 expect(getKanbanCounters()).toEqual(["15"]);
9587
9588 await contains(getKanbanProgressBars(0)[0]).click();
9589 expect(getKanbanCounters()).toEqual(["3"]);
9590
9591 await contains(getKanbanProgressBars(0)[2]).click();
9592 expect(getKanbanCounters()).toEqual(["4"]);
9593
9594 await contains(getKanbanProgressBars(0)[2]).click();
9595 expect(getKanbanCounters()).toEqual(["15"]);
9596 });
9597
9598 test("progress bar with aggregates: activate bars (grouped by date)", async () => {
9599 Partner._records = [
9600 { foo: "yop", date: "2023-10-08", int_field: 1 },
9601 { foo: "yop", date: "2023-10-08", int_field: 2 },
9602 { foo: "blip", date: "2023-10-08", int_field: 4 },
9603 { foo: "gnap", date: "2023-10-08", int_field: 8 },
9604 ];
9605
9606 await mountView({
9607 type: "kanban",
9608 resModel: "partner",
9609 arch: `
9610 <kanban>
9611 <progressbar field="foo" colors='{"yop": "success", "gnap": "warning", "blip": "danger"}' sum_field="int_field"/>
9612 <templates>
9613 <t t-name="card">
9614 <field name="foo"/>
9615 </t>
9616 </templates>
9617 </kanban>`,
9618 groupBy: ["date:week"],
9619 });
9620
9621 expect(getKanbanColumnTooltips(0)).toEqual(["2 yop", "1 gnap", "1 blip"]);
9622 expect(getKanbanCounters()).toEqual(["15"]);
9623
9624 await contains(getKanbanProgressBars(0)[0]).click();
9625 expect(getKanbanCounters()).toEqual(["3"]);
9626
9627 await contains(getKanbanProgressBars(0)[2]).click();
9628 expect(getKanbanCounters()).toEqual(["4"]);
9629
9630 await contains(getKanbanProgressBars(0)[2]).click();
9631 expect(getKanbanCounters()).toEqual(["15"]);
9632 });
9633
9634 test("progress bar with aggregates: Archive all in a column", async () => {
9635 Partner._fields.active = fields.Boolean({ default: true });
9636 Partner._records = [
9637 { foo: "yop", bar: true, int_field: 1, active: true },
9638 { foo: "yop", bar: true, int_field: 2, active: true },
9639 { foo: "blip", bar: true, int_field: 4, active: true },
9640 { foo: "gnap", bar: true, int_field: 8, active: true },
9641 { foo: "oups", bar: false, int_field: 268, active: true },
9642 ];
9643
9644 let def;
9645 onRpc("web_read_group", () => def);
9646
9647 await mountView({
9648 type: "kanban",
9649 resModel: "partner",
9650 arch: `
9651 <kanban>
9652 <progressbar field="foo" colors='{"yop": "success", "gnap": "warning", "blip": "danger"}' sum_field="int_field"/>
9653 <templates><t t-name="card">
9654 <field name="foo"/>
9655 </t></templates>
9656 </kanban>`,
9657 groupBy: ["bar"],
9658 loadActionMenus: true,
9659 });
9660
9661 expect(getKanbanColumnTooltips(1)).toEqual(["2 yop", "1 gnap", "1 blip"]);
9662 expect(getKanbanCounters()).toEqual(["268", "15"]);
9663 await keyDown("alt");
9664 await animationFrame();
9665 await contains(".o_kanban_group:nth-of-type(2) .o_kanban_record:nth-of-type(1)").click();
9666 await keyUp("alt");
9667 await contains(".o_kanban_group:nth-of-type(2) .o_kanban_record:nth-of-type(2)").click();
9668 await contains(".o_kanban_group:nth-of-type(2) .o_kanban_record:nth-of-type(3)").click();
9669 await contains(".o_kanban_group:nth-of-type(2) .o_kanban_record:nth-of-type(4)").click();
9670 await contains(".o_cp_action_menus button").click();
9671 await contains(".o_menu_item:contains(Archive)").click();
9672 expect(".o_dialog").toHaveCount(1);
9673 def = new Deferred();
9674 await contains(".modal-footer .btn-primary").click();
9675 expect(getKanbanColumnTooltips(1)).toEqual(["2 yop", "1 gnap", "1 blip"]);
9676 expect(getKanbanCounters()).toEqual(["268", "15"]);
9677 def.resolve();
9678 await animationFrame();
9679 expect(getKanbanColumnTooltips(1)).toEqual([]);
9680 expect(getKanbanCounters()).toEqual(["268", "0"]);
9681 });
9682
9683 test.tags("desktop");
9684 test("load more should load correct records after drag&drop event", async () => {
9685 Partner._order = ["sequence", "id"];
9686 Partner._records.forEach((r, i) => (r.sequence = i));
9687
9688 await mountView({
9689 type: "kanban",
9690 resModel: "partner",
9691 arch: `
9692 <kanban limit="1">
9693 <templates>
9694 <t t-name="card">
9695 <field name="id"/>
9696 </t>
9697 </templates>
9698 </kanban>`,
9699 groupBy: ["bar"],
9700 });
9701
9702 expect(getKanbanRecordTexts(0)).toEqual(["4"]);
9703 expect(getKanbanRecordTexts(1)).toEqual(["1"]);
9704
9705 // Drag the first kanban record on top of the last
9706 await contains(".o_kanban_group:first-child .o_kanban_record").dragAndDrop(
9707 ".o_kanban_group:last-child .o_kanban_record"
9708 );
9709
9710 // load more twice to load all records of second column
9711 await clickKanbanLoadMore(1);
9712 await clickKanbanLoadMore(1);
9713
9714 // Check records of the second column
9715 expect(getKanbanRecordTexts(1)).toEqual(["4", "1", "2", "3"]);
9716 });
9717
9718 test.tags("desktop");
9719 test("column progressbars on quick create with quick_create_view", async () => {
9720 Partner._views["form,some_view_ref"] = `<form><field name="int_field"/></form>`;
9721
9722 stepAllNetworkCalls();
9723
9724 await mountView({
9725 type: "kanban",
9726 resModel: "partner",
9727 arch: `
9728 <kanban on_create="quick_create" quick_create_view="some_view_ref">
9729 <progressbar field="foo" colors='{"yop": "success", "gnap": "warning", "blip": "danger"}' sum_field="int_field"/>
9730 <templates>
9731 <t t-name="card">
9732 <field name="foo"/>
9733 </t>
9734 </templates>
9735 </kanban>`,
9736 groupBy: ["bar"],
9737 });
9738
9739 expect(getKanbanCounters()).toEqual(["-4", "36"]);
9740
9741 await createKanbanRecord();
9742 await editKanbanRecordQuickCreateInput("int_field", 44);
9743 await validateKanbanRecord();
9744
9745 expect(getKanbanCounters()).toEqual(["40", "36"], {
9746 message: "kanban counters should have been updated on quick create",
9747 });
9748 expect.verifySteps([
9749 "/web/webclient/translations",
9750 "/web/webclient/load_menus",
9751 "get_views",
9752 "read_progress_bar",
9753 "web_read_group",
9754 "has_group",
9755 "get_views",
9756 "onchange",
9757 "web_save",
9758 "onchange",
9759 "web_read",
9760 "read_progress_bar",
9761 "formatted_read_group",
9762 ]);
9763 });
9764
9765 test.tags("desktop");
9766 test("progressbars and active filter with quick_create_view", async () => {
9767 Partner._views["form,some_view_ref"] = `
9768 <form>
9769 <field name="int_field"/>
9770 <field name="foo"/>
9771 </form>`;
9772
9773 stepAllNetworkCalls();
9774
9775 await mountView({
9776 type: "kanban",
9777 resModel: "partner",
9778 arch: `
9779 <kanban on_create="quick_create" quick_create_view="some_view_ref">
9780 <progressbar field="foo" colors='{"yop": "success", "gnap": "warning", "blip": "danger"}' sum_field="int_field"/>
9781 <templates>
9782 <t t-name="card">
9783 <field name="foo"/>
9784 </t>
9785 </templates>
9786 </kanban>`,
9787 groupBy: ["bar"],
9788 });
9789
9790 await contains(".progress-bar.bg-danger", { root: getKanbanColumn(0) }).click();
9791
9792 expect(queryAll(".o_kanban_record", { root: getKanbanColumn(0) })).toHaveCount(1);
9793 expect(queryAll(".oe_kanban_card_danger", { root: getKanbanColumn(0) })).toHaveCount(1);
9794 expect(getKanbanCounters()).toEqual(["-4", "36"]);
9795
9796 // open the quick create
9797 createKanbanRecord();
9798 await animationFrame();
9799
9800 // fill it with a record that satisfies the active filter
9801 await editKanbanRecordQuickCreateInput("int_field", 44);
9802 await editKanbanRecordQuickCreateInput("foo", "blip");
9803 await contains(".o_kanban_quick_create .o_kanban_add").click();
9804
9805 // fill it again with another record that DOES NOT satisfy the active filter
9806 await editKanbanRecordQuickCreateInput("int_field", 1000);
9807 await editKanbanRecordQuickCreateInput("foo", "yop");
9808 await contains(".o_kanban_quick_create .o_kanban_add").click();
9809
9810 expect(queryAll(".o_kanban_record", { root: getKanbanColumn(0) })).toHaveCount(3);
9811 expect(queryAll(".oe_kanban_card_danger", { root: getKanbanColumn(0) })).toHaveCount(2);
9812 expect(queryAll(".oe_kanban_card_success", { root: getKanbanColumn(0) })).toHaveCount(1);
9813 expect(getKanbanCounters()).toEqual(["40", "36"], {
9814 message:
9815 "kanban counters should have been updated on quick create, respecting the active filter",
9816 });
9817 expect.verifySteps([
9818 "/web/webclient/translations",
9819 "/web/webclient/load_menus",
9820 "get_views",
9821 "read_progress_bar",
9822 "web_read_group",
9823 "has_group",
9824 "formatted_read_group",
9825 "web_search_read",
9826 "read_progress_bar",
9827 "formatted_read_group",
9828 "formatted_read_group",
9829 "get_views",
9830 "onchange",
9831 "web_save",
9832 "onchange",
9833 "web_read",
9834 "read_progress_bar",
9835 "formatted_read_group",
9836 "formatted_read_group",
9837 "web_save",
9838 "onchange",
9839 "web_read",
9840 "read_progress_bar",
9841 "formatted_read_group",
9842 "formatted_read_group",
9843 ]);
9844 });
9845
9846 test.tags("desktop");
9847 test("quickcreate in first column after moving a record from it", async () => {
9848 onRpc("web_resequence", () => []);
9849
9850 await mountView({
9851 type: "kanban",
9852 resModel: "partner",
9853 arch: `
9854 <kanban on_create="quick_create">
9855 <templates>
9856 <t t-name="card">
9857 <field name="foo"/>
9858 </t>
9859 </templates>
9860 </kanban>`,
9861 groupBy: ["foo"],
9862 });
9863
9864 await createKanbanRecord();
9865
9866 expect(queryFirst(".o_kanban_group:has(.o_kanban_quick_create)")).toBe(
9867 queryFirst(".o_kanban_group")
9868 );
9869
9870 await contains(".o_kanban_record").dragAndDrop(".o_kanban_group:nth-child(2)");
9871 await createKanbanRecord();
9872
9873 expect(queryFirst(".o_kanban_group:has(.o_kanban_quick_create)")).toBe(
9874 queryFirst(".o_kanban_group")
9875 );
9876 });
9877
9878 test.tags("desktop");
9879 test("grouped kanban: clear groupby when reloading", async () => {
9880 // in this test, we simulate that clearing the domain is slow, so that
9881 // clearing the groupby does not corrupt the data handled while
9882 // reloading the kanban view.
9883 const def = new Deferred();
9884 onRpc("web_read_group", async function ({ kwargs, parent }) {
9885 const result = parent();
9886 if (kwargs.domain.length === 0 && kwargs.groupby && kwargs.groupby[0] === "bar") {
9887 await def; // delay 1st update
9888 }
9889 return result;
9890 });
9891
9892 await mountView({
9893 type: "kanban",
9894 resModel: "partner",
9895 arch: `
9896 <kanban>
9897 <templates>
9898 <t t-name="card">
9899 <field name="foo"/>
9900 </t>
9901 </templates>
9902 </kanban>`,
9903 searchViewArch: `
9904 <search>
9905 <filter name="my_filter" string="My Filter" domain="[['foo', '=', 'norecord']]"/>
9906 <filter name="group_by_bar" domain="[]" string="GroupBy Bar" context="{ 'group_by': 'bar' }"/>
9907 </search>`,
9908 context: {
9909 search_default_group_by_bar: 1,
9910 search_default_my_filter: 1,
9911 },
9912 });
9913
9914 expect(".o_kanban_renderer").toHaveClass("o_kanban_grouped");
9915 expect(".o_kanban_renderer").not.toHaveClass("o_kanban_ungrouped");
9916 expect(queryAllTexts(".o_facet_value")).toEqual(["My Filter", "GroupBy Bar"]);
9917
9918 await contains(".o_facet_remove:first").click();
9919 await contains(".o_facet_remove:only").click();
9920 def.resolve(); // simulate slow 1st update of kanban view
9921 await animationFrame();
9922
9923 expect(".o_kanban_renderer").not.toHaveClass("o_kanban_grouped");
9924 expect(".o_kanban_renderer").toHaveClass("o_kanban_ungrouped");
9925 });
9926
9927 test.tags("desktop");
9928 test("quick_create on grouped kanban without column", async () => {
9929 Partner._records = [];
9930
9931 await mountView({
9932 type: "kanban",
9933 resModel: "partner",
9934 // force group_create to false, otherwise the CREATE button in control panel is hidden
9935 arch: `
9936 <kanban group_create="0" on_create="quick_create">
9937 <templates>
9938 <t t-name="card">
9939 <field name="foo"/>
9940 </t>
9941 </templates>
9942 </kanban>`,
9943 groupBy: ["product_id"],
9944 createRecord: () => {
9945 expect.step("createKanbanRecord");
9946 },
9947 });
9948
9949 await createKanbanRecord();
9950 expect.verifySteps(["createKanbanRecord"]);
9951 });
9952
9953 test("keynav: right/left", async () => {
9954 await mountView({
9955 type: "kanban",
9956 resModel: "partner",
9957 arch: `
9958 <kanban>
9959 <templates>
9960 <t t-name="card">
9961 <field name="foo"/>
9962 </t>
9963 </templates>
9964 </kanban>`,
9965 });
9966
9967 await pointerDown(getKanbanRecord({ index: 0 }));
9968 expect(getKanbanRecord({ index: 0 })).toBeFocused();
9969
9970 await press("ArrowRight");
9971 expect(getKanbanRecord({ index: 1 })).toBeFocused();
9972
9973 await press("ArrowLeft");
9974 expect(getKanbanRecord({ index: 0 })).toBeFocused();
9975 });
9976
9977 test("keynav: down, with focus is inside a card", async () => {
9978 await mountView({
9979 type: "kanban",
9980 resModel: "partner",
9981 arch: `
9982 <kanban>
9983 <templates>
9984 <t t-name="card">
9985 <field name="foo"/>
9986 <a href="#" class="o-this-is-focussable">ho! this is focussable</a>
9987 </t>
9988 </templates>
9989 </kanban>`,
9990 });
9991
9992 await pointerDown(getKanbanRecord({ index: 0 }).querySelector(".o-this-is-focussable"));
9993 await press("ArrowDown");
9994
9995 expect(getKanbanRecord({ index: 1 })).toBeFocused();
9996 });
9997
9998 test.tags("desktop");
9999 test("keynav: grouped kanban", async () => {
10000 await mountView({
10001 type: "kanban",
10002 resModel: "partner",
10003 arch: `
10004 <kanban>
10005 <templates>
10006 <t t-name="card">
10007 <field name="foo"/>
10008 </t>
10009 </templates>
10010 </kanban>`,
10011 groupBy: ["bar"],
10012 });
10013 const cardsByColumn = queryAll(".o_kanban_group").map((root) =>
10014 queryAll(".o_kanban_record", { root })
10015 );
10016 const firstColumnFirstCard = cardsByColumn[0][0];
10017 const secondColumnFirstCard = cardsByColumn[1][0];
10018 const secondColumnSecondCard = cardsByColumn[1][1];
10019
10020 // DOWN should focus the first card
10021 await press("ArrowDown");
10022 expect(firstColumnFirstCard).toBeFocused({
10023 message: "LEFT should select the first card of the first column",
10024 });
10025
10026 // RIGHT should select the next column
10027 await press("ArrowRight");
10028 expect(secondColumnFirstCard).toBeFocused({
10029 message: "RIGHT should select the first card of the next column",
10030 });
10031
10032 // DOWN should move up one card
10033 await press("ArrowDown");
10034 expect(secondColumnSecondCard).toBeFocused({
10035 message: "DOWN should select the second card of the current column",
10036 });
10037
10038 // LEFT should go back to the first column
10039 await press("ArrowLeft");
10040 expect(firstColumnFirstCard).toBeFocused({
10041 message: "LEFT should select the first card of the first column",
10042 });
10043 });
10044
10045 test.tags("desktop");
10046 test("keynav: grouped kanban with empty columns", async () => {
10047 Partner._records[1].state = "abc";
10048
10049 onRpc("web_read_group", function ({ parent }) {
10050 // override web_read_group to return empty groups, as this is
10051 // the case for several models (e.g. project.task grouped
10052 // by stage_id)
10053 const result = parent();
10054 // add 2 empty columns in the middle
10055 result.groups.splice(1, 0, {
10056 __count: 0,
10057 state: "md1",
10058 __extra_domain: [["state", "=", "md1"]],
10059 });
10060 result.groups.splice(1, 0, {
10061 __count: 0,
10062 state: "md2",
10063 __extra_domain: [["state", "=", "md2"]],
10064 });
10065 // add 1 empty column in the beginning and the end
10066 result.groups.unshift({
10067 __count: 0,
10068 state: "beg",
10069 __extra_domain: [["state", "=", "beg"]],
10070 });
10071 result.groups.push({
10072 __count: 0,
10073 state: "end",
10074 __extra_domain: [["state", "=", "end"]],
10075 });
10076 return result;
10077 });
10078
10079 await mountView({
10080 type: "kanban",
10081 resModel: "partner",
10082 arch: `
10083 <kanban>
10084 <templates>
10085 <t t-name="card">
10086 <field name="foo"/>
10087 </t>
10088 </templates>
10089 </kanban>`,
10090 groupBy: ["state"],
10091 });
10092
10093 /**
10094 * Added columns in mockRPC are empty
10095 *
10096 * | BEG | ABC | MD1 | MD2 | GHI | END
10097 * |-----|------|-----|-----|------|-----
10098 * | | yop | | | gnap |
10099 * | | blip | | | blip |
10100 */
10101 const cardsByColumn = queryAll(".o_kanban_group").map((root) =>
10102 queryAll(".o_kanban_record", { root })
10103 );
10104 const yop = cardsByColumn[1][0];
10105 const gnap = cardsByColumn[4][0];
10106
10107 // DOWN should focus yop (first card)
10108 await press("ArrowDown");
10109 expect(yop).toBeFocused({
10110 message: "LEFT should select the first card of the first column that has a card",
10111 });
10112
10113 // RIGHT should select the next column that has a card
10114 await press("ArrowRight");
10115 expect(gnap).toBeFocused({
10116 message: "RIGHT should select the first card of the next column that has a card",
10117 });
10118
10119 // LEFT should go back to the first column that has a card
10120 await press("ArrowLeft");
10121 expect(yop).toBeFocused({
10122 message: "LEFT should select the first card of the first column that has a card",
10123 });
10124 });
10125
10126 test.tags("desktop");
10127 test("keynav: no global_click, press ENTER on card with a link", async () => {
10128 await mountView({
10129 type: "kanban",
10130 resModel: "partner",
10131 arch: `
10132 <kanban can_open="0">
10133 <templates>
10134 <t t-name="card">
10135 <a type="archive">Archive</a>
10136 </t>
10137 </templates>
10138 </kanban>`,
10139 selectRecord: (resId) => {
10140 expect.step("select record");
10141 },
10142 });
10143
10144 await press("ArrowDown");
10145 expect(".o_kanban_record:first").toBeFocused();
10146 await press("Enter");
10147
10148 await animationFrame();
10149 expect(".o_dialog").toHaveCount(1);
10150 expect(".o_dialog main").toHaveText("Are you sure that you want to archive this record?");
10151 expect.verifySteps([]); // should not try to open the record
10152 });
10153
10154 test.tags("desktop");
10155 test("keynav: kanban with global_click", async () => {
10156 expect.assertions(2);
10157
10158 await mountView({
10159 type: "kanban",
10160 resModel: "partner",
10161 arch: `
10162 <kanban>
10163 <templates>
10164 <t t-name="card">
10165 <field name="foo"/>
10166 <a name="action_test" type="object" />
10167 </t>
10168 </templates>
10169 </kanban>`,
10170 selectRecord(recordId) {
10171 expect(recordId).toBe(1, {
10172 message: "should call its selectRecord prop with the selected record",
10173 });
10174 },
10175 });
10176
10177 await press("ArrowDown");
10178 expect(".o_kanban_record:first").toBeFocused();
10179 await press("Enter");
10180 });
10181
10182 test.tags("desktop");
10183 test(`kanban should ask to scroll to top on page changes`, async () => {
10184 // add records to be able to scroll
10185 for (let i = 5; i < 200; i++) {
10186 Partner._records.push({ id: i, foo: "foo" });
10187 }
10188 patchWithCleanup(KanbanController.prototype, {
10189 onPageChangeScroll() {
10190 super.onPageChangeScroll(...arguments);
10191 expect.step("scroll");
10192 },
10193 });
10194
10195 await mountView({
10196 resModel: "partner",
10197 type: "kanban",
10198 arch: `
10199 <kanban>
10200 <templates>
10201 <t t-name="card">
10202 <field name="foo"/>
10203 </t>
10204 </templates>
10205 </kanban>`,
10206 });
10207 // switch pages (should ask to scroll)
10208 await pagerNext();
10209 await pagerPrevious();
10210 // should ask to scroll when switching pages
10211 expect.verifySteps(["scroll", "scroll"]);
10212
10213 // change the limit (should not ask to scroll)
10214 await contains(`.o_pager_value`).click();
10215 await contains(`.o_pager_value`).edit("1-100");
10216 await animationFrame();
10217 expect(getPagerValue()).toEqual([1, 100]);
10218 // should not ask to scroll when changing the limit
10219 expect.verifySteps([]);
10220
10221 await contains(".o_content").scroll({ top: 250 });
10222 expect(".o_content").toHaveProperty("scrollTop", 250);
10223
10224 // switch pages again (should still ask to scroll)
10225 await pagerNext();
10226 // this is still working after a limit change
10227 expect.verifySteps(["scroll"]);
10228 // Should effectively reset the scroll position
10229 expect(".o_content").toHaveProperty("scrollTop", 0);
10230 });
10231
10232 test.tags("mobile");
10233 test(`kanban should ask to scroll to top on page changes (mobile)`, async () => {
10234 // add records to be able to scroll
10235 for (let i = 5; i < 200; i++) {
10236 Partner._records.push({ id: i, foo: "foo" });
10237 }
10238 patchWithCleanup(KanbanController.prototype, {
10239 onPageChangeScroll() {
10240 super.onPageChangeScroll(...arguments);
10241 expect.step("scroll");
10242 },
10243 });
10244
10245 await mountView({
10246 resModel: "partner",
10247 type: "kanban",
10248 arch: `
10249 <kanban>
10250 <templates>
10251 <t t-name="card">
10252 <field name="foo"/>
10253 </t>
10254 </templates>
10255 </kanban>`,
10256 });
10257 // switch pages (should ask to scroll)
10258 await pagerNext();
10259 await pagerPrevious();
10260 // should ask to scroll when switching pages
10261 expect.verifySteps(["scroll", "scroll"]);
10262
10263 await contains(".o_kanban_view").scroll({ top: 250 });
10264 expect(".o_kanban_view").toHaveProperty("scrollTop", 250);
10265
10266 // switch pages again (should still ask to scroll)
10267 await pagerNext();
10268 expect.verifySteps(["scroll"]);
10269 // Should effectively reset the scroll position
10270 expect(".o_kanban_view").toHaveProperty("scrollTop", 0);
10271 });
10272
10273 test.tags("desktop");
10274 test("set cover image", async () => {
10275 expect.assertions(9);
10276
10277 IrAttachment._records = [
10278 {
10279 id: 1,
10280 name: "1.png",
10281 mimetype: "image/png",
10282 res_model: "partner",
10283 res_id: 1,
10284 create_uid: false,
10285 },
10286 {
10287 id: 2,
10288 name: "2.png",
10289 mimetype: "image/png",
10290 res_model: "partner",
10291 res_id: 2,
10292 create_uid: false,
10293 },
10294 ];
10295 Partner._fields.displayed_image_id = fields.Many2one({
10296 string: "Cover",
10297 relation: "ir.attachment",
10298 });
10299
10300 onRpc("partner", "web_save", ({ args }) => {
10301 expect.step(args[0][0]);
10302 });
10303
10304 await mountView({
10305 type: "kanban",
10306 resModel: "partner",
10307 arch: `
10308 <kanban>
10309 <templates>
10310 <t t-name="menu">
10311 <a type="set_cover" data-field="displayed_image_id" class="dropdown-item">Set Cover Image</a>
10312 </t>
10313 <t t-name="card">
10314 <field name="foo"/>
10315 <field name="displayed_image_id" widget="attachment_image"/>
10316 </t>
10317 </templates>
10318 </kanban>`,
10319 });
10320
10321 mockService("action", {
10322 switchView(_viewType, { readonly, resModel, res_id, view_type }) {
10323 expect({ readonly, resModel, res_id, view_type }).toBe({
10324 readonly: true,
10325 resModel: "partner",
10326 res_id: 1,
10327 view_type: "form",
10328 });
10329 },
10330 });
10331
10332 await toggleKanbanRecordDropdown(0);
10333 await contains(".oe_kanban_action", {
10334 root: getDropdownMenu(getKanbanRecord({ index: 0 })),
10335 }).click();
10336
10337 expect(queryAll("img", { root: getKanbanRecord({ index: 0 }) })).toHaveCount(0, {
10338 message: "Initially there is no image.",
10339 });
10340
10341 await contains(".modal .o_kanban_cover_image img").click();
10342 await contains(".modal .btn-primary:first-child").click();
10343
10344 expect('img[data-src*="/web/image/1"]').toHaveCount(1);
10345
10346 await toggleKanbanRecordDropdown(1);
10347 const coverButton = getDropdownMenu(getKanbanRecord({ index: 1 })).querySelector("a");
10348 expect(queryText(coverButton)).toBe("Set Cover Image");
10349 await contains(coverButton).click();
10350
10351 expect(".modal .o_kanban_cover_image").toHaveCount(1);
10352 expect(".modal .btn:contains(Select)").toHaveCount(1);
10353 expect(".modal .btn:contains(Discard)").toHaveCount(1);
10354 expect(".modal .btn:contains(Remove Cover Image)").toHaveCount(0);
10355
10356 await dblclick(".modal .o_kanban_cover_image img"); // doesn't work
10357 await animationFrame();
10358
10359 expect('img[data-src*="/web/image/2"]').toHaveCount(1);
10360
10361 await contains(".o_kanban_record:first-child .o_attachment_image").click(); //Not sure, to discuss
10362
10363 // should writes on both kanban records
10364 expect.verifySteps([1, 2]);
10365 });
10366
10367 test.tags("desktop");
10368 test("open file explorer if no cover image", async () => {
10369 expect.assertions(2);
10370
10371 Partner._fields.displayed_image_id = fields.Many2one({
10372 string: "Cover",
10373 relation: "ir.attachment",
10374 });
10375
10376 const uploadedPromise = new Deferred();
10377 await createFileInput({
10378 mockPost: async (route) => {
10379 if (route === "/web/binary/upload_attachment") {
10380 await uploadedPromise;
10381 }
10382 return "[]";
10383 },
10384 props: {},
10385 });
10386
10387 await mountView({
10388 type: "kanban",
10389 resModel: "partner",
10390 arch: `
10391 <kanban>
10392 <templates>
10393 <t t-name="menu">
10394 <a type="set_cover" data-field="displayed_image_id" class="dropdown-item">Set Cover Image</a>
10395 </t>
10396 <t t-name="card">
10397 <field name="foo"/>
10398 <field name="displayed_image_id" widget="attachment_image"/>
10399 </t>
10400 </templates>
10401 </kanban>`,
10402 });
10403
10404 await toggleKanbanRecordDropdown(0);
10405 await contains(".oe_kanban_action", {
10406 root: getDropdownMenu(getKanbanRecord({ index: 0 })),
10407 }).click();
10408 await setInputFiles([]);
10409 await animationFrame();
10410
10411 expect(`.o_dialog .o_file_input input`).not.toBeEnabled({
10412 message: "the upload button should be disabled on upload",
10413 });
10414 uploadedPromise.resolve();
10415 await animationFrame();
10416
10417 expect(`.o_dialog .o_file_input input`).toBeEnabled({
10418 message: "the upload button should be enabled for upload",
10419 });
10420 });
10421
10422 test.tags("desktop");
10423 test("unset cover image", async () => {
10424 IrAttachment._records = [
10425 {
10426 id: 1,
10427 name: "1.png",
10428 mimetype: "image/png",
10429 res_model: "partner",
10430 res_id: 1,
10431 create_uid: false,
10432 },
10433 {
10434 id: 2,
10435 name: "2.png",
10436 mimetype: "image/png",
10437 res_model: "partner",
10438 res_id: 2,
10439 create_uid: false,
10440 },
10441 ];
10442 Partner._fields.displayed_image_id = fields.Many2one({
10443 string: "Cover",
10444 relation: "ir.attachment",
10445 });
10446 Partner._records[0].displayed_image_id = 1;
10447 Partner._records[1].displayed_image_id = 2;
10448
10449 onRpc("partner", "web_save", ({ args }) => {
10450 expect.step(args[0][0]);
10451 expect(args[1].displayed_image_id).toBe(false);
10452 });
10453
10454 await mountView({
10455 type: "kanban",
10456 resModel: "partner",
10457 arch: `
10458 <kanban>
10459 <templates>
10460 <t t-name="menu">
10461 <a type="set_cover" data-field="displayed_image_id" class="dropdown-item">Set Cover Image</a>
10462 </t>
10463 <t t-name="card">
10464 <field name="foo"/>
10465 <field name="displayed_image_id" widget="attachment_image"/>
10466 </t>
10467 </templates>
10468 </kanban>`,
10469 });
10470
10471 await toggleKanbanRecordDropdown(0);
10472 await contains(".oe_kanban_action", {
10473 root: getDropdownMenu(getKanbanRecord({ index: 0 })),
10474 }).click();
10475
10476 expect(
10477 queryAll('img[data-src*="/web/image/1"]', { root: getKanbanRecord({ index: 0 }) })
10478 ).toHaveCount(1);
10479 expect(
10480 queryAll('img[data-src*="/web/image/2"]', { root: getKanbanRecord({ index: 1 }) })
10481 ).toHaveCount(1);
10482
10483 expect(".modal .o_kanban_cover_image").toHaveCount(1);
10484 expect(".modal .btn:contains(Select)").toHaveCount(1);
10485 expect(".modal .btn:contains(Discard)").toHaveCount(1);
10486 expect(".modal .btn:contains(Remove Cover Image)").toHaveCount(1);
10487
10488 await contains(".modal .btn-secondary").click(); // click on "Remove Cover Image" button
10489
10490 expect(queryAll("img", { root: getKanbanRecord({ index: 0 }) })).toHaveCount(0, {
10491 message: "The cover image should be removed.",
10492 });
10493
10494 await toggleKanbanRecordDropdown(1);
10495 const coverButton = getDropdownMenu(getKanbanRecord({ index: 1 })).querySelector("a");
10496 expect(queryText(coverButton)).toBe("Set Cover Image");
10497 await contains(coverButton).click();
10498
10499 await dblclick(".modal .o_kanban_cover_image img"); // doesn't work
10500 await animationFrame();
10501
10502 expect(queryAll("img", { root: getKanbanRecord({ index: 1 }) })).toHaveCount(0, {
10503 message: "The cover image should be removed.",
10504 });
10505 // should writes on both kanban records
10506 expect.verifySteps([1, 2]);
10507 });
10508
10509 test.tags("desktop");
10510 test("ungrouped kanban with handle field", async () => {
10511 expect.assertions(4);
10512
10513 onRpc("web_search_read", ({ kwargs }) => {
10514 expect.step(`web_search_read: order: ${kwargs.order}`);
10515 });
10516 onRpc("web_resequence", ({ args }) => {
10517 expect(args[0]).toEqual([2, 1, 3, 4], {
10518 message: "should write the sequence in correct order",
10519 });
10520 return [];
10521 });
10522
10523 await mountView({
10524 type: "kanban",
10525 resModel: "partner",
10526 arch: `
10527 <kanban>
10528 <field name="int_field" widget="handle" />
10529 <templates>
10530 <t t-name="card">
10531 <field name="foo"/>
10532 </t>
10533 </templates>
10534 </kanban>`,
10535 });
10536
10537 expect(getKanbanRecordTexts()).toEqual(["blip", "blip", "yop", "gnap"]);
10538
10539 await contains(".o_kanban_record").dragAndDrop(queryFirst(".o_kanban_record:nth-child(4)"));
10540
10541 expect(getKanbanRecordTexts()).toEqual(["blip", "yop", "gnap", "blip"]);
10542 expect.verifySteps(["web_search_read: order: int_field ASC, id ASC"]);
10543 });
10544
10545 test("ungrouped kanban without handle field", async () => {
10546 onRpc("web_resequence", () => {
10547 expect.step("resequence");
10548 return [];
10549 });
10550
10551 await mountView({
10552 type: "kanban",
10553 resModel: "partner",
10554 arch: `
10555 <kanban>
10556 <templates>
10557 <t t-name="card">
10558 <field name="foo"/>
10559 </t>
10560 </templates>
10561 </kanban>`,
10562 });
10563
10564 expect(getKanbanRecordTexts()).toEqual(["yop", "blip", "gnap", "blip"]);
10565
10566 await contains(".o_kanban_record").dragAndDrop(queryFirst(".o_kanban_record:nth-child(4)"));
10567
10568 expect(getKanbanRecordTexts()).toEqual(["yop", "blip", "gnap", "blip"]);
10569 expect.verifySteps([]);
10570 });
10571
10572 test("click on image field in kanban (with default global_click)", async () => {
10573 expect.assertions(2);
10574
10575 Partner._fields.image = fields.Binary();
10576 Partner._records[0].image = "R0lGODlhAQABAAD/ACwAAAAAAQABAAACAA==";
10577
10578 await mountView({
10579 type: "kanban",
10580 resModel: "partner",
10581 arch: `
10582 <kanban>
10583 <templates>
10584 <t t-name="card">
10585 <field name="image" widget="image"/>
10586 </t>
10587 </templates>
10588 </kanban>`,
10589 selectRecord(recordId) {
10590 expect(recordId).toBe(1, {
10591 message: "should call its selectRecord prop with the clicked record",
10592 });
10593 },
10594 });
10595
10596 expect(".o_kanban_record:not(.o_kanban_ghost)").toHaveCount(4);
10597
10598 await contains(".o_field_image").click();
10599 });
10600
10601 test("kanban view with boolean field", async () => {
10602 await mountView({
10603 type: "kanban",
10604 resModel: "partner",
10605 arch: `
10606 <kanban>
10607 <templates>
10608 <t t-name="card">
10609 <field name="bar"/>
10610 </t>
10611 </templates>
10612 </kanban>`,
10613 });
10614
10615 expect(".o_kanban_record input:disabled").toHaveCount(4);
10616 expect(".o_kanban_record input:checked").toHaveCount(3);
10617 expect(".o_kanban_record input:not(:checked)").toHaveCount(1);
10618 });
10619
10620 test("kanban view with boolean widget", async () => {
10621 await mountView({
10622 type: "kanban",
10623 resModel: "partner",
10624 arch: `
10625 <kanban>
10626 <templates>
10627 <t t-name="card">
10628 <field name="bar" widget="boolean"/>
10629 </t>
10630 </templates>
10631 </kanban>`,
10632 });
10633
10634 expect(
10635 queryAll("div.o_field_boolean .o-checkbox", { root: getKanbanRecord({ index: 0 }) })
10636 ).toHaveCount(1);
10637 });
10638
10639 test("kanban view with boolean toggle widget", async () => {
10640 await mountView({
10641 type: "kanban",
10642 resModel: "partner",
10643 arch: `
10644 <kanban>
10645 <templates>
10646 <t t-name="card">
10647 <field name="bar" widget="boolean_toggle"/>
10648 </t>
10649 </templates>
10650 </kanban>`,
10651 });
10652 expect(getKanbanRecord({ index: 0 }).querySelector("[name='bar'] input")).toBeChecked();
10653 expect(getKanbanRecord({ index: 1 }).querySelector("[name='bar'] input")).toBeChecked();
10654
10655 await click("[name='bar'] input:only", { root: getKanbanRecord({ index: 1 }) });
10656 await animationFrame();
10657
10658 expect(getKanbanRecord({ index: 0 }).querySelector("[name='bar'] input")).toBeChecked();
10659 expect(getKanbanRecord({ index: 1 }).querySelector("[name='bar'] input")).not.toBeChecked();
10660 });
10661
10662 test("kanban view with monetary and currency fields without widget", async () => {
10663 const mockedCurrencies = {};
10664 for (const record of Currency._records) {
10665 mockedCurrencies[record.id] = record;
10666 }
10667 patchWithCleanup(currencies, mockedCurrencies);
10668
10669 await mountView({
10670 type: "kanban",
10671 resModel: "partner",
10672 arch: `
10673 <kanban>
10674 <field name="currency_id"/>
10675 <templates>
10676 <t t-name="card">
10677 <field name="salary"/>
10678 </t>
10679 </templates>
10680 </kanban>`,
10681 });
10682
10683 expect(getKanbanRecordTexts()).toEqual([
10684 `$ 1,750.00`,
10685 `$ 1,500.00`,
10686 `2,000.00 €`,
10687 `$ 2,222.00`,
10688 ]);
10689 });
10690
10691 test.tags("desktop");
10692 test("quick create: keyboard navigation to buttons", async () => {
10693 await mountView({
10694 arch: `
10695 <kanban on_create="quick_create">
10696 <templates>
10697 <div t-name="card">
10698 <field name="display_name"/>
10699 </div>
10700 </templates>
10701 </kanban>`,
10702 groupBy: ["bar"],
10703 resModel: "partner",
10704 type: "kanban",
10705 });
10706
10707 // Open quick create
10708 await createKanbanRecord();
10709 expect(".o_kanban_group:first-child .o_kanban_quick_create").toHaveCount(1);
10710
10711 // Fill in mandatory field
10712 await editKanbanRecordQuickCreateInput("display_name", "aaa"); // pressed Tab to trigger "change"
10713 expect(".o_kanban_add").toBeFocused();
10714
10715 await press("Tab");
10716 expect(".o_kanban_edit").toBeFocused();
10717 });
10718
10719 test("progressbar filter state is kept unchanged when domain is updated (records still in group)", async () => {
10720 stepAllNetworkCalls();
10721
10722 await mountView({
10723 type: "kanban",
10724 resModel: "partner",
10725 arch: `
10726 <kanban default_group_by="bar">
10727 <progressbar field="foo" colors='{"yop": "success", "blip": "danger"}'/>
10728 <templates>
10729 <t t-name="card">
10730 <field name="id"/>
10731 <field name="foo"/>
10732 </t>
10733 </templates>
10734 </kanban>`,
10735 searchViewArch: `
10736 <search>
10737 <filter name="my_filter" string="My Filter" domain="[['foo', '=', 'yop']]"/>
10738 </search>`,
10739 });
10740
10741 // Check that we have 2 columns and check their progressbar's state
10742 expect(".o_kanban_group").toHaveCount(2);
10743 expect(".o_kanban_group.o_kanban_group_show").toHaveCount(0);
10744 expect(queryAllTexts(".o_column_title")).toEqual(["No", "Yes"]);
10745 expect(getKanbanColumnTooltips(0)).toEqual(["1 blip"]);
10746 expect(getKanbanColumnTooltips(1)).toEqual(["1 yop", "1 blip", "1 Other"]);
10747
10748 // Apply an active filter
10749 await contains(".o_kanban_group:nth-child(2) .progress-bar.bg-success").click();
10750
10751 expect(".o_kanban_group.o_kanban_group_show").toHaveCount(1);
10752 expect(queryAllTexts(".o_column_title")).toEqual(["No", "Yes"]);
10753
10754 // Add searchdomain to something restricting progressbars' values (records still in filtered group)
10755 await toggleSearchBarMenu();
10756 await toggleMenuItem("My Filter");
10757
10758 // Check that we have now 1 column only and check its progressbar's state
10759 expect(".o_kanban_group").toHaveCount(1);
10760 expect(".o_kanban_group.o_kanban_group_show").toHaveCount(1);
10761 expect(queryAllTexts(".o_column_title")).toEqual(["Yes"]);
10762 expect(getKanbanColumnTooltips()).toEqual(["1 yop"]);
10763
10764 // Undo searchdomain
10765 await toggleMenuItem("My Filter");
10766
10767 // Check that we have 2 columns back and check their progressbar's state
10768 expect(".o_kanban_group").toHaveCount(2);
10769 expect(".o_kanban_group.o_kanban_group_show").toHaveCount(1);
10770 expect(queryAllTexts(".o_column_title")).toEqual(["No", "Yes"]);
10771 expect(getKanbanColumnTooltips(0)).toEqual(["1 blip"]);
10772 expect(getKanbanColumnTooltips(1)).toEqual(["1 yop", "1 blip", "1 Other"]);
10773 expect.verifySteps([
10774 "/web/webclient/translations",
10775 "/web/webclient/load_menus",
10776 "get_views",
10777 "read_progress_bar",
10778 "web_read_group",
10779 "has_group",
10780 "web_search_read",
10781 "read_progress_bar",
10782 "read_progress_bar",
10783 "web_read_group",
10784 "read_progress_bar",
10785 "web_read_group",
10786 ]);
10787 });
10788
10789 test("progressbar filter state is kept unchanged when domain is updated (emptying group)", async () => {
10790 stepAllNetworkCalls();
10791
10792 await mountView({
10793 type: "kanban",
10794 resModel: "partner",
10795 arch: `
10796 <kanban default_group_by="bar">
10797 <progressbar field="foo" colors='{"yop": "success", "blip": "danger"}'/>
10798 <templates>
10799 <t t-name="card">
10800 <div>
10801 <field name="id"/>
10802 <field name="foo"/>
10803 </div>
10804 </t>
10805 </templates>
10806 </kanban>`,
10807 searchViewArch: `
10808 <search>
10809 <filter name="my_filter" string="My Filter" domain="[['foo', '=', 'blip']]"/>
10810 </search>`,
10811 });
10812
10813 // Check that we have 2 columns, check their progressbar's state and check records
10814 expect(".o_kanban_group").toHaveCount(2);
10815 expect(".o_kanban_group.o_kanban_group_show").toHaveCount(0);
10816 expect(queryAllTexts(".o_column_title")).toEqual(["No", "Yes"]);
10817 expect(getKanbanColumnTooltips(0)).toEqual(["1 blip"]);
10818 expect(getKanbanRecordTexts(0)).toEqual(["4blip"]);
10819 expect(getKanbanColumnTooltips(1)).toEqual(["1 yop", "1 blip", "1 Other"]);
10820 expect(getKanbanRecordTexts(1)).toEqual(["1yop", "2blip", "3gnap"]);
10821
10822 // Apply an active filter
10823 await contains(".o_kanban_group:nth-child(2) .progress-bar.bg-success").click();
10824
10825 expect(".o_kanban_group.o_kanban_group_show").toHaveCount(1);
10826 expect(queryAllTexts(".o_column_title")).toEqual(["No", "Yes"]);
10827 expect(getKanbanColumnTooltips(1)).toEqual(["1 yop", "1 blip", "1 Other"]);
10828 expect(getKanbanRecordTexts(1)).toEqual(["1yop"]);
10829
10830 // Add searchdomain to something restricting progressbars' values + emptying the filtered group
10831 await toggleSearchBarMenu();
10832 await toggleMenuItem("My Filter");
10833
10834 // Check that we still have 2 columns, check their progressbar's state and check records
10835 expect(".o_kanban_group").toHaveCount(2);
10836 expect(".o_kanban_group.o_kanban_group_show").toHaveCount(0);
10837 expect(queryAllTexts(".o_column_title")).toEqual(["No", "Yes"]);
10838 expect(getKanbanColumnTooltips(0)).toEqual(["1 blip"]);
10839 expect(getKanbanRecordTexts(0)).toEqual(["4blip"]);
10840 expect(getKanbanColumnTooltips(1)).toEqual(["1 blip"]);
10841 expect(getKanbanRecordTexts(1)).toEqual(["2blip"]);
10842
10843 // Undo searchdomain
10844 await toggleMenuItem("My Filter");
10845
10846 // Check that we still have 2 columns and check their progressbar's state
10847 expect(".o_kanban_group").toHaveCount(2);
10848 expect(".o_kanban_group.o_kanban_group_show").toHaveCount(0);
10849 expect(queryAllTexts(".o_column_title")).toEqual(["No", "Yes"]);
10850 expect(getKanbanColumnTooltips(0)).toEqual(["1 blip"]);
10851 expect(getKanbanRecordTexts(0)).toEqual(["4blip"]);
10852 expect(getKanbanColumnTooltips(1)).toEqual(["1 yop", "1 blip", "1 Other"]);
10853 expect(getKanbanRecordTexts(1)).toEqual(["1yop", "2blip", "3gnap"]);
10854 expect.verifySteps([
10855 "/web/webclient/translations",
10856 "/web/webclient/load_menus",
10857 "get_views",
10858 "read_progress_bar",
10859 "web_read_group",
10860 "has_group",
10861 "web_search_read",
10862 "read_progress_bar",
10863 "read_progress_bar",
10864 "web_read_group",
10865 "web_search_read",
10866 "read_progress_bar",
10867 "web_read_group",
10868 ]);
10869 });
10870
10871 test.tags("desktop");
10872 test("filtered column counters when dropping in non-matching record", async () => {
10873 stepAllNetworkCalls();
10874
10875 await mountView({
10876 type: "kanban",
10877 resModel: "partner",
10878 arch: `
10879 <kanban default_group_by="bar">
10880 <progressbar field="foo" colors='{"yop": "success", "blip": "danger"}'/>
10881 <templates>
10882 <t t-name="card">
10883 <div>
10884 <field name="id"/>
10885 <field name="foo"/>
10886 </div>
10887 </t>
10888 </templates>
10889 </kanban>`,
10890 });
10891
10892 // Check that we have 2 columns, check their progressbar's state, and check records
10893 expect(".o_kanban_group").toHaveCount(2);
10894 expect(".o_kanban_group.o_kanban_group_show").toHaveCount(0);
10895 expect(queryAllTexts(".o_column_title")).toEqual(["No", "Yes"]);
10896 expect(getKanbanColumnTooltips(0)).toEqual(["1 blip"]);
10897 expect(getKanbanRecordTexts(0)).toEqual(["4blip"]);
10898 expect(getKanbanColumnTooltips(1)).toEqual(["1 yop", "1 blip", "1 Other"]);
10899 expect(getKanbanRecordTexts(1)).toEqual(["1yop", "2blip", "3gnap"]);
10900
10901 // Apply an active filter
10902 await contains(".o_kanban_group:nth-child(2) .progress-bar.bg-success").click();
10903
10904 expect(getKanbanColumn(1)).toHaveClass("o_kanban_group_show");
10905 expect(".o_kanban_group.o_kanban_group_show").toHaveCount(1);
10906 expect(queryAllTexts(".o_column_title")).toEqual(["No", "Yes"]);
10907 expect(".o_kanban_group.o_kanban_group_show .o_kanban_record").toHaveCount(1);
10908 expect(getKanbanRecordTexts(1)).toEqual(["1yop"]);
10909
10910 // Drop in the non-matching record from first column
10911 await contains(".o_kanban_group:first-child .o_kanban_record").dragAndDrop(
10912 queryFirst(".o_kanban_group.o_kanban_group_show")
10913 );
10914
10915 // Check that we have 2 columns, check their progressbar's state, and check records
10916 expect(".o_kanban_group").toHaveCount(2);
10917 expect(".o_kanban_group.o_kanban_group_show").toHaveCount(1);
10918 expect(queryAllTexts(".o_column_title")).toEqual(["No", "Yes"]);
10919 expect(getKanbanColumnTooltips(0)).toEqual([]);
10920 expect(getKanbanRecordTexts(0)).toEqual([]);
10921 expect(getKanbanColumnTooltips(1)).toEqual(["1 yop", "2 blip", "1 Other"]);
10922 expect(getKanbanRecordTexts(1)).toEqual(["1yop", "4blip"]);
10923 expect.verifySteps([
10924 "/web/webclient/translations",
10925 "/web/webclient/load_menus",
10926 "get_views",
10927 "read_progress_bar",
10928 "web_read_group",
10929 "has_group",
10930 "web_search_read",
10931 "read_progress_bar",
10932 "web_save",
10933 "read_progress_bar",
10934 "web_resequence",
10935 ]);
10936 });
10937
10938 test.tags("desktop");
10939 test("filtered column is reloaded when dragging out its last record", async () => {
10940 stepAllNetworkCalls();
10941
10942 await mountView({
10943 type: "kanban",
10944 resModel: "partner",
10945 arch: `
10946 <kanban default_group_by="bar">
10947 <progressbar field="foo" colors='{"yop": "success", "blip": "danger"}'/>
10948 <templates>
10949 <t t-name="card">
10950 <div>
10951 <field name="id"/>
10952 <field name="foo"/>
10953 </div>
10954 </t>
10955 </templates>
10956 </kanban>`,
10957 });
10958
10959 // Check that we have 2 columns, check their progressbar's state, and check records
10960 expect(".o_kanban_group").toHaveCount(2);
10961 expect(".o_kanban_group.o_kanban_group_show").toHaveCount(0);
10962 expect(queryAllTexts(".o_column_title")).toEqual(["No", "Yes"]);
10963 expect(getKanbanColumnTooltips(0)).toEqual(["1 blip"]);
10964 expect(getKanbanRecordTexts(0)).toEqual(["4blip"]);
10965 expect(getKanbanColumnTooltips(1)).toEqual(["1 yop", "1 blip", "1 Other"]);
10966 expect(getKanbanRecordTexts(1)).toEqual(["1yop", "2blip", "3gnap"]);
10967 expect.verifySteps([
10968 "/web/webclient/translations",
10969 "/web/webclient/load_menus",
10970 "get_views",
10971 "read_progress_bar",
10972 "web_read_group",
10973 "has_group",
10974 ]);
10975
10976 // Apply an active filter
10977 await contains(".o_kanban_group:nth-child(2) .progress-bar.bg-success").click();
10978
10979 expect(getKanbanColumn(1)).toHaveClass("o_kanban_group_show");
10980 expect(".o_kanban_group.o_kanban_group_show").toHaveCount(1);
10981 expect(queryAllTexts(".o_column_title")).toEqual(["No", "Yes"]);
10982 expect(".o_kanban_group.o_kanban_group_show .o_kanban_record").toHaveCount(1);
10983 expect(getKanbanRecordTexts(1)).toEqual(["1yop"]);
10984 expect.verifySteps(["web_search_read", "read_progress_bar"]);
10985
10986 // Drag out its only record onto the first column
10987 await contains(".o_kanban_group.o_kanban_group_show .o_kanban_record").dragAndDrop(
10988 queryFirst(".o_kanban_group:first-child")
10989 );
10990
10991 // Check that we have 2 columns, check their progressbar's state, and check records
10992 expect(".o_kanban_group").toHaveCount(2);
10993 expect(".o_kanban_group.o_kanban_group_show").toHaveCount(0);
10994 expect(queryAllTexts(".o_column_title")).toEqual(["No", "Yes"]);
10995 expect(getKanbanColumnTooltips(0)).toEqual(["1 yop", "1 blip"]);
10996 expect(getKanbanRecordTexts(0)).toEqual(["4blip", "1yop"]);
10997 expect(getKanbanColumnTooltips(1)).toEqual(["1 blip", "1 Other"]);
10998 expect(getKanbanRecordTexts(1)).toEqual(["2blip", "3gnap"]);
10999 expect.verifySteps(["web_save", "read_progress_bar", "web_search_read", "web_resequence"]);
11000 });
11001
11002 test("kanban widget can extract props from attrs", async () => {
11003 class TestWidget extends Component {
11004 static template = xml`<div class="o-test-widget-option" t-esc="props.title"/>`;
11005 static props = ["*"];
11006 }
11007 const testWidget = {
11008 component: TestWidget,
11009 extractProps: ({ attrs }) => ({
11010 title: attrs.title,
11011 }),
11012 };
11013 viewWidgetRegistry.add("widget_test_option", testWidget);
11014 after(() => viewWidgetRegistry.remove("widget_test_option"));
11015
11016 await mountView({
11017 arch: `
11018 <kanban>
11019 <templates>
11020 <t t-name="card">
11021 <widget name="widget_test_option" title="Widget with Option"/>
11022 </t>
11023 </templates>
11024 </kanban>`,
11025 resModel: "partner",
11026 type: "kanban",
11027 });
11028
11029 expect(".o-test-widget-option").toHaveCount(4);
11030 expect(".o-test-widget-option:first").toHaveText("Widget with Option");
11031 });
11032
11033 test("action/type attributes on kanban arch, type='object'", async () => {
11034 mockService("action", {
11035 doActionButton(params) {
11036 expect.step(`doActionButton type ${params.type} name ${params.name}`);
11037 params.onClose();
11038 },
11039 });
11040
11041 stepAllNetworkCalls();
11042
11043 await mountView({
11044 type: "kanban",
11045 resModel: "partner",
11046 arch: `
11047 <kanban action="a1" type="object">
11048 <templates>
11049 <t t-name="card">
11050 <p>some value</p><field name="foo"/>
11051 </t>
11052 </templates>
11053 </kanban>`,
11054 });
11055
11056 expect.verifySteps([
11057 "/web/webclient/translations",
11058 "/web/webclient/load_menus",
11059 "get_views",
11060 "web_search_read",
11061 "has_group",
11062 ]);
11063 await contains(".o_kanban_record p").click();
11064 expect.verifySteps(["doActionButton type object name a1", "web_search_read"]);
11065 });
11066
11067 test("action/type attributes on kanban arch, type='action'", async () => {
11068 mockService("action", {
11069 doActionButton(params) {
11070 expect.step(`doActionButton type ${params.type} name ${params.name}`);
11071 params.onClose();
11072 },
11073 });
11074
11075 stepAllNetworkCalls();
11076
11077 await mountView({
11078 type: "kanban",
11079 resModel: "partner",
11080 arch: `
11081 <kanban action="a1" type="action">
11082 <templates>
11083 <t t-name="card">
11084 <p>some value</p><field name="foo"/>
11085 </t>
11086 </templates>
11087 </kanban>`,
11088 });
11089
11090 expect.verifySteps([
11091 "/web/webclient/translations",
11092 "/web/webclient/load_menus",
11093 "get_views",
11094 "web_search_read",
11095 "has_group",
11096 ]);
11097 await contains(".o_kanban_record p").click();
11098 expect.verifySteps(["doActionButton type action name a1", "web_search_read"]);
11099 });
11100
11101 test("Missing t-key is automatically filled with a warning", async () => {
11102 patchWithCleanup(console, { warn: () => expect.step("warning") });
11103
11104 await mountView({
11105 type: "kanban",
11106 resModel: "partner",
11107 arch: `
11108 <kanban>
11109 <templates>
11110 <t t-name="card">
11111 <div>
11112 <span t-foreach="[1, 2, 3]" t-as="i" t-esc="i" />
11113 </div>
11114 </t>
11115 </templates>
11116 </kanban>`,
11117 });
11118
11119 expect.verifySteps(["warning"]);
11120 expect(getKanbanRecord({ index: 0 })).toHaveText("123");
11121 });
11122
11123 test("Quick created record is rendered after load", async () => {
11124 let def;
11125 onRpc("web_read", () => {
11126 expect.step("web_read");
11127 return def;
11128 });
11129 onRpc("name_create", () => {
11130 expect.step("name_create");
11131 });
11132 await mountView({
11133 type: "kanban",
11134 resModel: "partner",
11135 arch: `
11136 <kanban on_create="quick_create">
11137 <field name="category_ids" />
11138 <progressbar field="foo" colors='{"yop": "success", "gnap": "warning", "blip": "danger"}' sum_field="int_field"/>
11139 <templates>
11140 <t t-name="card">
11141 <span t-esc="record.category_ids.raw_value.length" />
11142 </t>
11143 </templates>
11144 </kanban>`,
11145 groupBy: ["product_id"],
11146 });
11147
11148 expect(getKanbanRecordTexts(0)).toEqual(["0", "1"]);
11149 expect.verifySteps([]);
11150
11151 def = new Deferred();
11152
11153 await quickCreateKanbanRecord(0);
11154 await editKanbanRecordQuickCreateInput("display_name", "Test");
11155 await validateKanbanRecord();
11156 expect(getKanbanRecordTexts(0)).toEqual(["0", "1"]);
11157
11158 def.resolve();
11159 await animationFrame();
11160
11161 expect(getKanbanRecordTexts(0)).toEqual(["0", "0", "1"]);
11162 expect.verifySteps(["name_create", "web_read"]);
11163 });
11164
11165 test("Allow use of 'editable'/'deletable' in ungrouped kanban", async () => {
11166 await mountView({
11167 type: "kanban",
11168 resModel: "partner",
11169 arch: `
11170 <kanban on_create="quick_create">
11171 <templates>
11172 <div t-name="card">
11173 <button t-if="widget.editable">EDIT</button>
11174 <button t-if="widget.deletable">DELETE</button>
11175 </div>
11176 </templates>
11177 </kanban>`,
11178 });
11179
11180 expect(getKanbanRecordTexts()).toEqual([
11181 "EDITDELETE",
11182 "EDITDELETE",
11183 "EDITDELETE",
11184 "EDITDELETE",
11185 ]);
11186 });
11187
11188 test.tags("desktop");
11189 test("folded groups kept when leaving/coming back", async () => {
11190 Partner._views = {
11191 kanban: `
11192 <kanban>
11193 <templates>
11194 <t t-name="card">
11195 <field name="int_field"/>
11196 </t>
11197 </templates>
11198 </kanban>`,
11199 };
11200 await mountWithCleanup(WebClient);
11201 await getService("action").doAction({
11202 name: "Partners",
11203 res_model: "partner",
11204 type: "ir.actions.act_window",
11205 views: [
11206 [false, "kanban"],
11207 [false, "form"],
11208 ],
11209 context: {
11210 group_by: ["product_id"],
11211 },
11212 });
11213
11214 expect(".o_kanban_view").toHaveCount(1);
11215 expect(".o_kanban_group").toHaveCount(2);
11216 expect(".o_column_folded").toHaveCount(0);
11217 expect(".o_kanban_record").toHaveCount(4);
11218
11219 // fold the first group
11220 const clickColumnAction = await toggleKanbanColumnActions(0);
11221 await clickColumnAction("Fold");
11222 expect(".o_column_folded").toHaveCount(1);
11223 expect(".o_kanban_record").toHaveCount(2);
11224
11225 // open a record and go back
11226 await contains(".o_kanban_record").click();
11227 expect(".o_form_view").toHaveCount(1);
11228
11229 await contains(".breadcrumb-item a").click();
11230 expect(".o_column_folded").toHaveCount(1);
11231 expect(".o_kanban_record").toHaveCount(2);
11232 });
11233
11234 test.tags("desktop");
11235 test("filter groups kept when leaving/coming back", async () => {
11236 Partner._records[1].state = "abc";
11237 Partner._views = {
11238 kanban: `
11239 <kanban>
11240 <progressbar field="state" colors='{"abc": "success", "def": "warning", "ghi": "danger"}' />
11241 <templates>
11242 <t t-name="card">
11243 <field name="id" />
11244 </t>
11245 </templates>
11246 </kanban>`,
11247 form: `
11248 <form>
11249 <field name="state" widget="radio"/>
11250 </form>`,
11251 };
11252 await mountWithCleanup(WebClient);
11253 await getService("action").doAction({
11254 name: "Partners",
11255 res_model: "partner",
11256 type: "ir.actions.act_window",
11257 views: [
11258 [false, "kanban"],
11259 [false, "form"],
11260 ],
11261 context: {
11262 group_by: ["bar"],
11263 },
11264 });
11265
11266 // Filter on state "abc" => matches 2 records
11267 await contains(getKanbanProgressBars(1)[0]).click();
11268 expect(getKanbanRecordTexts(0)).toEqual(["4"]);
11269 expect(getKanbanRecordTexts(1)).toEqual(["1", "2"]);
11270
11271 // open a record
11272 await contains(getKanbanRecord({ index: 1 })).click();
11273 expect(".o_form_view").toHaveCount(1);
11274
11275 // go back to kanban view
11276 await contains(".breadcrumb-item a").click();
11277 expect(getKanbanRecordTexts(0)).toEqual(["4"]);
11278 expect(getKanbanRecordTexts(1)).toEqual(["1", "2"]);
11279
11280 // open a record
11281 await contains(getKanbanRecord({ index: 1 })).click();
11282 expect(".o_form_view").toHaveCount(1);
11283
11284 // select another state
11285 await contains(queryAll("input.o_radio_input")[1]).click();
11286 // go back to kanban view
11287 await contains(".breadcrumb-item a").click();
11288 expect(getKanbanRecordTexts(0)).toEqual(["4"]);
11289 expect(getKanbanRecordTexts(1)).toEqual(["2"]);
11290 });
11291
11292 test.tags("desktop");
11293 test("folded groups kept when leaving/coming back (grouped by date)", async () => {
11294 Partner._fields.date = fields.Date({ default: "2022-10-10" });
11295 Partner._records[0].date = "2022-05-10";
11296 Partner._views = {
11297 kanban: `
11298 <kanban>
11299 <templates>
11300 <t t-name="card">
11301 <field name="int_field"/>
11302 </t>
11303 </templates>
11304 </kanban>`,
11305 };
11306 await mountWithCleanup(WebClient);
11307 await getService("action").doAction({
11308 name: "Partners",
11309 res_model: "partner",
11310 type: "ir.actions.act_window",
11311 views: [
11312 [false, "kanban"],
11313 [false, "form"],
11314 ],
11315 context: {
11316 group_by: ["date"],
11317 },
11318 });
11319
11320 expect(".o_kanban_view").toHaveCount(1);
11321 expect(".o_kanban_group").toHaveCount(2);
11322 expect(".o_column_folded").toHaveCount(0);
11323 expect(".o_kanban_record").toHaveCount(4);
11324
11325 // fold the second column
11326 const clickColumnAction = await toggleKanbanColumnActions(1);
11327 await clickColumnAction("Fold");
11328 expect(".o_column_folded").toHaveCount(1);
11329 expect(".o_kanban_record").toHaveCount(1);
11330
11331 // open a record and go back
11332 await contains(".o_kanban_record").click();
11333 expect(".o_form_view").toHaveCount(1);
11334
11335 await contains(".breadcrumb-item a").click();
11336 expect(".o_column_folded").toHaveCount(1);
11337 expect(".o_kanban_record").toHaveCount(1);
11338 });
11339
11340 test.tags("desktop");
11341 test("loaded records kept when leaving/coming back", async () => {
11342 Partner._views = {
11343 kanban: `
11344 <kanban limit="1">
11345 <templates>
11346 <t t-name="card">
11347 <field name="int_field"/>
11348 </t>
11349 </templates>
11350 </kanban>`,
11351 };
11352 await mountWithCleanup(WebClient);
11353 await getService("action").doAction({
11354 name: "Partners",
11355 res_model: "partner",
11356 type: "ir.actions.act_window",
11357 views: [
11358 [false, "kanban"],
11359 [false, "form"],
11360 ],
11361 context: {
11362 group_by: ["product_id"],
11363 },
11364 });
11365
11366 expect(".o_kanban_view").toHaveCount(1);
11367 expect(".o_kanban_group").toHaveCount(2);
11368 expect(".o_kanban_record").toHaveCount(2);
11369
11370 // load more records in second group
11371 await clickKanbanLoadMore(1);
11372 expect(".o_kanban_record").toHaveCount(3);
11373
11374 // open a record and go back
11375 await contains(".o_kanban_record").click();
11376 expect(".o_form_view").toHaveCount(1);
11377
11378 await contains(".breadcrumb-item a").click();
11379 expect(".o_kanban_record").toHaveCount(3);
11380 });
11381
11382 test("basic rendering with 2 groupbys", async () => {
11383 stepAllNetworkCalls();
11384
11385 await mountView({
11386 type: "kanban",
11387 resModel: "partner",
11388 arch: `
11389 <kanban>
11390 <templates>
11391 <t t-name="card">
11392 <field name="foo" />
11393 </t>
11394 </templates>
11395 </kanban>`,
11396 groupBy: ["bar", "product_id"],
11397 });
11398
11399 expect(".o_kanban_renderer").toHaveClass("o_kanban_grouped");
11400 expect(".o_kanban_group").toHaveCount(2);
11401 expect(".o_kanban_group:first-child .o_kanban_record").toHaveCount(1);
11402 expect(".o_kanban_group:nth-child(2) .o_kanban_record").toHaveCount(3);
11403 expect.verifySteps([
11404 "/web/webclient/translations",
11405 "/web/webclient/load_menus",
11406 "get_views",
11407 "web_read_group",
11408 "has_group",
11409 ]);
11410 });
11411
11412 test("basic rendering with a date groupby with a granularity", async () => {
11413 Partner._records[0].date = "2022-06-23";
11414
11415 stepAllNetworkCalls();
11416 onRpc("web_read_group", ({ method, kwargs }) => {
11417 expect(kwargs.aggregates).toEqual([]);
11418 expect(kwargs.groupby).toEqual(["date:day"]);
11419 });
11420
11421 await mountView({
11422 type: "kanban",
11423 resModel: "partner",
11424 arch: `
11425 <kanban>
11426 <templates>
11427 <t t-name="card">
11428 <field name="foo" />
11429 </t>
11430 </templates>
11431 </kanban>`,
11432 groupBy: ["date:day"],
11433 });
11434
11435 expect(".o_kanban_renderer").toHaveClass("o_kanban_grouped");
11436 expect(".o_kanban_group").toHaveCount(2);
11437 expect(".o_kanban_group:first-child .o_kanban_record").toHaveCount(3);
11438 expect(".o_kanban_group:nth-child(2) .o_kanban_record").toHaveCount(1);
11439 expect.verifySteps([
11440 "/web/webclient/translations",
11441 "/web/webclient/load_menus",
11442 "get_views",
11443 "web_read_group",
11444 "has_group",
11445 ]);
11446 });
11447
11448 test.tags("desktop");
11449 test("quick create record and click outside (no dirty input)", async () => {
11450 await mountView({
11451 type: "kanban",
11452 resModel: "partner",
11453 arch: `
11454 <kanban limit="2">
11455 <templates>
11456 <t t-name="card">
11457 <field name="foo"/>
11458 </t>
11459 </templates>
11460 </kanban>`,
11461 groupBy: ["bar"],
11462 createRecord: () => {
11463 expect.step("create record");
11464 },
11465 });
11466
11467 expect(".o_kanban_quick_create").toHaveCount(0);
11468
11469 await quickCreateKanbanRecord();
11470
11471 expect(".o_kanban_quick_create").toHaveCount(1);
11472 expect(".o_kanban_group:nth-child(1) .o_kanban_quick_create").toHaveCount(1);
11473
11474 await contains(".o_control_panel").click();
11475
11476 expect(".o_kanban_quick_create").toHaveCount(0);
11477
11478 await quickCreateKanbanRecord();
11479
11480 expect(".o_kanban_quick_create").toHaveCount(1);
11481 expect(".o_kanban_group:nth-child(1) .o_kanban_quick_create").toHaveCount(1);
11482
11483 await quickCreateKanbanRecord(1);
11484
11485 expect(".o_kanban_quick_create").toHaveCount(1);
11486 expect(".o_kanban_group:nth-child(2) .o_kanban_quick_create").toHaveCount(1);
11487
11488 await contains(".o_kanban_load_more button").click();
11489
11490 expect(".o_kanban_quick_create").toHaveCount(0);
11491
11492 await quickCreateKanbanRecord();
11493
11494 expect(".o_kanban_quick_create").toHaveCount(1);
11495 expect(".o_kanban_group:nth-child(1) .o_kanban_quick_create").toHaveCount(1);
11496
11497 expect.verifySteps([]);
11498
11499 await createKanbanRecord();
11500
11501 expect.verifySteps(["create record"]);
11502 expect(".o_kanban_quick_create").toHaveCount(0);
11503 });
11504
11505 test.tags("desktop");
11506 test("quick create record and click outside (with dirty input)", async () => {
11507 await mountView({
11508 type: "kanban",
11509 resModel: "partner",
11510 arch: `
11511 <kanban limit="2">
11512 <templates>
11513 <t t-name="card">
11514 <field name="foo"/>
11515 </t>
11516 </templates>
11517 </kanban>`,
11518 groupBy: ["bar"],
11519 createRecord: () => {
11520 expect.step("create record");
11521 },
11522 });
11523
11524 expect(".o_kanban_quick_create").toHaveCount(0);
11525
11526 await quickCreateKanbanRecord();
11527
11528 expect(".o_kanban_quick_create").toHaveCount(1);
11529 expect(".o_kanban_group:nth-child(1) .o_kanban_quick_create").toHaveCount(1);
11530
11531 await editKanbanRecordQuickCreateInput("display_name", "ABC");
11532
11533 expect(".o_kanban_quick_create [name=display_name] input").toHaveValue("ABC");
11534
11535 await contains(".o_control_panel").click();
11536
11537 expect(".o_kanban_quick_create").toHaveCount(1);
11538 expect(".o_kanban_group:nth-child(1) .o_kanban_quick_create").toHaveCount(1);
11539 expect(".o_kanban_quick_create [name=display_name] input").toHaveValue("ABC");
11540
11541 await quickCreateKanbanRecord(1);
11542
11543 expect(".o_kanban_quick_create").toHaveCount(1);
11544 expect(".o_kanban_group:nth-child(2) .o_kanban_quick_create").toHaveCount(1);
11545 expect(".o_kanban_quick_create [name=display_name] input").toHaveValue("");
11546
11547 await editKanbanRecordQuickCreateInput("display_name", "ABC");
11548
11549 expect(".o_kanban_quick_create [name=display_name] input").toHaveValue("ABC");
11550
11551 await contains(".o_kanban_load_more button").click();
11552
11553 expect(".o_kanban_quick_create").toHaveCount(0);
11554
11555 await quickCreateKanbanRecord();
11556
11557 expect(".o_kanban_quick_create").toHaveCount(1);
11558 expect(".o_kanban_group:nth-child(1) .o_kanban_quick_create").toHaveCount(1);
11559
11560 await editKanbanRecordQuickCreateInput("display_name", "ABC");
11561
11562 expect(".o_kanban_quick_create [name=display_name] input").toHaveValue("ABC");
11563 expect.verifySteps([]);
11564
11565 await createKanbanRecord();
11566
11567 expect.verifySteps(["create record"]);
11568 expect(".o_kanban_quick_create").toHaveCount(0);
11569 });
11570
11571 test("quick create record and click on 'Load more'", async () => {
11572 await mountView({
11573 type: "kanban",
11574 resModel: "partner",
11575 arch: `
11576 <kanban limit="2">
11577 <templates>
11578 <t t-name="card">
11579 <field name="foo"/>
11580 </t>
11581 </templates>
11582 </kanban>`,
11583 groupBy: ["bar"],
11584 });
11585
11586 expect(".o_kanban_quick_create").toHaveCount(0);
11587
11588 await quickCreateKanbanRecord(1);
11589
11590 expect(".o_kanban_quick_create").toHaveCount(1);
11591 expect(".o_kanban_group:nth-child(2) .o_kanban_quick_create").toHaveCount(1);
11592 expect(".o_kanban_group:nth-child(2) .o_kanban_record").toHaveCount(2);
11593
11594 await contains(".o_kanban_load_more button").click();
11595
11596 expect(".o_kanban_quick_create").toHaveCount(0);
11597 expect(".o_kanban_group:nth-child(2) .o_kanban_record").toHaveCount(3);
11598 });
11599
11600 test("dropdown is closed on item click", async () => {
11601 Partner._records.splice(1, 3); // keep one record only
11602
11603 await mountView({
11604 type: "kanban",
11605 resModel: "partner",
11606 arch: `
11607 <kanban>
11608 <templates>
11609 <t t-name="menu">
11610 <a role="menuitem" class="dropdown-item">Item</a>
11611 </t>
11612 <t t-name="card">
11613 <div/>
11614 </t>
11615 </templates>
11616 </kanban>`,
11617 });
11618
11619 expect(".o-dropdown--menu").toHaveCount(0);
11620
11621 await toggleKanbanRecordDropdown();
11622
11623 expect(".o-dropdown--menu").toHaveCount(1);
11624
11625 await contains(".o-dropdown--menu .dropdown-item").click();
11626
11627 expect(".o-dropdown--menu").toHaveCount(0);
11628 });
11629
11630 test("can use JSON in kanban template", async () => {
11631 Partner._records = [{ id: 1, foo: '["g", "e", "d"]' }];
11632
11633 await mountView({
11634 type: "kanban",
11635 resModel: "partner",
11636 arch: `
11637 <kanban>
11638 <field name="foo"/>
11639 <templates>
11640 <t t-name="card">
11641 <div>
11642 <span t-foreach="JSON.parse(record.foo.raw_value)" t-as="v" t-key="v_index" t-esc="v"/>
11643 </div>
11644 </t>
11645 </templates>
11646 </kanban>`,
11647 });
11648
11649 expect(".o_kanban_record:not(.o_kanban_ghost)").toHaveCount(1);
11650 expect(".o_kanban_record span").toHaveCount(3);
11651 expect(".o_kanban_record:not(.o_kanban_ghost)").toHaveText("ged");
11652 });
11653
11654 test("Color '200' (gray) can be used twice (for false value and another value) in progress bar", async () => {
11655 Partner._records.push({ id: 5, bar: true }, { id: 6, bar: false });
11656
11657 stepAllNetworkCalls();
11658
11659 await mountView({
11660 type: "kanban",
11661 resModel: "partner",
11662 arch: `
11663 <kanban>
11664 <progressbar field="foo" colors='{"yop": "200", "gnap": "warning", "blip": "danger"}'/>
11665 <templates>
11666 <t t-name="card">
11667 <field name="state"/>
11668 </t>
11669 </templates>
11670 </kanban>`,
11671 groupBy: ["bar"],
11672 });
11673
11674 expect(".o_kanban_group:nth-child(1) .progress-bar").toHaveCount(2);
11675 expect(
11676 queryAll(".o_kanban_group:nth-child(1) .progress-bar").map((el) => el.dataset.tooltip)
11677 ).toEqual(["1 blip", "1 Other"]);
11678 expect(".o_kanban_group:nth-child(2) .progress-bar").toHaveCount(4);
11679 expect(
11680 queryAll(".o_kanban_group:nth-child(2) .progress-bar").map((el) => el.dataset.tooltip)
11681 ).toEqual(["1 yop", "1 gnap", "1 blip", "1 Other"]);
11682 expect(getKanbanCounters()).toEqual(["2", "4"]);
11683
11684 await contains(".o_kanban_group:nth-child(2) .progress-bar").click();
11685
11686 expect(getKanbanCounters()).toEqual(["2", "1"]);
11687 expect(".o_kanban_group:nth-child(2) .o_kanban_record").toHaveText("ABC");
11688 expect(".o_kanban_group:nth-child(2) .o_kanban_load_more").toHaveCount(0);
11689
11690 await contains(".o_kanban_group:nth-child(2) .progress-bar:nth-child(2)").click();
11691
11692 expect(getKanbanCounters()).toEqual(["2", "1"]);
11693 expect(".o_kanban_group:nth-child(2) .o_kanban_record").toHaveText("GHI");
11694 expect(".o_kanban_group:nth-child(2) .o_kanban_load_more").toHaveCount(0);
11695
11696 await contains(".o_kanban_group:nth-child(2) .progress-bar:nth-child(4)").click();
11697
11698 expect(getKanbanCounters()).toEqual(["2", "1"]);
11699 expect(".o_kanban_group:nth-child(2) .o_kanban_record").toHaveText("");
11700 expect(".o_kanban_group:nth-child(2) .o_kanban_load_more").toHaveCount(0);
11701 expect.verifySteps([
11702 "/web/webclient/translations",
11703 "/web/webclient/load_menus",
11704 "get_views",
11705 "read_progress_bar",
11706 "web_read_group",
11707 "has_group",
11708 "web_search_read",
11709 "read_progress_bar",
11710 "web_search_read",
11711 "read_progress_bar",
11712 "web_search_read",
11713 "read_progress_bar",
11714 ]);
11715 });
11716
11717 test("update field on which progress bars are computed", async () => {
11718 Partner._records.push({ id: 5, state: "abc", bar: true });
11719
11720 stepAllNetworkCalls();
11721
11722 await mountView({
11723 type: "kanban",
11724 resModel: "partner",
11725 arch: `
11726 <kanban>
11727 <progressbar field="state" colors='{"abc": "success", "def": "warning", "ghi": "danger"}' />
11728 <templates>
11729 <div t-name="card">
11730 <field name="state" widget="state_selection" />
11731 <field name="id" />
11732 </div>
11733 </templates>
11734 </kanban>`,
11735 groupBy: ["bar"],
11736 });
11737
11738 // Initial state: 2 columns, the "Yes" column contains 2 records "abc", 1 "def" and 1 "ghi"
11739 expect(getKanbanCounters()).toEqual(["1", "4"]);
11740 expect(queryAll(".o_kanban_record", { root: getKanbanColumn(1) })).toHaveCount(4);
11741 expect(queryAll(".o_column_progress .progress-bar", { root: getKanbanColumn(1) })).toHaveCount(
11742 3
11743 );
11744 expect(getKanbanProgressBars(1)[0].style.width).toBe("50%"); // abc: 2
11745 expect(getKanbanProgressBars(1)[1].style.width).toBe("25%"); // def: 1
11746 expect(getKanbanProgressBars(1)[2].style.width).toBe("25%"); // ghi: 1
11747
11748 // Filter on state "abc" => matches 2 records
11749 await contains(getKanbanProgressBars(1)[0]).click();
11750
11751 expect(getKanbanCounters()).toEqual(["1", "2"]);
11752 expect(queryAll(".o_kanban_record", { root: getKanbanColumn(1) })).toHaveCount(2);
11753 expect(queryAll(".o_column_progress .progress-bar", { root: getKanbanColumn(1) })).toHaveCount(
11754 3
11755 );
11756 expect(getKanbanProgressBars(1)[0].style.width).toBe("50%"); // abc: 2
11757 expect(getKanbanProgressBars(1)[1].style.width).toBe("25%"); // def: 1
11758 expect(getKanbanProgressBars(1)[2].style.width).toBe("25%"); // ghi: 1
11759
11760 // Changes the state of the first record of the "Yes" column to "def"
11761 // The updated record should remain visible
11762 await contains(".o_status", { root: getKanbanRecord({ index: 2 }) }).click();
11763 await contains(".o-dropdown-item:nth-child(2)", {
11764 root: getDropdownMenu(getKanbanRecord({ index: 2 })),
11765 }).click();
11766
11767 expect(getKanbanCounters()).toEqual(["1", "1"]);
11768 expect(queryAll(".o_kanban_record", { root: getKanbanColumn(1) })).toHaveCount(2);
11769 expect(queryAll(".o_column_progress .progress-bar", { root: getKanbanColumn(1) })).toHaveCount(
11770 3
11771 );
11772 expect(getKanbanProgressBars(1)[0].style.width).toBe("25%"); // abc: 1
11773 expect(getKanbanProgressBars(1)[1].style.width).toBe("50%"); // def: 2
11774 expect(getKanbanProgressBars(1)[2].style.width).toBe("25%"); // ghi: 1
11775
11776 // Filter on state "def" => matches 2 records (including the one we just changed)
11777 await contains(getKanbanProgressBars(1)[1]).click();
11778
11779 expect(getKanbanCounters()).toEqual(["1", "2"]);
11780 expect(queryAll(".o_kanban_record", { root: getKanbanColumn(1) })).toHaveCount(2);
11781 expect(getKanbanProgressBars(1)[0].style.width).toBe("25%"); // abc: 1
11782 expect(getKanbanProgressBars(1)[1].style.width).toBe("50%"); // def: 2
11783 expect(getKanbanProgressBars(1)[2].style.width).toBe("25%"); // ghi: 1
11784
11785 // Filter back on state "abc" => matches only 1 record
11786 await contains(getKanbanProgressBars(1)[0]).click();
11787
11788 expect(getKanbanCounters()).toEqual(["1", "1"]);
11789 expect(queryAll(".o_kanban_record", { root: getKanbanColumn(1) })).toHaveCount(1);
11790 expect(getKanbanProgressBars(1)[0].style.width).toBe("25%"); // abc: 1
11791 expect(getKanbanProgressBars(1)[1].style.width).toBe("50%"); // def: 2
11792 expect(getKanbanProgressBars(1)[2].style.width).toBe("25%"); // ghi: 1
11793 expect.verifySteps([
11794 "/web/webclient/translations",
11795 "/web/webclient/load_menus",
11796 "get_views",
11797 "read_progress_bar",
11798 "web_read_group",
11799 "has_group",
11800 "web_search_read",
11801 "read_progress_bar",
11802 "web_save",
11803 "read_progress_bar",
11804 "web_search_read",
11805 "read_progress_bar",
11806 "web_search_read",
11807 "read_progress_bar",
11808 ]);
11809 });
11810
11811 test("load more button shouldn't be visible when unfiltering column", async () => {
11812 Partner._records.push({ id: 5, state: "abc", bar: true });
11813
11814 let def;
11815 onRpc("web_search_read", () => def);
11816
11817 await mountView({
11818 type: "kanban",
11819 resModel: "partner",
11820 arch: `
11821 <kanban>
11822 <progressbar field="state" colors='{"abc": "success", "def": "warning", "ghi": "danger"}' />
11823 <templates>
11824 <div t-name="card">
11825 <field name="state" widget="state_selection" />
11826 <field name="id" />
11827 </div>
11828 </templates>
11829 </kanban>`,
11830 groupBy: ["bar"],
11831 });
11832
11833 // Initial state: 2 columns, the "No" column contains 1 record, The "Yes" column contains 4 records
11834 expect(getKanbanCounters()).toEqual(["1", "4"]);
11835
11836 // Filter on state "abc" => matches 2 records
11837 await contains(getKanbanProgressBars(1)[0]).click();
11838
11839 // Filtered state: 2 columns, the "No" column contains 1 record, The "Yes" column contains 2 records
11840 expect(getKanbanCounters()).toEqual(["1", "2"]);
11841
11842 def = new Deferred();
11843 // UnFiltered the "Yes" column
11844 await contains(getKanbanProgressBars(1)[0]).click();
11845 expect(".o_kanban_load_more").toHaveCount(0, {
11846 message: "The load more button should not be visible",
11847 });
11848
11849 def.resolve();
11850 await animationFrame();
11851
11852 // Return to initial state
11853 expect(getKanbanCounters()).toEqual(["1", "4"]);
11854 expect(".o_kanban_load_more").toHaveCount(0, {
11855 message: "The load more button should not be visible",
11856 });
11857 });
11858
11859 test("click on the progressBar of a new column", async () => {
11860 Partner._records = [];
11861
11862 onRpc("web_search_read", ({ kwargs }) => {
11863 expect.step("web_search_read");
11864 expect(kwargs.domain).toEqual([
11865 "&",
11866 "&",
11867 ["id", ">", 0],
11868 ["product_id", "=", 6],
11869 "!",
11870 ["state", "in", ["abc", "def", "ghi"]],
11871 ]);
11872 });
11873
11874 await mountView({
11875 type: "kanban",
11876 resModel: "partner",
11877 arch: `
11878 <kanban default_group_by="product_id" on_create="quick_create">
11879 <progressbar field="state" colors='{"abc": "success", "def": "warning", "ghi": "danger"}' />
11880 <templates>
11881 <div t-name="card">
11882 <field name="state" widget="state_selection" />
11883 <field name="id" />
11884 </div>
11885 </templates>
11886 </kanban>`,
11887 domain: [["id", ">", 0]],
11888 });
11889
11890 // Create a new column
11891 await editKanbanColumnName("new column");
11892 await validateKanbanColumn();
11893
11894 // Crete a record in the new column
11895 await quickCreateKanbanRecord();
11896 await editKanbanRecordQuickCreateInput("display_name", "new product");
11897 await validateKanbanRecord();
11898
11899 expect(".o_kanban_record").toHaveCount(1);
11900
11901 // Togggle the progressBar
11902 await contains(getKanbanProgressBars(0)[0]).click();
11903
11904 expect(".o_kanban_record").toHaveCount(1);
11905 expect.verifySteps(["web_search_read"]);
11906 });
11907
11908 test.tags("desktop");
11909 test("keep focus in cp when pressing arrowdown and no kanban card", async () => {
11910 Partner._records = [];
11911
11912 await mountView({
11913 type: "kanban",
11914 resModel: "partner",
11915 arch: `
11916 <kanban default_group_by="product_id" on_create="quick_create">
11917 <templates>
11918 <t t-name="card">
11919 <field name="display_name"/>
11920 </t>
11921 </templates>
11922 </kanban>`,
11923 });
11924
11925 // Check that there is a column quick create
11926 expect(".o_column_quick_create").toHaveCount(1);
11927 await editKanbanColumnName("new col");
11928 await validateKanbanColumn();
11929
11930 // Check that there is only one group and no kanban card
11931 expect(".o_kanban_group").toHaveCount(1);
11932 expect(".o_kanban_group.o_kanban_no_records").toHaveCount(1);
11933 expect(".o_kanban_record").toHaveCount(0);
11934
11935 // Check that the focus is on the searchview input
11936 await quickCreateKanbanRecord();
11937 expect(".o_kanban_group.o_kanban_no_records").toHaveCount(1);
11938 expect(".o_kanban_quick_create").toHaveCount(1);
11939 expect(".o_kanban_record").toHaveCount(0);
11940
11941 // Somehow give the focus in the control panel, i.e. in the search view
11942 // Note that a simple click in the control panel should normally close the quick
11943 // create, so in order to give the focus in the search input, the user would
11944 // normally have to right-click on it then press escape. These are behaviors
11945 // handled through the browser, so we simply call focus directly here.
11946 queryFirst(".o_searchview_input").focus();
11947
11948 // Make sure no async code will have a side effect on the focused element
11949 await animationFrame();
11950 expect(".o_searchview_input").toBeFocused();
11951
11952 // Trigger the ArrowDown hotkey
11953 await press("ArrowDown");
11954 await animationFrame();
11955 expect(".o_searchview_input").toBeFocused();
11956 });
11957
11958 test.tags("desktop");
11959 test("no leak of TransactionInProgress (grouped case)", async () => {
11960 const def = new Deferred();
11961 onRpc("web_resequence", () => {
11962 expect.step("resequence");
11963 return def;
11964 });
11965
11966 await mountView({
11967 type: "kanban",
11968 resModel: "partner",
11969 arch: `
11970 <kanban>
11971 <templates>
11972 <t t-name="card">
11973 <field name="foo"/>
11974 </t>
11975 </templates>
11976 </kanban>`,
11977 groupBy: ["state"],
11978 });
11979
11980 expect(".o_kanban_group:nth-child(1) .o_kanban_record").toHaveCount(1);
11981 expect(".o_kanban_group:nth-child(1) .o_kanban_record").toHaveText("yop");
11982 expect(".o_kanban_group:nth-child(2) .o_kanban_record").toHaveCount(1);
11983 expect(".o_kanban_group:nth-child(2) .o_kanban_record").toHaveText("blip");
11984 expect(".o_kanban_group:nth-child(3) .o_kanban_record").toHaveCount(2);
11985
11986 expect.verifySteps([]);
11987
11988 // move "yop" from first to second column
11989 await contains(".o_kanban_group:nth-child(1) .o_kanban_record").dragAndDrop(
11990 queryFirst(".o_kanban_group:nth-child(2)")
11991 );
11992
11993 expect(".o_kanban_group:nth-child(1) .o_kanban_record").toHaveCount(0);
11994 expect(".o_kanban_group:nth-child(2) .o_kanban_record").toHaveCount(2);
11995 expect(queryAllTexts(".o_kanban_group:nth-child(2) .o_kanban_record")).toEqual(["blip", "yop"]);
11996 expect(".o_kanban_group:nth-child(3) .o_kanban_record").toHaveCount(2);
11997 expect.verifySteps(["resequence"]);
11998
11999 // try to move "yop" from second to third column
12000 await contains(".o_kanban_group:nth-child(2) .o_kanban_record:nth-child(3)").dragAndDrop(
12001 ".o_kanban_group:nth-child(3)"
12002 );
12003
12004 expect(".o_kanban_group:nth-child(1) .o_kanban_record").toHaveCount(0);
12005 expect(".o_kanban_group:nth-child(2) .o_kanban_record").toHaveCount(2);
12006 expect(queryAllTexts(".o_kanban_group:nth-child(2) .o_kanban_record")).toEqual(["blip", "yop"]);
12007 expect(".o_kanban_group:nth-child(3) .o_kanban_record").toHaveCount(2);
12008 expect.verifySteps([]);
12009
12010 def.resolve();
12011 await animationFrame();
12012
12013 // try again to move "yop" from second to third column
12014 await contains(".o_kanban_group:nth-child(2) .o_kanban_record:nth-child(3)").dragAndDrop(
12015 ".o_kanban_group:nth-child(3)"
12016 );
12017
12018 expect(".o_kanban_group:nth-child(1) .o_kanban_record").toHaveCount(0);
12019 expect(".o_kanban_group:nth-child(2) .o_kanban_record").toHaveCount(1);
12020 expect(".o_kanban_group:nth-child(3) .o_kanban_record").toHaveCount(3);
12021 expect(queryAllTexts(".o_kanban_group:nth-child(3) .o_kanban_record")).toEqual([
12022 "gnap",
12023 "blip",
12024 "yop",
12025 ]);
12026 expect.verifySteps(["resequence"]);
12027 });
12028
12029 test.tags("desktop");
12030 test("no leak of TransactionInProgress (not grouped case)", async () => {
12031 const def = new Deferred();
12032 onRpc("web_resequence", () => {
12033 expect.step("resequence");
12034 return def;
12035 });
12036
12037 await mountView({
12038 type: "kanban",
12039 resModel: "partner",
12040 arch: `
12041 <kanban records_draggable="1">
12042 <field name="int_field" widget="handle" />
12043 <templates>
12044 <t t-name="card">
12045 <field name="foo"/>
12046 </t>
12047 </templates>
12048 </kanban>`,
12049 });
12050
12051 expect(".o_kanban_record:not(.o_kanban_ghost)").toHaveCount(4);
12052 expect(queryAllTexts(".o_kanban_record:not(.o_kanban_ghost)")).toEqual([
12053 "blip",
12054 "blip",
12055 "yop",
12056 "gnap",
12057 ]);
12058 expect.verifySteps([]);
12059
12060 // move second "blip" to third place
12061 await contains(".o_kanban_record:nth-child(2)").dragAndDrop(".o_kanban_record:nth-child(3)");
12062
12063 expect(queryAllTexts(".o_kanban_record:not(.o_kanban_ghost)")).toEqual([
12064 "blip",
12065 "yop",
12066 "blip",
12067 "gnap",
12068 ]);
12069 expect.verifySteps(["resequence"]);
12070
12071 // try again
12072 await contains(".o_kanban_record:nth-child(2)").dragAndDrop(".o_kanban_record:nth-child(3)");
12073 expect.verifySteps([]);
12074
12075 def.resolve();
12076 await animationFrame();
12077
12078 expect(queryAllTexts(".o_kanban_record:not(.o_kanban_ghost)")).toEqual([
12079 "blip",
12080 "yop",
12081 "blip",
12082 "gnap",
12083 ]);
12084
12085 await contains(".o_kanban_record:nth-child(3)").dragAndDrop(".o_kanban_record:nth-child(4)");
12086
12087 expect(queryAllTexts(".o_kanban_record:not(.o_kanban_ghost)")).toEqual([
12088 "blip",
12089 "yop",
12090 "gnap",
12091 "blip",
12092 ]);
12093 expect.verifySteps(["resequence"]);
12094 });
12095
12096 test("fieldDependencies support for fields", async () => {
12097 const customField = {
12098 component: class CustomField extends Component {
12099 static template = xml`<span t-esc="props.record.data.int_field"/>`;
12100 static props = ["*"];
12101 },
12102 fieldDependencies: [{ name: "int_field", type: "integer" }],
12103 };
12104 fieldRegistry.add("custom_field", customField);
12105 after(() => fieldRegistry.remove("custom_field"));
12106
12107 await mountView({
12108 resModel: "partner",
12109 type: "kanban",
12110 arch: `
12111 <kanban>
12112 <templates>
12113 <t t-name="card">
12114 <field name="foo" widget="custom_field"/>
12115 </t>
12116 </templates>
12117 </kanban>`,
12118 });
12119
12120 expect("[name=foo] span:first").toHaveText("10");
12121 });
12122
12123 test("fieldDependencies support for fields: dependence on a relational field", async () => {
12124 const customField = {
12125 component: class CustomField extends Component {
12126 static template = xml`<span t-esc="props.record.data.product_id.display_name"/>`;
12127 static props = ["*"];
12128 },
12129 fieldDependencies: [{ name: "product_id", type: "many2one", relation: "product" }],
12130 };
12131 fieldRegistry.add("custom_field", customField);
12132 after(() => fieldRegistry.remove("custom_field"));
12133
12134 stepAllNetworkCalls();
12135
12136 await mountView({
12137 resModel: "partner",
12138 type: "kanban",
12139 arch: `
12140 <kanban>
12141 <templates>
12142 <t t-name="card">
12143 <field name="foo" widget="custom_field"/>
12144 </t>
12145 </templates>
12146 </kanban>`,
12147 });
12148
12149 expect("[name=foo] span:first").toHaveText("hello");
12150 expect.verifySteps([
12151 "/web/webclient/translations",
12152 "/web/webclient/load_menus",
12153 "get_views",
12154 "web_search_read",
12155 "has_group",
12156 ]);
12157 });
12158
12159 test("column quick create - title and placeholder", async function (assert) {
12160 await mountView({
12161 type: "kanban",
12162 resModel: "partner",
12163 arch: `
12164 <kanban default_group_by="product_id">
12165 <templates>
12166 <t t-name="card">
12167 <field name="int_field"/>
12168 </t>
12169 </templates>
12170 </kanban>`,
12171 });
12172
12173 expect(".o_column_quick_create.o_quick_create_folded").toHaveProperty(
12174 "textContent",
12175 " Add Product"
12176 );
12177
12178 await quickCreateKanbanColumn();
12179
12180 expect(
12181 ".o_column_quick_create.o_quick_create_unfolded .input-group .form-control"
12182 ).toHaveAttribute("placeholder", "Product...");
12183 });
12184
12185 test.tags("desktop");
12186 test("fold a column and drag record on it should not unfold it", async () => {
12187 await mountView({
12188 type: "kanban",
12189 resModel: "partner",
12190 arch: `
12191 <kanban>
12192 <templates>
12193 <div t-name="card">
12194 <field name="id"/>
12195 </div>
12196 </templates>
12197 </kanban>`,
12198 groupBy: ["product_id"],
12199 });
12200
12201 expect(".o_kanban_group").toHaveCount(2);
12202 expect(queryAll(".o_kanban_record", { root: getKanbanColumn(0) })).toHaveCount(2);
12203 expect(queryAll(".o_kanban_record", { root: getKanbanColumn(1) })).toHaveCount(2);
12204
12205 const clickColumnAction = await toggleKanbanColumnActions(1);
12206 clickColumnAction("Fold");
12207 await animationFrame();
12208
12209 expect(queryAll(".o_kanban_record", { root: getKanbanColumn(0) })).toHaveCount(2);
12210 expect(getKanbanColumn(1)).toHaveClass("o_column_folded");
12211 expect(getKanbanColumn(1)).toHaveText("xmo\n(2)");
12212
12213 await contains(".o_kanban_group:first-child .o_kanban_record").dragAndDrop(".o_column_folded");
12214
12215 expect(queryAll(".o_kanban_record", { root: getKanbanColumn(0) })).toHaveCount(1);
12216 expect(getKanbanColumn(1)).toHaveClass("o_column_folded");
12217 expect(getKanbanColumn(1)).toHaveText("xmo\n(3)");
12218 });
12219
12220 test.tags("desktop");
12221 test("drag record on initially folded column should not unfold it", async () => {
12222 Product._records[1].fold = true;
12223
12224 await mountView({
12225 type: "kanban",
12226 resModel: "partner",
12227 arch: `
12228 <kanban>
12229 <templates>
12230 <div t-name="card">
12231 <field name="id"/>
12232 </div>
12233 </templates>
12234 </kanban>`,
12235 groupBy: ["product_id"],
12236 });
12237
12238 expect(queryAll(".o_kanban_record", { root: getKanbanColumn(0) })).toHaveCount(2);
12239 expect(getKanbanColumn(1)).toHaveClass("o_column_folded");
12240 expect(queryText(getKanbanColumn(1))).toBe("xmo\n(2)");
12241
12242 await contains(".o_kanban_group:first-child .o_kanban_record").dragAndDrop(".o_column_folded");
12243
12244 expect(queryAll(".o_kanban_record", { root: getKanbanColumn(0) })).toHaveCount(1);
12245 expect(getKanbanColumn(1)).toHaveClass("o_column_folded");
12246 expect(queryText(getKanbanColumn(1))).toBe("xmo\n(3)");
12247 });
12248
12249 test.tags("desktop");
12250 test("drag record to folded column, with progressbars", async () => {
12251 Partner._records[0].bar = false;
12252
12253 stepAllNetworkCalls();
12254
12255 await mountView({
12256 type: "kanban",
12257 resModel: "partner",
12258 arch: `
12259 <kanban>
12260 <progressbar field="foo" colors='{"yop": "success", "gnap": "warning", "blip": "danger"}' sum_field="int_field" />
12261 <templates>
12262 <div t-name="card">
12263 <field name="id" />
12264 </div>
12265 </templates>
12266 </kanban>`,
12267 groupBy: ["bar"],
12268 });
12269
12270 expect(".o_kanban_group").toHaveCount(2);
12271 expect(".o_kanban_group:first-child .o_kanban_record").toHaveCount(2);
12272 expect(".o_kanban_group:nth-child(2) .o_kanban_record").toHaveCount(2);
12273 expect(getKanbanProgressBars(0).map((pb) => pb.style.width)).toEqual(["50%", "50%"]);
12274 expect(getKanbanProgressBars(1).map((pb) => pb.style.width)).toEqual(["50%", "50%"]);
12275 expect(getKanbanCounters()).toEqual(["6", "26"]);
12276
12277 const clickColumnAction = await toggleKanbanColumnActions(1);
12278 clickColumnAction("Fold");
12279 await animationFrame();
12280
12281 expect(queryAll(".o_kanban_record", { root: getKanbanColumn(0) })).toHaveCount(2);
12282 expect(getKanbanColumn(1)).toHaveClass("o_column_folded");
12283 expect(queryText(getKanbanColumn(1))).toBe("Yes\n(2)");
12284
12285 await contains(".o_kanban_group:first-child .o_kanban_record").dragAndDrop(
12286 ".o_kanban_group:nth-child(2)"
12287 );
12288
12289 expect(queryAll(".o_kanban_record", { root: getKanbanColumn(0) })).toHaveCount(1);
12290 expect(queryText(getKanbanColumn(1))).toBe("Yes\n(3)");
12291 expect(getKanbanProgressBars(0).map((pb) => pb.style.width)).toEqual(["100%"]);
12292 expect(getKanbanCounters()).toEqual(["-4"]);
12293 expect.verifySteps([
12294 "/web/webclient/translations",
12295 "/web/webclient/load_menus",
12296 "get_views",
12297 "read_progress_bar",
12298 "web_read_group",
12299 "has_group",
12300 "web_save",
12301 "read_progress_bar",
12302 "formatted_read_group",
12303 ]);
12304 });
12305
12306 test.tags("desktop");
12307 test("quick create record in grouped kanban in a form view dialog", async () => {
12308 Partner._fields.foo = fields.Char({ default: "ABC" });
12309 Partner._views["form"] = `<form><field name="bar"/></form>`;
12310
12311 onRpc("name_create", ({ method }) => {
12312 throw makeServerError();
12313 });
12314 stepAllNetworkCalls();
12315
12316 await mountView({
12317 type: "kanban",
12318 resModel: "partner",
12319 arch: `
12320 <kanban on_create="quick_create">
12321 <templates>
12322 <t t-name="card">
12323 <t t-if="record.foo.raw_value" t-set="foo"/>
12324 <field name="foo"/>
12325 </t>
12326 </templates>
12327 </kanban>`,
12328 groupBy: ["product_id"],
12329 });
12330
12331 expect(".o_kanban_group:first-child .o_kanban_record").toHaveCount(2, {
12332 message: "first column should contain two records",
12333 });
12334 expect(queryAllTexts(".o_kanban_group:first-child .o_kanban_record")).toEqual(["yop", "gnap"]);
12335 expect(".modal").toHaveCount(0);
12336
12337 // click on 'Create', fill the quick create and validate
12338 await createKanbanRecord();
12339 await editKanbanRecordQuickCreateInput("display_name", "new partner");
12340 await validateKanbanRecord();
12341
12342 expect(".modal").toHaveCount(1);
12343
12344 await clickModalButton({ text: "Save" });
12345
12346 expect(".o_kanban_group:first-child .o_kanban_record").toHaveCount(3, {
12347 message: "first column should contain three records",
12348 });
12349 expect(queryAllTexts(".o_kanban_group:first-child .o_kanban_record")).toEqual([
12350 "ABC",
12351 "yop",
12352 "gnap",
12353 ]);
12354 expect.verifySteps([
12355 "/web/webclient/translations",
12356 "/web/webclient/load_menus",
12357 "get_views",
12358 "web_read_group", // initial web_read_group
12359 "has_group",
12360 "onchange", // quick create
12361 "name_create", // should perform a name_create to create the record
12362 "get_views", // load views for form view dialog
12363 "onchange", // load of a virtual record in form view dialog
12364 "web_save", // save virtual record
12365 "web_read", // read the created record to get foo value
12366 "onchange", // reopen the quick create automatically
12367 ]);
12368 });
12369
12370 test.tags("desktop");
12371 test("no sample data when all groups are folded then one is unfolded", async () => {
12372 Product._records.forEach((group) => {
12373 group.fold = true;
12374 });
12375
12376 await mountView({
12377 type: "kanban",
12378 resModel: "partner",
12379 arch: `
12380 <kanban sample="1">
12381 <templates>
12382 <div t-name="card">
12383 <field name="id"/>
12384 </div>
12385 </templates>
12386 </kanban>`,
12387 groupBy: ["product_id"],
12388 });
12389
12390 expect(".o_column_folded").toHaveCount(2);
12391
12392 await contains(".o_kanban_group").click();
12393
12394 expect(".o_column_folded").toHaveCount(1);
12395 expect(".o_kanban_record").toHaveCount(2);
12396 expect("o_view_sample_data").toHaveCount(0);
12397 });
12398
12399 test.tags("desktop");
12400 test("no content helper, all groups folded with (unloaded) records", async () => {
12401 Product._records.forEach((group) => {
12402 group.fold = true;
12403 });
12404
12405 await mountView({
12406 type: "kanban",
12407 resModel: "partner",
12408 arch: `
12409 <kanban>
12410 <templates>
12411 <div t-name="card">
12412 <field name="id"/>
12413 </div>
12414 </templates>
12415 </kanban>`,
12416 groupBy: ["product_id"],
12417 });
12418
12419 expect(".o_column_folded").toHaveCount(2);
12420 expect(queryAllTexts(".o_column_title")).toEqual(["hello\n(2)", "xmo\n(2)"]);
12421 expect(".o_nocontent_help").toHaveCount(0);
12422 });
12423
12424 test.tags("desktop");
12425 test("Move multiple records in different columns simultaneously", async () => {
12426 const def = new Deferred();
12427 onRpc("read", () => def);
12428
12429 await mountView({
12430 type: "kanban",
12431 resModel: "partner",
12432 arch: `
12433 <kanban>
12434 <templates>
12435 <div t-name="card">
12436 <field name="id" />
12437 </div>
12438 </templates>
12439 </kanban>`,
12440 groupBy: ["state"],
12441 });
12442
12443 expect(getKanbanRecordTexts()).toEqual(["1", "2", "3", "4"]);
12444
12445 // Move 3 at end of 1st column
12446 await contains(".o_kanban_group:last-of-type .o_kanban_record").dragAndDrop(
12447 ".o_kanban_group:first"
12448 );
12449
12450 expect(getKanbanRecordTexts()).toEqual(["1", "3", "2", "4"]);
12451
12452 // Move 4 at end of 1st column
12453 await contains(".o_kanban_group:last-of-type .o_kanban_record").dragAndDrop(
12454 ".o_kanban_group:first"
12455 );
12456
12457 expect(getKanbanRecordTexts()).toEqual(["1", "3", "4", "2"]);
12458
12459 def.resolve();
12460 await animationFrame();
12461
12462 expect(getKanbanRecordTexts()).toEqual(["1", "3", "4", "2"]);
12463 });
12464
12465 test.tags("desktop");
12466 test("drag & drop: content scrolls when reaching the edges", async () => {
12467 await mountView({
12468 type: "kanban",
12469 resModel: "partner",
12470 arch: `
12471 <kanban>
12472 <templates>
12473 <div t-name="card">
12474 <field name="id" />
12475 </div>
12476 </templates>
12477 </kanban>`,
12478 groupBy: ["state"],
12479 });
12480
12481 const width = 600;
12482 const content = queryOne(".o_content");
12483 content.setAttribute("style", `max-width:${width}px;overflow:auto;`);
12484
12485 expect(content.scrollLeft).toBe(0);
12486 expect(content.getBoundingClientRect().width).toBe(600);
12487 expect(".o_kanban_record.o_dragged").toHaveCount(0);
12488
12489 // Drag first record of first group to the right
12490 let dragActions = await contains(".o_kanban_record").drag();
12491 await dragActions.moveTo(".o_kanban_group:nth-child(3) .o_kanban_record:first");
12492
12493 expect(".o_kanban_record.o_dragged").toHaveCount(1);
12494
12495 // wait 30 frames, should be enough (default kanban speed is 20px per tick)
12496 await advanceFrame(30);
12497
12498 // Should be at the end of the content
12499 expect(content.scrollLeft + width).toBe(content.scrollWidth);
12500
12501 // Cancel drag: press "Escape"
12502 await press("Escape");
12503 await animationFrame();
12504
12505 expect(".o_kanban_record.o_dragged").toHaveCount(0);
12506
12507 // Drag first record of last group to the left
12508 dragActions = await contains(".o_kanban_group:nth-child(3) .o_kanban_record").drag();
12509 await dragActions.moveTo(".o_kanban_record:first");
12510
12511 expect(".o_kanban_record.o_dragged").toHaveCount(1);
12512
12513 await advanceFrame(30);
12514
12515 expect(content.scrollLeft).toBe(0);
12516
12517 // Cancel drag: click outside
12518 await contains(".o_kanban_renderer").click();
12519
12520 expect(".o_kanban_record.o_dragged").toHaveCount(0);
12521 });
12522
12523 test("attribute default_order", async () => {
12524 class CustomModel extends models.Model {
12525 _name = "custom.model";
12526
12527 int = fields.Integer();
12528
12529 _records = [
12530 { id: 1, int: 1 },
12531 { id: 2, int: 3 },
12532 { id: 3, int: 2 },
12533 ];
12534 }
12535 defineModels([CustomModel]);
12536
12537 await mountView({
12538 type: "kanban",
12539 resModel: "custom.model",
12540 arch: `
12541 <kanban default_order="int">
12542 <templates>
12543 <div t-name="card">
12544 <field name="int" />
12545 </div>
12546 </templates>
12547 </kanban>`,
12548 });
12549 expect(queryAllTexts(".o_kanban_record:not(.o_kanban_ghost)")).toEqual(["1", "2", "3"]);
12550 });
12551
12552 test.tags("desktop");
12553 test("d&d records grouped by m2o with m2o displayed in records", async () => {
12554 const readIds = [[2], [1, 3, 2]];
12555 const def = new Deferred();
12556 onRpc("read", ({ method, args }) => {
12557 expect(args[0]).toEqual(readIds[1]);
12558 return def;
12559 });
12560 stepAllNetworkCalls();
12561
12562 await mountView({
12563 type: "kanban",
12564 resModel: "partner",
12565 arch: `
12566 <kanban>
12567 <templates>
12568 <t t-name="card">
12569 <field name="product_id" widget="many2one"/>
12570 </t>
12571 </templates>
12572 </kanban>`,
12573 groupBy: ["product_id"],
12574 });
12575
12576 expect.verifySteps([
12577 "/web/webclient/translations",
12578 "/web/webclient/load_menus",
12579 "get_views",
12580 "web_read_group",
12581 "has_group",
12582 ]);
12583 expect(queryAllTexts(".o_kanban_record")).toEqual(["hello", "hello", "xmo", "xmo"]);
12584
12585 await contains(".o_kanban_group:nth-child(2) .o_kanban_record").dragAndDrop(
12586 ".o_kanban_group:first-child"
12587 );
12588 expect(queryAllTexts(".o_kanban_record")).toEqual(["hello", "hello", "hello", "xmo"]);
12589
12590 def.resolve();
12591 await animationFrame();
12592
12593 expect.verifySteps(["web_save", "web_resequence"]);
12594 expect(queryAllTexts(".o_kanban_record")).toEqual(["hello", "hello", "hello", "xmo"]);
12595 });
12596
12597 test("Can't use KanbanRecord implementation details in arch", async () => {
12598 await mountView({
12599 type: "kanban",
12600 resModel: "partner",
12601 arch: `
12602 <kanban>
12603 <templates>
12604 <t t-name="card">
12605 <div>
12606 <t t-esc="__owl__"/>
12607 <t t-esc="props"/>
12608 <t t-esc="env"/>
12609 <t t-esc="render"/>
12610 </div>
12611 </t>
12612 </templates>
12613 </kanban>`,
12614 });
12615 expect(".o_kanban_record:first").toHaveInnerHTML("<div></div>");
12616 });
12617
12618 test.tags("desktop");
12619 test("rerenders only once after resequencing records", async () => {
12620 // Actually it's not once, because we must render directly after the drag&drop s.t. the dropped
12621 // record remains where it has been dropped, once again after saving/reloading the record as
12622 // we rebuild record.data, and finally after the call to resequence, to re-enable the resequence
12623 // feature on the record (canResequence props).
12624 let saveDef = new Deferred();
12625 let resequenceDef = new Deferred();
12626 const renderCounts = {};
12627 patchWithCleanup(KanbanRecord.prototype, {
12628 setup() {
12629 super.setup();
12630 onWillRender(() => {
12631 const id = this.props.record.resId;
12632 renderCounts[id] = renderCounts[id] || 0;
12633 renderCounts[id]++;
12634 });
12635 },
12636 });
12637
12638 onRpc("web_save", () => saveDef);
12639 onRpc("web_resequence", () => resequenceDef);
12640 stepAllNetworkCalls();
12641
12642 await mountView({
12643 type: "kanban",
12644 resModel: "partner",
12645 arch: `
12646 <kanban>
12647 <templates>
12648 <t t-name="card">
12649 <field name="foo"/>
12650 </t>
12651 </templates>
12652 </kanban>`,
12653 groupBy: ["product_id"],
12654 });
12655
12656 expect(renderCounts).toEqual({ 1: 1, 2: 1, 3: 1, 4: 1 });
12657
12658 // drag yop to the second column
12659 await contains(".o_kanban_group:first-child .o_kanban_record").dragAndDrop(
12660 ".o_kanban_group:nth-child(2)"
12661 );
12662
12663 expect(renderCounts).toEqual({ 1: 2, 2: 1, 3: 1, 4: 1 });
12664
12665 saveDef.resolve();
12666 await animationFrame();
12667
12668 expect(renderCounts).toEqual({ 1: 3, 2: 1, 3: 1, 4: 1 });
12669
12670 resequenceDef.resolve();
12671 await animationFrame();
12672
12673 expect(renderCounts).toEqual({ 1: 4, 2: 1, 3: 1, 4: 1 });
12674
12675 // drag gnap to the second column
12676 saveDef = new Deferred();
12677 resequenceDef = new Deferred();
12678 await contains(".o_kanban_group:first-child .o_kanban_record").dragAndDrop(
12679 ".o_kanban_group:nth-child(2)"
12680 );
12681
12682 expect(renderCounts).toEqual({ 1: 4, 2: 1, 3: 2, 4: 1 });
12683
12684 saveDef.resolve();
12685 await animationFrame();
12686
12687 expect(renderCounts).toEqual({ 1: 4, 2: 1, 3: 3, 4: 1 });
12688
12689 resequenceDef.resolve();
12690 await animationFrame();
12691
12692 expect(renderCounts).toEqual({ 1: 4, 2: 1, 3: 4, 4: 1 });
12693
12694 expect.verifySteps([
12695 "/web/webclient/translations",
12696 "/web/webclient/load_menus",
12697 "get_views",
12698 "web_read_group",
12699 "has_group",
12700 "web_save",
12701 "web_resequence",
12702 "web_save",
12703 "web_resequence",
12704 ]);
12705 });
12706
12707 test("sample server: _mockWebReadGroup API", async () => {
12708 Partner._records = [];
12709
12710 patchWithCleanup(SampleServer.prototype, {
12711 async _mockWebReadGroup() {
12712 const result = await super._mockWebReadGroup(...arguments);
12713 const { "date:month": dateValue } = result.groups[0];
12714 expect(dateValue[1]).toBe("December 2022");
12715 return result;
12716 },
12717 });
12718
12719 onRpc("web_read_group", () => ({
12720 groups: [
12721 {
12722 __count: 0,
12723 __records: [],
12724 state: false,
12725 "date:month": ["2022-12-01", "December 2022"],
12726 __extra_domain: [
12727 ["date", ">=", "2022-12-01"],
12728 ["date", "<", "2023-01-01"],
12729 ],
12730 },
12731 ],
12732 length: 1,
12733 }));
12734
12735 await mountView({
12736 arch: `
12737 <kanban sample="1">
12738 <templates>
12739 <div t-name="card">
12740 <field name="display_name"/>
12741 </div>
12742 </templates>
12743 </kanban>`,
12744 groupBy: ["date:month"],
12745 resModel: "partner",
12746 type: "kanban",
12747 noContentHelp: "No content helper",
12748 });
12749
12750 expect(".o_kanban_view .o_view_sample_data").toHaveCount(1);
12751 expect(".o_kanban_group").toHaveCount(1);
12752 expect(".o_kanban_group .o_column_title").toHaveText("December 2022");
12753 expect(".o_kanban_group .o_kanban_record").toHaveCount(16);
12754 });
12755
12756 test.tags("desktop");
12757 test("scroll on group unfold and progressbar click", async () => {
12758 Product._records[1].fold = true;
12759 onRpc(function ({ method, parent }) {
12760 expect.step(method);
12761 });
12762
12763 await mountView({
12764 type: "kanban",
12765 resModel: "partner",
12766 arch: `
12767 <kanban>
12768 <progressbar field="foo" colors='{"yop": "success", "gnap": "warning", "blip": "danger"}' sum_field="int_field" />
12769 <templates>
12770 <t t-name="card">Record</t>
12771 </templates>
12772 </kanban>`,
12773 groupBy: ["product_id"],
12774 });
12775
12776 expect.verifySteps(["get_views", "read_progress_bar", "web_read_group", "has_group"]);
12777 queryOne(".o_content").style.maxHeight = "80px";
12778 on(".o_content", "scroll", () => expect.step("scrolled"));
12779
12780 await scroll(".o_content", { top: 50 }); // scroll down to allow auto-scroll to top
12781 await contains(getKanbanProgressBars(0)[0]).click();
12782
12783 expect.verifySteps([
12784 "scrolled",
12785 "formatted_read_group",
12786 "web_search_read",
12787 "read_progress_bar",
12788 "formatted_read_group",
12789 "formatted_read_group",
12790 ]);
12791 expect(getKanbanColumn(1)).toHaveClass("o_column_folded");
12792
12793 await scroll(".o_content", { top: 50 }); // scroll down to allow auto-scroll to top
12794 await contains(getKanbanColumn(1)).click();
12795
12796 expect.verifySteps(["scrolled", "web_search_read"]);
12797 });
12798
12799 test.tags("desktop");
12800 test(`kanban view: press "hotkey" to execute header button action`, async () => {
12801 mockService("action", {
12802 doActionButton(params) {
12803 const { name } = params;
12804 expect.step(`execute_action: ${name}`);
12805 },
12806 });
12807
12808 await mountView({
12809 type: "kanban",
12810 resModel: "partner",
12811 arch: `
12812 <kanban class="o_kanban_test">
12813 <header>
12814 <button name="display" type="object" class="display" string="display" display="always" data-hotkey="a"/>
12815 </header>
12816 <field name="bar" />
12817 <templates>
12818 <t t-name="card">
12819 <field name="foo"/>
12820 </t>
12821 </templates>
12822 </kanban>`,
12823 });
12824
12825 await press(["alt", "a"]);
12826 await tick();
12827 expect.verifySteps(["execute_action: display"]);
12828 });
12829
12830 test.tags("desktop");
12831 test("action button in controlPanel with display='always'", async () => {
12832 const domain = [["id", "=", 1]];
12833
12834 mockService("action", {
12835 async doActionButton(params) {
12836 const { buttonContext, context, name, resModel, resIds, type } = params;
12837 expect.step("execute_action");
12838 // Action's own properties
12839 expect(name).toBe("display");
12840 expect(type).toBe("object");
12841
12842 // The action's execution context
12843 expect(buttonContext).toEqual({
12844 active_domain: domain,
12845 active_ids: [],
12846 active_model: "partner",
12847 });
12848
12849 expect(context).toEqual({
12850 a: true,
12851 allowed_company_ids: [1],
12852 lang: "en",
12853 tz: "taht",
12854 uid: 7,
12855 });
12856 expect(resModel).toBe("partner");
12857 expect(resIds).toEqual([]);
12858 },
12859 });
12860
12861 await mountView({
12862 type: "kanban",
12863 resModel: "partner",
12864 arch: `
12865 <kanban class="o_kanban_test">
12866 <header>
12867 <button name="display" type="object" class="display" string="display" display="always"/>
12868 <button name="display" type="object" class="display_invisible" string="invisible 1" display="always" invisible="1"/>
12869 <button name="display" type="object" class="display_invisible_2" string="invisible context" display="always" invisible="context.get('a')"/>
12870 <button name="default-selection" type="object" class="default-selection" string="default-selection"/>
12871 </header>
12872 <templates>
12873 <t t-name="card">
12874 <field name="foo" />
12875 </t>
12876 </templates>
12877 </kanban>`,
12878 domain,
12879 context: {
12880 a: true,
12881 },
12882 });
12883
12884 const cpButtons = queryAll(".o_control_panel_main_buttons button:visible");
12885 expect(queryAllTexts(cpButtons)).toEqual(["New", "display"]);
12886 expect(cpButtons[1]).toHaveClass("display");
12887
12888 await contains(cpButtons[1]).click();
12889
12890 expect.verifySteps(["execute_action"]);
12891 });
12892
12893 test.tags("desktop");
12894 test("Keep scrollTop when loading records with load more", async () => {
12895 Partner._records[0].bar = false;
12896 Partner._records[1].bar = false;
12897 await mountView({
12898 type: "kanban",
12899 resModel: "partner",
12900 arch: `
12901 <kanban>
12902 <templates>
12903 <t t-name="card">
12904 <div style="height:1000px;"><field name="id"/></div>
12905 </t>
12906 </templates>
12907 </kanban>`,
12908 groupBy: ["bar"],
12909 limit: 1,
12910 });
12911 const clickKanbanLoadMoreButton = queryFirst(".o_kanban_load_more button");
12912 clickKanbanLoadMoreButton.scrollIntoView();
12913 const previousScrollTop = queryOne(".o_content").scrollTop;
12914 clickKanbanLoadMoreButton.click();
12915 await animationFrame();
12916 expect(previousScrollTop).not.toBe(0, { message: "Should not have the scrollTop value at 0" });
12917 expect(queryOne(".o_content").scrollTop).toBe(previousScrollTop);
12918 });
12919
12920 test("Kanban: no reset of the groupby when a non-empty column is deleted", async () => {
12921 await mountView({
12922 type: "kanban",
12923 resModel: "partner",
12924 arch: `
12925 <kanban default_group_by="product_id">
12926 <templates>
12927 <t t-name="card">
12928 <field name="foo"/>
12929 </t>
12930 </templates>
12931 </kanban>`,
12932 searchViewArch: `
12933 <search>
12934 <filter name="groupby_category" string="Category" context="{'group_by': 'category_ids'}"/>
12935 </search>`,
12936 });
12937
12938 // validate presence of the search arch info
12939 await toggleSearchBarMenu();
12940 expect(".o_group_by_menu span.o_menu_item").toHaveCount(1);
12941
12942 // select the groupby:category_ids filter
12943 await contains(".o_group_by_menu span.o_menu_item").click();
12944 // check the initial rendering
12945 expect(".o_kanban_group").toHaveCount(3, { message: "should have three columns" });
12946
12947 // check availability of delete action in kanban header's config dropdown
12948 await toggleKanbanColumnActions(2);
12949 expect(queryAll(".o_group_delete", { root: getKanbanColumnDropdownMenu(2) })).toHaveCount(1, {
12950 message: "should be able to delete the column",
12951 });
12952
12953 // delete second column (first cancel the confirm request, then confirm)
12954 let clickColumnAction = await toggleKanbanColumnActions(1);
12955 await clickColumnAction("Delete");
12956 await contains(".o_dialog footer .btn-secondary").click();
12957
12958 expect(queryText(".o_column_title", { root: getKanbanColumn(1) })).toBe("gold\n(1)");
12959
12960 clickColumnAction = await toggleKanbanColumnActions(1);
12961 await clickColumnAction("Delete");
12962 await contains(".o_dialog footer .btn-primary").click();
12963
12964 expect(".o_kanban_group").toHaveCount(2, { message: "should now have two columns" });
12965 expect(queryText(".o_column_title", { root: getKanbanColumn(1) })).toBe("silver\n(1)");
12966 expect(queryText(".o_column_title", { root: getKanbanColumn(0) })).toBe("None\n(3)");
12967 });
12968
12969 test.tags("desktop");
12970 test("searchbar filters are displayed directly", async () => {
12971 let def;
12972 onRpc("web_search_read", () => def);
12973
12974 await mountView({
12975 type: "kanban",
12976 resModel: "partner",
12977 arch: `
12978 <kanban>
12979 <templates>
12980 <t t-name="card">
12981 <field name="foo"/>
12982 </t>
12983 </templates>
12984 </kanban>`,
12985 searchViewArch: `
12986 <search>
12987 <filter name="some_filter" string="Some Filter" domain="[['foo', '!=', 'bar']]"/>
12988 </search>`,
12989 });
12990
12991 expect(getFacetTexts()).toEqual([]);
12992
12993 // toggle a filter, and slow down the web_search_read rpc
12994 def = new Deferred();
12995 await toggleSearchBarMenu();
12996 await toggleMenuItem("Some Filter");
12997 expect(getFacetTexts()).toEqual(["Some Filter"]);
12998
12999 def.resolve();
13000 await animationFrame();
13001 expect(getFacetTexts()).toEqual(["Some Filter"]);
13002 });
13003
13004 test("searchbar filters are displayed directly (with progressbar)", async () => {
13005 let def;
13006 onRpc("read_progress_bar", () => def);
13007
13008 await mountView({
13009 type: "kanban",
13010 resModel: "partner",
13011 arch: `
13012 <kanban>
13013 <progressbar field="state" colors='{"abc": "success", "def": "warning", "ghi": "danger"}' />
13014 <templates>
13015 <t t-name="card">
13016 <field name="foo"/>
13017 </t>
13018 </templates>
13019 </kanban>`,
13020 groupBy: ["int_field"],
13021 searchViewArch: `
13022 <search>
13023 <filter name="some_filter" string="Some Filter" domain="[['foo', '!=', 'bar']]"/>
13024 </search>`,
13025 });
13026
13027 expect(getFacetTexts()).toEqual([]);
13028
13029 // toggle a filter, and slow down the read_progress_bar rpc
13030 def = new Deferred();
13031 await toggleSearchBarMenu();
13032 await toggleMenuItem("Some Filter");
13033
13034 expect(getFacetTexts()).toEqual(["Some Filter"]);
13035
13036 def.resolve();
13037 await animationFrame();
13038 expect(getFacetTexts()).toEqual(["Some Filter"]);
13039 });
13040
13041 test.tags("desktop");
13042 test(`searchbar in kanban view doesn't take focus after unselected all items`, async () => {
13043 await mountView({
13044 resModel: "partner",
13045 type: "kanban",
13046 arch: `
13047 <kanban>
13048 <templates>
13049 <t t-name="card">
13050 <field name="foo"/>
13051 </t>
13052 </templates>
13053 </kanban>`,
13054 });
13055 expect(`.o_searchview_input`).toBeFocused({
13056 message: "The search input should have the focus",
13057 });
13058
13059 await contains(`.o_kanban_record`).click({ altKey: true });
13060 await contains(`.o_kanban_record.o_record_selected`).click();
13061 expect(`.o_searchview_input`).not.toBeFocused({
13062 message: "The search input shouldn't have the focus",
13063 });
13064 });
13065
13066 test.tags("desktop");
13067 test("group by properties and drag and drop", async () => {
13068 expect.assertions(7);
13069
13070 Partner._fields.properties = fields.Properties({
13071 definition_record: "parent_id",
13072 definition_record_field: "properties_definition",
13073 });
13074 Partner._fields.parent_id = fields.Many2one({ relation: "partner" });
13075 Partner._fields.properties_definition = fields.PropertiesDefinition();
13076
13077 Partner._records[0].properties_definition = [
13078 {
13079 name: "my_char",
13080 string: "My Char",
13081 type: "char",
13082 },
13083 ];
13084 Partner._records[1].parent_id = 1;
13085 Partner._records[2].parent_id = 1;
13086 Partner._records[3].parent_id = 2;
13087
13088 onRpc("web_read_group", () => ({
13089 groups: [
13090 {
13091 "properties.my_char": false,
13092 __extra_domain: [["properties.my_char", "=", false]],
13093 __count: 2,
13094 },
13095 {
13096 "properties.my_char": "aaa",
13097 __extra_domain: [["properties.my_char", "=", "aaa"]],
13098 __count: 1,
13099 __records: [
13100 {
13101 id: 2,
13102 properties: [
13103 {
13104 name: "my_char",
13105 string: "My Char",
13106 type: "char",
13107 value: "aaa",
13108 },
13109 ],
13110 },
13111 ],
13112 },
13113 {
13114 "properties.my_char": "bbb",
13115 __extra_domain: [["properties.my_char", "=", "bbb"]],
13116 __count: 1,
13117 __records: [
13118 {
13119 id: 3,
13120 properties: [
13121 {
13122 name: "my_char",
13123 string: "My Char",
13124 type: "char",
13125 value: "bbb",
13126 },
13127 ],
13128 },
13129 ],
13130 },
13131 ],
13132 length: 3,
13133 }));
13134 onRpc("web_resequence", () => {
13135 expect.step("resequence");
13136 return [];
13137 });
13138 onRpc("web_save", ({ args }) => {
13139 expect.step("web_save");
13140 const expected = {
13141 properties: [
13142 {
13143 name: "my_char",
13144 string: "My Char",
13145 type: "char",
13146 value: "bbb",
13147 },
13148 ],
13149 };
13150 expect(args[1]).toEqual(expected);
13151 });
13152 onRpc("get_property_definition", ({ args }) => {
13153 expect.step("get_property_definition");
13154 return {
13155 name: "my_char",
13156 type: "char",
13157 };
13158 });
13159
13160 await mountView({
13161 type: "kanban",
13162 resModel: "partner",
13163 arch: `
13164 <kanban on_create="quick_create">
13165 <templates>
13166 <t t-name="card">
13167 <field name="foo"/>
13168 <field name="properties"/>
13169 </t>
13170 </templates>
13171 </kanban>`,
13172 groupBy: ["properties.my_char"],
13173 });
13174
13175 expect.verifySteps(["get_property_definition"]);
13176 expect(".o_kanban_group:nth-child(2) .o_kanban_record").toHaveCount(1);
13177 expect(".o_kanban_group:nth-child(3) .o_kanban_record").toHaveCount(1);
13178
13179 await contains(".o_kanban_group:nth-child(2) .o_kanban_record").dragAndDrop(
13180 ".o_kanban_group:nth-child(3)"
13181 );
13182
13183 expect.verifySteps(["web_save", "resequence"]);
13184 expect(".o_kanban_group:nth-child(2) .o_kanban_record").toHaveCount(0);
13185 expect(".o_kanban_group:nth-child(3) .o_kanban_record").toHaveCount(2);
13186 });
13187
13188 test("kanbans with basic and custom compiler, same arch", async () => {
13189 // In this test, the exact same arch will be rendered by 2 different kanban renderers:
13190 // once with the basic one, and once with a custom renderer having a custom compiler. The
13191 // purpose of the test is to ensure that the template is compiled twice, once by each
13192 // compiler, even though the arch is the same.
13193 class MyKanbanCompiler extends KanbanCompiler {
13194 setup() {
13195 super.setup();
13196 this.compilers.push({ selector: "div", fn: this.compileDiv });
13197 }
13198
13199 compileDiv(node, params) {
13200 const compiledNode = this.compileGenericNode(node, params);
13201 compiledNode.setAttribute("class", "my_kanban_compiler");
13202 return compiledNode;
13203 }
13204 }
13205 viewRegistry.add("my_kanban", {
13206 ...kanbanView,
13207 Compiler: MyKanbanCompiler,
13208 });
13209 after(() => viewRegistry.remove("my_kanban"));
13210
13211 Partner._fields.one2many = fields.One2many({ relation: "partner" });
13212 Partner._records[0].one2many = [1];
13213 Partner._views["form"] = `<form><field name="one2many" mode="kanban"/></form>`;
13214 Partner._views["kanban"] = `
13215 <kanban js_class="my_kanban">
13216 <templates>
13217 <t t-name="card">
13218 <div><field name="foo"/></div>
13219 </t>
13220 </templates>
13221 </kanban>`;
13222
13223 await mountWithCleanup(WebClient);
13224 await getService("action").doAction({
13225 res_model: "partner",
13226 type: "ir.actions.act_window",
13227 views: [
13228 [false, "kanban"],
13229 [false, "form"],
13230 ],
13231 });
13232
13233 // main kanban, custom view
13234 expect(".o_kanban_view").toHaveCount(1);
13235 expect(".o_my_kanban_view").toHaveCount(1);
13236 expect(".my_kanban_compiler").toHaveCount(4);
13237
13238 // switch to form
13239 await contains(".o_kanban_record").click();
13240 await animationFrame();
13241 expect(".o_form_view").toHaveCount(1);
13242 expect(".o_form_view .o_field_widget[name=one2many]").toHaveCount(1);
13243
13244 // x2many kanban, basic renderer
13245 expect(".o_kanban_record:not(.o_kanban_ghost):not(.o-kanban-button-new)").toHaveCount(1);
13246 expect(".my_kanban_compiler").toHaveCount(0);
13247 });
13248
13249 test("grouped on field with readonly expression depending on context", async () => {
13250 await mountView({
13251 type: "kanban",
13252 resModel: "partner",
13253 arch: `
13254 <kanban>
13255 <templates>
13256 <t t-name="card">
13257 <field name="product_id" readonly="context.get('abc')" />
13258 </t>
13259 </templates>
13260 </kanban>`,
13261 groupBy: ["product_id"],
13262 context: { abc: true },
13263 });
13264
13265 expect(".o_kanban_group:first-child .o_kanban_record").toHaveCount(2);
13266 expect(".o_kanban_group:nth-child(2) .o_kanban_record").toHaveCount(2);
13267
13268 await contains(".o_kanban_group:first-child .o_kanban_record").dragAndDrop(
13269 ".o_kanban_group:nth-child(2)"
13270 );
13271
13272 expect(".o_kanban_group:first-child .o_kanban_record").toHaveCount(2);
13273 expect(".o_kanban_group:nth-child(2) .o_kanban_record").toHaveCount(2);
13274 });
13275
13276 test.tags("desktop");
13277 test("grouped on field with readonly expression depending on fields", async () => {
13278 // Fields are not available in the current context as the drag and drop must be enabled globally
13279 // for the view, it's not a per record thing.
13280 // So if the readonly expression contains fields, it will resolve to readonly === false and
13281 // the drag and drop will be enabled.
13282 await mountView({
13283 type: "kanban",
13284 resModel: "partner",
13285 arch: `
13286 <kanban>
13287 <templates>
13288 <t t-name="card">
13289 <field name="foo" />
13290 <field name="product_id" readonly="foo == 'yop'" />
13291 </t>
13292 </templates>
13293 </kanban>`,
13294 groupBy: ["product_id"],
13295 });
13296
13297 expect(".o_kanban_group:first-child .o_kanban_record").toHaveCount(2);
13298 expect(".o_kanban_group:nth-child(2) .o_kanban_record").toHaveCount(2);
13299
13300 await contains(".o_kanban_group:first-child .o_kanban_record").dragAndDrop(
13301 ".o_kanban_group:nth-child(2)"
13302 );
13303
13304 expect(".o_kanban_group:first-child .o_kanban_record").toHaveCount(1);
13305 expect(".o_kanban_group:nth-child(2) .o_kanban_record").toHaveCount(3);
13306 });
13307
13308 test.tags("desktop");
13309 test("quick create a column by pressing enter when input is focused", async () => {
13310 await mountView({
13311 type: "kanban",
13312 resModel: "partner",
13313 arch: `
13314 <kanban default_group_by="product_id">
13315 <templates>
13316 <t t-name="card">
13317 <field name="foo"/>
13318 </t>
13319 </templates>
13320 </kanban>`,
13321 groupBy: ["product_id"],
13322 });
13323
13324 expect(".o_kanban_group").toHaveCount(2);
13325
13326 await quickCreateKanbanColumn();
13327
13328 // We don't use the editInput helper as it would trigger a change event automatically.
13329 // We need to wait for the enter key to trigger the event.
13330 await press("N");
13331 await press("e");
13332 await press("w");
13333 await press("Enter");
13334 await animationFrame();
13335
13336 expect(".o_kanban_group").toHaveCount(3);
13337 });
13338
13339 test("Correct values for progress bar with toggling filter and slow RPC", async () => {
13340 let def;
13341 onRpc("read_progress_bar", () => def);
13342
13343 await mountView({
13344 type: "kanban",
13345 resModel: "partner",
13346 arch: `
13347 <kanban>
13348 <progressbar field="state" colors='{"abc": "success", "def": "warning", "ghi": "danger"}' />
13349 <templates>
13350 <t t-name="card">
13351 <field name="foo"/>
13352 </t>
13353 </templates>
13354 </kanban>`,
13355 groupBy: ["product_id"],
13356 searchViewArch: `
13357 <search>
13358 <filter name="some_filter" string="Some Filter" domain="[['state', '!=', 'ghi']]"/>
13359 </search>`,
13360 });
13361
13362 expect(".o_kanban_record").toHaveCount(4);
13363 // abc: 1, ghi: 1
13364 expect(getKanbanProgressBars(1).map((pb) => pb.style.width)).toEqual(["50%", "50%"]);
13365
13366 // toggle a filter, and slow down the read_progress_bar rpc
13367 def = new Deferred();
13368 await toggleSearchBarMenu();
13369 await toggleMenuItem("Some Filter");
13370 // abc: 1, ghi: 1
13371 expect(getKanbanProgressBars(1).map((pb) => pb.style.width)).toEqual(["50%", "50%"]);
13372
13373 def.resolve();
13374 await animationFrame();
13375 // After the call to read_progress_bar has resolved, the values should be updated correctly
13376 expect(".o_kanban_record").toHaveCount(2);
13377 // abc: 1
13378 expect(getKanbanProgressBars(1).map((pb) => pb.style.width)).toEqual(["100%"]);
13379 });
13380
13381 test("group by numeric field (with aggregator)", async () => {
13382 onRpc("web_read_group", ({ kwargs }) => {
13383 expect(kwargs.groupby).toEqual(["int_field"]);
13384 expect(kwargs.aggregates).toEqual([]); // No progressbar - no aggregate needed
13385 expect.step("web_read_group");
13386 });
13387 await mountView({
13388 type: "kanban",
13389 resModel: "partner",
13390 arch: `
13391 <kanban class="o_kanban_test">
13392 <field name="int_field" />
13393 <field name="float_field" />
13394 <templates>
13395 <t t-name="card">
13396 <div>
13397 <field name="foo" />
13398 </div>
13399 </t>
13400 </templates>
13401 </kanban>`,
13402 groupBy: ["int_field"],
13403 });
13404 expect.verifySteps(["web_read_group"]);
13405 });
13406
13407 test.tags("desktop");
13408 test("click on empty kanban must shake the NEW button", async () => {
13409 onRpc("web_read_group", () =>
13410 // override read_group to return empty groups, as this is
13411 // the case for several models (e.g. project.task grouped
13412 // by stage_id)
13413 ({
13414 groups: [
13415 {
13416 __extra_domain: [["product_id", "=", 3]],
13417 __count: 0,
13418 product_id: [3, "xplone"],
13419 },
13420 {
13421 __extra_domain: [["product_id", "=", 5]],
13422 __count: 0,
13423 product_id: [5, "xplan"],
13424 },
13425 ],
13426 length: 2,
13427 })
13428 );
13429
13430 await mountView({
13431 type: "kanban",
13432 resModel: "partner",
13433 arch: `
13434 <kanban on_create="quick_create">
13435 <templates>
13436 <t t-name="card">
13437 <field name="foo"/>
13438 </t>
13439 </templates>
13440 </kanban>`,
13441 groupBy: ["product_id"],
13442 });
13443
13444 expect(".o_kanban_group").toHaveCount(2, { message: "there should be 2 columns" });
13445 expect(".o_kanban_record").toHaveCount(0, { message: "both columns should be empty" });
13446
13447 await click(".o_kanban_renderer");
13448
13449 expect("[data-bounce-button]").toHaveClass("o_catch_attention");
13450 });
13451
13452 test.tags("mobile");
13453 test("Should load grouped kanban with folded column", async () => {
13454 Product._records[1].fold = true;
13455 await mountView({
13456 type: "kanban",
13457 resModel: "partner",
13458 arch: `
13459 <kanban>
13460 <progressbar field="foo" colors='{"yop": "success", "blip": "danger"}'/>
13461 <templates>
13462 <t t-name="card">
13463 <field name="foo"/>
13464 </t>
13465 </templates>
13466 </kanban>`,
13467 groupBy: ["product_id"],
13468 });
13469 expect(".o_column_progress").toHaveCount(2, { message: "Should have 2 progress bar" });
13470 expect(".o_kanban_group").toHaveCount(2, { message: "Should have 2 grouped column" });
13471 expect(".o_kanban_record").toHaveCount(2, { message: "Should have 2 loaded record" });
13472 expect(".o_kanban_load_more").toHaveCount(1, {
13473 message: "Should have a folded column with a load more button",
13474 });
13475 await contains(".o_kanban_load_more button").click();
13476 expect(".o_kanban_load_more").toHaveCount(0, { message: "Shouldn't have a load more button" });
13477 expect(".o_kanban_record").toHaveCount(4, { message: "Should have 4 loaded record" });
13478 });
13479
13480 test("kanban records are middle clickable by default", async () => {
13481 patchWithCleanup(browser, {
13482 open: (url) => {
13483 expect.step(`opened in new window: ${url}`);
13484 },
13485 });
13486 patchWithCleanup(browser.sessionStorage, {
13487 setItem(key, value) {
13488 expect.step(`set ${key}-${value}`);
13489 super.setItem(key, value);
13490 },
13491 getItem(key) {
13492 const res = super.getItem(key);
13493 expect.step(`get ${key}-${res}`);
13494 return res;
13495 },
13496 });
13497 Partner._views.kanban = /* xml */ `
13498 <kanban>
13499 <templates>
13500 <t t-name="card">
13501 <field name="foo"/>
13502 </t>
13503 </templates>
13504 </kanban>`;
13505 Partner._views.form = /* xml */ `
13506 <form>
13507 <field name="product_id"/>
13508 <field name="foo"/>
13509 </form>`;
13510
13511 await mountWithCleanup(WebClient);
13512 await getService("action").doAction({
13513 id: 1,
13514 res_model: "partner",
13515 type: "ir.actions.act_window",
13516 views: [
13517 [false, "kanban"],
13518 [false, "form"],
13519 ],
13520 });
13521
13522 await contains(".o_kanban_record").click({ ctrlKey: true });
13523 expect.verifySteps([
13524 "get menu_id-null",
13525 "get current_lang-null",
13526 "get current_state-null",
13527 "get current_action-null",
13528 'set current_state-{"actionStack":[{"displayName":"","action":1,"view_type":"kanban"}],"action":1}',
13529 'set current_action-{"id":1,"res_model":"partner","type":"ir.actions.act_window","views":[[false,"kanban"],[false,"form"]]}',
13530 "set current_lang-en",
13531 'get current_action-{"id":1,"res_model":"partner","type":"ir.actions.act_window","views":[[false,"kanban"],[false,"form"]]}',
13532 'get current_state-{"actionStack":[{"displayName":"","action":1,"view_type":"kanban"}],"action":1}',
13533 'set current_action-{"id":1,"res_model":"partner","type":"ir.actions.act_window","views":[[false,"kanban"],[false,"form"]]}',
13534 'set current_state-{"actionStack":[{"displayName":"","action":1,"view_type":"kanban"},{"displayName":"","action":1,"view_type":"form","resId":1}],"resId":1,"action":1}',
13535 "opened in new window: /odoo/action-1/1",
13536 'set current_action-{"id":1,"res_model":"partner","type":"ir.actions.act_window","views":[[false,"kanban"],[false,"form"]]}',
13537 'set current_state-{"actionStack":[{"displayName":"","action":1,"view_type":"kanban"}],"action":1}',
13538 ]);
13539 });
13540
13541 test("display 'None' for false group, when grouped by char field", async () => {
13542 Partner._records[0].foo = false;
13543
13544 await mountView({
13545 type: "kanban",
13546 resModel: "partner",
13547 arch: `
13548 <kanban>
13549 <templates>
13550 <t t-name="card">
13551 <field name="foo"/>
13552 </t>
13553 </templates>
13554 </kanban>`,
13555 groupBy: ["foo"],
13556 });
13557
13558 expect(".o_kanban_group:first-child .o_column_title").toHaveText("None\n(1)");
13559 });
13560
13561 test("display '0' for false group, when grouped by int field", async () => {
13562 Partner._records[0].int_field = 0;
13563
13564 await mountView({
13565 type: "kanban",
13566 resModel: "partner",
13567 arch: `
13568 <kanban>
13569 <templates>
13570 <t t-name="card">
13571 <field name="int_field"/>
13572 </t>
13573 </templates>
13574 </kanban>`,
13575 groupBy: ["int_field"],
13576 });
13577
13578 expect(".o_kanban_group:first-child .o_column_title").toHaveText("0\n(1)");
13579 });
13580
13581 test("display the field's falsy_value_label for false group, if defined", async () => {
13582 Partner._fields.foo.falsy_value_label = "I'm the false group";
13583 Partner._records[0].foo = false;
13584
13585 await mountView({
13586 type: "kanban",
13587 resModel: "partner",
13588 arch: `
13589 <kanban>
13590 <templates>
13591 <t t-name="card">
13592 <field name="foo"/>
13593 </t>
13594 </templates>
13595 </kanban>`,
13596 groupBy: ["foo"],
13597 });
13598
13599 expect(".o_kanban_group:first-child .o_column_title").toHaveText("I'm the false group\n(1)");
13600 });
13601
13602 test("selection can be enabled with the 'alt' key", async () => {
13603 Product._records[1].fold = true;
13604 await mountView({
13605 type: "kanban",
13606 resModel: "partner",
13607 arch: `
13608 <kanban>
13609 <progressbar field="foo" colors='{"yop": "success", "blip": "danger"}'/>
13610 <templates>
13611 <t t-name="card">
13612 <field name="foo"/>
13613 </t>
13614 </templates>
13615 </kanban>`,
13616 groupBy: ["product_id"],
13617 });
13618 expect(".o_selection_box").toHaveCount(0);
13619 await keyDown("alt");
13620 await animationFrame();
13621 expect(".o_kanban_record").toHaveClass("o_record_selection_available");
13622 expect(".o_kanban_record > .o_record_selection_tooltip").toHaveText("Click to select");
13623 await contains(".o_kanban_record:nth-of-type(1)").click();
13624 expect(".o_selection_box").toHaveCount(1);
13625 await keyUp("alt");
13626 await animationFrame();
13627 await contains(".o_kanban_record:nth-of-type(2)").click();
13628 expect(".o_selection_box span > b").toHaveText("2", {
13629 message: "selection counter has the right number of selected items",
13630 });
13631 expect(".o_record_selected").toHaveCount(2);
13632 });
13633
13634 test.tags("desktop");
13635 test("selection is reset when dragging is effective", async () => {
13636 mockTouch(true);
13637 Product._records[1].fold = true;
13638 await mountView({
13639 type: "kanban",
13640 resModel: "partner",
13641 arch: `
13642 <kanban>
13643 <progressbar field="foo" colors='{"yop": "success", "blip": "danger"}'/>
13644 <templates>
13645 <t t-name="card">
13646 <field name="foo"/>
13647 </t>
13648 </templates>
13649 </kanban>`,
13650 groupBy: ["product_id"],
13651 });
13652 expect(".o_selection_box").toHaveCount(0);
13653 const { moveTo } = await drag(".o_kanban_record:nth-of-type(1)");
13654 await advanceTime(600);
13655 expect(".o_selection_box").toHaveCount(1);
13656 await moveTo(".o_kanban_group:nth-of-type(2)");
13657 await runAllTimers();
13658 expect(".o_selection_box").toHaveCount(0);
13659 });
13660
13661 test("selection can be enabled by long touch", async () => {
13662 mockTouch(true);
13663 await mountView({
13664 type: "kanban",
13665 resModel: "partner",
13666 arch: `
13667 <kanban>
13668 <templates>
13669 <t t-name="card">
13670 <field name="foo"/>
13671 </t>
13672 </templates>
13673 </kanban>`,
13674 });
13675 expect(".o_selection_box").toHaveCount(0);
13676 await drag(".o_kanban_record:nth-of-type(2)");
13677 await advanceTime(400);
13678 expect(".o_selection_box").toHaveCount(1);
13679 });
13680
13681 test("selection can be enabled by long touch with drag & drop enabled", async () => {
13682 mockTouch(true);
13683 Product._records[1].fold = true;
13684 await mountView({
13685 type: "kanban",
13686 resModel: "partner",
13687 arch: `
13688 <kanban>
13689 <progressbar field="foo" colors='{"yop": "success", "blip": "danger"}'/>
13690 <templates>
13691 <t t-name="card">
13692 <field name="foo"/>
13693 </t>
13694 </templates>
13695 </kanban>`,
13696 groupBy: ["product_id"],
13697 });
13698 expect(".o_selection_box").toHaveCount(0);
13699 const { drop } = await drag(".o_kanban_record:nth-of-type(1)");
13700 await advanceTime(400);
13701 expect(".o_selection_box").toHaveCount(0, {
13702 message: "touch delay is longer when drag & drop is enabled",
13703 });
13704 await drop();
13705 const { drop: secondDrop } = await drag(".o_kanban_record:nth-of-type(1)");
13706 await advanceTime(600);
13707 expect(".o_selection_box").toHaveCount(1);
13708 await secondDrop();
13709 await contains(".o_kanban_record:nth-of-type(2)").click();
13710 expect(".o_selection_box span > b").toHaveText("2", {
13711 message: "selection counter has the right number of selected items",
13712 });
13713 expect(".o_record_selected").toHaveCount(2);
13714 await contains(".o_kanban_record:nth-of-type(1)").click();
13715 expect(".o_record_selected").toHaveCount(1);
13716 });
13717
13718 test.tags("desktop");
13719 test("selection can be enabled by pressing 'space' key", async () => {
13720 Product._records[1].fold = true;
13721 await mountView({
13722 type: "kanban",
13723 resModel: "partner",
13724 arch: `
13725 <kanban>
13726 <templates>
13727 <t t-name="card">
13728 <field name="foo"/>
13729 </t>
13730 </templates>
13731 </kanban>`,
13732 });
13733 expect(".o_selection_box").toHaveCount(0);
13734 await press("ArrowDown");
13735 await press("Space");
13736 await animationFrame();
13737 expect(".o_selection_box").toHaveCount(1);
13738 await press("ArrowDown");
13739 await press("Space");
13740 await animationFrame();
13741 expect(".o_record_selected").toHaveCount(2);
13742 await press("ArrowDown");
13743 await press("ArrowDown");
13744 await keyDown("Shift");
13745 await press("Space");
13746 await animationFrame();
13747 expect(".o_record_selected").toHaveCount(4);
13748 });
13749
13750 test.tags("desktop");
13751 test("selection can be enabled by pressing 'shift + space' key", async () => {
13752 await mountView({
13753 type: "kanban",
13754 resModel: "partner",
13755 arch: `
13756 <kanban>
13757 <templates>
13758 <t t-name="card">
13759 <field name="foo"/>
13760 </t>
13761 </templates>
13762 </kanban>`,
13763 });
13764 expect(".o_selection_box").toHaveCount(0);
13765 await press("ArrowDown");
13766 await keyDown("Shift");
13767 await press("Space");
13768 await animationFrame();
13769 expect(".o_record_selected").toHaveCount(1);
13770 await keyUp("Shift");
13771 await press("ArrowDown");
13772 await press("ArrowDown");
13773 await keyDown("Shift");
13774 await press("Space");
13775 await animationFrame();
13776 expect(".o_record_selected").toHaveCount(3);
13777 });
13778
13779 test.tags("desktop");
13780 test("drag and drop records and quickly open a record", async () => {
13781 Partner._views.kanban = /* xml */ `
13782 <kanban>
13783 <templates>
13784 <t t-name="card">
13785 <div><field name="foo"/></div>
13786 </t>
13787 </templates>
13788 </kanban>`;
13789 Partner._views.form = /* xml */ `
13790 <form>
13791 <field name="foo"/>
13792 </form>`;
13793
13794 const defs = [new Deferred(), new Deferred()];
13795 let saveCount = 0;
13796 onRpc("web_save", () => {
13797 expect.step("web_save");
13798 return defs[saveCount++];
13799 });
13800
13801 await mountWithCleanup(WebClient);
13802 await getService("action").doAction({
13803 res_model: "partner",
13804 type: "ir.actions.act_window",
13805 views: [
13806 [false, "kanban"],
13807 [false, "form"],
13808 ],
13809 context: {
13810 group_by: ["product_id"],
13811 },
13812 });
13813
13814 expect(".o_kanban_group:first-child .o_kanban_record").toHaveCount(2);
13815 expect(".o_kanban_group:nth-child(2) .o_kanban_record").toHaveCount(2);
13816
13817 await contains(".o_kanban_group:first-child .o_kanban_record").dragAndDrop(
13818 ".o_kanban_group:nth-child(2)"
13819 );
13820 await contains(".o_kanban_group:first-child .o_kanban_record").dragAndDrop(
13821 ".o_kanban_group:nth-child(2)"
13822 );
13823 await contains(".o_kanban_record:eq(0)").click();
13824 expect(".o_kanban_view").toHaveCount(1);
13825 expect(".o_kanban_group:first-child .o_kanban_record").toHaveCount(0);
13826 expect(".o_kanban_group:nth-child(2) .o_kanban_record").toHaveCount(4);
13827 expect.verifySteps(["web_save"]);
13828
13829 defs[0].resolve();
13830 await animationFrame();
13831 // because of the mutex in the model, the second web_save is done only once the first one
13832 // returned, but that rpc can't be done if the component has already been destroyed.
13833 expect(".o_kanban_view").toHaveCount(1);
13834 expect(".o_kanban_group:first-child .o_kanban_record").toHaveCount(0);
13835 expect(".o_kanban_group:nth-child(2) .o_kanban_record").toHaveCount(4);
13836 expect.verifySteps(["web_save"]);
13837
13838 defs[1].resolve();
13839 await animationFrame();
13840 expect(".o_form_view").toHaveCount(1);
13841 });
13842
13843 test.tags("desktop");
13844 test("groups will be scrolled to on unfold if outside of viewport", async () => {
13845 for (let i = 0; i < 12; i++) {
13846 Product._records.push({ id: 8 + i, name: `column ${i}` });
13847 Partner._records.push({ id: 20 + i, foo: "dumb entry", product_id: 8 + i });
13848 }
13849 Product._records[2].fold = true;
13850 Product._records[8].fold = true;
13851 Product._records[9].fold = true;
13852
13853 await mountView({
13854 type: "kanban",
13855 resModel: "partner",
13856 arch: `
13857 <kanban default_group_by="product_id">
13858 <templates>
13859 <t t-name="card">
13860 <field name="foo"/>
13861 </t>
13862 </templates>
13863 </kanban>`,
13864 });
13865 disableAnimations();
13866 expect(".o_content").toHaveProperty("scrollLeft", 0);
13867 await contains(".o_column_folded:eq(0)").click();
13868 await animationFrame();
13869 // Group completely inside the viewport after unfold, no scroll
13870 expect(".o_content").toHaveProperty("scrollLeft", 0);
13871 await contains(".o_content").scroll({ left: 1500 });
13872 await contains(".o_column_folded:eq(0)").click();
13873 // Group is followed by a folded group which is outside the viewport
13874 // after unfold, scroll to that group
13875 expect(".o_content").toHaveProperty("scrollLeft", 1844);
13876 let { x, width } = queryRect(".o_column_folded:eq(0)");
13877 // TODO JUM: change digits option
13878 expect(x + width).toBeCloseTo(window.innerWidth - 1, {
13879 digits: 0,
13880 message:
13881 "the next group (which is folded) should stick to the right of the screen after the scroll",
13882 });
13883 expect(".o_column_folded:eq(0)").toHaveText("column 7\n(1)");
13884 await contains('.o_kanban_group:contains("column 7 (1)")').click();
13885 expect(".o_content").toHaveProperty("scrollLeft", 2154);
13886 ({ x, width } = queryRect('.o_kanban_group:contains("column 7 (1)")'));
13887 // TODO JUM: change digits option
13888 expect(x + width).toBeCloseTo(window.innerWidth, {
13889 digits: 0,
13890 message:
13891 "this group was not followed by a folded group so it will be the one to stick to the right of the screen after the scroll",
13892 });
13893 // scroll to the end
13894 await contains(".o_content").scroll({ left: 5000 });
13895 expect(".o_content").toHaveProperty("scrollLeft", 3302);
13896 await contains(".o_kanban_group:last").click();
13897 expect(".o_content").toHaveProperty("scrollLeft", 3562);
13898 ({ x, width } = queryRect('.o_kanban_group:contains("column 11 (1)")'));
13899 // TODO JUM: change digits option
13900 expect(x + width).toBeCloseTo(window.innerWidth, {
13901 digits: 0,
13902 message: "same as above",
13903 });
13904 });
13905
13906 test("hide pager in the kanban view with sample data", async () => {
13907 Partner._records = [];
13908
13909 await mountView({
13910 arch: `
13911 <kanban sample="1">
13912 <templates>
13913 <div t-name="card">
13914 <field name="foo"/>
13915 <field name="int_field"/>
13916 </div>
13917 </templates>
13918 </kanban>`,
13919 resModel: "partner",
13920 type: "kanban",
13921 noContentHelp: "No content helper",
13922 });
13923
13924 expect(".o_content").toHaveClass("o_view_sample_data");
13925 expect(".o_cp_pager").not.toHaveCount();
13926 });
13927
13928 test.tags("desktop");
13929 test("kanban views make their control panel available directly", async () => {
13930 const def = new Deferred();
13931 onRpc("web_search_read", () => def);
13932 await mountView({
13933 arch: `
13934 <kanban>
13935 <templates>
13936 <div t-name="card">
13937 <field name="foo"/>
13938 </div>
13939 </templates>
13940 </kanban>`,
13941 resModel: "partner",
13942 type: "kanban",
13943 });
13944
13945 expect(".o_kanban_view").toHaveCount(1);
13946 expect(".o_kanban_view .o_control_panel .o_searchview").toHaveCount(1);
13947 expect(".o_kanban_view .o_kanban_renderer").toHaveCount(0);
13948
13949 def.resolve();
13950 await animationFrame();
13951 expect(".o_kanban_view .o_kanban_renderer").toHaveCount(1);
13952 expect(".o_kanban_view .o_kanban_record:not(.o_kanban_ghost)").toHaveCount(4);
13953 });
13954
13955 test.tags("desktop");
13956 test("interact with search view while kanban is loading", async () => {
13957 const defs = [new Deferred()];
13958 onRpc("web_search_read", () => defs.pop());
13959 await mountView({
13960 arch: `
13961 <kanban>
13962 <templates>
13963 <div t-name="card">
13964 <field name="foo"/>
13965 </div>
13966 </templates>
13967 </kanban>`,
13968 searchViewArch: `
13969 <search>
13970 <filter name="group_by_foo" domain="[]" string="GroupBy Foo" context="{ 'group_by': 'foo' }"/>
13971 </search>`,
13972 resModel: "partner",
13973 type: "kanban",
13974 });
13975
13976 expect(".o_kanban_view").toHaveCount(1);
13977 expect(".o_kanban_view .o_control_panel .o_searchview").toHaveCount(1);
13978 expect(".o_kanban_view .o_kanban_renderer").toHaveCount(0);
13979
13980 await toggleSearchBarMenu();
13981 await toggleMenuItem("GroupBy Foo");
13982 expect(".o_kanban_view .o_kanban_renderer").toHaveCount(1);
13983 expect(".o_kanban_view .o_kanban_group").toHaveCount(3);
13984 expect(".o_kanban_view .o_kanban_record").toHaveCount(4);
13985 });
13986
13987 test("click on New while kanban is loading", async () => {
13988 onRpc("web_search_read", () => new Deferred());
13989 await mountView({
13990 arch: `
13991 <kanban>
13992 <templates>
13993 <div t-name="card">
13994 <field name="foo"/>
13995 </div>
13996 </templates>
13997 </kanban>`,
13998 resModel: "partner",
13999 type: "kanban",
14000 createRecord: () => expect.step("create record"),
14001 });
14002
14003 expect(".o_kanban_view").toHaveCount(1);
14004 expect(".o_kanban_view .o_control_panel").toHaveCount(1);
14005 expect(".o_kanban_view .o_kanban_renderer").toHaveCount(0);
14006
14007 await createKanbanRecord();
14008 expect.verifySteps(["create record"]);
14009 });
14010
14011 test("click on New while kanban is loading (with quick create)", async () => {
14012 onRpc("web_read_group", () => new Deferred());
14013 await mountView({
14014 arch: `
14015 <kanban on_create="quick_create">
14016 <templates>
14017 <div t-name="card">
14018 <field name="foo"/>
14019 </div>
14020 </templates>
14021 </kanban>`,
14022 resModel: "partner",
14023 type: "kanban",
14024 groupBy: ["foo"],
14025 createRecord: () => expect.step("create record"),
14026 });
14027
14028 expect(".o_kanban_view").toHaveCount(1);
14029 expect(".o_kanban_view .o_control_panel").toHaveCount(1);
14030 expect(".o_kanban_view .o_kanban_renderer").toHaveCount(0);
14031
14032 await createKanbanRecord();
14033 expect.verifySteps(["create record"]);
14034 });
14035
14036 test(`kanban with custom cog action that has a confirmation target="new" action`, async () => {
14037 const contextualAction = {
14038 id: 80,
14039 name: "Sort of confirmation dialog",
14040 res_model: "partner",
14041 context: "{}",
14042 views: [[false, "form"]],
14043 type: "ir.actions.act_window",
14044 target: "new",
14045 };
14046 Partner._toolbar = {
14047 action: [contextualAction],
14048 print: [],
14049 };
14050 Partner._views = {
14051 kanban: `
14052 <kanban>
14053 <t t-name="card">
14054 <field name="foo"/>
14055 </t>
14056 </kanban>`,
14057 search: `<search/>`,
14058 form: `
14059 <form>
14060 Are you sure blablabla
14061 <footer>
14062 <button name="my_action" type="action" string="Do it"/>
14063 </footer>
14064 </form>`,
14065 };
14066 defineActions([
14067 {
14068 id: 1,
14069 name: "Partner",
14070 res_model: "partner",
14071 views: [[false, "kanban"]],
14072 },
14073 {
14074 id: 2,
14075 name: "Partner",
14076 res_model: "partner",
14077 views: [[false, "form"]],
14078 res_id: 1,
14079 xml_id: "my_action",
14080 },
14081 contextualAction,
14082 ]);
14083
14084 stepAllNetworkCalls();
14085 await mountWithCleanup(WebClient);
14086 await getService("action").doAction(1);
14087 expect(".o_kanban_view").toHaveCount(1);
14088
14089 await keyDown("alt");
14090 await contains(".o_kanban_record:nth-of-type(1)").click();
14091 expect(".o_selection_box").toHaveCount(1);
14092 await contains(`.o_cp_action_menus button:has(.fa-cog)`).click();
14093 await contains(`.o-dropdown-item:contains(Sort of confirmation dialog)`).click();
14094 expect(".o_dialog").toHaveCount(1);
14095
14096 await contains(".o_dialog footer button:contains(Do it)").click();
14097 expect(".o_dialog").toHaveCount(0);
14098 expect(".o_form_view").toHaveCount(1);
14099
14100 // should not reload the list view when confirming with Do it
14101 expect.verifySteps([
14102 "/web/webclient/translations",
14103 "/web/webclient/load_menus",
14104 "/web/action/load",
14105 "get_views",
14106 "web_search_read",
14107 "has_group",
14108 "/web/action/load",
14109 "get_views",
14110 "onchange",
14111 "web_save",
14112 "/web/action/load",
14113 "get_views",
14114 "web_read",
14115 ]);
14116 });
14117
14118 test(`cache web_read_group (no change)`, async () => {
14119 let def;
14120 onRpc("web_read_group", () => def);
14121
14122 Partner._views = {
14123 "list,false": `<list><field name="foo"/></list>`,
14124 "kanban,false": `
14125 <kanban default_group_by="bar">
14126 <templates>
14127 <t t-name="card">
14128 <field name="foo"/>
14129 </t>
14130 </templates>
14131 </kanban>`,
14132 "search,false": `<search/>`,
14133 };
14134
14135 defineActions([
14136 {
14137 id: 1,
14138 name: "Partners Action",
14139 res_model: "partner",
14140 views: [[false, "kanban"]],
14141 search_view_id: [false, "search"],
14142 },
14143 {
14144 id: 2,
14145 name: "Another action",
14146 res_model: "partner",
14147 views: [[false, "list"]],
14148 search_view_id: [false, "search"],
14149 },
14150 ]);
14151
14152 await mountWithCleanup(WebClient);
14153 await getService("action").doAction(1);
14154 expect(`.o_kanban_view`).toHaveCount(1);
14155 expect(`.o_kanban_group`).toHaveCount(2);
14156 expect(queryAllTexts(`.o_kanban_header`)).toEqual(["No\n(1)", "Yes\n(3)"]);
14157
14158 // execute another action to remove the kanban from the DOM
14159 await getService("action").doAction(2);
14160 expect(`.o_list_view`).toHaveCount(1);
14161
14162 // execute again action 1, but web_read_group is delayed
14163 def = new Deferred();
14164 await getService("action").doAction(1);
14165 expect(`.o_kanban_view`).toHaveCount(1);
14166 expect(`.o_kanban_group`).toHaveCount(2);
14167 expect(queryAllTexts(`.o_kanban_header`)).toEqual(["No\n(1)", "Yes\n(3)"]);
14168
14169 // simulate the return of web_read_group => nothing should have changed
14170 def.resolve();
14171 await animationFrame();
14172 expect(`.o_kanban_view`).toHaveCount(1);
14173 expect(`.o_kanban_group`).toHaveCount(2);
14174 expect(queryAllTexts(`.o_kanban_header`)).toEqual(["No\n(1)", "Yes\n(3)"]);
14175 });
14176
14177 test(`cache web_read_group (change)`, async () => {
14178 let def;
14179 onRpc("web_read_group", () => def);
14180
14181 Partner._views = {
14182 "list,false": `<list><field name="foo"/></list>`,
14183 "kanban,false": `
14184 <kanban default_group_by="int_field">
14185 <templates>
14186 <t t-name="card">
14187 <field name="foo"/>
14188 </t>
14189 </templates>
14190 </kanban>`,
14191 "search,false": `<search/>`,
14192 };
14193
14194 defineActions([
14195 {
14196 id: 1,
14197 name: "Partners Action",
14198 res_model: "partner",
14199 views: [[false, "kanban"]],
14200 search_view_id: [false, "search"],
14201 },
14202 {
14203 id: 2,
14204 name: "Another action",
14205 res_model: "partner",
14206 views: [[false, "list"]],
14207 search_view_id: [false, "search"],
14208 },
14209 ]);
14210
14211 await mountWithCleanup(WebClient);
14212 await getService("action").doAction(1);
14213 expect(`.o_kanban_view`).toHaveCount(1);
14214 expect(`.o_kanban_group`).toHaveCount(4);
14215 expect(queryAllTexts(`.o_kanban_group .o_kanban_header`)).toEqual([
14216 "-4\n(1)",
14217 "9\n(1)",
14218 "10\n(1)",
14219 "17\n(1)",
14220 ]);
14221
14222 // simulate the create of new records by someone else
14223 MockServer.env.partner.create([{ int_field: 44 }, { int_field: -4 }]);
14224
14225 // execute another action to remove the kanban from the DOM
14226 await getService("action").doAction(2);
14227 expect(`.o_list_view`).toHaveCount(1);
14228
14229 // execute again action 1, but web_read_group is delayed
14230 def = new Deferred();
14231 await getService("action").doAction(1);
14232 expect(`.o_kanban_view`).toHaveCount(1);
14233 expect(`.o_kanban_group`).toHaveCount(4);
14234 expect(queryAllTexts(`.o_kanban_group .o_kanban_header`)).toEqual([
14235 "-4\n(1)",
14236 "9\n(1)",
14237 "10\n(1)",
14238 "17\n(1)",
14239 ]);
14240
14241 // simulate the return of web_read_group => the data should have been updated
14242 def.resolve();
14243 await animationFrame();
14244 expect(`.o_kanban_view`).toHaveCount(1);
14245 expect(`.o_kanban_group`).toHaveCount(5);
14246 expect(queryAllTexts(`.o_kanban_group .o_kanban_header`)).toEqual([
14247 "-4\n(2)",
14248 "9\n(1)",
14249 "10\n(1)",
14250 "17\n(1)",
14251 "44\n(1)",
14252 ]);
14253 });
14254
14255 test(`cache web_read_group (no data, no change)`, async () => {
14256 let def;
14257 onRpc("web_read_group", () => def);
14258
14259 Partner._records = [];
14260 Partner._views = {
14261 "list,false": `<list><field name="foo"/></list>`,
14262 "kanban,false": `
14263 <kanban default_group_by="product_id">
14264 <templates>
14265 <t t-name="card">
14266 <field name="foo"/>
14267 </t>
14268 </templates>
14269 </kanban>`,
14270 "search,false": `<search/>`,
14271 };
14272
14273 defineActions([
14274 {
14275 id: 1,
14276 name: "Partners Action",
14277 res_model: "partner",
14278 views: [[false, "kanban"]],
14279 search_view_id: [false, "search"],
14280 },
14281 {
14282 id: 2,
14283 name: "Another action",
14284 res_model: "partner",
14285 views: [[false, "list"]],
14286 search_view_id: [false, "search"],
14287 },
14288 ]);
14289
14290 await mountWithCleanup(WebClient);
14291 await getService("action").doAction(1);
14292 expect(`.o_kanban_view .o_column_quick_create`).toHaveCount(1);
14293 expect(`.o_kanban_view .o_kanban_stages_nocontent`).toHaveCount(1);
14294
14295 // execute another action to remove the kanban from the DOM
14296 await getService("action").doAction(2);
14297 expect(`.o_list_view`).toHaveCount(1);
14298
14299 // execute again action 1, but web_read_group is delayed
14300 def = new Deferred();
14301 await getService("action").doAction(1);
14302 expect(`.o_kanban_view .o_column_quick_create`).toHaveCount(1);
14303 expect(`.o_kanban_view .o_kanban_stages_nocontent`).toHaveCount(1);
14304
14305 // simulate the return of web_read_group => the sample data should still be displayed
14306 def.resolve();
14307 await animationFrame();
14308 expect(`.o_kanban_view .o_column_quick_create`).toHaveCount(1);
14309 expect(`.o_kanban_view .o_kanban_stages_nocontent`).toHaveCount(1);
14310 });
14311
14312 test(`cache web_read_group (no data, change)`, async () => {
14313 let def;
14314 onRpc("web_read_group", () => def);
14315
14316 Partner._records = [];
14317 Partner._views = {
14318 "list,false": `<list><field name="foo"/></list>`,
14319 "kanban,false": `
14320 <kanban sample="1" default_group_by="product_id">
14321 <templates>
14322 <t t-name="card">
14323 <field name="foo"/>
14324 </t>
14325 </templates>
14326 </kanban>`,
14327 "search,false": `<search/>`,
14328 };
14329
14330 defineActions([
14331 {
14332 id: 1,
14333 name: "Partners Action",
14334 res_model: "partner",
14335 views: [[false, "kanban"]],
14336 search_view_id: [false, "search"],
14337 },
14338 {
14339 id: 2,
14340 name: "Another action",
14341 res_model: "partner",
14342 views: [[false, "list"]],
14343 search_view_id: [false, "search"],
14344 },
14345 ]);
14346
14347 await mountWithCleanup(WebClient);
14348 await getService("action").doAction(1);
14349 expect(`.o_kanban_view .o_column_quick_create`).toHaveCount(1);
14350 expect(`.o_kanban_view .o_kanban_stages_nocontent`).toHaveCount(1);
14351
14352 // simulate the create of new records by someone else
14353 MockServer.env.partner.create([{ product_id: 3 }, { product_id: 5 }]);
14354
14355 // execute another action to remove the kanban from the DOM
14356 await getService("action").doAction(2);
14357 expect(`.o_list_view`).toHaveCount(1);
14358
14359 // execute again action 1, but web_read_group is delayed
14360 def = new Deferred();
14361 await getService("action").doAction(1);
14362 expect(`.o_kanban_view .o_column_quick_create`).toHaveCount(1);
14363 expect(`.o_kanban_view .o_kanban_stages_nocontent`).toHaveCount(1);
14364
14365 // simulate the return of web_read_group => the data should have been updated
14366 def.resolve();
14367 await animationFrame();
14368 expect(`.o_kanban_view`).toHaveCount(1);
14369 expect(`.o_kanban_group`).toHaveCount(2);
14370 expect(queryAllTexts(`.o_kanban_group .o_kanban_header`)).toEqual(["hello\n(1)", "xmo\n(1)"]);
14371 });
14372
14373 test(`cache web_read_group (group_expand: groups, then no group)`, async () => {
14374 // this test simulates that we are on a grouped kanban, with the group_expand feature, i.e.
14375 // empty groups are shown, and when we first go to the view, there are groups, but empty, so
14376 // sample data is displayed. Then, when we come back, we retrieve the data from the cache, but
14377 // the rpc returns no group, so the view must be properly updated.
14378 let def;
14379 let withGroups = true;
14380 onRpc("web_read_group", async () => {
14381 if (withGroups) {
14382 return {
14383 groups: [
14384 {
14385 __extra_domain: [["product_id", "=", 3]],
14386 __records: [],
14387 __count: 0,
14388 product_id: [3, "xphone"],
14389 },
14390 ],
14391 length: 1,
14392 };
14393 } else {
14394 await def;
14395 return { groups: [], length: 0 };
14396 }
14397 });
14398
14399 Partner._records = [];
14400 Partner._views = {
14401 "list,false": `<list><field name="foo"/></list>`,
14402 "kanban,false": `
14403 <kanban sample="1" default_group_by="product_id">
14404 <templates>
14405 <t t-name="card">
14406 <field name="foo"/>
14407 </t>
14408 </templates>
14409 </kanban>`,
14410 "search,false": `<search/>`,
14411 };
14412
14413 defineActions([
14414 {
14415 id: 1,
14416 name: "Partners Action",
14417 res_model: "partner",
14418 views: [[false, "kanban"]],
14419 search_view_id: [false, "search"],
14420 },
14421 {
14422 id: 2,
14423 name: "Another action",
14424 res_model: "partner",
14425 views: [[false, "list"]],
14426 search_view_id: [false, "search"],
14427 },
14428 ]);
14429
14430 await mountWithCleanup(WebClient);
14431 await getService("action").doAction(1);
14432 expect(`.o_kanban_view .o_view_sample_data`).toHaveCount(1);
14433 expect(`.o_kanban_view .o_kanban_group`).toHaveCount(1);
14434
14435 // execute another action to remove the kanban from the DOM
14436 await getService("action").doAction(2);
14437 expect(`.o_list_view`).toHaveCount(1);
14438
14439 // simulate the removal of the (only) empty group
14440 withGroups = false;
14441
14442 // execute again action 1, but web_read_group is delayed
14443 def = new Deferred();
14444 await getService("action").doAction(1);
14445 expect(`.o_kanban_view .o_view_sample_data`).toHaveCount(1);
14446 expect(`.o_kanban_view .o_kanban_group`).toHaveCount(1);
14447
14448 // simulate the return of web_read_group => the data should have been updated
14449 def.resolve();
14450 await animationFrame();
14451 expect(`.o_kanban_view`).toHaveCount(1);
14452 expect(`.o_kanban_view .o_view_sample_data`).toHaveCount(0);
14453 expect(`.o_kanban_view .o_column_quick_create`).toHaveCount(1);
14454 expect(`.o_kanban_view .o_kanban_stages_nocontent`).toHaveCount(1);
14455 });
14456
14457 test(`cache web_read_group (group_expand: groups, then more groups)`, async () => {
14458 // this test simulates that we are on a grouped kanban, with the group_expand feature, i.e.
14459 // empty groups are shown, and when we first go to the view, there are groups, but empty, so
14460 // sample data is displayed. Then, when we come back, we retrieve the data from the cache, but
14461 // the rpc returns more (or less, but still some) groups. Theoretically, we should remain in
14462 // sample mode and display the updated groups. We do correctly display the groups, but the
14463 // sample mode is left, because it is a quite complex usecase to deal with, and we don't think
14464 // it would be worth the complexity. This test simply encodes the current behavior, that we may
14465 // change in the future if we want to.
14466 let def;
14467 const groups = [
14468 {
14469 __extra_domain: [["product_id", "=", 3]],
14470 __records: [],
14471 __count: 0,
14472 product_id: [3, "xphone"],
14473 },
14474 ];
14475 onRpc("web_read_group", async () => {
14476 await def;
14477 return {
14478 groups,
14479 length: groups.length,
14480 };
14481 });
14482
14483 Partner._records = [];
14484 Partner._views = {
14485 "list,false": `<list><field name="foo"/></list>`,
14486 "kanban,false": `
14487 <kanban sample="1" default_group_by="product_id">
14488 <templates>
14489 <t t-name="card">
14490 <field name="foo"/>
14491 </t>
14492 </templates>
14493 </kanban>`,
14494 "search,false": `<search/>`,
14495 };
14496
14497 defineActions([
14498 {
14499 id: 1,
14500 name: "Partners Action",
14501 res_model: "partner",
14502 views: [[false, "kanban"]],
14503 search_view_id: [false, "search"],
14504 },
14505 {
14506 id: 2,
14507 name: "Another action",
14508 res_model: "partner",
14509 views: [[false, "list"]],
14510 search_view_id: [false, "search"],
14511 },
14512 ]);
14513
14514 await mountWithCleanup(WebClient);
14515 await getService("action").doAction(1);
14516 expect(`.o_kanban_view .o_view_sample_data`).toHaveCount(1);
14517 expect(`.o_kanban_view .o_kanban_group`).toHaveCount(1);
14518
14519 // execute another action to remove the kanban from the DOM
14520 await getService("action").doAction(2);
14521 expect(`.o_list_view`).toHaveCount(1);
14522
14523 // simulate the addition of another empty group
14524 groups.push({
14525 __extra_domain: [["product_id", "=", 5]],
14526 __records: [],
14527 __count: 0,
14528 product_id: [5, "xpad"],
14529 });
14530
14531 // execute again action 1, but web_read_group is delayed
14532 def = new Deferred();
14533 await getService("action").doAction(1);
14534 expect(`.o_kanban_view .o_view_sample_data`).toHaveCount(1);
14535 expect(`.o_kanban_view .o_kanban_group`).toHaveCount(1);
14536
14537 // simulate the return of web_read_group => the data should have been updated
14538 def.resolve();
14539 await animationFrame();
14540 expect(`.o_kanban_view .o_view_sample_data`).toHaveCount(0); // would be ok to remain in sample
14541 expect(`.o_kanban_view .o_kanban_group`).toHaveCount(2);
14542 });
14543
14544 test(`cache web_read_group: less groups than in cache`, async () => {
14545 // this test simulates that we are on a grouped kanban and the rpc returns less groups than we
14546 // got from the cache. Those missing groups should be properly removed from the UI on update.
14547 let def;
14548 onRpc("web_read_group", () => def);
14549
14550 Partner._views = {
14551 "list,false": `<list><field name="foo"/></list>`,
14552 "kanban,false": `
14553 <kanban sample="1" default_group_by="product_id">
14554 <templates>
14555 <t t-name="card">
14556 <field name="foo"/>
14557 </t>
14558 </templates>
14559 </kanban>`,
14560 "search,false": `<search/>`,
14561 };
14562
14563 defineActions([
14564 {
14565 id: 1,
14566 name: "Partners Action",
14567 res_model: "partner",
14568 views: [[false, "kanban"]],
14569 search_view_id: [false, "search"],
14570 },
14571 {
14572 id: 2,
14573 name: "Another action",
14574 res_model: "partner",
14575 views: [[false, "list"]],
14576 search_view_id: [false, "search"],
14577 },
14578 ]);
14579
14580 await mountWithCleanup(WebClient);
14581 await getService("action").doAction(1);
14582 expect(`.o_kanban_view .o_kanban_group`).toHaveCount(2);
14583 expect(queryAllTexts(`.o_kanban_group .o_kanban_header`)).toEqual(["hello\n(2)", "xmo\n(2)"]);
14584
14585 // execute another action to remove the kanban from the DOM
14586 await getService("action").doAction(2);
14587 expect(`.o_list_view`).toHaveCount(1);
14588
14589 // simulate a move of records from first group to the second one
14590 MockServer.env.partner.write([1, 3], { product_id: 5 });
14591
14592 // execute again action 1, but web_read_group is delayed
14593 def = new Deferred();
14594 await getService("action").doAction(1);
14595 expect(`.o_kanban_view .o_kanban_group`).toHaveCount(2);
14596 expect(queryAllTexts(`.o_kanban_group .o_kanban_header`)).toEqual(["hello\n(2)", "xmo\n(2)"]);
14597
14598 // simulate the return of web_read_group => the data should have been updated
14599 def.resolve();
14600 await animationFrame();
14601 expect(`.o_kanban_view .o_kanban_group`).toHaveCount(1);
14602 expect(queryAllTexts(`.o_kanban_group .o_kanban_header`)).toEqual(["xmo\n(4)"]);
14603 });
14604
14605 test.tags("desktop");
14606 test("Cache: folded is now unfolded", async () => {
14607 Product._records[1].fold = true;
14608
14609 Partner._views = {
14610 "kanban,false": `
14611 <kanban default_group_by="product_id">
14612 <templates>
14613 <div t-name="card">
14614 <field name="id"/>
14615 </div>
14616 </templates>
14617 </kanban>`,
14618 "search,false": `<search/>`,
14619 };
14620
14621 defineActions([
14622 {
14623 id: 1,
14624 name: "Partners Action",
14625 res_model: "partner",
14626 views: [[false, "kanban"]],
14627 search_view_id: [false, "search"],
14628 },
14629 ]);
14630
14631 await mountWithCleanup(WebClient);
14632 await getService("action").doAction(1);
14633
14634 expect(queryAll(".o_kanban_record", { root: getKanbanColumn(0) })).toHaveCount(2);
14635 expect(getKanbanColumn(1)).toHaveClass("o_column_folded");
14636 expect(queryText(getKanbanColumn(1))).toBe("xmo\n(2)");
14637
14638 MockServer.env["product"].write(5, { fold: false });
14639 await getService("action").doAction(1);
14640
14641 expect(queryAll(".o_kanban_record", { root: getKanbanColumn(0) })).toHaveCount(2);
14642 expect(queryAll(".o_kanban_record", { root: getKanbanColumn(1) })).toHaveCount(2);
14643 });
14644
14645 test.tags("desktop");
14646 test("Cache: unfolded is now folded", async () => {
14647 Product._records[1].fold = false;
14648
14649 Partner._views = {
14650 "kanban,false": `
14651 <kanban default_group_by="product_id">
14652 <templates>
14653 <div t-name="card">
14654 <field name="id"/>
14655 </div>
14656 </templates>
14657 </kanban>`,
14658 "search,false": `<search/>`,
14659 };
14660
14661 defineActions([
14662 {
14663 id: 1,
14664 name: "Partners Action",
14665 res_model: "partner",
14666 views: [[false, "kanban"]],
14667 search_view_id: [false, "search"],
14668 },
14669 ]);
14670
14671 await mountWithCleanup(WebClient);
14672 await getService("action").doAction(1);
14673
14674 expect(queryAll(".o_kanban_record", { root: getKanbanColumn(0) })).toHaveCount(2);
14675 expect(queryAll(".o_kanban_record", { root: getKanbanColumn(1) })).toHaveCount(2);
14676
14677 MockServer.env["product"].write(5, { fold: true });
14678 await getService("action").doAction(1);
14679 expect(queryAll(".o_kanban_record", { root: getKanbanColumn(0) })).toHaveCount(2);
14680 expect(getKanbanColumn(1)).toHaveClass("o_column_folded");
14681 expect(queryText(getKanbanColumn(1))).toBe("xmo\n(2)");
14682 });
14683
14684 test.tags("desktop");
14685 test("Cache: kanban view progressbar, filter, open a record, edit, come back", async () => {
14686 // This test encodes a very specify scenario involving a kanban with progressbar, where the
14687 // filter was lost when coming back due to the cache callback, which removed the groups
14688 // information.
14689 Product._records[1].fold = false;
14690
14691 let def;
14692 onRpc("web_read_group", () => def);
14693
14694 Partner._views = {
14695 "kanban,false": `
14696 <kanban default_group_by="product_id" on_create="quick_create" quick_create_view="some_view_ref">
14697 <progressbar field="foo" colors='{"yop": "success", "gnap": "warning", "blip": "danger"}'/>
14698 <templates>
14699 <t t-name="card">
14700 <field name="foo"/>
14701 </t>
14702 </templates>
14703 </kanban>`,
14704 "form,false": `<form><field name="product_id" widget="statusbar" options="{'clickable': true}"/></form>`,
14705 "search,false": `<search/>`,
14706 };
14707
14708 defineActions([
14709 {
14710 id: 1,
14711 name: "Partners Action",
14712 res_model: "partner",
14713 views: [
14714 [false, "kanban"],
14715 [false, "form"],
14716 ],
14717 search_view_id: [false, "search"],
14718 },
14719 ]);
14720
14721 await mountWithCleanup(WebClient);
14722 await getService("action").doAction(1);
14723 expect(".o_kanban_group").toHaveCount(2);
14724 expect(".o_kanban_group:eq(0) .o_kanban_record").toHaveCount(2);
14725
14726 // Filter the first column with the progressbar
14727 await contains(".o_column_progress .progress-bar", { root: getKanbanColumn(0) }).click();
14728 expect(".o_kanban_group:eq(0) .o_kanban_record").toHaveCount(1);
14729
14730 // Open a record, then go back, s.t. we populate the cache with the current params of the kanban
14731 await contains(".o_kanban_group:eq(1) .o_kanban_record").click();
14732 expect(".o_form_view").toHaveCount(1);
14733 await contains(".o_back_button").click();
14734 expect(".o_kanban_group:eq(0) .o_kanban_record").toHaveCount(1);
14735
14736 // Open again and make a change which will have an impact on the kanban, then go back
14737 await contains(".o_kanban_group:eq(1) .o_kanban_record").click();
14738 expect(".o_form_view").toHaveCount(1);
14739 await contains(".o_field_widget[name=product_id] button[data-value='3']").click();
14740 // Slow down the rpc s.t. we first use data from the cache, and then we update
14741 def = new Deferred();
14742 await contains(".o_back_button").click();
14743 expect(".o_kanban_group:eq(0) .o_kanban_record").toHaveCount(1);
14744
14745 // Resolve the promise
14746 def.resolve();
14747 await animationFrame();
14748 expect(".o_kanban_group:eq(0) .o_kanban_record").toHaveCount(1);
14749
14750 // Open a last time and come back => the filter should still be applied correctly
14751 await contains(".o_kanban_group:eq(1) .o_kanban_record").click();
14752 await contains(".o_back_button").click();
14753 expect(".o_kanban_group:eq(0) .o_kanban_record").toHaveCount(1);
14754 });
14755
14756 test.tags("desktop");
14757 test("scroll position is restored when coming back to kanban view", async () => {
14758 Partner._views = {
14759 kanban: `
14760 <kanban>
14761 <templates>
14762 <t t-name="card">
14763 <field name="foo"/>
14764 </t>
14765 </templates>
14766 </kanban>`,
14767 list: `<list><field name="foo"/></list>`,
14768 search: `<search />`,
14769 };
14770
14771 for (let i = 1; i < 10; i++) {
14772 Product._records.push({ id: 100 + i, name: `Product ${i}` });
14773 for (let j = 1; j < 20; j++) {
14774 Partner._records.push({
14775 id: 100 * i + j,
14776 product_id: 100 + i,
14777 foo: `Record ${i}/${j}`,
14778 });
14779 }
14780 }
14781
14782 let def;
14783 onRpc("web_read_group", () => def);
14784 await resize({ width: 800, height: 300 });
14785 await mountWithCleanup(WebClient);
14786 await getService("action").doAction({
14787 res_model: "partner",
14788 type: "ir.actions.act_window",
14789 views: [
14790 [false, "kanban"],
14791 [false, "list"],
14792 ],
14793 context: {
14794 group_by: ["product_id"],
14795 },
14796 });
14797
14798 expect(".o_kanban_view").toHaveCount(1);
14799 // simulate scrolls in the kanban view
14800 queryOne(".o_content").scrollTop = 100;
14801 queryOne(".o_content").scrollLeft = 400;
14802
14803 await getService("action").switchView("list");
14804 expect(".o_list_view").toHaveCount(1);
14805
14806 // the kanban is "lazy", so it displays the control panel directly, and the renderer later with
14807 // the data => simulate this and check that the scroll position is correctly restored
14808 def = new Deferred();
14809 await getService("action").switchView("kanban");
14810 expect(".o_kanban_view").toHaveCount(1);
14811 expect(".o_kanban_renderer").toHaveCount(0);
14812 def.resolve();
14813 await animationFrame();
14814 expect(".o_kanban_renderer").toHaveCount(1);
14815 expect(".o_content").toHaveProperty("scrollTop", 100);
14816 expect(".o_content").toHaveProperty("scrollLeft", 400);
14817 });
14818
14819 test.tags("mobile");
14820 test("scroll position is restored when coming back to kanban view (mobile)", async () => {
14821 Partner._views = {
14822 kanban: `
14823 <kanban>
14824 <templates>
14825 <t t-name="card">
14826 <field name="foo"/>
14827 </t>
14828 </templates>
14829 </kanban>`,
14830 list: `<list><field name="foo"/></list>`,
14831 search: `<search />`,
14832 };
14833
14834 for (let i = 1; i < 20; i++) {
14835 Partner._records.push({
14836 id: 100 + i,
14837 foo: `Record ${i}`,
14838 });
14839 }
14840
14841 let def;
14842 onRpc("web_search_read", () => def);
14843 await mountWithCleanup(WebClient);
14844 await getService("action").doAction({
14845 res_model: "partner",
14846 type: "ir.actions.act_window",
14847 views: [
14848 [false, "kanban"],
14849 [false, "list"],
14850 ],
14851 });
14852
14853 expect(".o_kanban_view").toHaveCount(1);
14854 // simulate a scroll in the kanban view
14855 queryOne(".o_kanban_view").scrollTop = 100;
14856
14857 await getService("action").switchView("list");
14858 expect(".o_list_view").toHaveCount(1);
14859
14860 // the kanban is "lazy", so it displays the control panel directly, and the renderer later with
14861 // the data => simulate this and check that the scroll position is correctly restored
14862 def = new Deferred();
14863 await getService("action").switchView("kanban");
14864 expect(".o_kanban_view").toHaveCount(1);
14865 expect(".o_kanban_renderer").toHaveCount(0);
14866 def.resolve();
14867 await animationFrame();
14868 expect(".o_kanban_renderer").toHaveCount(1);
14869 expect(".o_kanban_view").toHaveProperty("scrollTop", 100);
14870 });
14871
14872 test.tags("mobile");
14873 test("scroll position is restored when coming back to kanban view (grouped, mobile)", async () => {
14874 Partner._views = {
14875 kanban: `
14876 <kanban>
14877 <templates>
14878 <t t-name="card">
14879 <field name="foo"/>
14880 </t>
14881 </templates>
14882 </kanban>`,
14883 list: `<list><field name="foo"/></list>`,
14884 search: `<search />`,
14885 };
14886
14887 Partner._records = [];
14888 for (let i = 1; i < 5; i++) {
14889 Product._records.push({ id: 100 + i, name: `Product ${i}` });
14890 for (let j = 1; j < 20; j++) {
14891 Partner._records.push({
14892 id: 100 * i + j,
14893 product_id: 100 + i,
14894 foo: `Record ${i}/${j}`,
14895 });
14896 }
14897 }
14898
14899 let def;
14900 onRpc("web_read_group", () => def);
14901 await resize({ width: 375, height: 667 }); // iphone se
14902 await mountWithCleanup(WebClient);
14903 await getService("action").doAction({
14904 res_model: "partner",
14905 type: "ir.actions.act_window",
14906 views: [
14907 [false, "kanban"],
14908 [false, "list"],
14909 ],
14910 context: {
14911 group_by: ["product_id"],
14912 },
14913 });
14914
14915 expect(".o_kanban_view").toHaveCount(1);
14916 // simulate scrolls in the kanban view
14917 queryOne(".o_kanban_renderer").scrollLeft = 656; // scroll to the third column
14918 queryAll(".o_kanban_group")[2].scrollTop = 200;
14919
14920 await getService("action").switchView("list");
14921 expect(".o_list_view").toHaveCount(1);
14922
14923 // the kanban is "lazy", so it displays the control panel directly, and the renderer later with
14924 // the data => simulate this and check that the scroll position is correctly restored
14925 def = new Deferred();
14926 await getService("action").switchView("kanban");
14927 expect(".o_kanban_view").toHaveCount(1);
14928 expect(".o_kanban_renderer").toHaveCount(0);
14929 def.resolve();
14930 await animationFrame();
14931 expect(".o_kanban_renderer").toHaveCount(1);
14932 expect(".o_kanban_group:eq(2)").toHaveProperty("scrollTop", 200);
14933 expect(".o_kanban_renderer").toHaveProperty("scrollLeft", 656);
14934 });
14935
14936 test.tags("desktop");
14937 test("limit is reset when restoring a view after ungrouping", async () => {
14938 Partner._views["kanban"] = `
14939 <kanban sample="1">
14940 <templates>
14941 <t t-name="card">
14942 <field name="foo"/>
14943 </t>
14944 </templates>
14945 </kanban>`;
14946 Partner._views["list"] = '<list><field name="foo"/></list>';
14947 Partner._views.search = `
14948 <search>
14949 <group>
14950 <filter name="foo" string="Foo" context="{'group_by': 'foo'}"/>
14951 </group>
14952 </search>
14953 `;
14954
14955 onRpc("partner", "web_search_read", ({ kwargs }) => {
14956 const { domain, limit } = kwargs;
14957 if (!domain.length) {
14958 expect.step(`limit=${limit}`);
14959 }
14960 });
14961
14962 patchWithCleanup(user, {
14963 hasGroup: () => true,
14964 });
14965
14966 await mountWithCleanup(WebClient);
14967
14968 await getService("action").doAction({
14969 type: "ir.actions.act_window",
14970 id: 450,
14971 xml_id: "action_450",
14972 name: "Partners",
14973 res_model: "partner",
14974 views: [
14975 [false, "kanban"],
14976 [false, "list"],
14977 [false, "form"],
14978 ],
14979 context: { search_default_foo: true },
14980 });
14981
14982 await switchView("list");
14983 await removeFacet("Foo");
14984 expect.verifySteps(["limit=80"]);
14985 await switchView("kanban");
14986 expect.verifySteps(["limit=40"]);
14987 });
14988
14989 test.tags("desktop");
14990 test("add o-navigable to buttons with dropdown-item class and view buttons", async () => {
14991 Partner._records.splice(1, 3); // keep one record only
14992
14993 await mountView({
14994 type: "kanban",
14995 resModel: "partner",
14996 arch: `
14997 <kanban>
14998 <templates>
14999 <t t-name="menu">
15000 <a role="menuitem" class="dropdown-item">Item</a>
15001 <a role="menuitem" type="set_cover" class="dropdown-item">Item</a>
15002 <a role="menuitem" type="object" class="dropdown-item">Item</a>
15003 </t>
15004 <t t-name="card">
15005 <div/>
15006 </t>
15007 </templates>
15008 </kanban>`,
15009 });
15010
15011 expect(".o-dropdown--menu").toHaveCount(0);
15012 await toggleKanbanRecordDropdown();
15013 expect(".o-dropdown--menu .dropdown-item.o-navigable").toHaveCount(3);
15014 expect(".o-dropdown--menu .dropdown-item.o-navigable.focus").toHaveCount(0);
15015
15016 // Check that navigation is working
15017 await hover(".o-dropdown--menu .dropdown-item.o-navigable");
15018 expect(".o-dropdown--menu .dropdown-item.o-navigable.focus").toHaveCount(1);
15019
15020 await press("arrowdown");
15021 expect(".o-dropdown--menu .dropdown-item.o-navigable:nth-child(2)").toHaveClass("focus");
15022
15023 await press("arrowdown");
15024 expect(".o-dropdown--menu .dropdown-item.o-navigable:nth-child(3)").toHaveClass("focus");
15025 });