Debian Codegraph @

addons/web/static/tests/views/list/list_view.test.js

raw
1 import { expect, getFixture, test } from "@odoo/hoot";
2 import {
3 clear,
4 click,
5 edit,
6 hover,
7 keyDown,
8 keyUp,
9 middleClick,
10 pointerDown,
11 pointerUp,
12 press,
13 queryAll,
14 queryAllProperties,
15 queryAllTexts,
16 queryFirst,
17 queryOne,
18 queryRect,
19 queryText,
20 unload,
21 waitFor,
22 } from "@odoo/hoot-dom";
23 import {
24 animationFrame,
25 Deferred,
26 mockDate,
27 mockTimeZone,
28 runAllTimers,
29 tick,
30 } from "@odoo/hoot-mock";
31 import { Component, markup, onRendered, onWillStart, useRef, xml } from "@odoo/owl";
32 import { getPickerCell } from "@web/../tests/core/datetime/datetime_test_helpers";
33 import {
34 clickFieldDropdown,
35 clickModalButton,
36 clickSave,
37 contains,
38 defineActions,
39 defineModels,
40 defineParams,
41 editFavoriteName,
42 editSelectMenu,
43 fields,
44 getFacetTexts,
45 getMenuItemTexts,
46 getMockEnv,
47 getPagerLimit,
48 getPagerValue,
49 getService,
50 installLanguages,
51 makeKwArgs,
52 makeServerError,
53 MockServer,
54 mockService,
55 models,
56 mountView,
57 mountViewInDialog,
58 mountWithCleanup,
59 onRpc,
60 pagerNext,
61 pagerPrevious,
62 patchWithCleanup,
63 removeFacet,
64 saveFavorite,
65 selectFieldDropdownItem,
66 selectGroup,
67 serverState,
68 stepAllNetworkCalls,
69 switchView,
70 toggleActionMenu,
71 toggleMenuItem,
72 toggleSaveFavorite,
73 toggleSearchBarMenu,
74 validateSearch,
75 webModels,
76 } from "@web/../tests/web_test_helpers";
77
78 import { localization } from "@web/core/l10n/localization";
79 import { buildSelector } from "@web/../tests/_framework/view_test_helpers";
80 import { currencies } from "@web/core/currency";
81 import { Domain } from "@web/core/domain";
82 import { registry } from "@web/core/registry";
83 import { user } from "@web/core/user";
84 import { useBus } from "@web/core/utils/hooks";
85 import { omit } from "@web/core/utils/objects";
86 import { RelationalModel } from "@web/model/relational_model/relational_model";
87 import { session } from "@web/session";
88 import { floatField } from "@web/views/fields/float/float_field";
89 import { Many2XAutocomplete } from "@web/views/fields/relational_utils";
90 import { standardFieldProps } from "@web/views/fields/standard_field_props";
91 import { ListController } from "@web/views/list/list_controller";
92 import { WebClient } from "@web/webclient/webclient";
93
94 const { ResCompany, ResPartner, ResUsers } = webModels;
95
96 class Foo extends models.Model {
97 foo = fields.Char();
98 bar = fields.Boolean();
99 date = fields.Date();
100 datetime = fields.Datetime();
101 int_field = fields.Integer();
102 qux = fields.Float();
103 m2o = fields.Many2one({ relation: "bar" });
104 o2m = fields.One2many({ relation: "bar" });
105 m2m = fields.Many2many({ relation: "bar" });
106 text = fields.Text();
107 amount = fields.Monetary({ currency_field: "currency_id" });
108 currency_id = fields.Many2one({ relation: "res.currency", default: 1 });
109 reference = fields.Reference({
110 selection: [
111 ["bar", "Bar"],
112 ["res.currency", "Currency"],
113 ],
114 });
115 properties = fields.Properties({
116 definition_record: "m2o",
117 definition_record_field: "definitions",
118 });
119
120 _records = [
121 {
122 id: 1,
123 foo: "yop",
124 bar: true,
125 date: "2017-01-25",
126 datetime: "2016-12-12 10:55:05",
127 int_field: 10,
128 qux: 0.4,
129 m2o: 1,
130 m2m: [1, 2],
131 amount: 1200,
132 currency_id: 2,
133 reference: "bar,1",
134 },
135 {
136 id: 2,
137 foo: "blip",
138 bar: true,
139 int_field: 9,
140 qux: 13,
141 m2o: 2,
142 m2m: [1, 2, 3],
143 amount: 500,
144 reference: "res.currency,1",
145 },
146 {
147 id: 3,
148 foo: "gnap",
149 bar: true,
150 int_field: 17,
151 qux: -3,
152 m2o: 1,
153 m2m: [],
154 amount: 300,
155 reference: "res.currency,2",
156 },
157 {
158 id: 4,
159 foo: "blip",
160 bar: false,
161 int_field: -4,
162 qux: 9,
163 m2o: 1,
164 m2m: [1],
165 amount: 0,
166 },
167 ];
168 }
169
170 class Bar extends models.Model {
171 name = fields.Char();
172 definitions = fields.PropertiesDefinition();
173
174 _records = [
175 { id: 1, name: "Value 1", definitions: [] },
176 { id: 2, name: "Value 2", definitions: [] },
177 { id: 3, name: "Value 3", definitions: [] },
178 ];
179 }
180
181 class Currency extends models.Model {
182 _name = "res.currency";
183
184 name = fields.Char();
185 symbol = fields.Char();
186 position = fields.Selection({
187 selection: [
188 ["after", "A"],
189 ["before", "B"],
190 ],
191 });
192 inverse_rate = fields.Float();
193
194 _records = [
195 { id: 1, name: "USD", symbol: "$", position: "before", inverse_rate: 1 },
196 { id: 2, name: "EUR", symbol: "€", position: "after", inverse_rate: 0.5 },
197 ];
198 }
199
200 defineModels([Foo, Bar, Currency, ResCompany, ResPartner, ResUsers]);
201
202 async function clickControlPanelAction(buttonName) {
203 if (getMockEnv().isSmall) {
204 await contains(".o_control_panel_breadcrumbs .o_cp_action_menus .fa-cog").click();
205 await contains(`.o-dropdown-item button[name="${buttonName}"]`).click();
206 } else {
207 await contains(`.o_control_panel_actions button[name="${buttonName}"]`).click();
208 }
209 }
210
211 async function clickRecordSelector() {
212 if (getMockEnv().isSmall) {
213 await contains(".o_data_row").drag();
214 } else {
215 await contains(`.o_data_row .o_list_record_selector input`).click();
216 }
217 }
218
219 async function selectAllRecords() {
220 if (getMockEnv().isSmall) {
221 const cells = queryAll("tbody tr.o_data_row[data-id]:not(.o_data_row_selected)");
222 for (const cell of cells) {
223 await contains(cell).drag();
224 }
225 } else {
226 await contains(`thead .o_list_record_selector input`).click();
227 }
228 }
229 async function unselectAllRecords() {
230 if (getMockEnv().isSmall) {
231 const cells = queryAll("tbody tr.o_data_row.o_data_row_selected[data-id]");
232 for (const cell of cells) {
233 await contains(cell).drag();
234 }
235 } else {
236 await contains(`thead .o_list_record_selector input`).click();
237 }
238 }
239
240 async function selectMany2xItem(fieldName, value) {
241 await contains(`.o_field_cell:has(>.o_field_widget[name="${fieldName}"])`).click();
242 if (getMockEnv().isSmall) {
243 await contains(`.o_selected_row .o_field_widget[name="${fieldName}"] input`).click();
244 await contains(`.o_dialog .o_kanban_record:contains(${value})`).click();
245 } else {
246 await selectFieldDropdownItem(fieldName, value);
247 }
248 }
249
250 async function toggleMultiCurrencyPopover(el) {
251 if (getMockEnv().isSmall) {
252 await contains(el).click();
253 } else {
254 await contains(el).hover();
255 }
256 }
257
258 test(`simple readonly list`, async () => {
259 await mountView({
260 resModel: "foo",
261 type: "list",
262 arch: `<list><field name="foo"/><field name="int_field"/></list>`,
263 });
264
265 expect(`th:not(.o_list_record_selector)`).toHaveCount(2, {
266 message: "should have 1 th for checkbox (desktop only), 2 th for columns",
267 });
268 expect(`td:contains(gnap)`).toHaveCount(1, { message: "should contain gnap" });
269 expect(`tbody tr`).toHaveCount(4, { message: "should have 4 rows" });
270 expect(`th.o_column_sortable`).toHaveCount(2, { message: "should have 2 sortable column" });
271 expect(`thead th:not(.o_list_record_selector):eq(1) .o_list_number_th`).toHaveCount(1, {
272 message: "header cells of integer fields should have o_list_number_th class",
273 });
274 expect(`tbody tr:eq(0) td:not(.o_list_record_selector):eq(1)`).toHaveStyle(
275 { "text-align": "right" },
276 { message: "integer cells should be right aligned" }
277 );
278 expect(`.o_list_button_add`).toBeVisible();
279 expect(`.o_list_button_save`).not.toHaveCount();
280 expect(`.o_list_button_discard`).not.toHaveCount();
281 });
282
283 test.tags("desktop");
284 test(`select record range with shift click`, async () => {
285 await mountView({
286 resModel: "foo",
287 type: "list",
288 arch: `<list><field name="foo"/><field name="int_field"/></list>`,
289 });
290 await contains(`.o_data_row .o_list_record_selector input`).click();
291 expect(`.o_control_panel_actions .o_selection_box`).toHaveCount(1);
292 expect(`.o_selection_box .o_select_domain`).toHaveCount(0);
293 expect(`.o_selection_box`).toHaveText("1\nselected");
294 expect(`.o_data_row .o_list_record_selector input:checked`).toHaveCount(1);
295
296 // shift click the 4th record to have 0-1-2-3 toggled
297 await contains(`.o_data_row .o_list_record_selector input:eq(3)`).click({ shiftKey: true });
298 expect(`.o_selection_box`).toHaveText("4\nselected");
299 expect(`.o_data_row .o_list_record_selector input:checked`).toHaveCount(4);
300
301 // shift click the 3rd record to untoggle 2-3
302 await contains(`.o_data_row .o_list_record_selector input:eq(2)`).click({ shiftKey: true });
303 expect(`.o_selection_box`).toHaveText("2\nselected");
304 expect(`.o_data_row.o_data_row_selected`).toHaveCount(2);
305
306 // shift click the 1st record to untoggle 0-1
307 await contains(`.o_data_row .o_list_record_selector input:eq(0)`).click({ shiftKey: true });
308 expect(`.o_data_row.o_data_row_selected`).toHaveCount(0);
309 });
310
311 test.tags("desktop");
312 test(`select record range with shift+space`, async () => {
313 await mountView({
314 resModel: "foo",
315 type: "list",
316 arch: `<list><field name="foo"/><field name="int_field"/></list>`,
317 });
318
319 // Go to the first checkbox and check it
320 await press("ArrowDown");
321 await press("ArrowDown");
322 await animationFrame();
323 expect(`.o_data_row:eq(0) .o_list_record_selector input`).toBeFocused();
324
325 await contains(`.o_data_row:eq(0) .o_list_record_selector input`).click();
326 expect(`.o_data_row:eq(0) .o_list_record_selector input`).toBeChecked();
327
328 // Go to the fourth checkbox and shift+space
329 await press("ArrowDown");
330 await press("ArrowDown");
331 await press("ArrowDown");
332 await animationFrame();
333 expect(`.o_data_row:eq(3) .o_list_record_selector input`).toBeFocused();
334 expect(`.o_data_row:eq(3) .o_list_record_selector input`).not.toBeChecked();
335
336 await press(["shift", "space"]);
337 await animationFrame();
338 // focus is on the input and not in the td cell
339 expect(`.o_data_row:eq(3) .o_list_record_selector input`).toBeFocused();
340
341 // Check that all checkbox is checked
342 expect(`.o_data_row:eq(0) .o_list_record_selector input`).toBeChecked();
343 expect(`.o_data_row:eq(1) .o_list_record_selector input`).toBeChecked();
344 expect(`.o_data_row:eq(2) .o_list_record_selector input`).toBeChecked();
345 expect(`.o_data_row:eq(3) .o_list_record_selector input`).toBeChecked();
346 });
347
348 test.tags("desktop");
349 test(`expand range of checkbox with shift+arrow`, async () => {
350 await mountView({
351 resModel: "foo",
352 type: "list",
353 arch: `<list><field name="foo"/><field name="int_field"/></list>`,
354 });
355
356 // Go to the first checkbox and check it
357 await press("ArrowDown");
358 await press("ArrowDown");
359 await animationFrame();
360 expect(`.o_data_row:eq(0) .o_list_record_selector input`).toBeFocused();
361
362 await contains(`.o_data_row:eq(0) .o_list_record_selector input`).click();
363 expect(`.o_data_row:eq(0) .o_list_record_selector input`).toBeChecked();
364
365 // expand the checkbox with arrowdown
366 await press(["shift", "ArrowDown"]);
367 await press(["shift", "ArrowDown"]);
368 await press(["shift", "ArrowDown"]);
369 await press(["shift", "ArrowUp"]);
370 await animationFrame();
371 expect(`.o_data_row:eq(2) .o_list_record_selector input`).toBeFocused();
372 expect(`.o_data_row:eq(2) .o_list_record_selector input`).toBeChecked();
373
374 // Check that the three checkbox are checked
375 expect(`.o_data_row:eq(1) .o_list_record_selector input`).toBeChecked();
376 expect(`.o_data_row:eq(2) .o_list_record_selector input`).toBeChecked();
377 expect(`.o_data_row:eq(3) .o_list_record_selector input`).toBeChecked();
378 });
379
380 test.tags("desktop");
381 test(`multiple interactions to change the range of checked boxes`, async () => {
382 for (let i = 0; i < 5; i++) {
383 Foo._records.push({ id: 5 + i, bar: true, foo: "foo" + i });
384 }
385
386 await mountView({
387 resModel: "foo",
388 type: "list",
389 arch: `<list><field name="foo"/><field name="int_field"/></list>`,
390 });
391
392 await press("down");
393 await animationFrame();
394 expect(`.o_data_row:eq(0) .o_list_record_selector input`).not.toBeFocused();
395
396 await keyDown("shift");
397 await press("down");
398 await animationFrame();
399 expect(`.o_data_row:eq(0) .o_list_record_selector input`).toBeFocused();
400
401 await press("down");
402 await press("down");
403 await press("down");
404 await press("up");
405 await keyUp("shift");
406 await press("down");
407 await press("down");
408 await press(["shift", "down"]);
409 await animationFrame();
410
411 await contains(`.o_data_row:eq(7) .o_list_record_selector .o-checkbox`).click();
412 await press(["shift", "down"]);
413 await animationFrame();
414
415 expect(`.o_data_row:eq(0) .o_list_record_selector input`).toBeChecked();
416 expect(`.o_data_row:eq(1) .o_list_record_selector input`).toBeChecked();
417 expect(`.o_data_row:eq(2) .o_list_record_selector input`).toBeChecked();
418 expect(`.o_data_row:eq(3) .o_list_record_selector input`).not.toBeChecked();
419 expect(`.o_data_row:eq(4) .o_list_record_selector input`).toBeChecked();
420 expect(`.o_data_row:eq(5) .o_list_record_selector input`).toBeChecked();
421 expect(`.o_data_row:eq(6) .o_list_record_selector input`).not.toBeChecked();
422 expect(`.o_data_row:eq(7) .o_list_record_selector input`).toBeChecked();
423 expect(`.o_data_row:eq(8) .o_list_record_selector input`).toBeChecked();
424 });
425
426 test(`list with class and style attributes`, async () => {
427 await mountView({
428 resModel: "foo",
429 type: "list",
430 arch: `
431 <list class="myClass" style="border: 1px solid red;">
432 <field name="foo"/>
433 </list>
434 `,
435 });
436 expect(
437 `.o_view_controller[style*='border: 1px solid red;'], .o_view_controller [style*='border: 1px solid red;']`
438 ).toHaveCount(0, { message: "style attribute should not be copied" });
439 expect(`.o_view_controller.o_list_view.myClass`).toHaveCount(1, {
440 message: "class attribute should be passed to the view controller",
441 });
442 expect(`.myClass`).toHaveCount(1, {
443 message: "class attribute should ONLY be passed to the view controller",
444 });
445 });
446
447 test(`list with integer field with human_readable option`, async () => {
448 Foo._records[0].int_field = 5 * 1000 * 1000;
449 await mountView({
450 type: "list",
451 resModel: "foo",
452 arch: `
453 <list>
454 <field name="int_field" options="{'human_readable': true}"/>
455 </list>`,
456 });
457
458 expect(queryAllTexts(".o_data_cell")).toEqual(["5M", "9", "17", "-4"]);
459 expect(".o_field_widget").toHaveCount(0);
460 });
461
462 test(`list with create="0"`, async () => {
463 await mountView({
464 resModel: "foo",
465 type: "list",
466 arch: `<list create="0"><field name="foo"/></list>`,
467 });
468 expect(`.o_list_button_add`).toHaveCount(0, { message: "should not have the 'Create' button" });
469 });
470
471 test.tags("desktop");
472 test(`searchbar in listview doesn't take focus after unselected all items`, async () => {
473 await mountView({
474 resModel: "foo",
475 type: "list",
476 arch: `<list><field name="foo"/></list>`,
477 });
478 expect(`.o_searchview_input`).toBeFocused({
479 message: "The search input should be have the focus",
480 });
481
482 await contains(`tbody .o_data_row:eq(0) input[type="checkbox"]`).click();
483 await contains(`tbody input[type="checkbox"]:checked`).click();
484 expect(`.o_searchview_input`).not.toBeFocused({
485 message: "The search input shouldn't have the focus",
486 });
487 });
488
489 test.tags("desktop");
490 test(`basic list view and command palette`, async () => {
491 await mountView({
492 resModel: "foo",
493 type: "list",
494 arch: `<list><field name="foo"/></list>`,
495 });
496
497 await press(["control", "k"]);
498 await animationFrame();
499 expect(queryAllTexts(`.o_command_hotkey`)).toEqual([
500 "New\nALT + C",
501 "Actions\nALT + U",
502 "Search...\nALT + Q",
503 "Toggle search panel\nALT + SHIFT + Q",
504 ]);
505 });
506
507 test(`list with delete="0"`, async () => {
508 await mountView({
509 resModel: "foo",
510 type: "list",
511 arch: `<list delete="0"><field name="foo"/></list>`,
512 actionMenus: {},
513 });
514 expect(`div.o_control_panel .o_cp_action_menus`).toHaveCount(1);
515 expect(`tbody tr.o_data_row[data-id]`).toHaveCount(4, { message: "should have 4 records" });
516
517 await clickRecordSelector();
518 await toggleActionMenu();
519 expect(`.o-dropdown-item`).toHaveCount(2);
520 expect(queryAllTexts(`.o-dropdown-item`)).toEqual(["Export", "Duplicate"]);
521 });
522
523 test.tags("desktop");
524 test(`editable list with edit="0"`, async () => {
525 await mountView({
526 resModel: "foo",
527 type: "list",
528 arch: `<list editable="top" edit="0"><field name="foo"/></list>`,
529 selectRecord(resId, options) {
530 expect.step(`switch to form - resId: ${resId} activeIds: ${options.activeIds}`);
531 },
532 });
533 expect(`tbody tr.o_data_row[data-id]`).toHaveCount(4);
534
535 await contains(`.o_data_cell`).click();
536 expect(`tbody tr.o_selected_row`).toHaveCount(0, { message: "should not have editable row" });
537 expect.verifySteps(["switch to form - resId: 1 activeIds: 1,2,3,4"]);
538 });
539
540 test(`non-editable list with open_form_view`, async () => {
541 await mountView({
542 resModel: "foo",
543 type: "list",
544 arch: `<list open_form_view="1"><field name="foo"/></list>`,
545 });
546 expect(".o_optional_columns_dropdown").toHaveCount(0);
547 expect(`td.o_list_record_open_form_view`).toHaveCount(0, {
548 message: "button to open form view should not be present on non-editable list",
549 });
550 });
551
552 test.tags("desktop");
553 test(`editable list with open_form_view not set`, async () => {
554 await mountView({
555 resModel: "foo",
556 type: "list",
557 arch: `<list editable="top"><field name="foo"/></list>`,
558 });
559 expect(`td.o_list_record_open_form_view`).toHaveCount(0, {
560 message: "button to open form view should not be present",
561 });
562 });
563
564 test.tags("desktop");
565 test(`editable list with open_form_view`, async () => {
566 await mountView({
567 resModel: "foo",
568 type: "list",
569 arch: `<list editable="top" open_form_view="1"><field name="foo"/></list>`,
570 selectRecord(resId, options) {
571 expect.step(`switch to form - resId: ${resId} activeIds: ${options.activeIds}`);
572 },
573 });
574 expect(".o_optional_columns_dropdown").toHaveCount(0);
575 expect(`td.o_list_record_open_form_view`).toHaveCount(4, {
576 message: "button to open form view should be present on each rows",
577 });
578
579 await contains(`td.o_list_record_open_form_view`).click();
580 expect.verifySteps(["switch to form - resId: 1 activeIds: 1,2,3,4"]);
581 });
582
583 test.tags("desktop");
584 test(`editable list with open_form_view in debug`, async () => {
585 serverState.debug = "1";
586 await mountView({
587 resModel: "foo",
588 type: "list",
589 arch: `<list editable="top" open_form_view="1"><field name="foo"/></list>`,
590 });
591 expect(".o_optional_columns_dropdown").toHaveCount(0);
592 expect(`td.o_list_record_open_form_view`).toHaveCount(4, {
593 message: "button to open form view should be present on each rows",
594 });
595 });
596
597 test.tags("desktop");
598 test(`editable list without open_form_view in debug`, async () => {
599 patchWithCleanup(localStorage, {
600 getItem(key) {
601 const value = super.getItem(...arguments);
602 if (key.startsWith("debug_open_view")) {
603 expect.step(["getItem", key, value]);
604 }
605 return value;
606 },
607 setItem(key, value) {
608 if (key.startsWith("debug_open_view")) {
609 expect.step(["setItem", key, value]);
610 }
611 super.setItem(...arguments);
612 },
613 });
614 serverState.debug = "1";
615 await mountView({
616 resModel: "foo",
617 type: "list",
618 arch: `<list editable="top"><field name="foo"/></list>`,
619 viewId: 1,
620 selectRecord(resId, options) {
621 expect.step(`switch to form - resId: ${resId} activeIds: ${options.activeIds}`);
622 },
623 });
624 const localStorageKey = "debug_open_view,foo,list,1,foo";
625 expect.verifySteps([["getItem", localStorageKey, null]]);
626 expect(`td.o_list_record_open_form_view`).toHaveCount(0);
627 expect(".o_optional_columns_dropdown").toHaveCount(1);
628 await contains(".o_optional_columns_dropdown button").click();
629 expect(".o-dropdown-item:contains('View Button')").toHaveCount(1);
630 await contains(".o-dropdown-item:contains('View Button')").click();
631 expect.verifySteps([
632 ["setItem", localStorageKey, true],
633 ["getItem", localStorageKey, "true"],
634 ]);
635
636 expect(`td.o_list_record_open_form_view`).toHaveCount(4, {
637 message: "button to open form view should be present on each rows",
638 });
639
640 await contains(`td.o_list_record_open_form_view`).click();
641 expect.verifySteps(["switch to form - resId: 1 activeIds: 1,2,3,4"]);
642
643 await contains(".o_optional_columns_dropdown button").click();
644 await contains(".o-dropdown-item:contains('View Button')").click();
645 expect.verifySteps([
646 ["setItem", localStorageKey, false],
647 ["getItem", localStorageKey, "false"],
648 ]);
649 expect(`td.o_list_record_open_form_view`).toHaveCount(0, {
650 message: "button to open form view should no longer be present",
651 });
652 });
653
654 test(`non-editable list in debug`, async () => {
655 serverState.debug = "1";
656 await mountView({
657 resModel: "foo",
658 type: "list",
659 arch: `<list><field name="foo"/></list>`,
660 });
661 expect(".o_optional_columns_dropdown").toHaveCount(0);
662 });
663
664 test(`editable readonly list with open_form_view`, async () => {
665 Foo._fields.foo_o2m = fields.One2many({ relation: "foo" });
666 Foo._records.push({ id: 5, bar: true, foo: "xxx" }, { id: 6, bar: true, foo: "yyy" });
667 Foo._records[0].foo_o2m = [5, 6];
668
669 await mountView({
670 resModel: "foo",
671 type: "form",
672 resId: 1,
673 arch: `
674 <form>
675 <sheet>
676 <field name="foo_o2m" readonly="1">
677 <list editable="top" open_form_view="1">
678 <field name="foo"/>
679 <field name="bar"/>
680 </list>
681 </field>
682 </sheet>
683 </form>
684 `,
685 });
686 expect(`td.o_list_record_open_form_view`).toHaveCount(2, {
687 message: "button to open form view should be present on each rows",
688 });
689 });
690
691 test(`export feature in list for users not in base.group_allow_export`, async () => {
692 onRpc("has_group", ({ args }) => args[1] !== "base.group_allow_export");
693 await mountView({
694 resModel: "foo",
695 type: "list",
696 arch: `<list><field name="foo"/></list>`,
697 actionMenus: {},
698 });
699 expect(`div.o_control_panel .o_cp_action_menus`).toHaveCount(0);
700 expect(`.o_data_row`).toHaveCount(4);
701 expect(`div.o_control_panel .o_cp_buttons .o_list_export_xlsx`).toHaveCount(0);
702
703 await clickRecordSelector();
704 expect(`div.o_control_panel .o_cp_action_menus`).toHaveCount(1);
705
706 await toggleActionMenu();
707 expect(queryAllTexts(`.o-dropdown--menu .o_menu_item`)).toEqual(["Duplicate", "Delete"], {
708 message: "action menu should not contain the Export button",
709 });
710 });
711
712 test(`list with export button`, async () => {
713 onRpc("has_group", ({ args }) => args[1] === "base.group_allow_export");
714 await mountView({
715 resModel: "foo",
716 type: "list",
717 arch: `<list><field name="foo"/></list>`,
718 actionMenus: {},
719 });
720 expect(`div.o_control_panel .o_cp_action_menus`).toHaveCount(1);
721 expect(`.o_data_row`).toHaveCount(4);
722
723 await clickRecordSelector();
724 expect(`div.o_control_panel .o_cp_action_menus`).toHaveCount(1);
725
726 await toggleActionMenu();
727 expect(queryAllTexts(`.o-dropdown--menu .o_menu_item`)).toEqual(
728 ["Export", "Duplicate", "Delete"],
729 { message: "action menu should have Export button" }
730 );
731 });
732
733 test(`Direct export button invisible`, async () => {
734 onRpc("has_group", ({ args }) => args[1] === "base.group_allow_export");
735 await mountView({
736 resModel: "foo",
737 type: "list",
738 arch: `<list export_xlsx="0"><field name="foo"/></list>`,
739 });
740 expect(`.o_list_export_xlsx`).toHaveCount(0);
741 });
742
743 test(`list view with adjacent buttons`, async () => {
744 await mountView({
745 resModel: "foo",
746 type: "list",
747 arch: `
748 <list>
749 <button name="a" type="object" icon="fa-car"/>
750 <field name="foo"/>
751 <button name="x" type="object" icon="fa-star"/>
752 <button name="y" type="object" icon="fa-refresh"/>
753 <button name="z" type="object" icon="fa-exclamation"/>
754 </list>
755 `,
756 });
757 expect(`th:not(.o_list_record_selector)`).toHaveCount(3, {
758 message: "adjacent buttons in the arch must be grouped in a single column",
759 });
760 expect(`.o_data_row:eq(0) td.o_list_button`).toHaveCount(2);
761 });
762
763 test(`list view with adjacent buttons and invisible field and button`, async () => {
764 await mountView({
765 type: "list",
766 resModel: "foo",
767 arch: `
768 <list>
769 <button name="a" type="object" icon="fa-car"/>
770 <field name="foo" column_invisible="1"/>
771 <!--Here the column_invisible=1 is used to simulate a group on the case that the user
772 don't have the rights to see the button.-->
773 <button name="b" type="object" icon="fa-car" column_invisible="1"/>
774 <button name="x" type="object" icon="fa-star"/>
775 <button name="y" type="object" icon="fa-refresh"/>
776 <button name="z" type="object" icon="fa-exclamation"/>
777 </list>
778 `,
779 });
780 expect(`th:not(.o_list_record_selector)`).toHaveCount(2, {
781 message: "adjacent buttons in the arch must be grouped in a single column",
782 });
783 expect(`tr:first-child button`).toHaveCount(4, { message: "Only 4 buttons should be visible" });
784 expect(`.o_data_row:first-child td.o_list_button`).toHaveCount(2);
785 });
786
787 test(`list view with adjacent buttons and invisible field (modifier)`, async () => {
788 await mountView({
789 resModel: "foo",
790 type: "list",
791 arch: `
792 <list>
793 <button name="a" type="object" icon="fa-car"/>
794 <field name="foo" invisible="foo == 'blip'"/>
795 <button name="x" type="object" icon="fa-star"/>
796 <button name="y" type="object" icon="fa-refresh"/>
797 <button name="z" type="object" icon="fa-exclamation"/>
798 </list>
799 `,
800 });
801 expect(`th:not(.o_list_record_selector)`).toHaveCount(3, {
802 message: "adjacent buttons in the arch must be grouped in a single column",
803 });
804 expect(`.o_data_row:eq(0) td.o_list_button`).toHaveCount(2);
805 });
806
807 test(`list view with adjacent buttons and optional field`, async () => {
808 await mountView({
809 resModel: "foo",
810 type: "list",
811 arch: `
812 <list>
813 <button name="a" type="object" icon="fa-car"/>
814 <field name="foo" optional="hide"/>
815 <button name="x" type="object" icon="fa-star"/>
816 <button name="y" type="object" icon="fa-refresh"/>
817 <button name="z" type="object" icon="fa-exclamation"/>
818 </list>
819 `,
820 });
821 expect(`th:not(.o_list_record_selector)`).toHaveCount(3, {
822 message: "adjacent buttons in the arch must be grouped in a single column",
823 });
824 expect(`.o_data_row:eq(0) td.o_list_button`).toHaveCount(2);
825 });
826
827 test(`wait the view reload before closing the dialog (save)`, async () => {
828 let searchReadDef;
829 onRpc("web_search_read", () => searchReadDef);
830 Foo._views = {
831 form: `<form><field name="foo"/></form>`,
832 };
833 onRpc("/web/dataset/call_button/foo/a", () => ({
834 type: "ir.actions.act_window",
835 name: "Archive Action",
836 res_model: "foo",
837 res_id: 1,
838 view_mode: "form",
839 target: "new",
840 views: [[false, "form"]],
841 }));
842
843 await mountView({
844 resModel: "foo",
845 type: "list",
846 arch: `
847 <list editable="bottom">
848 <field name="foo"/>
849 <button name="a" type="object" icon="fa-car"/>
850 </list>
851 `,
852 });
853 searchReadDef = new Deferred();
854 await contains(`tbody .o_list_button button:eq(0)`).click();
855 expect(`.o_dialog`).toHaveCount(1);
856 await contains(`.o_form_renderer .o_field_widget[name='foo'] input`).edit("plop");
857 await contains(`.o_dialog .o_form_button_save`).click();
858
859 await animationFrame(); // not needed but to be sure that the dialog is not closed.
860 expect(`.o_dialog`).toHaveCount(1);
861 searchReadDef.resolve();
862
863 await animationFrame();
864 expect(`.o_dialog`).toHaveCount(0);
865 expect(`tbody .o_list_char:eq(0)`).toHaveText("plop");
866 });
867
868 test(`wait the view reload before closing the dialog (cancel)`, async () => {
869 let searchReadDef;
870 onRpc("web_search_read", () => searchReadDef);
871 Foo._views = {
872 form: `<form><field name="foo"/></form>`,
873 };
874 onRpc("/web/dataset/call_button/foo/a", () => ({
875 type: "ir.actions.act_window",
876 name: "Archive Action",
877 res_model: "foo",
878 res_id: 1,
879 view_mode: "form",
880 target: "new",
881 views: [[false, "form"]],
882 }));
883
884 await mountView({
885 resModel: "foo",
886 type: "list",
887 arch: `
888 <list editable="bottom">
889 <field name="foo"/>
890 <button name="a" type="object" icon="fa-car"/>
891 </list>
892 `,
893 });
894 searchReadDef = new Deferred();
895 await contains(`tbody .o_list_button button:eq(0)`).click();
896 expect(`.o_dialog`).toHaveCount(1);
897 await contains(`.o_form_renderer .o_field_widget[name='foo'] input`).edit("plop");
898 await contains(`.o_dialog .o_form_button_cancel`).click();
899
900 await animationFrame(); // not needed but to be sure that the dialog is not closed.
901 expect(`.o_dialog`).toHaveCount(1);
902 searchReadDef.resolve();
903
904 await animationFrame();
905 expect(`.o_dialog`).toHaveCount(0);
906 expect(`tbody .o_list_char:eq(0)`).toHaveText("yop");
907 });
908
909 test(`list view with adjacent buttons with invisible modifier`, async () => {
910 await mountView({
911 resModel: "foo",
912 type: "list",
913 arch: `
914 <list>
915 <field name="foo"/>
916 <button name="x" type="object" icon="fa-star" invisible="foo == 'blip'"/>
917 <button name="y" type="object" icon="fa-refresh" invisible="foo == 'yop'"/>
918 <button name="z" type="object" icon="fa-exclamation" invisible="foo == 'gnap'"/>
919 </list>
920 `,
921 });
922 expect(`th:not(.o_list_record_selector)`).toHaveCount(2, {
923 message: "adjacent buttons in the arch must be grouped in a single column",
924 });
925 expect(`.o_data_row`).toHaveCount(4);
926 expect(`.o_data_row td.o_list_button`).toHaveCount(4);
927 expect(queryAllTexts(`.o_data_cell`)).toEqual(["yop", "", "blip", "", "gnap", "", "blip", ""]);
928 expect(`td button i.fa-star`).toHaveCount(2);
929 expect(`td button i.fa-refresh`).toHaveCount(3);
930 expect(`td button i.fa-exclamation`).toHaveCount(3);
931 });
932
933 test(`list view with adjacent buttons with width attribute`, async () => {
934 await mountView({
935 resModel: "foo",
936 type: "list",
937 arch: `
938 <list>
939 <field name="foo"/>
940 <button icon="fa-play"/>
941 <button icon="fa-heart" width="25px"/>
942 <button icon="fa-cog"/>
943 <button icon="fa-list"/>
944 </list>
945 `,
946 });
947 expect(`th:not(.o_list_record_selector)`).toHaveCount(4, {
948 message: "adjacent buttons with no width in the arch must be grouped in a single column",
949 });
950 expect(".o_data_row td:not(.o_list_record_selector):eq(1) .fa-play").toHaveCount(1);
951 expect(".o_data_row td:not(.o_list_record_selector):eq(2) .fa-heart").toHaveCount(1);
952 expect(".o_data_row td:not(.o_list_record_selector):eq(3) .fa-cog").toHaveCount(1);
953 expect(".o_data_row td:not(.o_list_record_selector):eq(3) .fa-list").toHaveCount(1);
954 });
955
956 test(`list view with icon buttons`, async () => {
957 Foo._records.splice(1);
958
959 await mountView({
960 resModel: "foo",
961 type: "list",
962 arch: `
963 <list>
964 <button name="x" type="object" icon="fa-asterisk"/>
965 <button name="x" type="object" icon="fa-star" class="o_yeah"/>
966 <button name="x" type="object" icon="fa-refresh" string="Refresh" class="o_yeah"/>
967 <button name="x" type="object" icon="fa-exclamation" string="Danger" class="o_yeah btn-danger"/>
968 </list>
969 `,
970 });
971 expect(`button.btn.btn-link i.fa.fa-asterisk`).toHaveCount(1);
972 expect(`button.btn.btn-link.o_yeah i.fa.fa-star`).toHaveCount(1);
973 expect(`button.btn.btn-link.o_yeah:contains(Refresh) i.fa.fa-refresh`).toHaveCount(1);
974 expect(`button.btn.btn-danger.o_yeah:contains(Danger) i.fa.fa-exclamation`).toHaveCount(1);
975 expect(`button.btn.btn-link.btn-danger`).toHaveCount(0);
976 });
977
978 test(`list view with disabled button`, async () => {
979 await mountView({
980 resModel: "foo",
981 type: "list",
982 arch: `
983 <list>
984 <button name="a" icon="fa-coffee"/>
985 <button name="b" icon="fa-car" disabled="disabled"/>
986 </list>
987 `,
988 });
989 expect(queryAll(`button[name='a']`).every((btn) => !btn.disabled)).toBe(true);
990 expect(queryAll(`button[name='b']`).every((btn) => btn.disabled)).toBe(true);
991 });
992
993 test.tags("desktop");
994 test(`list view: action button in controlPanel basic rendering on desktop`, async () => {
995 await mountView({
996 resModel: "foo",
997 type: "list",
998 arch: `
999 <list>
1000 <header>
1001 <button name="x" type="object" class="plaf" string="plaf"/>
1002 <button name="y" type="object" class="plouf" string="plouf" invisible="not context.get('bim')"/>
1003 </header>
1004 <field name="foo"/>
1005 </list>
1006 `,
1007 });
1008 expect(`.o_control_panel_actions button[name=x]`).toHaveCount(0);
1009 expect(`.o_control_panel_actions .o_selection_box`).toHaveCount(0);
1010 expect(`.o_control_panel_actions button[name="y"]`).toHaveCount(0);
1011
1012 await contains(`.o_data_row .o_list_record_selector input[type="checkbox"]`).click();
1013 expect(`.o_control_panel_actions button[name=x]`).toHaveCount(1);
1014 expect(`.o_control_panel_actions button[name=x]`).toHaveClass("btn btn-secondary plaf");
1015 expect(`.o_control_panel_actions .o_selection_box`).toHaveCount(1);
1016 expect(queryFirst(`.o_control_panel_actions button[name=x]`).previousElementSibling).toBe(
1017 queryFirst(`.o_control_panel_actions .o_selection_box`)
1018 );
1019 expect(`.o_control_panel_actions button[name=y]`).toHaveCount(0);
1020
1021 await contains(`.o_data_row .o_list_record_selector input[type="checkbox"]`).click();
1022 expect(`.o_control_panel_actions button[name=x]`).toHaveCount(0);
1023 expect(`.o_control_panel_actions .o_selection_box`).toHaveCount(0);
1024 expect(`.o_control_panel_actions button[name="y"]`).toHaveCount(0);
1025 });
1026
1027 test.tags("mobile");
1028 test(`list view: action button in controlPanel basic rendering on mobile`, async () => {
1029 await mountView({
1030 resModel: "foo",
1031 type: "list",
1032 arch: `
1033 <list>
1034 <header>
1035 <button name="x" type="object" class="plaf" string="plaf"/>
1036 <button name="y" type="object" class="plouf" string="plouf" invisible="not context.get('bim')"/>
1037 </header>
1038 <field name="foo"/>
1039 </list>
1040 `,
1041 });
1042 expect(`.o_control_panel_actions > *`).toHaveCount(0);
1043 await contains(".o_control_panel_breadcrumbs .o_cp_action_menus .fa-cog").click();
1044 expect(queryAllTexts(`.o-dropdown--menu .o-dropdown-item`)).toEqual(["Export All"]);
1045 await clickRecordSelector();
1046 await contains(".o_control_panel_breadcrumbs .o_cp_action_menus .fa-cog").click();
1047 expect(queryAllTexts(`.o-dropdown--menu .o-dropdown-item`)).toEqual([
1048 "plaf",
1049 "Export",
1050 "Duplicate",
1051 "Delete",
1052 ]);
1053 await clickRecordSelector();
1054 await contains(".o_control_panel_breadcrumbs .o_cp_action_menus .fa-cog").click();
1055 expect(queryAllTexts(`.o-dropdown--menu .o-dropdown-item`)).toEqual(["Export All"]);
1056 });
1057
1058 test.tags("desktop");
1059 test(`list view: action button in controlPanel with display='always' on desktop`, async () => {
1060 await mountView({
1061 resModel: "foo",
1062 type: "list",
1063 arch: `
1064 <list>
1065 <header>
1066 <button name="display" type="object" class="display" string="display" display="always"/>
1067 <button name="display" type="object" class="display_invisible" string="invisible 1" display="always" invisible="1"/>
1068 <button name="display" type="object" class="display_invisible" string="invisible context" display="always" invisible="context.get('a')"/>
1069 <button name="default-selection" type="object" class="default-selection" string="default-selection"/>
1070 </header>
1071 <field name="foo"/>
1072 </list>
1073 `,
1074 context: {
1075 a: true,
1076 },
1077 });
1078 expect(
1079 queryAllTexts(`div.o_control_panel_breadcrumbs button, div.o_control_panel_actions button`)
1080 ).toEqual([
1081 "New",
1082 "display",
1083 "", // magnifying glass btn
1084 "", // cog dropdown
1085 "", // search btn
1086 ]);
1087
1088 await contains(`.o_data_row .o_list_record_selector input[type="checkbox"]`).click();
1089 expect(
1090 queryAllTexts(`div.o_control_panel_breadcrumbs button, div.o_control_panel_actions button`)
1091 ).toEqual(["New", "display", "" /* unselect all btn */, "default-selection"]);
1092
1093 await contains(`.o_data_row .o_list_record_selector input[type="checkbox"]`).click();
1094 expect(
1095 queryAllTexts(`div.o_control_panel_breadcrumbs button, div.o_control_panel_actions button`)
1096 ).toEqual([
1097 "New",
1098 "display",
1099 "", // magnifying glass btn
1100 "", // cog dropdown
1101 "", // search btn
1102 ]);
1103 });
1104
1105 test.tags("mobile");
1106 test(`list view: action button in controlPanel with display='always' on mobile`, async () => {
1107 await mountView({
1108 resModel: "foo",
1109 type: "list",
1110 arch: `
1111 <list>
1112 <header>
1113 <button name="display" type="object" class="display" string="display" display="always"/>
1114 <button name="display" type="object" class="display_invisible" string="invisible 1" display="always" invisible="1"/>
1115 <button name="display" type="object" class="display_invisible" string="invisible context" display="always" invisible="context.get('a')"/>
1116 <button name="default-selection" type="object" class="default-selection" string="default-selection"/>
1117 </header>
1118 <field name="foo"/>
1119 </list>
1120 `,
1121 context: {
1122 a: true,
1123 },
1124 });
1125 expect(
1126 queryAllTexts(`div.o_control_panel_breadcrumbs button, div.o_control_panel_actions button`)
1127 ).toEqual([
1128 "New",
1129 "display",
1130 "", // mobile dropdown
1131 "", // default selection
1132 ]);
1133
1134 await clickRecordSelector();
1135 await contains(".o_control_panel_breadcrumbs .o_cp_action_menus .fa-cog").click();
1136 expect(queryAllTexts(`.o-dropdown--menu .o-dropdown-item`)).toEqual([
1137 "",
1138 "default-selection",
1139 "Export",
1140 "Duplicate",
1141 "Delete",
1142 ]);
1143
1144 await clickRecordSelector();
1145 expect(
1146 queryAllTexts(`div.o_control_panel_breadcrumbs button, div.o_control_panel_actions button`)
1147 ).toEqual([
1148 "New",
1149 "display",
1150 "", // mobile dropdown
1151 "",
1152 ]);
1153 });
1154
1155 test(`list view: give a context dependent on the current context to a header button`, async () => {
1156 mockService("action", {
1157 doActionButton(action) {
1158 expect.step("doActionButton");
1159 expect(action.buttonContext).toEqual({
1160 active_domain: [],
1161 active_ids: [],
1162 active_model: "foo",
1163 b: "yop",
1164 });
1165 },
1166 });
1167
1168 await mountView({
1169 resModel: "foo",
1170 type: "list",
1171 arch: `
1172 <list>
1173 <header>
1174 <button name="toDo" type="object" string="toDo" display="always" context="{'b': context.get('a')}"/>
1175 </header>
1176 <field name="foo"/>
1177 </list>
1178 `,
1179 context: {
1180 a: "yop",
1181 },
1182 });
1183 if (getMockEnv().isSmall) {
1184 await contains(".btn.dropdown-toggle").click();
1185 }
1186 await contains(`button[name=toDo]`).click();
1187 expect.verifySteps(["doActionButton"]);
1188 });
1189
1190 test(`list view: action button executes action on click: buttons are disabled and re-enabled`, async () => {
1191 const executeActionDef = new Deferred();
1192 mockService("action", {
1193 async doActionButton() {
1194 await executeActionDef;
1195 },
1196 });
1197
1198 await mountView({
1199 resModel: "foo",
1200 type: "list",
1201 arch: `
1202 <list>
1203 <header>
1204 <button name="x" type="object" class="plaf" string="plaf"/>
1205 </header>
1206 <field name="foo"/>
1207 </list>
1208 `,
1209 });
1210 await clickRecordSelector();
1211 const cpButtons = queryAll`div.o_control_panel_breadcrumbs button, div.o_control_panel_actions button`;
1212 expect(cpButtons.every((btn) => !btn.disabled)).toBe(true);
1213
1214 await clickControlPanelAction("x");
1215 expect(cpButtons.every((btn) => btn.disabled)).toBe(true);
1216
1217 executeActionDef.resolve();
1218 await animationFrame();
1219 expect(cpButtons.every((btn) => !btn.disabled)).toBe(true);
1220 });
1221
1222 test(`list view: buttons handler is called once on double click`, async () => {
1223 const executeActionDef = new Deferred();
1224 mockService("action", {
1225 async doActionButton() {
1226 expect.step("execute_action");
1227 await executeActionDef;
1228 },
1229 });
1230
1231 await mountView({
1232 resModel: "foo",
1233 type: "list",
1234 arch: `
1235 <list>
1236 <field name="foo"/>
1237 <button name="x" type="object" class="do_something" string="Do Something"/>
1238 </list>
1239 `,
1240 });
1241 await contains(`tbody .o_list_button button:eq(0)`).click();
1242 expect(`tbody .o_list_button button:eq(0)`).toHaveProperty("disabled", true);
1243
1244 executeActionDef.resolve();
1245 await animationFrame();
1246 expect(`tbody .o_list_button button:eq(0)`).toHaveProperty("disabled", false);
1247 expect.verifySteps(["execute_action"]);
1248 });
1249
1250 test(`list view: click on an action button saves the record before executing the action`, async () => {
1251 onRpc("/web/dataset/call_button/*", () => true);
1252 stepAllNetworkCalls();
1253
1254 await mountView({
1255 resModel: "foo",
1256 type: "list",
1257 arch: `
1258 <list editable="bottom">
1259 <field name="foo"/>
1260 <button name="toDo" type="object" class="do_something" string="Do Something"/>
1261 </list>
1262 `,
1263 });
1264 await contains(`.o_data_cell`).click();
1265 await contains(`.o_data_row [name='foo'] input`).edit("plop", { confirm: false });
1266 expect(`.o_data_row [name='foo'] input`).toHaveValue("plop");
1267
1268 await contains(`.o_data_row button`).click();
1269 expect(queryFirst(`.o_data_row [name='foo']`)).toHaveText("plop");
1270 expect.verifySteps([
1271 "/web/webclient/translations",
1272 "/web/webclient/load_menus",
1273 "get_views",
1274 "web_search_read",
1275 "has_group",
1276 "web_save",
1277 "toDo",
1278 "web_search_read",
1279 ]);
1280 });
1281
1282 test(`list view: action button executes action on click: correct parameters`, async () => {
1283 mockService("action", {
1284 async doActionButton(params) {
1285 expect.step("doActionButton");
1286
1287 const { buttonContext, context, name, resModel, resIds, type } = params;
1288 // Action's own properties
1289 expect(name).toBe("x");
1290 expect(type).toBe("object");
1291
1292 // The action's execution context
1293 expect(buttonContext).toEqual({
1294 active_domain: [],
1295 // active_id: 1, //FGE TODO
1296 active_ids: [1],
1297 active_model: "foo",
1298 plouf: "plif",
1299 });
1300
1301 expect(resModel).toBe("foo");
1302 expect([...resIds]).toEqual([1]);
1303 expect(context).toEqual({
1304 lang: "en",
1305 paf: "pif",
1306 tz: "taht",
1307 uid: 7,
1308 allowed_company_ids: [1],
1309 });
1310 },
1311 });
1312
1313 await mountView({
1314 resModel: "foo",
1315 type: "list",
1316 arch: `
1317 <list>
1318 <header>
1319 <button name="x" type="object" class="plaf" string="plaf" context="{'plouf': 'plif'}"/>
1320 </header>
1321 <field name="foo"/>
1322 </list>
1323 `,
1324 context: {
1325 paf: "pif",
1326 },
1327 });
1328 await clickRecordSelector();
1329 await clickControlPanelAction("x");
1330 expect.verifySteps(["doActionButton"]);
1331 });
1332
1333 test(`list view: action button executes action on click with domain selected: correct parameters`, async () => {
1334 mockService("action", {
1335 async doActionButton(params) {
1336 expect.step("doActionButton");
1337
1338 const { buttonContext, context, name, resModel, resIds, type } = params;
1339 expect.step("execute_action");
1340 // Action's own properties
1341 expect(name).toBe("x");
1342 expect(type).toBe("object");
1343
1344 // The action's execution context
1345 expect(buttonContext).toEqual({
1346 active_domain: [],
1347 // active_id: 1, // FGE TODO
1348 active_ids: [1, 2, 3, 4],
1349 active_model: "foo",
1350 });
1351
1352 expect(context).toEqual({
1353 lang: "en",
1354 tz: "taht",
1355 uid: 7,
1356 allowed_company_ids: [1],
1357 });
1358 expect(resModel).toBe("foo");
1359 expect(resIds).toEqual([1, 2, 3, 4]);
1360 },
1361 });
1362
1363 onRpc("search", ({ args, model }) => {
1364 expect.step("search");
1365 expect(model).toBe("foo");
1366 expect(args).toEqual([[]]); // empty domain since no domain in searchView
1367 });
1368
1369 await mountView({
1370 resModel: "foo",
1371 type: "list",
1372 arch: `
1373 <list limit="1">
1374 <header>
1375 <button name="x" type="object" class="plaf" string="plaf"/>
1376 </header>
1377 <field name="foo"/>
1378 </list>
1379 `,
1380 });
1381 await clickRecordSelector();
1382 await contains(`.o_select_domain`).click();
1383 expect.verifySteps([]);
1384
1385 await clickControlPanelAction("x");
1386 expect.verifySteps(["search", "doActionButton", "execute_action"]);
1387 });
1388
1389 test.tags("desktop");
1390 test(`list view: press "hotkey" to execute header button action`, async () => {
1391 mockService("action", {
1392 doActionButton(params) {
1393 const { name } = params;
1394 expect.step(`execute_action: ${name}`);
1395 },
1396 });
1397
1398 await mountView({
1399 resModel: "foo",
1400 type: "list",
1401 arch: `
1402 <list>
1403 <header>
1404 <button name="toDo" type="object" string="toDo" display="always" data-hotkey="a"/>
1405 </header>
1406 <field name="foo"/>
1407 </list>
1408 `,
1409 });
1410 await press(["alt", "a"]);
1411 await tick();
1412 expect.verifySteps(["execute_action: toDo"]);
1413 });
1414
1415 test(`column names (noLabel, label, string and default)`, async () => {
1416 const charField = registry.category("fields").get("char");
1417
1418 class NoLabelCharField extends charField.component {}
1419 registry.category("fields").add("nolabel_char", {
1420 ...charField,
1421 component: NoLabelCharField,
1422 label: false,
1423 });
1424
1425 class LabelCharField extends charField.component {}
1426 registry.category("fields").add("label_char", {
1427 ...charField,
1428 component: LabelCharField,
1429 label: "Some static label",
1430 });
1431
1432 await mountView({
1433 resModel: "foo",
1434 type: "list",
1435 arch: `
1436 <list>
1437 <field name="display_name" widget="nolabel_char" optional="show"/>
1438 <field name="foo" widget="label_char" optional="show"/>
1439 <field name="int_field" string="My custom label" optional="show"/>
1440 <field name="text" optional="show"/>
1441 </list>
1442 `,
1443 });
1444 expect(queryAllTexts(`thead th:not(.o_list_record_selector)`)).toEqual([
1445 "",
1446 "Some static label",
1447 "My custom label",
1448 "Text",
1449 "",
1450 ]);
1451
1452 await contains(`table .o_optional_columns_dropdown .dropdown-toggle`).click();
1453 expect(queryAllTexts(`.o-dropdown--menu .dropdown-item`)).toEqual([
1454 "Display name",
1455 "Some static label",
1456 "My custom label",
1457 "Text",
1458 ]);
1459 });
1460
1461 test.tags("desktop");
1462 test(`simple editable rendering`, async () => {
1463 await mountView({
1464 resModel: "foo",
1465 type: "list",
1466 arch: `<list editable="bottom"><field name="foo"/><field name="bar"/></list>`,
1467 });
1468 expect(`th`).toHaveCount(3);
1469 expect(`.o_list_record_selector input:enabled`).toHaveCount(5);
1470 expect(`td:contains(yop)`).toHaveCount(1);
1471 expect(`.o_list_button_add`).toHaveCount(1);
1472 expect(`.o_list_button_save`).toHaveCount(0);
1473 expect(`.o_list_button_discard`).toHaveCount(0);
1474
1475 await contains(`.o_field_cell`).click();
1476 expect(`.o_list_button_add`).toHaveCount(0);
1477 expect(`.o_list_button_save`).toHaveCount(1);
1478 expect(`.o_list_button_discard`).toHaveCount(1);
1479 expect(`.o_list_record_selector input:enabled`).toHaveCount(0);
1480
1481 await contains(`.o_list_button_save`).click();
1482 expect(`.o_list_button_add`).toHaveCount(1);
1483 expect(`.o_list_button_save`).toHaveCount(0);
1484 expect(`.o_list_button_discard`).toHaveCount(0);
1485 expect(`.o_list_record_selector input:enabled`).toHaveCount(5);
1486 });
1487
1488 test(`invisible columns are not displayed`, async () => {
1489 await mountView({
1490 resModel: "foo",
1491 type: "list",
1492 arch: `
1493 <list>
1494 <field name="foo"/>
1495 <field name="bar" column_invisible="1"/>
1496 </list>
1497 `,
1498 });
1499 expect(`th:not(.o_list_record_selector)`).toHaveCount(1, {
1500 message: "should have 1 th for checkbox (desktop only), 1 th for visible column",
1501 });
1502 });
1503
1504 test(`invisible column based on the context are correctly displayed`, async () => {
1505 await mountView({
1506 resModel: "foo",
1507 type: "list",
1508 arch: `
1509 <list>
1510 <field name="date" column_invisible="True"/>
1511 <field name="foo" column_invisible="context.get('notInvisible')"/>
1512 <field name="bar" column_invisible="context.get('invisible')"/>
1513 </list>
1514 `,
1515 context: {
1516 invisible: true,
1517 notInvisible: false,
1518 },
1519 });
1520
1521 expect(`th:not(.o_list_record_selector)`).toHaveCount(1, {
1522 message: "should have 1 th for checkbox, 1 th for foo",
1523 });
1524 expect(`th:not(.o_list_record_selector)`).toHaveAttribute("data-name", "foo");
1525 });
1526
1527 test(`invisible column based on the context are correctly displayed in o2m`, async () => {
1528 Foo._fields.foo_o2m = fields.One2many({ relation: "foo" });
1529
1530 await mountView({
1531 resModel: "foo",
1532 type: "form",
1533 arch: `
1534 <form>
1535 <sheet>
1536 <field name="foo_o2m">
1537 <list>
1538 <field name="foo" column_invisible="context.get('notInvisible')"/>
1539 <field name="bar" column_invisible="context.get('invisible')"/>
1540 </list>
1541 </field>
1542 </sheet>
1543 </form>
1544 `,
1545 resId: 1,
1546 context: {
1547 invisible: true,
1548 notInvisible: false,
1549 },
1550 });
1551
1552 // 1 for 1 visible column (foo), 1 th for delete button
1553 expect(`th`).toHaveCount(2, { message: "should have 2 th" });
1554 expect(`th:eq(0)`).toHaveAttribute("data-name", "foo");
1555 });
1556
1557 test(`invisible column based on the parent are correctly displayed in o2m`, async () => {
1558 Foo._fields.foo_o2m = fields.One2many({ relation: "foo" });
1559
1560 await mountView({
1561 resModel: "foo",
1562 type: "form",
1563 arch: `
1564 <form>
1565 <sheet>
1566 <field name="int_field"/>
1567 <field name="m2m" invisible="True"/>
1568 <field name="properties" invisible="True"/>
1569 <field name="foo_o2m">
1570 <list>
1571 <field name="date" column_invisible="True"/>
1572 <field name="foo" column_invisible="parent.int_field == 3"/>
1573 <field name="bar" column_invisible="parent.int_field == 10"/>
1574 <field name="qux" column_invisible="parent.m2m"/>
1575 <field name="amount" column_invisible="parent.properties"/>
1576 </list>
1577 </field>
1578 </sheet>
1579 </form>
1580 `,
1581 resId: 1,
1582 });
1583
1584 // 1 for 2 visible column (foo, properties), 1 th for delete button
1585 expect(`th`).toHaveCount(3, { message: "should have 3 th" });
1586 expect(`th:eq(0)`).toHaveAttribute("data-name", "foo");
1587 expect(`th:eq(1)`).toHaveAttribute("data-name", "amount");
1588 });
1589
1590 test(`save a record with an invisible required field`, async () => {
1591 Foo._fields.foo = fields.Char({ required: true });
1592
1593 stepAllNetworkCalls();
1594 onRpc("web_save", ({ args }) => {
1595 expect(args[1]).toEqual({ int_field: 1, foo: false });
1596 });
1597
1598 await mountView({
1599 resModel: "foo",
1600 type: "list",
1601 arch: `
1602 <list editable="top">
1603 <field name="foo" column_invisible="1"/>
1604 <field name="int_field"/>
1605 </list>
1606 `,
1607 });
1608 expect(`.o_data_row`).toHaveCount(4);
1609 expect.verifySteps([
1610 "/web/webclient/translations",
1611 "/web/webclient/load_menus",
1612 "get_views",
1613 "web_search_read",
1614 "has_group",
1615 ]);
1616
1617 await contains(`.o_list_button_add`).click();
1618 await contains(`[name='int_field'] input`).edit("1", { confirm: false });
1619 await contains(`.o_list_view`).click();
1620 expect(`.o_data_row`).toHaveCount(5);
1621 expect(`.o_data_row:eq(0) [name='int_field']`).toHaveText("1");
1622 expect.verifySteps(["onchange", "web_save"]);
1623 });
1624
1625 test.tags("desktop");
1626 test("multi_edit: edit a required field with invalid value", async () => {
1627 Foo._fields.foo.required = true;
1628
1629 stepAllNetworkCalls();
1630
1631 await mountView({
1632 resModel: "foo",
1633 type: "list",
1634 arch: `
1635 <list multi_edit="1">
1636 <field name="foo"/>
1637 <field name="int_field"/>
1638 </list>
1639 `,
1640 });
1641
1642 expect(`.o_data_row`).toHaveCount(4);
1643 expect.verifySteps([
1644 "/web/webclient/translations",
1645 "/web/webclient/load_menus",
1646 "get_views",
1647 "web_search_read",
1648 "has_group",
1649 ]);
1650
1651 await contains(`.o_data_row:eq(0) .o_list_record_selector input`).click();
1652 await contains(`.o_data_row:eq(0) .o_data_cell[name='foo']`).click();
1653 await contains(`.o_field_widget[name=foo] input`).clear();
1654
1655 expect(`.o_notification`).toHaveCount(1);
1656 expect(`.o_notification`).toHaveText("Missing required fields");
1657 expect(`.o_data_row:eq(0) .o_data_cell[name='foo']`).toHaveText("yop");
1658 expect(`.o_data_row:eq(0)`).toHaveClass("o_data_row_selected");
1659 expect(`.o_data_row:eq(0)`).not.toHaveClass("o_selected_row");
1660 expect.verifySteps([]);
1661 });
1662
1663 test.tags("desktop");
1664 test(`multi_edit: clicking on a readonly field switches the focus to the next editable field`, async () => {
1665 await mountView({
1666 resModel: "foo",
1667 type: "list",
1668 arch: `
1669 <list multi_edit="1">
1670 <field name="int_field" readonly="1"/>
1671 <field name="foo"/>
1672 </list>
1673 `,
1674 });
1675 await contains(`.o_list_record_selector input`).click();
1676 await contains(`.o_data_row:eq(0) [name=int_field]`).click();
1677 expect(`.o_field_widget[name=foo] input`).toBeFocused();
1678
1679 await contains(`.o_data_row:eq(0) [name=int_field]`).click();
1680 expect(`.o_field_widget[name=foo] input`).toBeFocused();
1681 });
1682
1683 test.tags("desktop");
1684 test(`save a record with an required field computed by another`, async () => {
1685 Foo._onChanges = {
1686 foo(record) {
1687 if (record.foo) {
1688 record.text = "plop";
1689 }
1690 },
1691 };
1692
1693 await mountView({
1694 resModel: "foo",
1695 type: "list",
1696 arch: `
1697 <list editable="top">
1698 <field name="foo"/>
1699 <field name="int_field"/>
1700 <field name="text" required="1"/>
1701 </list>
1702 `,
1703 });
1704 expect(`.o_data_row`).toHaveCount(4);
1705 expect(`.o_selected_row`).toHaveCount(0);
1706
1707 await contains(`.o_list_button_add`).click();
1708 await contains(`[name='int_field'] input`).edit("1");
1709 await contains(`.o_list_view`).click();
1710 expect(`.o_data_row`).toHaveCount(5);
1711 expect(`.o_field_invalid`).toHaveCount(1);
1712 expect(`.o_selected_row`).toHaveCount(1);
1713
1714 await contains(`[name=foo] input`).edit("hello");
1715 expect(`.o_field_invalid`).toHaveCount(0);
1716 expect(`.o_selected_row`).toHaveCount(1);
1717
1718 await contains(`.o_list_view`).click();
1719 expect(`.o_data_row`).toHaveCount(5);
1720 expect(`.o_selected_row`).toHaveCount(0);
1721 });
1722
1723 test(`field with nolabel has no title`, async () => {
1724 await mountView({
1725 resModel: "foo",
1726 type: "list",
1727 arch: `<list><field name="foo" nolabel="1"/></list>`,
1728 });
1729 expect(`thead tr:eq(0) th:not(.o_list_record_selector)`).toHaveText("");
1730 });
1731
1732 test(`field titles are not escaped`, async () => {
1733 Foo._records[0].foo = "<div>Hello</div>";
1734
1735 await mountView({
1736 resModel: "foo",
1737 type: "list",
1738 arch: `<list><field name="foo"/></list>`,
1739 });
1740 expect(`tbody tr:eq(0) .o_data_cell`).toHaveText("<div>Hello</div>");
1741 expect(`tbody tr:eq(0) .o_data_cell`).toHaveAttribute("data-tooltip", "<div>Hello</div>");
1742 });
1743
1744 test(`record-depending invisible lines are correctly aligned`, async () => {
1745 await mountView({
1746 resModel: "foo",
1747 type: "list",
1748 arch: `
1749 <list>
1750 <field name="foo"/>
1751 <field name="bar" invisible="id == 1"/>
1752 <field name="int_field"/>
1753 </list>
1754 `,
1755 });
1756 expect(`.o_data_row`).toHaveCount(4);
1757 expect(`.o_data_row td:not(.o_list_record_selector)`).toHaveCount(12); // 3 cells per row (td checkboxes selector excluded)
1758 expect(`.o_data_row td:not(.o_list_record_selector):eq(1)`).toHaveInnerHTML("");
1759 });
1760
1761 test(`invisble fields must not have a tooltip`, async () => {
1762 await mountView({
1763 resModel: "foo",
1764 type: "list",
1765 arch: `<list><field name="foo" invisible="id == 1"/></list>`,
1766 });
1767 expect(`.o_data_row`).toHaveCount(4);
1768 expect(`.o_data_row td[data-tooltip]`).toHaveCount(3);
1769 });
1770
1771 test(`do not perform extra RPC to read invisible many2one fields`, async () => {
1772 Foo._fields.m2o = fields.Many2one({ relation: "bar", default: 2 });
1773
1774 stepAllNetworkCalls();
1775 await mountView({
1776 resModel: "foo",
1777 type: "list",
1778 arch: `
1779 <list editable="top">
1780 <field name="foo"/>
1781 <field name="m2o" column_invisible="1"/>
1782 </list>
1783 `,
1784 });
1785
1786 await contains(`.o_list_button_add`).click();
1787 // no nameget should be done
1788 expect.verifySteps([
1789 "/web/webclient/translations",
1790 "/web/webclient/load_menus",
1791 "get_views",
1792 "web_search_read",
1793 "has_group",
1794 "onchange",
1795 ]);
1796 });
1797
1798 test.tags("desktop");
1799 test(`editable list datepicker destroy widget (edition)`, async () => {
1800 await mountView({
1801 resModel: "foo",
1802 type: "list",
1803 arch: `<list editable="top"><field name="date"/></list>`,
1804 });
1805 expect(`.o_data_row`).toHaveCount(4);
1806
1807 await contains(`.o_data_cell`).click();
1808 expect(`.o_selected_row`).toHaveCount(1);
1809
1810 await contains(`.o_field_date input`).click();
1811 expect(`.o_datetime_picker`).toHaveCount(1);
1812
1813 await press("Escape");
1814 await animationFrame();
1815 expect(`.o_selected_row`).toHaveCount(0);
1816 expect(`.o_data_row`).toHaveCount(4);
1817 });
1818
1819 test.tags("desktop");
1820 test(`editable list datepicker destroy widget (new line)`, async () => {
1821 await mountView({
1822 resModel: "foo",
1823 type: "list",
1824 arch: `<list editable="top"><field name="date"/></list>`,
1825 });
1826 expect(`.o_data_row`).toHaveCount(4, { message: "There should be 4 rows" });
1827
1828 await contains(`.o_list_button_add`).click();
1829 expect(`.o_selected_row`).toHaveCount(1);
1830
1831 await contains(`.o_field_date input`).click();
1832 expect(`.o_datetime_picker`).toHaveCount(1, { message: "datepicker should be opened" });
1833
1834 await press("escape");
1835 await animationFrame();
1836 expect(`.o_selected_row`).toHaveCount(0, { message: "the row is no longer in edition" });
1837 expect(`.o_data_row`).toHaveCount(4, { message: "There should still be 4 rows" });
1838 });
1839
1840 test(`at least 4 rows are rendered, even if less data`, async () => {
1841 await mountView({
1842 resModel: "foo",
1843 type: "list",
1844 arch: `<list><field name="bar"/></list>`,
1845 domain: [["bar", "=", true]],
1846 });
1847 expect(`tbody tr`).toHaveCount(4, { message: "should have 4 rows" });
1848 });
1849
1850 test(`discard a new record in editable="top" list with less than 4 records`, async () => {
1851 await mountView({
1852 resModel: "foo",
1853 type: "list",
1854 arch: `<list editable="top"><field name="bar"/></list>`,
1855 domain: [["bar", "=", true]],
1856 });
1857 expect(`.o_data_row`).toHaveCount(3);
1858 expect(`tbody tr`).toHaveCount(4);
1859
1860 await contains(`.o_list_button_add`).click();
1861 expect(`.o_data_row`).toHaveCount(4);
1862 expect(`tbody tr:eq(0)`).toHaveClass("o_selected_row");
1863
1864 if (getMockEnv().isSmall) {
1865 await contains(".o_control_panel_main_buttons button > .oi-ellipsis-v").click();
1866 }
1867
1868 await contains(`.o_list_button_discard`).click();
1869 expect(`.o_data_row`).toHaveCount(3);
1870 expect(`tbody tr`).toHaveCount(4);
1871 expect(`tbody tr:eq(0)`).toHaveClass("o_data_row");
1872 });
1873
1874 test(`basic grouped list rendering`, async () => {
1875 await mountView({
1876 resModel: "foo",
1877 type: "list",
1878 arch: `<list><field name="foo"/><field name="bar"/></list>`,
1879 groupBy: ["bar"],
1880 });
1881 expect(`th:contains(Foo)`).toHaveCount(1, { message: "should contain Foo" });
1882 expect(`th:contains(Bar)`).toHaveCount(1, { message: "should contain Bar" });
1883 expect(`tr.o_group_header`).toHaveCount(2, { message: "should have 2 .o_group_header" });
1884 expect(`th.o_group_name`).toHaveCount(2, { message: "should have 2 .o_group_name" });
1885 });
1886
1887 test(`basic grouped list rendering with widget="handle" col`, async () => {
1888 await mountView({
1889 resModel: "foo",
1890 type: "list",
1891 arch: `
1892 <list>
1893 <field name="int_field" widget="handle"/>
1894 <field name="foo"/>
1895 <field name="bar"/>
1896 </list>
1897 `,
1898 groupBy: ["bar"],
1899 });
1900 expect(`thead th:not(.o_list_record_selector)`).toHaveCount(4, {
1901 message:
1902 "should have 1 th for checkbox (desktop only), 1 th for handle, 1 th for Foo, 1 th for Bar and 1 for eventual cog",
1903 });
1904 expect(`thead th[data-name=foo]`).toHaveCount(1);
1905 expect(`thead th[data-name=bar]`).toHaveCount(1);
1906 expect(`thead th[data-name=int_field]`).toHaveCount(1);
1907 expect(`tr.o_group_header`).toHaveCount(2);
1908 expect(`th.o_group_name`).toHaveCount(2);
1909 expect(`.o_group_header:eq(0) th`).toHaveCount(3); // group name + colspan 2 + cog placeholder
1910 expect(`.o_group_header:eq(0) .o_list_number`).toHaveCount(0);
1911 });
1912
1913 test(`basic grouped list rendering with a date field between two fields with a aggregator`, async () => {
1914 await mountView({
1915 resModel: "foo",
1916 type: "list",
1917 arch: `
1918 <list>
1919 <field name="int_field"/>
1920 <field name="date"/>
1921 <field name="int_field"/>
1922 </list>
1923 `,
1924 groupBy: ["bar"],
1925 });
1926 expect(`thead th:not(.o_list_record_selector)`).toHaveCount(4, {
1927 message:
1928 "should have 1 th for checkbox (desktop only), 1 th for Foo, 1 Int, 1 Date, 1 Int, 1 cog placeholder",
1929 });
1930 expect(queryAllTexts(`thead th:not(.o_list_record_selector)`)).toEqual([
1931 "Int field",
1932 "Date",
1933 "Int field",
1934 "",
1935 ]);
1936 expect(`tr.o_group_header`).toHaveCount(2);
1937 expect(`th.o_group_name`).toHaveCount(2);
1938 expect(queryAllTexts(`.o_group_header:eq(0) td`)).toEqual(["-4", "", "-4"]);
1939 });
1940
1941 test(`basic grouped list rendering 1 col without selector and with optional field`, async () => {
1942 await mountView({
1943 resModel: "foo",
1944 type: "list",
1945 arch: `<list><field name="foo"/><field name="bar" optional="hidden"/></list>`,
1946 groupBy: ["bar"],
1947 allowSelectors: false,
1948 });
1949 expect(`.o_group_header:eq(0) th`).toHaveCount(2);
1950 expect(`.o_group_header th:eq(0)`).toHaveAttribute("colspan", "1");
1951 });
1952
1953 test(`basic grouped list rendering 1 col without selector`, async () => {
1954 await mountView({
1955 resModel: "foo",
1956 type: "list",
1957 arch: `<list><field name="foo"/></list>`,
1958 groupBy: ["bar"],
1959 allowSelectors: false,
1960 });
1961 expect(`.o_group_header:eq(0) th`).toHaveCount(2);
1962 expect(`.o_group_header th:eq(0)`).toHaveAttribute("colspan", "1");
1963 });
1964
1965 test.tags("desktop");
1966 test(`basic grouped list rendering 1 col with selector on desktop`, async () => {
1967 await mountView({
1968 resModel: "foo",
1969 type: "list",
1970 arch: `<list><field name="foo"/></list>`,
1971 groupBy: ["bar"],
1972 });
1973 expect(`.o_group_header:eq(0) th`).toHaveCount(2);
1974 expect(`.o_group_header th:eq(0)`).toHaveAttribute("colspan", "2");
1975 });
1976
1977 test.tags("mobile");
1978 test(`basic grouped list rendering 1 col with selector on mobile`, async () => {
1979 await mountView({
1980 resModel: "foo",
1981 type: "list",
1982 arch: `<list><field name="foo"/></list>`,
1983 groupBy: ["bar"],
1984 });
1985 expect(`.o_group_header:eq(0) th`).toHaveCount(2);
1986 expect(`.o_group_header th:eq(0)`).toHaveAttribute("colspan", "1");
1987 });
1988
1989 test(`basic grouped list rendering 2 cols without selector`, async () => {
1990 await mountView({
1991 resModel: "foo",
1992 type: "list",
1993 arch: `<list><field name="foo"/><field name="bar"/></list>`,
1994 groupBy: ["bar"],
1995 allowSelectors: false,
1996 });
1997 expect(`.o_group_header:eq(0) th`).toHaveCount(3);
1998 expect(`.o_group_header th:eq(0)`).toHaveAttribute("colspan", "1");
1999 });
2000
2001 test(`basic grouped list rendering 3 cols without selector`, async () => {
2002 await mountView({
2003 resModel: "foo",
2004 type: "list",
2005 arch: `<list><field name="foo"/><field name="bar"/><field name="text"/></list>`,
2006 groupBy: ["bar"],
2007 allowSelectors: false,
2008 });
2009 expect(`.o_group_header:eq(0) th`).toHaveCount(3);
2010 expect(`.o_group_header th:eq(0)`).toHaveAttribute("colspan", "2");
2011 });
2012
2013 test(`basic grouped list rendering 3 cols without selector and with optional fields`, async () => {
2014 await mountView({
2015 resModel: "foo",
2016 type: "list",
2017 arch: `
2018 <list>
2019 <field name="foo"/>
2020 <field name="bar"/>
2021 <field name="text"/>
2022 <field name="date" optional="hidden"/>
2023 </list>
2024 `,
2025 groupBy: ["bar"],
2026 allowSelectors: false,
2027 });
2028 expect(`.o_group_header:eq(0) th`).toHaveCount(3);
2029 expect(`.o_group_header th:eq(0)`).toHaveAttribute("colspan", "2");
2030 });
2031
2032 test.tags("desktop");
2033 test(`basic grouped list rendering 2 col with selector on desktop`, async () => {
2034 await mountView({
2035 resModel: "foo",
2036 type: "list",
2037 arch: `<list><field name="foo"/><field name="bar"/></list>`,
2038 groupBy: ["bar"],
2039 allowSelectors: true,
2040 });
2041 expect(`.o_group_header:eq(0) th`).toHaveCount(3);
2042 expect(`.o_group_header th:eq(0)`).toHaveAttribute("colspan", "2");
2043 });
2044
2045 test.tags("mobile");
2046 test(`basic grouped list rendering 2 col with selector on mobile`, async () => {
2047 await mountView({
2048 resModel: "foo",
2049 type: "list",
2050 arch: `<list><field name="foo"/><field name="bar"/></list>`,
2051 groupBy: ["bar"],
2052 allowSelectors: true,
2053 });
2054 expect(`.o_group_header:eq(0) th`).toHaveCount(3);
2055 expect(`.o_group_header th:eq(0)`).toHaveAttribute("colspan", "1");
2056 });
2057
2058 test.tags("desktop");
2059 test(`basic grouped list rendering 3 cols with selector on desktop`, async () => {
2060 await mountView({
2061 resModel: "foo",
2062 type: "list",
2063 arch: `<list><field name="foo"/><field name="bar"/><field name="text"/></list>`,
2064 groupBy: ["bar"],
2065 allowSelectors: true,
2066 });
2067
2068 expect(`.o_group_header:eq(0) th`).toHaveCount(3);
2069 expect(`.o_group_header th:eq(0)`).toHaveAttribute("colspan", "3");
2070 });
2071
2072 test.tags("mobile");
2073 test(`basic grouped list rendering 3 cols with selector on mobile`, async () => {
2074 await mountView({
2075 resModel: "foo",
2076 type: "list",
2077 arch: `<list><field name="foo"/><field name="bar"/><field name="text"/></list>`,
2078 groupBy: ["bar"],
2079 allowSelectors: true,
2080 });
2081
2082 expect(`.o_group_header:eq(0) th`).toHaveCount(3);
2083 expect(`.o_group_header th:eq(0)`).toHaveAttribute("colspan", "2");
2084 });
2085
2086 test.tags("desktop");
2087 test(`basic grouped list rendering 7 cols with aggregates and selector on desktop`, async () => {
2088 await mountView({
2089 resModel: "foo",
2090 type: "list",
2091 arch: `
2092 <list>
2093 <field name="datetime"/>
2094 <field name="foo"/>
2095 <field name="int_field" sum="Sum1"/>
2096 <field name="bar"/>
2097 <field name="qux" sum="Sum2"/>
2098 <field name="date"/>
2099 <field name="text"/>
2100 </list>
2101 `,
2102 groupBy: ["bar"],
2103 });
2104 expect(`.o_group_header:eq(0) th, .o_group_header:eq(0) td`).toHaveCount(6);
2105 expect(`.o_group_header th:eq(0)`).toHaveAttribute("colspan", "3");
2106 expect(`.o_group_header:eq(0) td`).toHaveCount(3, {
2107 message: "there should be 3 tds (aggregates + fields in between)",
2108 });
2109 expect(`.o_group_header th:eq(4)`).toHaveAttribute("colspan", "2", {
2110 message: "pager cell in the group header should span on the two last fields (colspan 2)",
2111 });
2112 });
2113
2114 test.tags("mobile");
2115 test(`basic grouped list rendering 7 cols with aggregates and selector on mobile`, async () => {
2116 await mountView({
2117 resModel: "foo",
2118 type: "list",
2119 arch: `
2120 <list>
2121 <field name="datetime"/>
2122 <field name="foo"/>
2123 <field name="int_field" sum="Sum1"/>
2124 <field name="bar"/>
2125 <field name="qux" sum="Sum2"/>
2126 <field name="date"/>
2127 <field name="text"/>
2128 </list>
2129 `,
2130 groupBy: ["bar"],
2131 });
2132 expect(`.o_group_header:eq(0) th, .o_group_header:eq(0) td`).toHaveCount(6);
2133 expect(`.o_group_header th:eq(0)`).toHaveAttribute("colspan", "2");
2134 expect(`.o_group_header:eq(0) td`).toHaveCount(3, {
2135 message: "there should be 3 tds (aggregates + fields in between)",
2136 });
2137 expect(`.o_group_header th:eq(-2)`).toHaveAttribute("colspan", "2", {
2138 message: "pager cell in the group header should span on the two last fields (colspan 2)",
2139 });
2140 });
2141
2142 test.tags("desktop");
2143 test(`basic grouped list rendering 7 cols with aggregates, selector and optional on desktop`, async () => {
2144 await mountView({
2145 resModel: "foo",
2146 type: "list",
2147 arch: `
2148 <list>
2149 <field name="datetime"/>
2150 <field name="foo"/>
2151 <field name="int_field" sum="Sum1"/>
2152 <field name="bar"/>
2153 <field name="qux" sum="Sum2"/>
2154 <field name="date"/>
2155 <field name="text" optional="show"/>
2156 </list>
2157 `,
2158 groupBy: ["bar"],
2159 });
2160 expect(`.o_group_header:eq(0) th, .o_group_header:eq(0) td`).toHaveCount(6);
2161 expect(`.o_group_header th:eq(0)`).toHaveAttribute("colspan", "3");
2162 expect(`.o_group_header:eq(0) td`).toHaveCount(3, {
2163 message: "there should be 3 tds (aggregates + fields in between)",
2164 });
2165 expect(`.o_group_header th:eq(-2)`).toHaveAttribute("colspan", "2", {
2166 message: "pager cell in the group header should span on the two last fields (colspan 2)",
2167 });
2168 });
2169
2170 test.tags("mobile");
2171 test(`basic grouped list rendering 7 cols with aggregates, selector and optional on mobile`, async () => {
2172 await mountView({
2173 resModel: "foo",
2174 type: "list",
2175 arch: `
2176 <list>
2177 <field name="datetime"/>
2178 <field name="foo"/>
2179 <field name="int_field" sum="Sum1"/>
2180 <field name="bar"/>
2181 <field name="qux" sum="Sum2"/>
2182 <field name="date"/>
2183 <field name="text" optional="show"/>
2184 </list>
2185 `,
2186 groupBy: ["bar"],
2187 });
2188 expect(`.o_group_header:eq(0) th, .o_group_header:eq(0) td`).toHaveCount(6);
2189 expect(`.o_group_header th:eq(0)`).toHaveAttribute("colspan", "2");
2190 expect(`.o_group_header:eq(0) td`).toHaveCount(3, {
2191 message: "there should be 3 tds (aggregates + fields in between)",
2192 });
2193 expect(`.o_group_header th:eq(-2)`).toHaveAttribute("colspan", "2", {
2194 message: "pager cell in the group header should span on the two last fields (colspan 2)",
2195 });
2196 });
2197
2198 test.tags("desktop");
2199 test(`basic grouped list rendering 4 cols with aggregates, selector and openFormView on desktop`, async () => {
2200 await mountView({
2201 resModel: "foo",
2202 type: "list",
2203 arch: `
2204 <list open_form_view="True">
2205 <field name="datetime"/>
2206 <field name="int_field" sum="Sum1"/>
2207 <field name="bar"/>
2208 <field name="m2o"/>
2209 <field name="qux" sum="Sum2" optional="hide"/>
2210 </list>
2211 `,
2212 groupBy: ["bar"],
2213 });
2214 expect(`.o_group_header th:eq(0)`).toHaveAttribute("colspan", "2");
2215 expect(`.o_group_header th:eq(-2)`).toHaveAttribute("colspan", "2");
2216 });
2217
2218 test.tags("mobile");
2219 test(`basic grouped list rendering 4 cols with aggregates, selector and openFormView on mobile`, async () => {
2220 await mountView({
2221 resModel: "foo",
2222 type: "list",
2223 arch: `
2224 <list open_form_view="True">
2225 <field name="datetime"/>
2226 <field name="int_field" sum="Sum1"/>
2227 <field name="bar"/>
2228 <field name="m2o"/>
2229 <field name="qux" sum="Sum2" optional="hide"/>
2230 </list>
2231 `,
2232 groupBy: ["bar"],
2233 });
2234 expect(`.o_group_header th:eq(0)`).toHaveAttribute("colspan", "1");
2235 expect(`.o_group_header th:eq(-2)`).toHaveAttribute("colspan", "2");
2236 });
2237
2238 test.tags("desktop");
2239 test(`basic grouped list rendering 4 cols with aggregates, selector, optional and openFormView on desktop`, async () => {
2240 await mountView({
2241 resModel: "foo",
2242 type: "list",
2243 arch: `
2244 <list open_form_view="True">
2245 <field name="datetime"/>
2246 <field name="int_field" sum="Sum1"/>
2247 <field name="bar"/>
2248 <field name="qux" sum="Sum2" optional="show"/>
2249 </list>
2250 `,
2251 groupBy: ["bar"],
2252 });
2253 expect(`.o_group_header th:eq(0)`).toHaveAttribute("colspan", "2");
2254 expect(`.o_group_header th:eq(-1)`).not.toHaveAttribute("colspan");
2255 });
2256
2257 test.tags("mobile");
2258 test(`basic grouped list rendering 4 cols with aggregates, selector, optional and openFormView on mobile`, async () => {
2259 await mountView({
2260 resModel: "foo",
2261 type: "list",
2262 arch: `
2263 <list open_form_view="True">
2264 <field name="datetime"/>
2265 <field name="int_field" sum="Sum1"/>
2266 <field name="bar"/>
2267 <field name="qux" sum="Sum2" optional="show"/>
2268 </list>
2269 `,
2270 groupBy: ["bar"],
2271 });
2272 expect(`.o_group_header th:eq(0)`).toHaveAttribute("colspan", "1");
2273 expect(`.o_group_header th:eq(-2)`).toHaveAttribute("colspan", "1");
2274 });
2275
2276 test(`group a list view with the aggregable field 'value'`, async () => {
2277 Foo._fields.value = fields.Integer();
2278 for (const record of Foo._records) {
2279 record.value = 1;
2280 }
2281
2282 await mountView({
2283 resModel: "foo",
2284 type: "list",
2285 arch: `
2286 <list>
2287 <field name="bar"/>
2288 <field name="value" sum="Sum1"/>
2289 </list>
2290 `,
2291 groupBy: ["bar"],
2292 });
2293 expect(`.o_group_header`).toHaveCount(2);
2294 expect(queryAllTexts(`.o_group_header`)).toEqual(["No (1)\n 1", "Yes (3)\n 3"]);
2295 });
2296
2297 test(`basic grouped list rendering with groupby m2m field`, async () => {
2298 await mountView({
2299 resModel: "foo",
2300 type: "list",
2301 arch: `
2302 <list>
2303 <field name="foo"/>
2304 <field name="m2m" widget="many2many_tags"/>
2305 </list>
2306 `,
2307 groupBy: ["m2m"],
2308 });
2309 expect(`.o_group_header`).toHaveCount(4, { message: "should contain 4 open groups" });
2310 expect(`.o_group_open`).toHaveCount(0, { message: "no group is open" });
2311 expect(queryAllTexts(`.o_group_header .o_group_name`)).toEqual([
2312 "Value 1 (3)",
2313 "Value 2 (2)",
2314 "Value 3 (1)",
2315 "None (1)",
2316 ]);
2317
2318 // Open all groups
2319 await contains(`.o_group_name`).click();
2320 await contains(`.o_group_name:eq(1)`).click();
2321 await contains(`.o_group_name:eq(2)`).click();
2322 await contains(`.o_group_name:eq(3)`).click();
2323 expect(`.o_group_open`).toHaveCount(4, { message: "all groups are open" });
2324 expect(queryAllTexts(`.o_list_view tbody > tr`)).toEqual([
2325 "Value 1 (3)",
2326 "yop \nValue 1\nValue 2",
2327 "blip \nValue 1\nValue 2\nValue 3",
2328 "blip \nValue 1",
2329 "Value 2 (2)",
2330 "yop \nValue 1\nValue 2",
2331 "blip \nValue 1\nValue 2\nValue 3",
2332 "Value 3 (1)",
2333 "blip \nValue 1\nValue 2\nValue 3",
2334 "None (1)",
2335 "gnap",
2336 ]);
2337 });
2338
2339 test(`grouped list rendering with groupby m2o and m2m field`, async () => {
2340 await mountView({
2341 resModel: "foo",
2342 type: "list",
2343 arch: `
2344 <list>
2345 <field name="foo"/>
2346 <field name="m2o"/>
2347 <field name="m2m" widget="many2many_tags"/>
2348 </list>
2349 `,
2350 groupBy: ["m2o", "m2m"],
2351 });
2352 expect(`.o_list_footer td > button`).toHaveCount(0, {
2353 message: "no quick create since no default groupby",
2354 });
2355 expect(queryAllTexts(`tbody > tr`)).toEqual(["Value 1 (3)", "Value 2 (1)"]);
2356
2357 await contains(`th.o_group_name`).click();
2358 expect(queryAllTexts(`tbody > tr`)).toEqual([
2359 "Value 1 (3)",
2360 "Value 1 (2)",
2361 "Value 2 (1)",
2362 "None (1)",
2363 "Value 2 (1)",
2364 ]);
2365
2366 await contains(`tbody th.o_group_name:eq(4)`).click();
2367 expect(queryAllTexts(`.o_list_view tbody > tr`)).toEqual([
2368 "Value 1 (3)",
2369 "Value 1 (2)",
2370 "Value 2 (1)",
2371 "None (1)",
2372 "Value 2 (1)",
2373 "Value 1 (1)",
2374 "Value 2 (1)",
2375 "Value 3 (1)",
2376 ]);
2377 });
2378
2379 test(`grouped list rendering with default_group_by m2o field: add group`, async () => {
2380 onRpc("name_create", ({ args }) => {
2381 expect(args[0]).toBe("New group");
2382 expect.step("name_create");
2383 });
2384 await mountView({
2385 resModel: "foo",
2386 type: "list",
2387 arch: `<list default_group_by="m2o"><field name="foo"/></list>`,
2388 });
2389 expect(`.o_group_header:eq(0) th`).toHaveCount(2);
2390 expect(queryAllTexts(".o_group_name")).toEqual(["Value 1 (3)", "Value 2 (1)"]);
2391 expect(`.o_list_footer td > button`).toHaveText("Add a M2o");
2392 await contains(`.o_list_footer td > button`).click();
2393 expect(`.o_list_footer td > button`).toHaveCount(0);
2394 expect(`.o_list_footer td input`).toHaveCount(1);
2395 await contains(`.o_list_footer td input`).edit("New group", { confirm: false });
2396 await contains(`.o_list_footer .o_list_group_confirm`).click();
2397 expect.verifySteps(["name_create"]);
2398 expect(queryAllTexts(".o_group_name")).toEqual(["Value 1 (3)", "Value 2 (1)", "New group (0)"]);
2399 });
2400
2401 test(`grouped list rendering with groupby m2o field: group_create = false`, async () => {
2402 await mountView({
2403 resModel: "foo",
2404 type: "list",
2405 arch: `<list group_create="false"><field name="foo"/></list>`,
2406 groupBy: ["m2o"],
2407 });
2408 expect(`.o_list_footer td > button`).toHaveCount(0);
2409 });
2410
2411 test(`grouped list rendering with groupby m2o field: edit group`, async () => {
2412 Bar._views = {
2413 form: `<form><field name="name"/></form>`,
2414 };
2415 Foo._views = {
2416 "list,1": `<list default_group_by="m2o"><field name="foo"/></list>`,
2417 "search,1": `<search/>`,
2418 };
2419 onRpc("bar", "web_save", ({ args }) => {
2420 expect(args).toEqual([[1], { name: "Value edit" }]);
2421 expect.step("web_save");
2422 });
2423 defineActions([
2424 {
2425 id: 1,
2426 name: "Action 1",
2427 res_model: "foo",
2428 views: [[1, "list"]],
2429 search_view_id: [1, "search"],
2430 },
2431 ]);
2432 await mountWithCleanup(WebClient);
2433 await getService("action").doAction(1);
2434
2435 expect(queryAllTexts(`.o_group_name`)).toEqual(["Value 1 (3)", "Value 2 (1)"]);
2436 expect(`.o_group_header:first th:last .o_group_config`).toHaveCount(1);
2437 await contains(`.o_group_header:first .o_group_config button`, { visible: false }).click();
2438 expect(`.o-dropdown--group-config-menu`).toHaveCount(1);
2439 await contains(`.o-dropdown--group-config-menu .o_group_edit`).click();
2440 expect(`.o_dialog`).toHaveCount(1);
2441 expect(`.o_dialog .o_form_renderer .o_field_char[name="name"]`).toHaveCount(1);
2442 await contains(`.o_dialog .o_form_renderer .o_field_char[name="name"] input`).edit(
2443 "Value edit"
2444 );
2445 await contains(`.o_dialog .o_form_button_save`).click();
2446 expect(`.o_dialog`).toHaveCount(0);
2447 expect.verifySteps(["web_save"]);
2448 expect(queryAllTexts(`.o_group_name`)).toEqual(["Value edit (3)", "Value 2 (1)"]);
2449 await contains(`.o_group_header:first .o_group_config button`, { visible: false }).click();
2450 if (getMockEnv().isSmall) {
2451 await contains(".o_bottom_sheet_backdrop").click();
2452 } else {
2453 await contains(getFixture()).click();
2454 }
2455 expect(`.o-dropdown--group-config-menu`).toHaveCount(0, {
2456 message: "Close on click away should occur properly",
2457 });
2458 });
2459
2460 test(`grouped list rendering with groupby m2o field: delete group`, async () => {
2461 onRpc("bar", "unlink", ({ args }) => {
2462 expect.step("unlink");
2463 expect(args[0][0]).toBe(1);
2464 });
2465 await mountView({
2466 resModel: "foo",
2467 type: "list",
2468 arch: `<list><field name="foo"/></list>`,
2469 groupBy: ["m2o"],
2470 });
2471
2472 expect(queryAllTexts(`.o_group_name`)).toEqual(["Value 1 (3)", "Value 2 (1)"]);
2473 expect(`.o_group_header:first .o_group_config`).toHaveCount(1);
2474 await contains(`.o_group_header:first .o_group_config button`, { visible: false }).click();
2475 expect(`.o-dropdown--group-config-menu`).toHaveCount(1);
2476 await contains(`.o-dropdown--group-config-menu .o_group_delete`).click();
2477 expect(`.o_dialog`).toHaveCount(1);
2478 expect(`.o_dialog .modal-body`).toHaveText("Are you sure you want to delete this column?");
2479 await contains(`.o_dialog footer button:contains(Delete)`).click();
2480 expect.verifySteps(["unlink"]);
2481 expect(queryAllTexts(`.o_group_name`)).toEqual(["Value 2 (1)", "None (3)"]);
2482 });
2483
2484 test(`grouped list rendering with groupby non m2o field`, async () => {
2485 await mountView({
2486 resModel: "foo",
2487 type: "list",
2488 arch: `<list group_create="false"><field name="foo"/></list>`,
2489 groupBy: ["bar"],
2490 });
2491 expect(`.o_list_footer td > button`).toHaveCount(0);
2492 });
2493
2494 test.tags("desktop");
2495 test(`grouped list with (disabled) pager inside group`, async () => {
2496 let def;
2497 onRpc("web_search_read", () => def);
2498
2499 await mountView({
2500 resModel: "foo",
2501 type: "list",
2502 arch: `
2503 <list limit="2">
2504 <field name="foo"/>
2505 </list>
2506 `,
2507 groupBy: ["m2o"],
2508 });
2509
2510 expect(".o_group_header").toHaveCount(2);
2511
2512 await contains(".o_group_header:first").click();
2513
2514 expect(".o_data_row").toHaveCount(2);
2515 expect(".o_group_header .o_pager").toHaveCount(1);
2516
2517 def = new Deferred();
2518
2519 await click(".o_group_header .o_pager_next:enabled");
2520 await animationFrame();
2521
2522 expect(".o_group_header .o_pager_next").toHaveAttribute("disabled");
2523
2524 await click(".o_group_header .o_pager_next");
2525 await click(".o_group_header .o_pager_next");
2526 await animationFrame();
2527
2528 expect(".o_data_row").toHaveCount(2);
2529 });
2530
2531 test(`list view with multiple groupbys`, async () => {
2532 await mountView({
2533 resModel: "foo",
2534 type: "list",
2535 arch: `<list><field name="foo"/><field name="bar"/></list>`,
2536 groupBy: ["bar", "foo"],
2537 noContentHelp: "<p>should not be displayed</p>",
2538 });
2539 expect(`.o_view_nocontent`).toHaveCount(0);
2540 expect(`.o_group_has_content`).toHaveCount(2);
2541 expect(queryAllTexts(`.o_group_has_content`)).toEqual(["No (1)", "Yes (3)"]);
2542 });
2543
2544 test(`enabling archive in list when groupby m2m field`, async () => {
2545 onRpc("has_group", () => false);
2546 // add active field on foo model and make all records active
2547 Foo._fields.active = fields.Boolean({ default: true });
2548
2549 await mountView({
2550 resModel: "foo",
2551 type: "list",
2552 arch: `
2553 <list>
2554 <field name="foo"/>
2555 <field name="m2m" widget="many2many_tags"/>
2556 </list>
2557 `,
2558 actionMenus: {},
2559 groupBy: ["m2m"],
2560 });
2561 await contains(`.o_group_name:eq(0)`).click(); // open group "Value 1"
2562 await contains(`.o_group_name:eq(1)`).click(); // open group "Value 2"
2563 // Check for the initial number of records
2564 expect(`.o_data_row`).toHaveCount(5, { message: "Checking initial number of records" });
2565 await clickRecordSelector(); // select first task
2566 await contains(`div.o_control_panel .o_cp_action_menus .dropdown-toggle`).click(); // click on actions
2567 // check that all the options are available
2568 expect(`.o-dropdown--menu .o_menu_item`).toHaveCount(4, {
2569 message: "archive, unarchive, duplicate and delete option should be present",
2570 });
2571
2572 await toggleMenuItem("Archive"); // toggle archive action
2573 await contains(`.modal-footer .btn-primary`).click(); // confirm the archive action
2574 // check that after archive the record is removed from both 2nd and 3rd groups
2575 expect(`.o_data_row`).toHaveCount(3, {
2576 message: "record should be archived from both the groups",
2577 });
2578 });
2579
2580 test.tags("desktop");
2581 test(`enabling archive in list when groupby m2m field and multi selecting the same record`, async () => {
2582 onRpc("has_group", () => false);
2583 onRpc("action_archive", ({ args }) => {
2584 expect.step("action_archive");
2585 expect(args[0]).toEqual([1], {
2586 message: "the archive action rpc should only contain unique ids in arguments",
2587 });
2588 });
2589 // add active field on foo model and make all records active
2590 Foo._fields.active = fields.Boolean({ default: true });
2591
2592 await mountView({
2593 resModel: "foo",
2594 type: "list",
2595 arch: `
2596 <list>
2597 <field name="foo"/>
2598 <field name="m2m" widget="many2many_tags"/>
2599 </list>
2600 `,
2601 actionMenus: {},
2602 groupBy: ["m2m"],
2603 });
2604 await contains(`.o_group_name:eq(0)`).click(); // open group "Value 1"
2605 await contains(`.o_group_name:eq(1)`).click(); // open group "Value 2"
2606 // Check for the initial number of records
2607 expect(`.o_data_row`).toHaveCount(5, { message: "Checking initial number of records" });
2608
2609 await contains(`.o_data_row:eq(0) .o_list_record_selector input`).click(); // select first record
2610 await contains(`.o_data_row:eq(3) .o_list_record_selector input`).click(); // select the same record in another group
2611 await contains(`div.o_control_panel .o_cp_action_menus .dropdown-toggle`).click(); // click on actions
2612
2613 await toggleMenuItem("Archive"); // toggle archive action
2614 await contains(`.modal-footer .btn-primary`).click(); // confirm the archive action
2615 // check that after archive the record is removed from both 2nd and 3rd groups
2616 expect(`.o_data_row`).toHaveCount(3, {
2617 message: "record should be archived from both the groups",
2618 });
2619 expect.verifySteps(["action_archive"]);
2620 });
2621
2622 test(`enabling duplicate in list when groupby m2m field`, async () => {
2623 onRpc("has_group", () => false);
2624 // add active field on foo model and make all records active
2625 Foo._fields.active = fields.Boolean({ default: true });
2626
2627 await mountView({
2628 resModel: "foo",
2629 type: "list",
2630 arch: `
2631 <list>
2632 <field name="foo"/>
2633 <field name="m2m" widget="many2many_tags"/>
2634 </list>
2635 `,
2636 actionMenus: {},
2637 groupBy: ["m2m"],
2638 });
2639 await contains(`.o_group_name:eq(0)`).click(); // open group "Value 1"
2640 await contains(`.o_group_name:eq(1)`).click(); // open group "Value 2"
2641 // Check for the initial number of records
2642 expect(`.o_data_row`).toHaveCount(5, { message: "Checking initial number of records" });
2643
2644 await clickRecordSelector(); // select first task
2645 await contains(`div.o_control_panel .o_cp_action_menus .dropdown-toggle`).click(); // click on actions
2646 // check that all the options are available
2647 expect(`.o-dropdown--menu .o_menu_item`).toHaveCount(4, {
2648 message: "archive, unarchive, duplicate and delete option should be present",
2649 });
2650
2651 await toggleMenuItem("Duplicate"); // toggle duplicate action
2652 // check that after duplicate the record is duplicated in both 2nd and 3rd groups
2653 expect(`.o_data_row`).toHaveCount(7, {
2654 message: "record should be duplicated in both the groups",
2655 });
2656 });
2657
2658 test.tags("desktop");
2659 test(`enabling duplicate in list when groupby m2m field and multi selecting the same record`, async () => {
2660 onRpc("has_group", () => false);
2661 onRpc("copy", ({ args }) => {
2662 expect.step("copy");
2663 expect(args[0]).toEqual([1], {
2664 message: "the copy rpc should only contain unique ids in arguments",
2665 });
2666 });
2667 // add active field on foo model and make all records active
2668 Foo._fields.active = fields.Boolean({ default: true });
2669
2670 await mountView({
2671 resModel: "foo",
2672 type: "list",
2673 arch: `
2674 <list>
2675 <field name="foo"/>
2676 <field name="m2m" widget="many2many_tags"/>
2677 </list>
2678 `,
2679 actionMenus: {},
2680 groupBy: ["m2m"],
2681 });
2682 await contains(`.o_group_name:eq(0)`).click(); // open group "Value 1"
2683 await contains(`.o_group_name:eq(1)`).click(); // open group "Value 2"
2684 // Check for the initial number of records
2685 expect(`.o_data_row`).toHaveCount(5, { message: "Checking initial number of records" });
2686
2687 await contains(`.o_data_row:eq(0) .o_list_record_selector input`).click(); // select first record
2688 await contains(`.o_data_row:eq(3) .o_list_record_selector input`).click(); // select the same record in another group
2689 await contains(`div.o_control_panel .o_cp_action_menus .dropdown-toggle`).click(); // click on actions
2690
2691 await toggleMenuItem("Duplicate"); // toggle duplicate action
2692 // check that after duplicate the record is duplicated in both 2nd and 3rd groups
2693 expect(`.o_data_row`).toHaveCount(7, {
2694 message: "record should be duplicated in both the groups",
2695 });
2696 expect.verifySteps(["copy"]);
2697 });
2698
2699 test(`enabling delete in list when groupby m2m field`, async () => {
2700 onRpc("has_group", () => false);
2701 // add active field on foo model and make all records active
2702 Foo._fields.active = fields.Boolean({ default: true });
2703
2704 await mountView({
2705 resModel: "foo",
2706 type: "list",
2707 arch: `
2708 <list>
2709 <field name="foo"/>
2710 <field name="m2m" widget="many2many_tags"/>
2711 </list>
2712 `,
2713 actionMenus: {},
2714 groupBy: ["m2m"],
2715 });
2716 await contains(`.o_group_name:eq(0)`).click(); // open group "Value 1"
2717 await contains(`.o_group_name:eq(1)`).click(); // open group "Value 2"
2718 // Check for the initial number of records
2719 expect(`.o_data_row`).toHaveCount(5, { message: "Checking initial number of records" });
2720
2721 await clickRecordSelector(); // select first task
2722 await contains(`div.o_control_panel .o_cp_action_menus .dropdown-toggle`).click(); // click on actions
2723 // check that all the options are available
2724 expect(`.o-dropdown--menu .o_menu_item`).toHaveCount(4, {
2725 message: "archive, unarchive, duplicate and delete option should be present",
2726 });
2727
2728 await toggleMenuItem("Delete"); // toggle delete action
2729 await contains(`.modal-footer .btn-primary`).click(); // confirm the delete action
2730 // check that after delete the record is deleted in both 2nd and 3rd groups
2731 expect(`.o_data_row`).toHaveCount(3, {
2732 message: "record should be deleted from both the groups",
2733 });
2734 });
2735
2736 test.tags("desktop");
2737 test(`enabling delete in list when groupby m2m field and multi selecting the same record`, async () => {
2738 onRpc("has_group", () => false);
2739 onRpc("unlink", ({ args }) => {
2740 expect.step("unlink");
2741 expect(args[0]).toEqual([1], {
2742 message: "the unlink rpc should only contain unique ids in arguments",
2743 });
2744 });
2745 // add active field on foo model and make all records active
2746 Foo._fields.active = fields.Boolean({ default: true });
2747
2748 await mountView({
2749 resModel: "foo",
2750 type: "list",
2751 arch: `
2752 <list>
2753 <field name="foo"/>
2754 <field name="m2m" widget="many2many_tags"/>
2755 </list>
2756 `,
2757 actionMenus: {},
2758 groupBy: ["m2m"],
2759 });
2760 await contains(`.o_group_name:eq(0)`).click(); // open group "Value 1"
2761 await contains(`.o_group_name:eq(1)`).click(); // open group "Value 2"
2762 // Check for the initial number of records
2763 expect(`.o_data_row`).toHaveCount(5, { message: "Checking initial number of records" });
2764
2765 await contains(`.o_data_row:eq(0) .o_list_record_selector input`).click(); // select first record
2766 await contains(`.o_data_row:eq(3) .o_list_record_selector input`).click(); // select the same record in another group
2767 await contains(`div.o_control_panel .o_cp_action_menus .dropdown-toggle`).click(); // click on actions
2768
2769 await toggleMenuItem("Delete"); // toggle delete action
2770 await contains(`.modal-footer .btn-primary`).click(); // confirm the delete action
2771 // check that after delete the record is deleted in both 2nd and 3rd groups
2772 expect(`.o_data_row`).toHaveCount(3, {
2773 message: "record should be deleted from both the groups",
2774 });
2775 expect.verifySteps(["unlink"]);
2776 });
2777
2778 test(`enabling unarchive in list when groupby m2m field`, async () => {
2779 onRpc("has_group", () => false);
2780 // add active field on foo model and make all records active
2781 Foo._fields.active = fields.Boolean({ default: true });
2782 // creating archived records
2783 Foo._records = [
2784 { id: 1, foo: "First record", m2m: [1, 2], active: false },
2785 { id: 2, foo: "Second record", m2m: [1, 2], active: false },
2786 ];
2787
2788 await mountView({
2789 resModel: "foo",
2790 type: "list",
2791 arch: `
2792 <list>
2793 <field name="foo"/>
2794 <field name="m2m" widget="many2many_tags"/>
2795 </list>
2796 `,
2797 actionMenus: {},
2798 groupBy: ["m2m"],
2799 // apply the filter to show only records with active = false
2800 domain: [["active", "=", false]],
2801 });
2802
2803 await contains(`.o_group_name:eq(0)`).click(); // open first group
2804 await contains(`.o_group_name:eq(1)`).click(); // open second group
2805 // Check for the initial number of records
2806 expect(`.o_data_row`).toHaveCount(4, { message: "Checking initial number of records" });
2807
2808 await clickRecordSelector(); // select first task
2809 await contains(`div.o_control_panel .o_cp_action_menus .dropdown-toggle`).click(); // click on actions
2810 // check that all the options are available
2811 expect(`.o-dropdown--menu .o_menu_item`).toHaveCount(4, {
2812 message: "archive, unarchive, duplicate and delete option should be present",
2813 });
2814
2815 await toggleMenuItem("Unarchive"); // toggle unarchive action
2816 // check that after unarchive the record is unarchived in both 1st and 2nd groups
2817 expect(`.o_data_row`).toHaveCount(2, {
2818 message: "record should be unarchived from both the groups",
2819 });
2820 });
2821
2822 test.tags("desktop");
2823 test(`enabling unarchive in list when groupby m2m field and multi selecting the same record`, async () => {
2824 onRpc("has_group", () => false);
2825 onRpc("action_unarchive", ({ args }) => {
2826 expect.step("action_unarchive");
2827 expect(args[0]).toEqual([1], {
2828 message: "the unarchive action rpc should only contain unique ids in arguments",
2829 });
2830 });
2831 // add active field on foo model and make all records active
2832 Foo._fields.active = fields.Boolean({ default: true });
2833 // creating archived records
2834 Foo._records = [
2835 { id: 1, foo: "First record", m2m: [1, 2], active: false },
2836 { id: 2, foo: "Second record", m2m: [1, 2], active: false },
2837 ];
2838
2839 await mountView({
2840 resModel: "foo",
2841 type: "list",
2842 arch: `
2843 <list>
2844 <field name="foo"/>
2845 <field name="m2m" widget="many2many_tags"/>
2846 </list>
2847 `,
2848 actionMenus: {},
2849 groupBy: ["m2m"],
2850 // apply the filter to show only records with active = false
2851 domain: [["active", "=", false]],
2852 });
2853
2854 await contains(`.o_group_name:eq(0)`).click(); // open first group
2855 await contains(`.o_group_name:eq(1)`).click(); // open second group
2856 // Check for the initial number of records
2857 expect(`.o_data_row`).toHaveCount(4, { message: "Checking initial number of records" });
2858
2859 await contains(`.o_data_row:eq(0) .o_list_record_selector input`).click(); // select first record
2860 await contains(`.o_data_row:eq(2) .o_list_record_selector input`).click(); // select the same record in another group
2861 await contains(`div.o_control_panel .o_cp_action_menus .dropdown-toggle`).click(); // click on actions
2862
2863 await toggleMenuItem("Unarchive"); // toggle unarchive action
2864 // check that after unarchive the record is unarchived in both 1st and 2nd groups
2865 expect(`.o_data_row`).toHaveCount(2, {
2866 message: "record should be unarchived from both the groups",
2867 });
2868 expect.verifySteps(["action_unarchive"]);
2869 });
2870
2871 test(`add record in list grouped by m2m`, async () => {
2872 onRpc("onchange", ({ kwargs }) => {
2873 expect.step("onchange");
2874 expect(kwargs.context.default_m2m).toEqual([1]);
2875 });
2876
2877 await mountView({
2878 resModel: "foo",
2879 type: "list",
2880 arch: `
2881 <list editable="bottom">
2882 <field name="foo"/>
2883 <field name="m2m" widget="many2many_tags"/>
2884 </list>
2885 `,
2886 groupBy: ["m2m"],
2887 });
2888
2889 expect(`.o_group_header`).toHaveCount(4);
2890 expect(queryAllTexts(`.o_group_header`)).toEqual([
2891 "Value 1 (3)",
2892 "Value 2 (2)",
2893 "Value 3 (1)",
2894 "None (1)",
2895 ]);
2896
2897 await contains(`.o_group_header`).click();
2898 expect(`.o_data_row`).toHaveCount(3);
2899
2900 await contains(`.o_group_field_row_add a`).click();
2901 expect(`.o_selected_row`).toHaveCount(1);
2902 expect(`.o_selected_row .o_field_tags .o_tag`).toHaveCount(1);
2903 expect(`.o_selected_row .o_field_tags .o_tag`).toHaveText("Value 1");
2904 expect.verifySteps(["onchange"]);
2905 });
2906
2907 test.tags("desktop");
2908 test(`editing a record should change same record in other groups when grouped by m2m field on desktop`, async () => {
2909 await mountView({
2910 resModel: "foo",
2911 type: "list",
2912 arch: `
2913 <list editable="bottom">
2914 <field name="foo"/>
2915 <field name="m2m" widget="many2many_tags"/>
2916 </list>
2917 `,
2918 groupBy: ["m2m"],
2919 });
2920 await contains(`.o_group_header`).click(); // open Value 1 group
2921 await contains(`.o_group_header:eq(1)`).click(); // open Value 2 group
2922 expect(queryAllTexts(`.o_list_char`)).toEqual(["yop", "blip", "blip", "yop", "blip"]);
2923
2924 await contains(`.o_data_row .o_data_cell`).click();
2925 await contains(`.o_data_row .o_list_char input`).edit("xyz");
2926 await contains(`.o_list_view`).click();
2927 expect(queryAllTexts(`.o_list_char`)).toEqual(["xyz", "blip", "blip", "xyz", "blip"]);
2928 });
2929
2930 test.tags("mobile");
2931 test(`editing a record should change same record in other groups when grouped by m2m field on mobile`, async () => {
2932 await mountView({
2933 resModel: "foo",
2934 type: "list",
2935 arch: `
2936 <list editable="bottom">
2937 <field name="foo"/>
2938 <field name="m2m" widget="many2many_tags"/>
2939 </list>
2940 `,
2941 groupBy: ["m2m"],
2942 });
2943 await contains(`.o_group_header`).click(); // open Value 1 group
2944 await contains(`.o_group_header:eq(1)`).click(); // open Value 2 group
2945 expect(queryAllTexts(`.o_list_char`)).toEqual(["yop", "blip", "blip", "yop", "blip"]);
2946
2947 await contains(`.o_data_row .o_data_cell`).click();
2948 await contains(`.o_data_row .o_list_char input`).edit("xyz");
2949 await contains(`.o_list_view`).click();
2950 expect(queryAllTexts(`.o_list_char`)).toEqual(["xyz", "blip", "blip", "xyz", "blip"]);
2951 });
2952
2953 test.tags("desktop");
2954 test(`selecting the same record on different groups and editing it when grouping by m2m field`, async () => {
2955 onRpc("web_save", ({ args }) => {
2956 expect.step("web_save");
2957 expect(args[0]).toEqual([1], {
2958 message: "the web_save rpc should only contain unique ids in arguments",
2959 });
2960 });
2961
2962 await mountView({
2963 resModel: "foo",
2964 type: "list",
2965 arch: `
2966 <list multi_edit="1">
2967 <field name="foo"/>
2968 <field name="m2m" widget="many2many_tags"/>
2969 </list>
2970 `,
2971 groupBy: ["m2m"],
2972 });
2973
2974 await contains(`.o_group_header`).click(); // open Value 1 group
2975 await contains(`.o_group_header:eq(1)`).click(); // open Value 2 group
2976 expect(queryAllTexts(`.o_list_char`)).toEqual(["yop", "blip", "blip", "yop", "blip"]);
2977
2978 await contains(`.o_data_row:eq(0) .o_list_record_selector input`).click(); // select first record
2979 await contains(`.o_data_row:eq(3) .o_list_record_selector input`).click(); // select the same record in another group
2980 await contains(`.o_data_row .o_data_cell`).click();
2981 await contains(`.o_data_row .o_list_char input`).edit("xyz");
2982 await contains(`.o_list_view`).click();
2983 expect(`.modal`).toHaveCount(1);
2984
2985 await contains(`.modal .modal-footer .btn-primary`).click();
2986 expect(`.modal`).toHaveCount(0);
2987 expect(queryAllTexts(`.o_list_char`)).toEqual(["xyz", "blip", "blip", "xyz", "blip"]);
2988 expect.verifySteps(["web_save"]);
2989 });
2990
2991 test(`change a record field in readonly should change same record in other groups when grouped by m2m field`, async () => {
2992 Foo._fields.priority = fields.Selection({
2993 selection: [
2994 [0, "Not Prioritary"],
2995 [1, "Prioritary"],
2996 ],
2997 default: 0,
2998 });
2999
3000 onRpc("web_save", ({ args }) => {
3001 expect.step("web_save");
3002 expect(args[0]).toEqual([1], { message: "should write on the correct record" });
3003 expect(args[1]).toEqual({
3004 priority: 1,
3005 });
3006 });
3007
3008 await mountView({
3009 resModel: "foo",
3010 type: "list",
3011 arch: `
3012 <list>
3013 <field name="foo"/>
3014 <field name="priority" widget="priority"/>
3015 <field name="m2m" widget="many2many_tags"/>
3016 </list>
3017 `,
3018 groupBy: ["m2m"],
3019 domain: [["m2o", "=", 1]],
3020 });
3021 await contains(`.o_group_header`).click(); // open Value 1 group
3022 await contains(`.o_group_header:eq(1)`).click(); // open Value 2 group
3023 expect(queryAllTexts(`.o_list_char`)).toEqual(["yop", "blip", "yop"]);
3024 expect(`.o_priority_star.fa-star`).toHaveCount(0, {
3025 message: "should not have any starred records",
3026 });
3027
3028 await contains(`.o_priority_star`).click();
3029 expect(`.o_priority_star.fa-star`).toHaveCount(2, {
3030 message: "both 'yop' records should have been starred",
3031 });
3032 expect.verifySteps(["web_save"]);
3033 });
3034
3035 test(`ordered target, sort attribute in context`, async () => {
3036 onRpc("create_filter", ({ args }) => {
3037 const favorite = args[0];
3038 expect.step(favorite.sort);
3039 return [7];
3040 });
3041
3042 await mountView({
3043 resModel: "foo",
3044 type: "list",
3045 arch: `<list><field name="foo"/><field name="date"/></list>`,
3046 });
3047
3048 // Descending order on Foo
3049 await contains(`th.o_column_sortable[data-name=foo]`).click();
3050 await contains(`th.o_column_sortable[data-name=foo]`).click();
3051
3052 // Ascending order on Date
3053 await contains(`th.o_column_sortable[data-name=date]`).click();
3054 await toggleSearchBarMenu();
3055 await toggleSaveFavorite();
3056 await editFavoriteName("My favorite");
3057 await saveFavorite();
3058 expect.verifySteps([`["date","foo desc"]`]);
3059 });
3060
3061 test(`Loading a filter with a sort attribute`, async () => {
3062 Foo._filters = [
3063 {
3064 context: "{}",
3065 domain: "[]",
3066 id: 7,
3067 is_default: true,
3068 name: "My favorite",
3069 sort: '["date asc", "foo desc"]',
3070 user_ids: [2],
3071 },
3072 {
3073 context: "{}",
3074 domain: "[]",
3075 id: 8,
3076 is_default: false,
3077 name: "My second favorite",
3078 sort: '["date desc", "foo asc"]',
3079 user_ids: [2],
3080 },
3081 ];
3082
3083 onRpc("web_search_read", ({ kwargs }) => expect.step(kwargs.order));
3084 await mountView({
3085 resModel: "foo",
3086 type: "list",
3087 arch: `
3088 <list>
3089 <field name="foo"/>
3090 <field name="date"/>
3091 </list>
3092 `,
3093 loadIrFilters: true,
3094 });
3095 await toggleSearchBarMenu();
3096 await toggleMenuItem("My second favorite");
3097 expect.verifySteps(["date ASC, foo DESC", "date DESC, foo ASC"]);
3098 });
3099
3100 test(`many2one field rendering`, async () => {
3101 await mountView({
3102 resModel: "foo",
3103 type: "list",
3104 arch: `<list><field name="m2o"/></list>`,
3105 });
3106 expect(queryAllTexts(`.o_data_cell`)).toEqual(["Value 1", "Value 2", "Value 1", "Value 1"]);
3107 });
3108
3109 test(`many2one field rendering with many2one widget`, async () => {
3110 Bar._records[0].name = false;
3111 await mountView({
3112 resModel: "foo",
3113 type: "list",
3114 arch: `<list><field name="m2o" widget="many2one"/></list>`,
3115 });
3116 expect(queryAllTexts(`.o_data_cell`)).toEqual(["Unnamed", "Value 2", "Unnamed", "Unnamed"]);
3117 });
3118
3119 test(`many2one field rendering when display_name is falsy`, async () => {
3120 Bar._records[0].name = false;
3121
3122 stepAllNetworkCalls();
3123 await mountView({
3124 resModel: "foo",
3125 type: "list",
3126 arch: `<list><field name="m2o"/></list>`,
3127 });
3128 expect(queryAllTexts(`.o_data_cell`)).toEqual(["Unnamed", "Value 2", "Unnamed", "Unnamed"]);
3129 expect.verifySteps([
3130 "/web/webclient/translations",
3131 "/web/webclient/load_menus",
3132 "get_views",
3133 "web_search_read",
3134 "has_group",
3135 ]);
3136 });
3137
3138 test(`grouped list view, with 1 open group`, async () => {
3139 await mountView({
3140 resModel: "foo",
3141 type: "list",
3142 arch: `<list><field name="foo"/><field name="int_field"/></list>`,
3143 groupBy: ["foo"],
3144 });
3145 expect(`tr.o_group_header`).toHaveCount(3);
3146 expect(`tr.o_data_row`).toHaveCount(0);
3147
3148 await contains(`th.o_group_name`).click();
3149 expect(`tr.o_group_header`).toHaveCount(3);
3150 expect(`tr.o_data_row`).toHaveCount(2);
3151 expect(`td:contains(9)`).toHaveCount(1, { message: "should contain 9" });
3152 expect(`td:contains(-4)`).toHaveCount(1, { message: "should contain -4" });
3153 expect(`td:contains(10)`).toHaveCount(1, { message: "should contain 10" }); // FIXME: missing aggregates
3154 expect(`tr.o_group_header td:contains(10)`).toHaveCount(1, {
3155 message: "but 10 should be in a header",
3156 });
3157 });
3158
3159 test(`opening records when clicking on record`, async () => {
3160 const listView = registry.category("views").get("list");
3161 class CustomListController extends listView.Controller {
3162 openRecord(record) {
3163 expect.step("openRecord");
3164 expect(record.resId).toBe(2);
3165 }
3166 }
3167 registry.category("views").add("custom_list", {
3168 ...listView,
3169 Controller: CustomListController,
3170 });
3171
3172 await mountView({
3173 resModel: "foo",
3174 type: "list",
3175 arch: `<list js_class="custom_list"><field name="foo"/></list>`,
3176 });
3177 await contains(`tr:nth-child(2) td:not(.o_list_record_selector)`).click();
3178 await selectGroup("foo");
3179 expect(`tr.o_group_header`).toHaveCount(3, { message: "list should be grouped" });
3180
3181 await contains(`th.o_group_name`).click();
3182 await contains(`tr:not(.o_group_header) td:not(.o_list_record_selector)`).click();
3183 expect.verifySteps(["openRecord", "openRecord"]);
3184 });
3185
3186 test(`execute an action before and after each valid save in a list view`, async () => {
3187 const listView = registry.category("views").get("list");
3188 class CustomListController extends listView.Controller {
3189 async onRecordSaved(record) {
3190 expect.step(`onRecordSaved ${record.resId}`);
3191 }
3192
3193 async onWillSaveRecord(record) {
3194 expect.step(`onWillSaveRecord ${record.resId}`);
3195 }
3196 }
3197 registry.category("views").add(
3198 "custom_list",
3199 {
3200 ...listView,
3201 Controller: CustomListController,
3202 },
3203 { force: true }
3204 );
3205
3206 onRpc("web_save", ({ args }) => expect.step(`web_save ${args[0]}`));
3207 await mountView({
3208 resModel: "foo",
3209 type: "list",
3210 arch: `<list js_class="custom_list" editable="top"><field name="foo" required="1"/></list>`,
3211 });
3212 await contains(`.o_data_cell`).click();
3213 await contains(`[name=foo] input`).edit("");
3214 await contains(`.o_list_view`).click();
3215 expect.verifySteps([]);
3216
3217 await contains(`[name=foo] input`).edit("YOLO");
3218 await contains(`.o_list_view`).click();
3219 expect.verifySteps(["onWillSaveRecord 1", "web_save 1", "onRecordSaved 1"]);
3220 });
3221
3222 test(`execute an action before and after each valid save in a grouped list view`, async () => {
3223 const listView = registry.category("views").get("list");
3224 class CustomListController extends listView.Controller {
3225 async onRecordSaved(record) {
3226 expect.step(`onRecordSaved ${record.resId}`);
3227 }
3228
3229 async onWillSaveRecord(record) {
3230 expect.step(`onWillSaveRecord ${record.resId}`);
3231 }
3232 }
3233 registry.category("views").add("custom_list", {
3234 ...listView,
3235 Controller: CustomListController,
3236 });
3237
3238 onRpc("web_save", ({ args }) => expect.step(`web_save ${args[0]}`));
3239 await mountView({
3240 resModel: "foo",
3241 type: "list",
3242 arch: `<list js_class="custom_list" editable="top" expand="1"><field name="foo" required="1"/></list>`,
3243 groupBy: ["bar"],
3244 });
3245 await contains(`.o_data_cell[name='foo']`).click();
3246 await contains(`[name=foo] input`).edit("");
3247 await contains(`.o_list_view`).click();
3248 expect.verifySteps([]);
3249
3250 await contains(`[name=foo] input`).edit("YOLO");
3251 await contains(`.o_list_view`).click();
3252 expect.verifySteps(["onWillSaveRecord 4", "web_save 4", "onRecordSaved 4"]);
3253 });
3254
3255 test(`don't exec a valid save with onWillSaveRecord in a list view`, async () => {
3256 const listView = registry.category("views").get("list");
3257 class ListViewCustom extends listView.Controller {
3258 async onRecordSaved(record) {
3259 throw new Error("should not execute onRecordSaved");
3260 }
3261
3262 async onWillSaveRecord(record) {
3263 expect.step(`onWillSaveRecord ${record.resId}`);
3264 return false;
3265 }
3266 }
3267 registry.category("views").add(
3268 "list",
3269 {
3270 ...listView,
3271 Controller: ListViewCustom,
3272 },
3273 { force: true }
3274 );
3275
3276 onRpc("web_save", () => {
3277 throw new Error("should not save the record");
3278 });
3279 await mountView({
3280 resModel: "foo",
3281 type: "list",
3282 arch: `<list editable="top"><field name="foo" required="1"/></list>`,
3283 });
3284 await contains(`.o_data_cell`).click();
3285 await contains(`[name=foo] input`).edit("");
3286 await contains(`.o_list_view`).click();
3287 expect.verifySteps([]);
3288
3289 await contains(`.o_data_cell`).click();
3290 await contains(`[name=foo] input`).edit("YOLO", { confirm: false });
3291 await contains(`.o_list_view`).click();
3292 expect.verifySteps(["onWillSaveRecord 1"]);
3293 });
3294
3295 test(`action/type attributes on tree arch, type='object'`, async () => {
3296 mockService("action", {
3297 doActionButton(params) {
3298 expect.step(`doActionButton type ${params.type} name ${params.name}`);
3299 params.onClose();
3300 },
3301 });
3302
3303 stepAllNetworkCalls();
3304 await mountView({
3305 resModel: "foo",
3306 type: "list",
3307 arch: `<list action="a1" type="object"><field name="foo"/></list>`,
3308 });
3309 expect.verifySteps([
3310 "/web/webclient/translations",
3311 "/web/webclient/load_menus",
3312 "get_views",
3313 "web_search_read",
3314 "has_group",
3315 ]);
3316
3317 await contains(`.o_data_cell`).click();
3318 expect.verifySteps(["doActionButton type object name a1", "web_search_read"]);
3319 });
3320
3321 test(`action/type attributes on tree arch, type='action'`, async () => {
3322 mockService("action", {
3323 doActionButton(params) {
3324 expect.step(`doActionButton type ${params.type} name ${params.name}`);
3325 params.onClose();
3326 },
3327 });
3328
3329 stepAllNetworkCalls();
3330 await mountView({
3331 resModel: "foo",
3332 type: "list",
3333 arch: `<list action="a1" type="action"><field name="foo"/></list>`,
3334 });
3335 expect.verifySteps([
3336 "/web/webclient/translations",
3337 "/web/webclient/load_menus",
3338 "get_views",
3339 "web_search_read",
3340 "has_group",
3341 ]);
3342
3343 await contains(`.o_data_cell`).click();
3344 expect.verifySteps(["doActionButton type action name a1", "web_search_read"]);
3345 });
3346
3347 test.tags("desktop");
3348 test(`editable list view: readonly fields cannot be edited`, async () => {
3349 Foo._fields.foo = fields.Char({ readonly: true });
3350
3351 await mountView({
3352 resModel: "foo",
3353 type: "list",
3354 arch: `
3355 <list editable="bottom">
3356 <field name="foo"/>
3357 <field name="bar"/>
3358 <field name="int_field" readonly="1"/>
3359 </list>
3360 `,
3361 });
3362 await contains(`.o_field_cell`).click();
3363 expect(`.o_data_row:eq(0)`).toHaveClass("o_selected_row", {
3364 message: "row should be in edit mode",
3365 });
3366 expect(`.o_field_widget[name=foo]`).toHaveClass("o_readonly_modifier", {
3367 message: "foo field should be readonly in edit mode",
3368 });
3369 expect(`.o_field_widget[name=bar]`).not.toHaveClass("o_readonly_modifier", {
3370 message: "bar field should be editable",
3371 });
3372 expect(`.o_field_widget[name=int_field]`).toHaveClass("o_readonly_modifier", {
3373 message: "int_field field should be readonly in edit mode",
3374 });
3375 expect(`.o_data_cell:eq(0)`).toHaveClass("o_readonly_modifier");
3376 });
3377
3378 test.tags("desktop");
3379 test(`editable list view: line with no active element`, async () => {
3380 Bar._fields.titi = fields.Char();
3381 Bar._fields.grosminet = fields.Boolean();
3382 Bar._records = [
3383 { id: 1, titi: "cui", grosminet: true },
3384 { id: 2, titi: "cuicui", grosminet: false },
3385 { id: 3, titi: "cuicuicui", grosminet: false },
3386 ];
3387 Foo._records[0].o2m = [1, 2];
3388
3389 onRpc("web_save", () => expect.step("web_save"));
3390 await mountView({
3391 resModel: "foo",
3392 type: "form",
3393 arch: `
3394 <form>
3395 <field name="o2m">
3396 <list editable="top">
3397 <field name="titi" readonly="1"/>
3398 <field name="grosminet" widget="boolean_toggle"/>
3399 </list>
3400 </field>
3401 </form>
3402 `,
3403 resId: 1,
3404 });
3405 expect(`.o_data_cell:eq(1)`).toHaveClass("o_boolean_toggle_cell");
3406
3407 await contains(`.o_data_cell`).click();
3408 expect(`.o_data_row:eq(0)`).toHaveClass("o_selected_row");
3409 expect(`.o_data_cell:eq(0)`).toHaveClass("o_readonly_modifier");
3410
3411 await contains(`.o_data_cell:eq(1) .o_boolean_toggle input`).click();
3412 expect.verifySteps([]);
3413 });
3414
3415 test.tags("desktop");
3416 test(`editable list view: click on last element after creation empty new line`, async () => {
3417 Bar._fields.titi = fields.Char({ required: true });
3418 Bar._fields.int_field = fields.Integer({ required: true });
3419 Bar._records = [
3420 { id: 1, titi: "cui", int_field: 2 },
3421 { id: 2, titi: "cuicui", int_field: 4 },
3422 { id: 3, titi: "cuicuicui", int_field: 1 },
3423 ];
3424 Foo._records[0].o2m = [1, 2];
3425
3426 await mountView({
3427 resModel: "foo",
3428 type: "form",
3429 arch: `
3430 <form>
3431 <field name="o2m">
3432 <list editable="top">
3433 <field name="int_field" widget="handle"/>
3434 <field name="titi"/>
3435 </list>
3436 </field>
3437 </form>
3438 `,
3439 resId: 1,
3440 });
3441 await contains(`.o_field_x2many_list_row_add a`).click();
3442 await contains(`.o_data_row:last td.o_list_char`).click();
3443 // This test ensure that they aren't traceback when clicking on the last row.
3444 expect(`.o_data_row`).toHaveCount(2, { message: "list should have exactly 2 rows" });
3445 });
3446
3447 test(`edit field in editable field without editing the row`, async () => {
3448 // some widgets are editable in readonly (e.g. priority, boolean_toggle...) and they
3449 // thus don't require the row to be switched in edition to be edited
3450
3451 onRpc("web_save", ({ args }) => expect.step("web_save: " + args[1].bar));
3452 await mountView({
3453 resModel: "foo",
3454 type: "list",
3455 arch: `
3456 <list editable="top">
3457 <field name="foo"/>
3458 <field name="bar" widget="boolean_toggle"/>
3459 </list>
3460 `,
3461 });
3462
3463 // toggle the boolean value of the first row without editing the row
3464 expect(`.o_data_row:eq(0) .o_boolean_toggle input`).toBeChecked();
3465 expect(`.o_selected_row`).toHaveCount(0);
3466
3467 await contains(`.o_data_row .o_boolean_toggle input`).click();
3468 expect(`.o_data_row:eq(0) .o_boolean_toggle input`).not.toBeChecked();
3469 expect(`.o_selected_row`).toHaveCount(0);
3470 expect.verifySteps(["web_save: false"]);
3471
3472 // toggle the boolean value after switching the row in edition
3473 expect(`.o_selected_row`).toHaveCount(0);
3474
3475 await contains(`.o_data_row .o_data_cell .o_field_boolean_toggle div`).click();
3476 expect(`.o_selected_row`).toHaveCount(1);
3477
3478 await contains(`.o_selected_row .o_field_boolean_toggle div`).click();
3479 expect.verifySteps(["web_save: true"]);
3480 });
3481
3482 test(`basic operations for editable list renderer`, async () => {
3483 await mountView({
3484 resModel: "foo",
3485 type: "list",
3486 arch: `<list editable="bottom"><field name="foo"/><field name="bar"/></list>`,
3487 });
3488 expect(`.o_data_row`).toHaveCount(4);
3489 expect(`.o_data_row .o_selected_row`).toHaveCount(0);
3490
3491 await contains(`.o_data_cell`).click();
3492 expect(`.o_data_row:eq(0)`).toHaveClass("o_selected_row");
3493 });
3494
3495 test.tags("desktop");
3496 test(`editable list: add a line and discard`, async () => {
3497 await mountView({
3498 resModel: "foo",
3499 type: "list",
3500 arch: `<list editable="bottom"><field name="foo"/><field name="bar"/></list>`,
3501 domain: [["foo", "=", "yop"]],
3502 });
3503 expect(`tbody tr`).toHaveCount(4, { message: "list should contain 4 rows" });
3504 expect(`.o_data_row`).toHaveCount(1, {
3505 message: "list should contain one record (and thus 3 empty rows)",
3506 });
3507 expect(`.o_pager_value`).toHaveText("1-1", { message: "pager should be correct" });
3508
3509 await contains(`.o_list_button_add`).click();
3510 expect(`tbody tr`).toHaveCount(4, { message: "list should still contain 4 rows" });
3511 expect(`.o_data_row`).toHaveCount(2, {
3512 message: "list should contain two record (and thus 2 empty rows)",
3513 });
3514 expect(`.o_pager_value`).toHaveText("1-2", { message: "pager should be correct" });
3515
3516 await contains(`.o_list_button_discard:not(.dropdown-item)`).click();
3517 expect(`tbody tr`).toHaveCount(4, { message: "list should still contain 4 rows" });
3518 expect(`.o_data_row`).toHaveCount(1, {
3519 message: "list should contain one record (and thus 3 empty rows)",
3520 });
3521 expect(`.o_pager_value`).toHaveText("1-1", { message: "pager should be correct" });
3522 });
3523
3524 test(`grouped editable list: edit a record and click on "Add a line"`, async () => {
3525 await mountView({
3526 resModel: "foo",
3527 type: "list",
3528 arch: `<list editable="bottom"><field name="foo" required="1"/><field name="bar"/></list>`,
3529 groupBy: ["foo"],
3530 });
3531
3532 expect(".o_group_header").toHaveCount(3);
3533 expect(".o_data_row").toHaveCount(0);
3534
3535 await contains(".o_group_header").click();
3536 expect(".o_data_row").toHaveCount(2);
3537
3538 // edit an existing row and click on "Add a line" => edited record should not be discarded
3539 await contains(".o_data_row .o_data_cell").click();
3540 await contains(".o_data_row .o_data_cell .o_field_widget[name=foo] input").edit("coucou");
3541 await contains(".o_group_field_row_add a").click();
3542 expect(".o_data_row .o_data_cell:first").toHaveText("coucou");
3543 expect(".o_data_row").toHaveCount(3);
3544
3545 // edit the new line, and click again on "Add a line" => created record should not be discarded
3546 await contains(".o_data_row .o_data_cell .o_field_widget[name=foo] input").edit("new line");
3547 await contains(".o_group_field_row_add a").click();
3548 expect(".o_data_row").toHaveCount(4);
3549 });
3550
3551 test(`field changes are triggered correctly`, async () => {
3552 Foo._onChanges = {
3553 foo() {
3554 expect.step("onchange");
3555 },
3556 };
3557
3558 await mountView({
3559 resModel: "foo",
3560 type: "list",
3561 arch: `<list editable="bottom"><field name="foo"/><field name="bar"/></list>`,
3562 });
3563 await contains(`.o_data_cell`).click();
3564 expect(`.o_data_row:eq(0)`).toHaveClass("o_selected_row");
3565
3566 await contains(`.o_field_widget[name=foo] input`).edit("abc");
3567 expect.verifySteps(["onchange"]);
3568
3569 await contains(`.o_data_cell:eq(2)`).click();
3570 expect(`.o_data_row:eq(1)`).toHaveClass("o_selected_row");
3571 expect.verifySteps([]);
3572 });
3573
3574 test.tags("desktop");
3575 test(`editable list view: basic char field edition`, async () => {
3576 await mountView({
3577 resModel: "foo",
3578 type: "list",
3579 arch: `<list editable="bottom"><field name="foo"/><field name="bar"/></list>`,
3580 });
3581 await contains(`.o_field_cell`).click();
3582 expect(`.o_data_row:eq(0)`).toHaveClass("o_selected_row");
3583
3584 await contains(`.o_field_char input`).edit("abc", { confirm: false });
3585 expect(`.o_field_char input`).toHaveValue("abc", {
3586 message: "char field has been edited correctly",
3587 });
3588
3589 await contains(`.o_data_row:eq(1) .o_data_cell`).click();
3590 expect(`.o_field_cell:eq(0)`).toHaveText("abc", {
3591 message: "changes should be saved correctly",
3592 });
3593 expect(`.o_data_row:eq(0)`).not.toHaveClass("o_selected_row");
3594 expect(`.o_data_row:eq(1)`).toHaveClass("o_selected_row");
3595 expect(MockServer.env["foo"].browse(1)[0].foo).toBe("abc", {
3596 message: "the edition should have been properly saved",
3597 });
3598 });
3599
3600 test.tags("desktop");
3601 test(`editable list view: edit an invalid row`, async () => {
3602 Foo._records[0].foo = "";
3603 await mountView({
3604 resModel: "foo",
3605 type: "list",
3606 arch: `
3607 <list editable="bottom">
3608 <field name="foo" required="1"/>
3609 <field name="int_field"/>
3610 </list>`,
3611 });
3612
3613 expect(queryAllTexts(`.o_data_cell`)).toEqual([
3614 "",
3615 "10",
3616 "blip",
3617 "9",
3618 "gnap",
3619 "17",
3620 "blip",
3621 "-4",
3622 ]);
3623
3624 // switch first row on edition, then click out
3625 await contains(`.o_field_cell`).click();
3626 expect(`.o_data_row:eq(0)`).toHaveClass("o_selected_row");
3627 expect(`.o_selected_row .o_invalid_cell`).toHaveCount(1);
3628
3629 await contains(`.o_control_panel`).click();
3630 expect(`.o_selected_row`).toHaveCount(0);
3631
3632 // switch again first row on edition, edit, and click out
3633 await contains(`.o_field_cell`).click();
3634 expect(`.o_data_row:eq(0)`).toHaveClass("o_selected_row");
3635 expect(`.o_selected_row .o_invalid_cell`).toHaveCount(1);
3636
3637 await contains(`.o_field_widget[name=int_field] input`).edit("14");
3638 await contains(`.o_control_panel`).click();
3639 expect(`.o_selected_row`).toHaveCount(1);
3640 });
3641
3642 test.tags("desktop");
3643 test(`editable list view: save data when list sorting in edit mode`, async () => {
3644 onRpc("web_save", ({ args }) => {
3645 expect.step("web_save");
3646 expect(args).toEqual([[1], { foo: "xyz" }], {
3647 message: "should correctly save the edited record",
3648 });
3649 });
3650
3651 await mountView({
3652 resModel: "foo",
3653 type: "list",
3654 arch: `<list editable="bottom"><field name="foo"/></list>`,
3655 });
3656 await contains(`.o_data_cell`).click();
3657 await contains(`.o_field_widget[name=foo] input`).edit("xyz");
3658 await contains(`.o_column_sortable`).click();
3659 expect(`.o_selected_row`).toHaveCount(0);
3660 expect.verifySteps(["web_save"]);
3661 });
3662
3663 test.tags("desktop");
3664 test(`editable list view: check that controlpanel buttons are updating when groupby applied`, async () => {
3665 Foo._fields.foo = fields.Char({ required: true });
3666 Foo._views = {
3667 "list,3": `<list editable="top"><field name="display_name"/><field name="foo"/></list>`,
3668 "search,9": `
3669 <search>
3670 <filter string="candle" name="itsName" context="{'group_by': 'foo'}"/>
3671 </search>
3672 `,
3673 };
3674
3675 defineActions([
3676 {
3677 id: 11,
3678 name: "Partners Action 11",
3679 res_model: "foo",
3680 views: [[3, "list"]],
3681 search_view_id: [9, "search"],
3682 },
3683 ]);
3684
3685 await mountWithCleanup(WebClient);
3686 await getService("action").doAction(11);
3687 await contains(`.o_list_button_add`).click();
3688 expect(`.o_list_button_add`).toHaveCount(0);
3689 expect(`.o_list_button_save`).toHaveCount(1, {
3690 message: "Should have 2 save button (small and xl screens)",
3691 });
3692
3693 await toggleSearchBarMenu();
3694 await toggleMenuItem("candle");
3695 expect(`.o_list_button_add`).toHaveCount(1, {
3696 message: "Create available as list is grouped",
3697 });
3698 expect(`.o_list_button_save`).toHaveCount(0, {
3699 message: "Save not available as no row in edition",
3700 });
3701 });
3702
3703 test.tags("desktop");
3704 test(`editable list view: check that add button is present when groupby applied`, async () => {
3705 Foo._fields.foo = fields.Char({ required: true });
3706 Foo._views = {
3707 "list,3": `<list editable="top"><field name="display_name"/><field name="foo"/></list>`,
3708 "form,4": `<form><field name="display_name"/><field name="foo"/></form>`,
3709 "search,9": `
3710 <search>
3711 <filter string="candle" name="itsName" context="{'group_by': 'foo'}"/>
3712 </search>
3713 `,
3714 };
3715
3716 defineActions([
3717 {
3718 id: 11,
3719 name: "Partners Action 11",
3720 res_model: "foo",
3721 views: [
3722 [3, "list"],
3723 [4, "form"],
3724 ],
3725 search_view_id: [9, "search"],
3726 },
3727 ]);
3728
3729 await mountWithCleanup(WebClient);
3730 await getService("action").doAction(11);
3731 expect(`.o_list_button_add`).toHaveCount(1);
3732
3733 await contains(`.o_searchview_dropdown_toggler`).click();
3734 await contains(`.o_menu_item:contains(candle)`).click();
3735 expect(`.o_list_button_add`).toHaveCount(1);
3736 expect(`.o_list_view`).toHaveCount(1);
3737
3738 await contains(`.o_list_button_add`).click();
3739 expect(`.o_form_view`).toHaveCount(1);
3740 });
3741
3742 test(`list view not groupable`, async () => {
3743 Foo._views = {
3744 search: `
3745 <search>
3746 <filter context="{'group_by': 'foo'}" name="foo"/>
3747 </search>
3748 `,
3749 };
3750
3751 onRpc("formatted_read_group", () => {
3752 throw new Error("Should not do a formatted_read_group RPC");
3753 });
3754 await mountView({
3755 resModel: "foo",
3756 type: "list",
3757 arch: `
3758 <list editable="top">
3759 <field name="display_name"/>
3760 <field name="foo"/>
3761 </list>
3762 `,
3763 searchMenuTypes: ["filter", "favorite"],
3764 context: { search_default_foo: 1 },
3765 });
3766 expect(`.o_control_panel div.o_search_options div.o_group_by_menu`).toHaveCount(0, {
3767 message: "there should not be groupby menu",
3768 });
3769 expect(getFacetTexts()).toEqual([]);
3770 });
3771
3772 test("group order by count", async () => {
3773 let readGroupCount = 0;
3774 onRpc("foo", "web_read_group", ({ kwargs, method }) => {
3775 if (readGroupCount < 2) {
3776 readGroupCount++;
3777 } else {
3778 expect.step(`${method} ${kwargs.groupby} order by ${kwargs.order}`);
3779 }
3780 });
3781 await mountView({
3782 resModel: "foo",
3783 type: "list",
3784 arch: `<list>
3785 <field name="foo"/>
3786 <field name="bar"/>
3787 </list>`,
3788 });
3789 await toggleSearchBarMenu();
3790 await selectGroup("foo");
3791 await selectGroup("currency_id");
3792 expect("tr.o_group_header").toHaveCount(3, { message: "list should be grouped" });
3793 await contains(".o_searchview_facet_label").click();
3794 expect.verifySteps(["web_read_group foo,currency_id order by __count DESC"]);
3795 await contains("tr.o_group_header:eq(0)").click();
3796 expect.verifySteps(["web_read_group currency_id order by __count DESC"]);
3797 await contains(".o_searchview_facet_label").click();
3798 expect.verifySteps(["web_read_group foo,currency_id order by __count ASC"]);
3799 await contains(".o_searchview_facet_label").click();
3800 expect.verifySteps(["web_read_group foo,currency_id order by __count DESC"]);
3801 });
3802
3803 test("order by count reset", async () => {
3804 let readGroupCount = 0;
3805 onRpc("foo", "web_read_group", ({ kwargs, method }) => {
3806 if (readGroupCount < 2) {
3807 readGroupCount++;
3808 } else {
3809 expect.step(`${method} ${kwargs.groupby} order by ${kwargs.order}`);
3810 }
3811 });
3812 await mountView({
3813 resModel: "foo",
3814 type: "list",
3815 arch: `<list>
3816 <field name="foo"/>
3817 <field name="bar"/>
3818 </list>`,
3819 searchViewArch: `
3820 <search>
3821 <filter name="my_filter" string="My Filter" domain="[('id', '=', 0)]"/>
3822 </search>
3823 `,
3824 });
3825 await toggleSearchBarMenu();
3826 await selectGroup("foo");
3827 await selectGroup("currency_id");
3828 await toggleMenuItem("My Filter");
3829 await contains(".o_searchview_facet_label").click();
3830 expect.verifySteps([
3831 "web_read_group foo,currency_id order by ",
3832 "web_read_group foo,currency_id order by __count DESC",
3833 ]);
3834 await toggleSearchBarMenu();
3835 await toggleMenuItem("My Filter");
3836 expect.verifySteps(["web_read_group foo,currency_id order by __count DESC"]);
3837 await toggleMenuItem("My Filter");
3838 expect.verifySteps(["web_read_group foo,currency_id order by __count DESC"]);
3839 await toggleMenuItem("Currency");
3840 expect.verifySteps(["web_read_group foo order by __count DESC"]);
3841 await toggleMenuItem("Foo");
3842 await toggleMenuItem("Foo");
3843 expect.verifySteps(["web_read_group foo order by "]);
3844 });
3845
3846 test.tags("desktop");
3847 test(`selection changes are triggered correctly on desktop`, async () => {
3848 patchWithCleanup(ListController.prototype, {
3849 setup() {
3850 super.setup(...arguments);
3851 onRendered(() => {
3852 expect.step("onRendered ListController");
3853 });
3854 },
3855 });
3856
3857 await mountView({
3858 resModel: "foo",
3859 type: "list",
3860 arch: `<list><field name="foo"/><field name="bar"/></list>`,
3861 });
3862 expect(`.o_data_row .o_list_record_selector input:checked`).toHaveCount(0, {
3863 message: "no record should be selected",
3864 });
3865 expect.verifySteps(["onRendered ListController", "onRendered ListController"]);
3866
3867 // tbody checkbox click
3868 await contains(`tbody .o_list_record_selector input`).click();
3869 expect(`.o_data_row .o_list_record_selector input:checked`).toHaveCount(1, {
3870 message: "only 1 record should be selected",
3871 });
3872 expect.verifySteps(["onRendered ListController"]);
3873
3874 await contains(`tbody .o_list_record_selector input`).click();
3875 expect(`.o_data_row .o_list_record_selector input:checked`).toHaveCount(0, {
3876 message: "no record should be selected",
3877 });
3878 expect.verifySteps(["onRendered ListController"]);
3879
3880 // head checkbox click
3881 await contains(`thead .o_list_record_selector input`).click();
3882 expect(`.o_data_row .o_list_record_selector input:checked`).toHaveCount(4, {
3883 message: "all records should be selected",
3884 });
3885 expect.verifySteps(["onRendered ListController"]);
3886
3887 await contains(`thead .o_list_record_selector input`).click();
3888 expect(`.o_data_row .o_list_record_selector input:checked`).toHaveCount(0, {
3889 message: "no records should be selected",
3890 });
3891 expect.verifySteps(["onRendered ListController"]);
3892 });
3893
3894 test.tags("mobile");
3895 test(`selection changes are triggered correctly on mobile`, async () => {
3896 patchWithCleanup(ListController.prototype, {
3897 setup() {
3898 super.setup(...arguments);
3899 onRendered(() => {
3900 expect.step("onRendered ListController");
3901 });
3902 },
3903 });
3904
3905 await mountView({
3906 resModel: "foo",
3907 type: "list",
3908 arch: `<list><field name="foo"/><field name="bar"/></list>`,
3909 });
3910 expect(`.o_data_row.o_data_row_selected`).toHaveCount(0, {
3911 message: "no record should be selected",
3912 });
3913 expect.verifySteps(["onRendered ListController", "onRendered ListController"]);
3914
3915 // tbody checkbox click
3916 await clickRecordSelector();
3917 expect(`.o_data_row.o_data_row_selected`).toHaveCount(1, {
3918 message: "only 1 record should be selected",
3919 });
3920 expect.verifySteps(["onRendered ListController"]);
3921
3922 await clickRecordSelector();
3923 expect(`.o_data_row.o_data_row_selected`).toHaveCount(0, {
3924 message: "no record should be selected",
3925 });
3926 expect.verifySteps(["onRendered ListController"]);
3927 });
3928
3929 test.tags("desktop");
3930 test(`Row selection checkbox can be toggled by clicking on the cell`, async () => {
3931 await mountView({
3932 resModel: "foo",
3933 type: "list",
3934 arch: `<list><field name="foo"/><field name="bar"/></list>`,
3935 });
3936 expect(`.o_data_row .o_list_record_selector input:checked`).toHaveCount(0, {
3937 message: "no record should be selected",
3938 });
3939
3940 await contains(`tbody .o_list_record_selector`).click();
3941 expect(`tbody .o_list_record_selector input:checked`).toHaveCount(1);
3942 expect(`.o_data_row .o_list_record_selector input:checked`).toHaveCount(1, {
3943 message: "only 1 record should be selected",
3944 });
3945
3946 await contains(`tbody .o_list_record_selector`).click();
3947 expect(`.o_list_record_selector input:checked`).toHaveCount(0);
3948 expect(`.o_data_row .o_list_record_selector input:checked`).toHaveCount(0, {
3949 message: "no record should be selected",
3950 });
3951
3952 await contains(`thead .o_list_record_selector`).click();
3953 expect(`.o_list_record_selector input:checked`).toHaveCount(5);
3954 expect(`.o_data_row .o_list_record_selector input:checked`).toHaveCount(4, {
3955 message: "all records should be selected",
3956 });
3957
3958 await contains(`thead .o_list_record_selector`).click();
3959 expect(`.o_list_record_selector input:checked`).toHaveCount(0);
3960 expect(`.o_data_row .o_list_record_selector input:checked`).toHaveCount(0, {
3961 message: "no record should be selected",
3962 });
3963 });
3964
3965 test.tags("desktop");
3966 test(`head selector is toggled by the other selectors`, async () => {
3967 await mountView({
3968 resModel: "foo",
3969 type: "list",
3970 arch: `<list><field name="foo"/><field name="bar"/></list>`,
3971 groupBy: ["bar"],
3972 });
3973 expect(`thead .o_list_record_selector input`).not.toBeChecked({
3974 message: "Head selector should be unchecked",
3975 });
3976
3977 await contains(`.o_group_header:nth-child(2)`).click();
3978 await contains(`thead .o_list_record_selector input`).click();
3979 expect(`tbody .o_list_record_selector input:checked`).toHaveCount(3, {
3980 message: "All visible checkboxes should be checked",
3981 });
3982
3983 await contains(`.o_group_header:eq(0)`).click();
3984 expect(`thead .o_list_record_selector input`).not.toBeChecked({
3985 message: "Head selector should be unchecked",
3986 });
3987
3988 await contains(`tbody:nth-child(2) .o_list_record_selector input`).click();
3989 expect(`thead .o_list_record_selector input`).toBeChecked({
3990 message: "Head selector should be checked",
3991 });
3992
3993 await contains(`tbody .o_list_record_selector input`).click();
3994 expect(`thead .o_list_record_selector input`).not.toBeChecked({
3995 message: "Head selector should be unchecked",
3996 });
3997
3998 await contains(`.o_group_header`).click();
3999 expect(`thead .o_list_record_selector input`).toBeChecked({
4000 message: "Head selector should be checked",
4001 });
4002 });
4003
4004 test.tags("desktop");
4005 test(`selection box is properly displayed (single page)`, async () => {
4006 await mountView({
4007 resModel: "foo",
4008 type: "list",
4009 arch: `<list><field name="foo"/><field name="bar"/></list>`,
4010 });
4011 expect(`.o_data_row`).toHaveCount(4);
4012 expect(`.o_control_panel_actions .o_selection_box`).toHaveCount(0);
4013
4014 // select a record
4015 await contains(`.o_data_row .o_list_record_selector input`).click();
4016 expect(`.o_control_panel_actions .o_selection_box`).toHaveCount(1);
4017 expect(`.o_selection_box .o_select_domain`).toHaveCount(0);
4018 expect(`.o_selection_box`).toHaveText("1\nselected");
4019
4020 // select all records of first page
4021 await contains(`thead .o_list_record_selector input`).click();
4022 expect(`.o_control_panel_actions .o_selection_box`).toHaveCount(1);
4023 expect(`.o_selection_box .o_select_domain`).toHaveCount(0);
4024 expect(`.o_selection_box`).toHaveText("4\nselected");
4025
4026 // unselect a record
4027 await contains(`.o_data_row .o_list_record_selector input:eq(1)`).click();
4028 expect(`.o_control_panel_actions .o_selection_box`).toHaveCount(1);
4029 expect(`.o_selection_box .o_select_domain`).toHaveCount(0);
4030 expect(`.o_selection_box`).toHaveText("3\nselected");
4031
4032 await contains(`.o_unselect_all`).click();
4033 expect(`.o_selection_box`).toHaveCount(0, {
4034 message: "selection options are no longer visible",
4035 });
4036 expect(`.o_data_row .o_list_record_selector input:checked`).toHaveCount(0, {
4037 message: "no records should be selected",
4038 });
4039 });
4040
4041 test.tags("desktop");
4042 test(`selection box is properly displayed (multi pages) on desktop`, async () => {
4043 await mountView({
4044 resModel: "foo",
4045 type: "list",
4046 arch: `<list limit="3"><field name="foo"/><field name="bar"/></list>`,
4047 });
4048 expect(`.o_data_row`).toHaveCount(3);
4049 expect(`.o_control_panel_actions .o_selection_box`).toHaveCount(0);
4050
4051 // select a record
4052 await contains(`.o_data_row .o_list_record_selector input`).click();
4053 expect(`.o_control_panel_actions .o_selection_box`).toHaveCount(1);
4054 expect(`.o_selection_box .o_select_domain`).toHaveCount(0);
4055 expect(`.o_selection_box`).toHaveText("1\nselected");
4056
4057 // select all records of first page
4058 await contains(`thead .o_list_record_selector input`).click();
4059 expect(`.o_control_panel_actions .o_selection_box`).toHaveCount(1);
4060 expect(`.o_selection_box .o_select_domain`).toHaveCount(1);
4061 expect(`.o_selection_box`).toHaveText("3\nselected\n Select all 4");
4062
4063 // select all domain
4064 await contains(`.o_selection_box .o_select_domain`).click();
4065 expect(`.o_control_panel_actions .o_selection_box`).toHaveCount(1);
4066 expect(`.o_selection_box`).toHaveText("All 4 selected");
4067
4068 await contains(`.o_unselect_all`).click();
4069 expect(`.o_selection_box`).toHaveCount(0, {
4070 message: "selection options are no longer visible",
4071 });
4072 });
4073
4074 test.tags("mobile");
4075 test("selection box is properly displayed (multi pages) on mobile", async () => {
4076 await mountView({
4077 type: "list",
4078 resModel: "foo",
4079 arch: `
4080 <list limit="3">
4081 <field name="foo"/>
4082 <field name="bar"/>
4083 </list>
4084 `,
4085 loadActionMenus: true,
4086 });
4087
4088 expect(".o_data_row").toHaveCount(3);
4089 expect(".o_selection_box").toHaveCount(0);
4090
4091 // select a record
4092 await contains(".o_data_row:nth-child(1)").drag();
4093 await animationFrame();
4094
4095 expect(".o_selection_box").toHaveCount(1);
4096 expect(".o_selection_box .o_select_domain").toHaveCount(1);
4097 expect(".o_selection_box").toHaveText("1\nselected\nAll");
4098 expect(".o_selection_box").toHaveCount(1);
4099 expect("div.o_control_panel .o_cp_action_menus").toHaveCount(1);
4100
4101 await toggleActionMenu();
4102
4103 expect(getMenuItemTexts()).toEqual(["Export", "Duplicate", "Delete"]);
4104 // select all records of first page
4105 await contains(".o_data_row:nth-child(2)").drag();
4106 await contains(".o_data_row:nth-child(3)").drag();
4107 await animationFrame();
4108
4109 expect(".o_selection_box").toHaveCount(1);
4110 expect(".o_selection_box .o_select_domain").toHaveCount(1);
4111 expect(".o_selection_box").toHaveText("3\nselected\nAll");
4112
4113 expect(".o_select_domain").toHaveCount(1);
4114
4115 // select all domain
4116 await contains(".o_selection_box .o_select_domain").click();
4117 expect(".o_selection_box").toHaveCount(1);
4118 expect(".o_selection_box").toHaveText("All 4 selected");
4119 });
4120
4121 test.tags("desktop");
4122 test(`selection box shows '+' suffix on selection count beyond count_limit`, async () => {
4123 await mountView({
4124 resModel: "foo",
4125 type: "list",
4126 arch: `<list limit="2" count_limit="3"><field name="foo"/><field name="bar"/></list>`,
4127 });
4128 // select all records of first page
4129 await contains(`thead .o_list_record_selector input`).click();
4130 expect(`.o_selection_box`).toHaveText("2\nselected\n Select all 3+");
4131 // select all domain
4132 await contains(`.o_selection_box .o_select_domain`).click();
4133 expect(`.o_selection_box`).toHaveText("All 3+ selected");
4134 });
4135
4136 test.tags("desktop");
4137 test(`selection box is properly displayed (group list)`, async () => {
4138 await mountView({
4139 resModel: "foo",
4140 type: "list",
4141 arch: `<list><field name="foo"/><field name="bar"/></list>`,
4142 groupBy: ["foo"],
4143 });
4144 expect(`.o_group_header`).toHaveCount(3);
4145 expect(`.o_control_panel_actions .o_selection_box`).toHaveCount(0);
4146
4147 // open first group
4148 await contains(`.o_group_header`).click();
4149
4150 // select a record
4151 await contains(`.o_data_row .o_list_record_selector input`).click();
4152 expect(`.o_control_panel_actions .o_selection_box`).toHaveCount(1);
4153 expect(`.o_selection_box .o_select_domain`).toHaveCount(0);
4154 expect(`.o_selection_box`).toHaveText("1\nselected");
4155
4156 // select all records of first page
4157 await contains(`thead .o_list_record_selector input`).click();
4158 expect(`.o_control_panel_actions .o_selection_box`).toHaveCount(1);
4159 expect(`.o_selection_box .o_select_domain`).toHaveCount(1);
4160 expect(`.o_selection_box`).toHaveText("2\nselected\n Select all 4");
4161
4162 // select all domain
4163 await contains(`.o_selection_box .o_select_domain`).click();
4164 expect(`.o_control_panel_actions .o_selection_box`).toHaveCount(1);
4165 expect(`.o_selection_box`).toHaveText("All 4 selected");
4166
4167 await contains(`.o_unselect_all`).click();
4168 expect(`.o_selection_box`).toHaveCount(0, {
4169 message: "selection options are no longer visible",
4170 });
4171 });
4172
4173 test.tags("desktop");
4174 test(`selection box: grouped list, all groups folded`, async () => {
4175 await mountView({
4176 resModel: "foo",
4177 type: "list",
4178 arch: `<list><field name="foo"/><field name="bar"/></list>`,
4179 groupBy: ["foo"],
4180 });
4181 expect(`.o_group_header`).toHaveCount(3);
4182 expect(`.o_data_row`).toHaveCount(0);
4183 expect(`.o_searchview`).toHaveCount(1);
4184 expect(`.o_control_panel_actions .o_selection_box`).toHaveCount(0);
4185 expect(`.o_control_panel_breadcrumbs_actions .o_cp_action_menus`).toHaveCount(1);
4186
4187 // click on the checkbox in the thead
4188 await contains(`thead .o_list_record_selector input`).click();
4189 expect(`.o_control_panel_actions .o_selection_box`).toHaveCount(1);
4190 expect(`.o_control_panel_breadcrumbs_actions .o_cp_action_menus`).toHaveCount(0);
4191 expect(`.o_searchview`).toHaveCount(0);
4192 expect(`.o_selection_box`).toHaveText("All 4 selected");
4193
4194 // remove selection by clicking on the cross in the selection box
4195 await contains(`.o_unselect_all`).click();
4196 expect(`.o_selection_box`).toHaveCount(0);
4197
4198 // click again on the checkbox in the thead
4199 await contains(`thead .o_list_record_selector input`).click();
4200 expect(`.o_control_panel_actions .o_selection_box`).toHaveCount(1);
4201 expect(`.o_selection_box`).toHaveText("All 4 selected");
4202
4203 // remove selection by clicking on the checkbox in the thead
4204 await contains(`thead .o_list_record_selector input`).click();
4205 expect(`.o_searchview`).toHaveCount(1);
4206 expect(`.o_control_panel_actions .o_selection_box`).toHaveCount(0);
4207 });
4208
4209 test.tags("desktop");
4210 test(`selection box in grouped list, multi pages`, async () => {
4211 await mountView({
4212 resModel: "foo",
4213 type: "list",
4214 arch: '<list groups_limit="2"><field name="foo"/><field name="bar"/></list>',
4215 groupBy: ["int_field"],
4216 });
4217
4218 expect(".o_group_header").toHaveCount(2);
4219 expect(".o_selection_box").toHaveCount(0);
4220 expect(".o_pager_value").toHaveText("1-2");
4221 expect(".o_pager_limit").toHaveText("4");
4222
4223 // open first group and select all records of first page
4224 await contains(".o_group_header").click();
4225 expect(".o_data_row").toHaveCount(1);
4226 await contains("thead .o_list_record_selector input").click();
4227 expect(".o_control_panel_actions .o_selection_box").toHaveCount(1);
4228 expect(".o_selection_box .o_select_domain").toHaveCount(1);
4229 expect(queryOne(".o_selection_box").innerText.replace(/\s+/g, " ").trim()).toBe(
4230 "1 selected Select all" // we don't know the total count, so we don't display it
4231 );
4232
4233 // select all domain
4234 await contains(".o_selection_box .o_select_domain").click();
4235 expect(".o_control_panel_actions .o_selection_box").toHaveCount(1);
4236 expect(".o_selection_box").toHaveText("All 4 selected");
4237 });
4238
4239 test.tags("desktop");
4240 test(`selection box: grouped list, select domain, open group`, async () => {
4241 await mountView({
4242 resModel: "foo",
4243 type: "list",
4244 arch: '<list><field name="foo"/><field name="bar"/></list>',
4245 groupBy: ["foo"],
4246 });
4247
4248 expect(".o_group_header").toHaveCount(3);
4249 expect(".o_data_row").toHaveCount(0);
4250 expect(".o_control_panel_actions .o_selection_box").toHaveCount(0);
4251
4252 // select all domain by ticking the thead checkbox
4253 await contains(`thead .o_list_record_selector input`).click();
4254 expect(`.o_selection_box`).toHaveText("All 4 selected");
4255
4256 // open first group
4257 await contains(".o_group_header").click();
4258 expect(".o_data_row").toHaveCount(2);
4259 expect(".o_data_row .o_list_record_selector input:checked").toHaveCount(2);
4260
4261 // open another group
4262 await contains(queryAll(".o_group_header")[1]).click();
4263 expect(".o_data_row").toHaveCount(3);
4264 expect(".o_data_row .o_list_record_selector input:checked").toHaveCount(3);
4265 });
4266
4267 test.tags("desktop");
4268 test(`selection box: grouped list, select domain, use pager (inside group)`, async () => {
4269 await mountView({
4270 resModel: "foo",
4271 type: "list",
4272 arch: '<list limit="2"><field name="foo"/><field name="bar"/></list>',
4273 groupBy: ["bar"],
4274 });
4275
4276 expect(".o_group_header").toHaveCount(2);
4277 expect(".o_data_row").toHaveCount(0);
4278 expect(".o_control_panel_actions .o_selection_box").toHaveCount(0);
4279
4280 // open second group and select all domain
4281 await contains(queryAll(".o_group_header")[1]).click();
4282 await contains("thead .o_list_record_selector input").click();
4283 await contains(".o_selection_box .o_select_domain").click();
4284 expect(".o_data_row").toHaveCount(2);
4285 expect(".o_group_header .o_pager_value").toHaveText("1-2");
4286 expect(".o_group_header .o_pager_limit").toHaveText("3");
4287 expect(".o_control_panel_actions .o_selection_box").toHaveCount(1);
4288 expect(".o_selection_box").toHaveText("All 4 selected");
4289
4290 // click pager next in the opened group
4291 await contains(".o_group_header .o_pager_next").click();
4292 expect(".o_data_row").toHaveCount(1);
4293 expect(".o_data_row .o_list_record_selector input:checked").toHaveCount(1);
4294 expect(".o_selection_box").toHaveText("All 4 selected");
4295 });
4296
4297 test.tags("desktop");
4298 test(`selection box: grouped list, select domain, use main pager`, async () => {
4299 await mountView({
4300 resModel: "foo",
4301 type: "list",
4302 arch: '<list groups_limit="2"><field name="foo"/><field name="bar"/></list>',
4303 groupBy: ["foo"],
4304 });
4305
4306 expect(".o_group_header").toHaveCount(2);
4307 expect(".o_data_row").toHaveCount(0);
4308 expect(".o_control_panel_actions .o_selection_box").toHaveCount(0);
4309
4310 // select all domain by ticking the thead checkbox
4311 await contains(`thead .o_list_record_selector input`).click();
4312 expect(`.o_selection_box`).toHaveText("All 4 selected");
4313
4314 // go to second page
4315 await contains(".o_pager_next").click();
4316 expect(".o_group_header").toHaveCount(1);
4317 expect(".o_data_row").toHaveCount(0);
4318 expect(`.o_selection_box`).toHaveText("All 4 selected");
4319
4320 // open a group
4321 await contains(".o_group_header").click();
4322 expect(".o_data_row").toHaveCount(1);
4323 expect(".o_data_row .o_list_record_selector input:checked").toHaveCount(1);
4324
4325 // go to previous page and come back, to check that selection is still ok
4326 await contains(".o_pager_previous").click();
4327 await contains(".o_pager_next").click();
4328 expect(".o_data_row").toHaveCount(1);
4329 expect(".o_data_row .o_list_record_selector input:checked").toHaveCount(1);
4330 expect(`.o_selection_box`).toHaveText("All 4 selected");
4331 });
4332
4333 test.tags("desktop");
4334 test(`selection box: grouped list, select domain, reduce limit`, async () => {
4335 await mountView({
4336 resModel: "foo",
4337 type: "list",
4338 arch: '<list><field name="foo"/><field name="bar"/></list>',
4339 groupBy: ["foo"],
4340 });
4341
4342 expect(".o_group_header").toHaveCount(3);
4343 expect(".o_data_row").toHaveCount(0);
4344 expect(".o_control_panel_actions .o_selection_box").toHaveCount(0);
4345
4346 // select all domain by ticking the thead checkbox
4347 await contains(`thead .o_list_record_selector input`).click();
4348 expect(`.o_selection_box`).toHaveText("All 4 selected");
4349
4350 // reduce limit to 2
4351 await contains(".o_pager_value").click();
4352 await contains("input.o_pager_value").edit("1-2");
4353 expect(".o_group_header").toHaveCount(2);
4354 expect(`.o_selection_box`).toHaveText("All 4 selected");
4355 });
4356
4357 test.tags("desktop");
4358 test(`selection box is displayed as first action button`, async () => {
4359 await mountView({
4360 resModel: "foo",
4361 type: "list",
4362 arch: `
4363 <list>
4364 <header>
4365 <button name="x" type="object" class="plaf" string="plaf"/>
4366 <button name="y" type="object" class="plouf" string="plouf"/>
4367 </header>
4368 <field name="foo"/>
4369 <field name="bar"/>
4370 </list>
4371 `,
4372 });
4373 expect(`.o_data_row`).toHaveCount(4);
4374 expect(`.o_control_panel_actions .o_selection_box`).toHaveCount(0);
4375
4376 // select a record
4377 await contains(`.o_data_row:eq(0) .o_list_record_selector input`).click();
4378 expect(`.o_control_panel_actions .o_selection_box`).toHaveCount(1);
4379 const firstElement = queryFirst(`.o_control_panel_actions > div`).firstElementChild;
4380 expect(firstElement).toBe(queryFirst(`.o_control_panel_actions .o_selection_box`), {
4381 message: "last element should selection box",
4382 });
4383 expect(`.o_selection_box`).toHaveText("1\nselected");
4384 });
4385
4386 test.tags("desktop");
4387 test(`selection box: select domain, then untick a record`, async () => {
4388 await mountView({
4389 resModel: "foo",
4390 type: "list",
4391 arch: `<list limit="2"><field name="foo"/><field name="bar"/></list>`,
4392 });
4393 expect(`.o_data_row`).toHaveCount(2);
4394 expect(`.o_control_panel_actions .o_selection_box`).toHaveCount(0);
4395
4396 // select all records of first page
4397 await contains(`thead .o_list_record_selector input`).click();
4398 expect(`.o_control_panel_actions .o_selection_box`).toHaveCount(1);
4399 expect(`.o_selection_box .o_select_domain`).toHaveCount(1);
4400 expect(queryOne(".o_selection_box").innerText.replace(/\s+/g, " ").trim()).toBe(
4401 "2 selected Select all 4"
4402 );
4403
4404 // select domain
4405 await contains(`.o_selection_box .o_select_domain`).click();
4406 expect(`.o_selection_box`).toHaveText("All 4 selected");
4407
4408 // untick a record
4409 await contains(`.o_data_row .o_list_record_selector input`).click();
4410 expect(`.o_selection_box .o_select_domain`).toHaveCount(0);
4411 expect(queryOne(`.o_selection_box`).innerText.replace(/\s+/g, " ").trim()).toBe("1 selected");
4412 expect(`thead .o_list_record_selector input`).not.toBeChecked();
4413 });
4414
4415 test.tags("desktop");
4416 test(`selection box is not removed after multi record edition`, async () => {
4417 await mountView({
4418 resModel: "foo",
4419 type: "list",
4420 arch: `<list multi_edit="1"><field name="foo"/><field name="bar"/></list>`,
4421 });
4422 expect(`.o_data_row`).toHaveCount(4, { message: "there should be 4 records" });
4423 expect(`.o_control_panel_actions .o_selection_box`).toHaveCount(0, {
4424 message: "list selection box should not be displayed",
4425 });
4426
4427 // select all records
4428 await contains(`.o_list_record_selector input`).click();
4429 expect(`.o_control_panel_actions .o_selection_box`).toHaveCount(1, {
4430 message: "list selection box should be displayed",
4431 });
4432 expect(`.o_data_row .o_list_record_selector input:checked`).toHaveCount(4, {
4433 message: "all 4 records should be selected",
4434 });
4435
4436 // edit selected records
4437 await contains(`.o_data_row .o_data_cell`).click();
4438 await contains(`.o_data_row [name=foo] input`).edit("legion");
4439 await contains(`.modal-dialog button.btn-primary`).click();
4440 expect(`.o_control_panel_actions .o_selection_box`).toHaveCount(1, {
4441 message: "list selection box should still be displayed",
4442 });
4443 expect(`.o_data_row .o_list_record_selector input:checked`).toHaveCount(4, {
4444 message: "same records should be selected",
4445 });
4446 });
4447
4448 test.tags("desktop");
4449 test(`selection is reset on reload`, async () => {
4450 await mountView({
4451 resModel: "foo",
4452 type: "list",
4453 arch: `
4454 <list>
4455 <field name="foo"/>
4456 <field name="int_field" sum="Sum"/>
4457 </list>
4458 `,
4459 });
4460 expect(`.o_control_panel_actions .o_selection_box`).toHaveCount(0);
4461 expect(`tfoot .o_list_number`).toHaveText("32", {
4462 message: "total should be 32 (no record selected)",
4463 });
4464
4465 // select first record
4466 await contains(`tbody .o_list_record_selector input`).click();
4467 expect(`tbody .o_list_record_selector input:eq(0)`).toBeChecked({
4468 message: "first row should be selected",
4469 });
4470 expect(`.o_control_panel_actions .o_selection_box`).toHaveCount(1);
4471 expect(`tfoot .o_list_number`).toHaveText("10", {
4472 message: "total should be 10 (first record selected)",
4473 });
4474
4475 await contains(`.o_pager_value`).click();
4476 await contains(`input.o_pager_value`).edit("1-4");
4477 expect(`tbody .o_list_record_selector input:eq(0)`).not.toBeChecked({
4478 message: "first row should be selected",
4479 });
4480 expect(`.o_control_panel_actions .o_selection_box`).toHaveCount(0);
4481 expect(`tfoot .o_list_number`).toHaveText("32", {
4482 message: "total should be 10 (first record selected)",
4483 });
4484 });
4485
4486 test.tags("desktop");
4487 test(`selection is kept on render without reload`, async () => {
4488 await mountView({
4489 resModel: "foo",
4490 type: "list",
4491 arch: `
4492 <list>
4493 <field name="foo"/>
4494 <field name="int_field" sum="Sum"/>
4495 </list>
4496 `,
4497 groupBy: ["foo"],
4498 actionMenus: {},
4499 });
4500 expect(`div.o_control_panel .o_cp_action_menus`).toHaveCount(1);
4501 expect(`.o_control_panel_actions .o_selection_box`).toHaveCount(0);
4502
4503 // open blip grouping and check all lines
4504 await contains(`.o_group_header:contains(blip (2))`).click();
4505 await contains(`.o_data_row input`).click();
4506 expect(`div.o_control_panel .o_cp_action_menus`).toHaveCount(1);
4507 expect(`.o_control_panel_actions .o_selection_box`).toHaveCount(1);
4508
4509 // open yop grouping and verify blip are still checked
4510 await contains(`.o_group_header:contains(yop (1))`).click();
4511 expect(`.o_data_row input:checked`).toHaveCount(1, {
4512 message: "opening a grouping does not uncheck others",
4513 });
4514 expect(`div.o_control_panel .o_cp_action_menus`).toHaveCount(1);
4515 expect(`.o_control_panel_actions .o_selection_box`).toHaveCount(1);
4516
4517 // close and open blip grouping and verify blip are unchecked
4518 await contains(`.o_group_header:contains(blip (2))`).click();
4519 await contains(`.o_group_header:contains(blip (2))`).click();
4520 expect(`.o_data_row input:checked`).toHaveCount(0, {
4521 message: "opening and closing a grouping uncheck its elements",
4522 });
4523 expect(`div.o_control_panel .o_cp_action_menus`).toHaveCount(1);
4524 expect(`.o_control_panel_actions .o_selection_box`).toHaveCount(0);
4525 });
4526
4527 test.tags("desktop");
4528 test(`select a record in list grouped by date with granularity`, async () => {
4529 await mountView({
4530 resModel: "foo",
4531 type: "list",
4532 arch: `<list><field name="foo"/><field name="bar"/></list>`,
4533 groupBy: ["date:year"],
4534 // keep the actionMenus, it is relevant as it computes isM2MGrouped which crashes if we
4535 // don't correctly extract the fieldName/granularity from the groupBy
4536 actionMenus: {},
4537 });
4538 expect(`.o_group_header`).toHaveCount(2);
4539 expect(`.o_control_panel_actions .o_selection_box`).toHaveCount(0);
4540
4541 await contains(`.o_group_header`).click();
4542 expect(`.o_data_row`).toHaveCount(1);
4543
4544 await contains(`.o_data_row .o_list_record_selector`).click();
4545 expect(`.o_control_panel_actions .o_selection_box`).toHaveCount(1);
4546 });
4547
4548 test.tags("desktop");
4549 test(`aggregates are computed correctly on desktop`, async () => {
4550 // map: foo record id -> qux value
4551 const quxVals = { 1: 1.0, 2: 2.0, 3: 3.0, 4: 0 };
4552
4553 Foo._records = Foo._records.map((r) => ({
4554 ...r,
4555 qux: quxVals[r.id],
4556 }));
4557
4558 await mountView({
4559 resModel: "foo",
4560 type: "list",
4561 arch: `
4562 <list>
4563 <field name="foo"/>
4564 <field name="int_field" sum="Sum"/>
4565 <field name="qux" avg="Average"/>
4566 </list>
4567 `,
4568 searchViewArch: `
4569 <search>
4570 <filter name="my_filter" string="My Filter" domain="[('id', '=', 0)]"/>
4571 </search>
4572 `,
4573 });
4574 expect(queryAllTexts(`tfoot td`)).toEqual(["", "32", "1.50"]);
4575
4576 await contains(`tbody .o_list_record_selector input:eq(0)`).click();
4577 await contains(`tbody .o_list_record_selector input:eq(3)`).click();
4578 expect(queryAllTexts(`tfoot td`)).toEqual(["", "6", "0.50"]);
4579
4580 await contains(`thead .o_list_record_selector input`).click();
4581 expect(queryAllTexts(`tfoot td`)).toEqual(["", "32", "1.50"]);
4582
4583 // Let's update the view to dislay NO records
4584 await contains(`.o_unselect_all`).click();
4585 await toggleSearchBarMenu();
4586 await toggleMenuItem("My Filter");
4587 expect(queryAllTexts(`tfoot td`)).toEqual([""]);
4588 });
4589
4590 test.tags("mobile");
4591 test(`aggregates are computed correctly on mobile`, async () => {
4592 // map: foo record id -> qux value
4593 const quxVals = { 1: 1.0, 2: 2.0, 3: 3.0, 4: 0 };
4594
4595 Foo._records = Foo._records.map((r) => ({
4596 ...r,
4597 qux: quxVals[r.id],
4598 }));
4599
4600 await mountView({
4601 resModel: "foo",
4602 type: "list",
4603 arch: `
4604 <list>
4605 <field name="foo"/>
4606 <field name="int_field" sum="Sum"/>
4607 <field name="qux" avg="Average"/>
4608 </list>
4609 `,
4610 searchViewArch: `
4611 <search>
4612 <filter name="my_filter" string="My Filter" domain="[('id', '=', 0)]"/>
4613 </search>
4614 `,
4615 });
4616 expect(queryAllTexts(`tfoot td`)).toEqual(["", "32", "1.50"]);
4617
4618 await contains("tbody td.o_data_cell:eq(0)").drag();
4619 await contains("tbody td.o_data_cell:eq(9)").drag();
4620 expect(queryAllTexts(`tfoot td`)).toEqual(["", "6", "0.50"]);
4621
4622 await contains(`thead th`).click();
4623 expect(queryAllTexts(`tfoot td`)).toEqual(["", "32", "1.50"]);
4624
4625 // Let's update the view to dislay NO records
4626 await toggleSearchBarMenu();
4627 await toggleMenuItem("My Filter");
4628 expect(queryAllTexts(`tfoot td`)).toEqual([""]);
4629 });
4630
4631 test(`aggregates are computed correctly in grouped lists`, async () => {
4632 await mountView({
4633 resModel: "foo",
4634 type: "list",
4635 groupBy: ["m2o"],
4636 arch: `<list editable="bottom"><field name="foo"/><field name="int_field" sum="Sum"/></list>`,
4637 });
4638 expect(`.o_group_header:eq(0) td:eq(-1)`).toHaveText("23", {
4639 message: "first group total should be 23",
4640 });
4641 expect(`.o_group_header:eq(1) td:eq(-1)`).toHaveText("9", {
4642 message: "second group total should be 9",
4643 });
4644 expect(`tfoot td:eq(-1)`).toHaveText("32", { message: "total should be 32" });
4645 await contains(`.o_group_header:eq(0)`).click();
4646 await clickRecordSelector();
4647 expect(`tfoot td:eq(-1)`).toHaveText("10", {
4648 message: "total should be 10 as first record of first group is selected",
4649 });
4650 });
4651
4652 test(`aggregates are formatted correctly in grouped lists`, async () => {
4653 // in this scenario, there is a widget on an aggregated field, and this widget has no
4654 // associated formatter, so we fallback on the formatter corresponding to the field type
4655 registry.category("fields").add("my_float", floatField);
4656 Foo._records[0].qux = 5.1654846456;
4657
4658 await mountView({
4659 resModel: "foo",
4660 type: "list",
4661 arch: `
4662 <list>
4663 <field name="foo"/>
4664 <field name="qux" widget="my_float" sum="Sum"/>
4665 </list>
4666 `,
4667 groupBy: ["int_field"],
4668 });
4669 expect(queryAllTexts(`.o_group_header .o_list_number`)).toEqual([
4670 "9.00",
4671 "13.00",
4672 "5.17",
4673 "-3.00",
4674 ]);
4675 });
4676
4677 test(`monetary aggregates in grouped list`, async () => {
4678 await mountView({
4679 resModel: "foo",
4680 type: "list",
4681 arch: `
4682 <list>
4683 <field name="foo"/>
4684 <field name="amount" sum="Sum"/>
4685 <field name="qux" widget="monetary" sum="Sum"/>
4686 <field name="currency_id"/>
4687 </list>
4688 `,
4689 groupBy: ["currency_id"],
4690 });
4691 expect(`.o_group_header`).toHaveCount(2);
4692 await contains(`.o_group_header:first`).click();
4693 await contains(`.o_group_header:last`).click();
4694 // Don't handle currencies in aggregates for non monetary fields even with the widget:
4695 // it is bad practice and the server won't send the information anyway
4696 expect(`.o_group_header:first`).toHaveText("USD (3)\n $ 800.00 19.00");
4697 expect(`.o_group_header:last`).toHaveText("EUR (1)\n 1,200.00 € 0.40");
4698 expect(`.o_list_footer .o_list_number span:first`).toHaveText("$ 1,400.00?");
4699 await toggleMultiCurrencyPopover(".o_list_footer .o_list_number span:first sup");
4700 expect(".o_multi_currency_popover").toHaveCount(1);
4701 expect(".o_multi_currency_popover").toHaveText("2,800.00 € at $ 0.50");
4702 });
4703
4704 test(`monetary aggregates in grouped list (!= currencies in same group)`, async () => {
4705 await mountView({
4706 resModel: "foo",
4707 type: "list",
4708 arch: `
4709 <list>
4710 <field name="foo"/>
4711 <field name="amount" widget="monetary" sum="Sum"/>
4712 <field name="currency_id"/>
4713 </list>
4714 `,
4715 groupBy: ["bar"],
4716 });
4717 expect(`.o_group_header`).toHaveCount(2);
4718 await contains(`.o_group_header:first`).click();
4719 await contains(`.o_group_header:last`).click();
4720 expect(`.o_group_header:first`).toHaveText("No (1)\n $ 0.00");
4721 expect(`.o_group_header:last`).toHaveText("Yes (3)\n $ 2,000.00?");
4722 expect(`.o_list_footer .o_list_number span`).toHaveText("$ 2,000.00?");
4723 });
4724
4725 test(`monetary aggregates in grouped list (!= currencies in same group, delete)`, async () => {
4726 await mountView({
4727 resModel: "foo",
4728 type: "list",
4729 arch: `
4730 <list>
4731 <field name="foo"/>
4732 <field name="amount" widget="monetary" sum="Sum"/>
4733 <field name="currency_id"/>
4734 </list>
4735 `,
4736 groupBy: ["bar"],
4737 actionMenus: {},
4738 });
4739 expect(`.o_group_header`).toHaveCount(2);
4740 expect(`.o_group_header:last`).toHaveText("Yes (3)\n $ 2,000.00?");
4741 await contains(`.o_group_header:last`).click();
4742 expect(`.o_data_row`).toHaveCount(3);
4743 await selectAllRecords();
4744 expect(`.o_data_row_selected`).toHaveCount(3);
4745 await toggleActionMenu();
4746 await toggleMenuItem("Delete");
4747 await contains(`.o_dialog footer .btn-primary`).click(); // confirm
4748 expect(`.o_data_row`).toHaveCount(0);
4749 expect(`.o_group_header:last`).toHaveText("Yes (0)\n 0.00");
4750 });
4751
4752 test(`list with monetary field with attribute column_invisible="1"`, async () => {
4753 await mountView({
4754 resModel: "foo",
4755 type: "list",
4756 arch: `
4757 <list>
4758 <field name="foo"/>
4759 <field name="qux" widget="monetary" sum="Sum" column_invisible="1"/>
4760 <field name="currency_id"/>
4761 </list>
4762 `,
4763 });
4764
4765 expect(`.o_data_row`).toHaveCount(4);
4766 expect(queryAllTexts(`.o_data_cell`)).toEqual([
4767 "yop",
4768 "EUR",
4769 "blip",
4770 "USD",
4771 "gnap",
4772 "USD",
4773 "blip",
4774 "USD",
4775 ]);
4776 });
4777
4778 test(`handle false values in aggregates`, async () => {
4779 Foo._fields.false_amount = fields.Monetary({ currency_field: "currency_test" });
4780 Foo._fields.currency_test = fields.Many2one({ relation: "res.currency", default: 1 });
4781 onRpc("web_read_group", ({ parent }) => {
4782 expect.step("web_read_group");
4783 const res = parent();
4784 res.groups[1]["qux:sum"] = false;
4785 res.groups[1]["false_amount:sum"] = false;
4786 return res;
4787 });
4788 await mountView({
4789 resModel: "foo",
4790 type: "list",
4791 arch: `
4792 <list>
4793 <field name="foo"/>
4794 <field name="qux" sum="Sum"/>
4795 <field name="amount"/>
4796 <field name="false_amount"/>
4797 </list>
4798 `,
4799 groupBy: ["bar"],
4800 });
4801 expect.verifySteps(["web_read_group"]);
4802 expect(`.o_group_header:first`).toHaveText("No (1)\n 9.00 $ 0.00 $ 0.00");
4803 expect(`.o_group_header:last`).toHaveText("Yes (3)\n $ 2,000.00?", {
4804 message: "false values are just hidden except for monetary field with multiple currencies",
4805 });
4806 });
4807
4808 test(`aggregates in grouped lists with buttons`, async () => {
4809 await mountView({
4810 resModel: "foo",
4811 type: "list",
4812 groupBy: ["m2o"],
4813 arch: `
4814 <list>
4815 <field name="foo"/>
4816 <field name="int_field" sum="Sum"/>
4817 <button name="a" type="object"/>
4818 <field name="qux" sum="Sum"/>
4819 </list>
4820 `,
4821 });
4822 expect(queryAllTexts(`.o_list_number`)).toEqual(["23", "6.40", "9", "13.00", "32", "19.40"]);
4823 });
4824
4825 test(`date field aggregates in grouped lists`, async () => {
4826 // this test simulates a scenario where a date field has a aggregator
4827 // and the web_read_group thus return a value for that field for each group
4828
4829 onRpc("web_read_group", ({ parent }) => {
4830 const res = parent();
4831 res.groups[0].date = "2021-03-15";
4832 res.groups[1].date = "2021-02-11";
4833 return res;
4834 });
4835 await mountView({
4836 resModel: "foo",
4837 type: "list",
4838 groupBy: ["m2o"],
4839 arch: `
4840 <list>
4841 <field name="foo"/>
4842 <field name="date"/>
4843 </list>
4844 `,
4845 });
4846 expect(`.o_group_header`).toHaveCount(2);
4847 expect(queryAllTexts(`.o_group_header`)).toEqual([`Value 1 (3)`, `Value 2 (1)`]);
4848 });
4849
4850 test(`hide aggregated value in grouped lists when no data provided by RPC call`, async () => {
4851 onRpc("web_read_group", ({ parent }) => {
4852 const res = parent();
4853 for (const group of res.groups) {
4854 delete group["qux:sum"];
4855 }
4856 return res;
4857 });
4858 await mountView({
4859 resModel: "foo",
4860 type: "list",
4861 groupBy: ["bar"],
4862 arch: `
4863 <list editable="bottom">
4864 <field name="foo"/>
4865 <field name="qux" widget="float_time" sum="Sum"/>
4866 </list>
4867 `,
4868 });
4869 expect(`tfoot`).toHaveText("", { message: "There isn't any aggregated value" });
4870 });
4871
4872 test(`aggregates are updated when a line is edited`, async () => {
4873 await mountView({
4874 resModel: "foo",
4875 type: "list",
4876 arch: `<list editable="bottom"><field name="int_field" sum="Sum"/></list>`,
4877 });
4878 expect(`span[data-tooltip="Sum"]`).toHaveText("32", { message: "current total should be 32" });
4879
4880 await contains(`tr.o_data_row td.o_data_cell`).click();
4881 await contains(`td.o_data_cell input`).edit("15");
4882 expect(`span[data-tooltip="Sum"]`).toHaveText("37", { message: "current total should be 37" });
4883 });
4884
4885 test(`aggregates are formatted according to field widget`, async () => {
4886 await mountView({
4887 resModel: "foo",
4888 type: "list",
4889 arch: `
4890 <list>
4891 <field name="foo"/>
4892 <field name="qux" widget="float_time" sum="Sum"/>
4893 </list>
4894 `,
4895 });
4896 expect(`tfoot`).toHaveText("19:24", {
4897 message: "total should be formatted as a float_time",
4898 });
4899 });
4900
4901 test(`aggregates of monetary widget with no currency data in grouped list`, async () => {
4902 await mountView({
4903 resModel: "foo",
4904 type: "list",
4905 groupBy: ["bar"],
4906 arch: `
4907 <list>
4908 <field name="qux" widget="monetary" options="{'currency_field': 'currency_id'}" sum="Sum"/>
4909 <field name="currency_id" column_invisible="True"/>
4910 </list>`,
4911 });
4912 expect(`tfoot`).toHaveText("19.40", {
4913 message: "aggregates monetary should still be displayed without currency",
4914 });
4915 });
4916
4917 test(`aggregates of monetary field with no currency field`, async () => {
4918 await mountView({
4919 resModel: "foo",
4920 type: "list",
4921 arch: `<list><field name="amount" widget="monetary" sum="Sum"/></list>`,
4922 });
4923 expect(`.o_data_row td:not(.o_list_record_selector):eq(0)`).toHaveText("1,200.00", {
4924 message: "field should still be formatted based on currency",
4925 });
4926 expect(`tfoot`).toHaveText("2,000.00", {
4927 message: "aggregates monetary should still be displayed without currency",
4928 });
4929 });
4930
4931 test(`aggregates monetary (same currency)`, async () => {
4932 Foo._records[0].currency_id = 1;
4933
4934 await mountView({
4935 resModel: "foo",
4936 type: "list",
4937 arch: `
4938 <list>
4939 <field name="amount" widget="monetary" sum="Sum"/>
4940 <field name="currency_id"/>
4941 </list>
4942 `,
4943 });
4944 expect(queryAllTexts(`tbody .o_monetary_cell`)).toEqual([
4945 "$ 1,200.00",
4946 "$ 500.00",
4947 "$ 300.00",
4948 "$ 0.00",
4949 ]);
4950 expect(`tfoot`).toHaveText("$ 2,000.00");
4951 });
4952
4953 test(`aggregates monetary (different currencies)`, async () => {
4954 await mountView({
4955 resModel: "foo",
4956 type: "list",
4957 arch: `
4958 <list>
4959 <field name="amount" widget="monetary" sum="Sum"/>
4960 <field name="currency_id"/>
4961 </list>
4962 `,
4963 });
4964 expect(queryAllTexts(`tbody .o_monetary_cell`)).toEqual([
4965 "1,200.00 €",
4966 "$ 500.00",
4967 "$ 300.00",
4968 "$ 0.00",
4969 ]);
4970 expect(`tfoot`).toHaveText("$ 1,400.00?");
4971 await toggleMultiCurrencyPopover("tfoot span sup");
4972 expect(".o_multi_currency_popover").toHaveCount(1);
4973 expect(".o_multi_currency_popover").toHaveText("2,800.00 € at $ 0.50");
4974 });
4975
4976 test(`aggregates monetary (currency field not in view)`, async () => {
4977 Foo._fields.currency_test = fields.Many2one({ relation: "res.currency", default: 1 });
4978
4979 await mountView({
4980 resModel: "foo",
4981 type: "list",
4982 arch: `
4983 <list>
4984 <field name="amount" widget="monetary" sum="Sum" options="{'currency_field': 'currency_test'}"/>
4985 <field name="currency_id"/>
4986 </list>
4987 `,
4988 });
4989 expect(queryAllTexts(`tbody .o_monetary_cell`)).toEqual([
4990 "1,200.00",
4991 "500.00",
4992 "300.00",
4993 "0.00",
4994 ]);
4995 expect(`tfoot`).toHaveText("2,000.00");
4996 });
4997
4998 test(`aggregates monetary (currency field in view)`, async () => {
4999 Foo._fields.amount = fields.Monetary({ currency_field: "currency_test" });
5000 Foo._fields.currency_test = fields.Many2one({ relation: "res.currency", default: 1 });
5001
5002 await mountView({
5003 resModel: "foo",
5004 type: "list",
5005 arch: `
5006 <list>
5007 <field name="amount" widget="monetary" sum="Sum"/>
5008 <field name="currency_test"/>
5009 </list>
5010 `,
5011 });
5012 expect(queryAllTexts(`tbody .o_monetary_cell`)).toEqual([
5013 "$ 1,200.00",
5014 "$ 500.00",
5015 "$ 300.00",
5016 "$ 0.00",
5017 ]);
5018 expect(`tfoot`).toHaveText("$ 2,000.00");
5019 });
5020
5021 test(`aggregates monetary (currency field not set)`, async () => {
5022 Foo._fields.amount = fields.Monetary({ currency_field: "currency_test" });
5023 Foo._fields.currency_test = fields.Many2one({ relation: "res.currency" });
5024 Foo._records[0].currency_test = 1;
5025
5026 await mountView({
5027 resModel: "foo",
5028 type: "list",
5029 arch: `
5030 <list>
5031 <field name="amount" widget="monetary" sum="Sum"/>
5032 <field name="currency_test"/>
5033 </list>
5034 `,
5035 });
5036 expect(queryAllTexts(`tbody .o_monetary_cell`)).toEqual([
5037 "$ 1,200.00",
5038 "500.00",
5039 "300.00",
5040 "0.00",
5041 ]);
5042 expect(`tfoot`).toHaveText("$ 0.00?");
5043 });
5044
5045 test(`aggregates monetary (currency field not set on first record)`, async () => {
5046 Foo._fields.amount = fields.Monetary({ currency_field: "currency_test" });
5047 Foo._fields.currency_test = fields.Many2one({ relation: "res.currency" });
5048 Foo._records[1].currency_test = 1;
5049
5050 await mountView({
5051 resModel: "foo",
5052 type: "list",
5053 arch: `
5054 <list>
5055 <field name="amount" widget="monetary" sum="Sum"/>
5056 <field name="currency_test"/>
5057 </list>
5058 `,
5059 });
5060 expect(queryAllTexts(`tbody .o_monetary_cell`)).toEqual([
5061 "1,200.00",
5062 "$ 500.00",
5063 "300.00",
5064 "0.00",
5065 ]);
5066 expect(`tfoot`).toHaveText("$ 0.00?");
5067 });
5068
5069 test(`aggregates monetary with custom digits (same currency)`, async () => {
5070 Foo._records = Foo._records.map((record) => ({
5071 ...record,
5072 currency_id: 1,
5073 }));
5074
5075 patchWithCleanup(currencies[1], { digits: [42, 4] });
5076
5077 await mountView({
5078 resModel: "foo",
5079 type: "list",
5080 arch: `
5081 <list>
5082 <field name="amount" sum="Sum"/>
5083 <field name="currency_id"/>
5084 </list>
5085 `,
5086 });
5087 expect(queryAllTexts(`tbody [name='amount']`)).toEqual([
5088 "$ 1,200.0000",
5089 "$ 500.0000",
5090 "$ 300.0000",
5091 "$ 0.0000",
5092 ]);
5093 expect(`tfoot`).toHaveText("$ 2,000.0000");
5094 });
5095
5096 test(`aggregates float with monetary widget and custom digits (same currency)`, async () => {
5097 Foo._records = Foo._records.map((record) => ({
5098 ...record,
5099 currency_id: 1,
5100 }));
5101
5102 patchWithCleanup(currencies[1], { digits: [42, 4] });
5103
5104 await mountView({
5105 resModel: "foo",
5106 type: "list",
5107 arch: `
5108 <list>
5109 <field name="qux" widget="monetary" sum="Sum"/>
5110 <field name="currency_id"/>
5111 </list>
5112 `,
5113 });
5114 expect(queryAllTexts(`tbody .o_monetary_cell`)).toEqual([
5115 "$ 0.4000",
5116 "$ 13.0000",
5117 "$ -3.0000",
5118 "$ 9.0000",
5119 ]);
5120 expect(`tfoot`).toHaveText("$ 19.4000");
5121 });
5122
5123 test(`currency_field is taken into account when formatting monetary values`, async () => {
5124 Foo._fields.company_currency_id = fields.Many2one({ relation: "res.currency", default: 2 });
5125 Foo._fields.amount_currency = fields.Monetary({ currency_field: "company_currency_id" });
5126 Foo._records[0].amount_currency = 1100;
5127 Foo._records[0].company_currency_id = 1;
5128
5129 await mountView({
5130 resModel: "foo",
5131 type: "list",
5132 arch: `
5133 <list>
5134 <field name="company_currency_id" column_invisible="1"/>
5135 <field name="currency_id" column_invisible="1"/>
5136 <field name="amount" sum="Sum"/>
5137 <field name="amount_currency"/>
5138 </list>
5139 `,
5140 });
5141 expect(`.o_data_row:eq(0) td[name=amount]`).toHaveText("1,200.00 €", {
5142 message: "field should be formatted based on currency_id",
5143 });
5144 expect(`.o_data_row:eq(0) td[name=amount_currency]`).toHaveText("$ 1,100.00", {
5145 message: "field should be formatted based on company_currency_id",
5146 });
5147 expect(`tfoot td.o_list_number`).toHaveText("$ 1,400.00?", {
5148 message: "aggregates monetary should indicate when different currencies are used",
5149 });
5150 expect(`tfoot td.o_list_number ~ td`).toHaveCount(0, {
5151 message:
5152 "monetary aggregation should only be attempted with an active aggregation function when using different currencies",
5153 });
5154 });
5155
5156 test(`groups can be sorted on the first field of the groupBy`, async () => {
5157 onRpc("web_read_group", ({ kwargs }) => {
5158 expect.step("web_read_group");
5159 expect(kwargs.order).toEqual("bar DESC");
5160 });
5161
5162 await mountView({
5163 resModel: "foo",
5164 type: "list",
5165 arch: `<list default_order="bar desc"><field name="foo"/><field name="bar"/></list>`,
5166 groupBy: ["bar"],
5167 });
5168 expect(`.o_group_header:eq(0)`).toHaveText("Yes (3)");
5169 expect(`.o_group_header:eq(-1)`).toHaveText("No (1)");
5170 expect.verifySteps(["web_read_group"]);
5171 });
5172
5173 test(`groups can be sorted on aggregates`, async () => {
5174 onRpc("web_read_group", ({ kwargs }) => {
5175 expect.step(kwargs.order);
5176 });
5177
5178 await mountView({
5179 resModel: "foo",
5180 type: "list",
5181 groupBy: ["foo"],
5182 arch: `
5183 <list editable="bottom">
5184 <field name="foo"/>
5185 <field name="int_field" sum="Sum"/>
5186 </list>
5187 `,
5188 });
5189 expect(queryAllTexts(`tbody .o_list_number`)).toEqual(["5", "17", "10"], {
5190 message: "initial order should be 5, 17, 10",
5191 });
5192 expect(`tfoot td:eq(-1)`).toHaveText("32", { message: "total should be 32" });
5193
5194 await contains(`.o_column_sortable[data-name=int_field]`).click();
5195 expect(queryAllTexts(`tbody .o_list_number`)).toEqual(["5", "10", "17"], {
5196 message: "order should be 5, 10, 17",
5197 });
5198 expect(`tfoot td:eq(-1)`).toHaveText("32", { message: "total should still be 32" });
5199
5200 await contains(`.o_column_sortable[data-name=int_field]`).click();
5201 expect(queryAllTexts(`tbody .o_list_number`)).toEqual(["17", "10", "5"], {
5202 message: "initial order should be 17, 10, 5",
5203 });
5204 expect(`tfoot td:eq(-1)`).toHaveText("32", { message: "total should still be 32" });
5205 expect.verifySteps(["", "int_field ASC", "int_field DESC"]);
5206 });
5207
5208 test(`groups cannot be sorted on non-aggregable fields if every group is folded`, async () => {
5209 Foo._fields.sort_field = fields.Char({ default: "value" });
5210 Foo._records.forEach((elem) => {
5211 elem.sort_field = "value" + elem.id;
5212 });
5213
5214 onRpc("web_read_group", ({ kwargs }) => {
5215 expect.step(kwargs.order);
5216 });
5217
5218 await mountView({
5219 resModel: "foo",
5220 type: "list",
5221 groupBy: ["foo"],
5222 arch: `
5223 <list editable="bottom">
5224 <field name="foo"/>
5225 <field name="int_field"/>
5226 <field name="sort_field"/>
5227 </list>
5228 `,
5229 });
5230 expect.verifySteps([""]);
5231
5232 // we cannot sort by sort_field since it doesn't have a aggregator
5233 await contains(`.o_column_sortable[data-name='sort_field']`).click();
5234 expect.verifySteps([]);
5235
5236 // we can sort by int_field since it has a aggregator
5237 await contains(`.o_column_sortable[data-name='int_field']`).click();
5238 expect.verifySteps(["int_field ASC"]);
5239
5240 // we keep previous order
5241 await contains(`.o_column_sortable[data-name='sort_field']`).click();
5242 expect.verifySteps([]);
5243
5244 // we can sort on foo since we are groupped by foo + previous order
5245 await contains(`.o_column_sortable[data-name='foo']`).click();
5246 expect.verifySteps(["foo ASC, int_field ASC"]);
5247 });
5248
5249 test(`groups can be sorted on non-aggregable fields if a group isn't folded`, async () => {
5250 onRpc("web_read_group", ({ kwargs }) => {
5251 const order = kwargs.order || "default order";
5252 expect.step(`web_read_group: ${order}`);
5253 });
5254 onRpc("web_search_read", ({ kwargs }) => {
5255 expect.step(`web_search_read: ${kwargs.order || "default order"}`);
5256 });
5257
5258 await mountView({
5259 resModel: "foo",
5260 type: "list",
5261 arch: `<list editable="bottom"><field name="foo"/></list>`,
5262 groupBy: ["bar"],
5263 });
5264 await contains(`.o_group_header:eq(1)`).click();
5265 expect(queryAllTexts(`.o_data_cell[name='foo']`)).toEqual(["yop", "blip", "gnap"]);
5266 expect.verifySteps(["web_read_group: default order", "web_search_read: default order"]);
5267
5268 await contains(`.o_column_sortable[data-name='foo']`).click();
5269 expect(queryAllTexts(`.o_data_cell[name='foo']`)).toEqual(["blip", "gnap", "yop"]);
5270 expect.verifySteps(["web_read_group: foo ASC"]);
5271 });
5272
5273 test(`groups can be sorted on non-aggregable fields if a group isn't folded with expand='1'`, async () => {
5274 onRpc("web_read_group", ({ kwargs }) => {
5275 const order = kwargs.order || "default order";
5276 expect.step(`web_read_group: ${order}`);
5277 });
5278
5279 await mountView({
5280 resModel: "foo",
5281 type: "list",
5282 arch: `<list editable="bottom" expand="1"><field name="foo"/></list>`,
5283 groupBy: ["bar"],
5284 });
5285 expect(queryAllTexts(`.o_data_cell[name='foo']`)).toEqual(["blip", "yop", "blip", "gnap"]);
5286 expect.verifySteps(["web_read_group: default order"]);
5287
5288 await contains(`.o_column_sortable[data-name='foo']`).click();
5289 expect(queryAllTexts(`.o_data_cell[name='foo']`)).toEqual(["blip", "blip", "gnap", "yop"]);
5290 expect.verifySteps(["web_read_group: foo ASC"]);
5291 });
5292
5293 test(`properly apply onchange in simple case`, async () => {
5294 Foo._onChanges = {
5295 foo(record) {
5296 record.int_field = record.foo.length + 1000;
5297 },
5298 };
5299
5300 await mountView({
5301 resModel: "foo",
5302 type: "list",
5303 arch: `<list editable="top"><field name="foo"/><field name="int_field"/></list>`,
5304 });
5305 await contains(`.o_field_cell`).click();
5306 expect(`.o_field_widget[name=int_field] input`).toHaveValue("10", {
5307 message: "should contain initial value",
5308 });
5309
5310 await contains(`.o_field_widget[name=foo] input`).edit("tralala", { confirm: "tab" });
5311 expect(`.o_field_widget[name=int_field] input`).toHaveValue("1,007", {
5312 message: "should contain input with onchange applied",
5313 });
5314 });
5315
5316 test(`colspan of empty lines is correct in readonly`, async () => {
5317 Foo._fields.foo_o2m = fields.One2many({ relation: "foo" });
5318
5319 await mountView({
5320 resModel: "foo",
5321 type: "form",
5322 arch: `
5323 <form edit="0">
5324 <sheet>
5325 <field name="foo_o2m">
5326 <list editable="bottom">
5327 <field name="int_field"/>
5328 </list>
5329 </field>
5330 </sheet>
5331 </form>
5332 `,
5333 resId: 1,
5334 });
5335 // in readonly mode, the delete action is not available
5336 expect(`tbody td:eq(0)`).toHaveAttribute("colspan", "1");
5337 });
5338
5339 test(`colspan of empty lines is correct in edit`, async () => {
5340 Foo._fields.foo_o2m = fields.One2many({ relation: "foo" });
5341
5342 await mountView({
5343 resModel: "foo",
5344 type: "form",
5345 arch: `
5346 <form>
5347 <sheet>
5348 <field name="foo_o2m">
5349 <list editable="bottom">
5350 <field name="int_field"/>
5351 </list>
5352 </field>
5353 </sheet>
5354 </form>
5355 `,
5356 resId: 1,
5357 });
5358 // in edit mode, the delete action is available and the empty lines should cover that col
5359 expect(`tbody td:eq(0)`).toHaveAttribute("colspan", "2");
5360 });
5361
5362 test(`colspan of empty lines is correct in readonly with optional fields`, async () => {
5363 Foo._fields.foo_o2m = fields.One2many({ relation: "foo" });
5364
5365 await mountView({
5366 resModel: "foo",
5367 type: "form",
5368 arch: `
5369 <form edit="0">
5370 <sheet>
5371 <field name="foo_o2m">
5372 <list editable="bottom">
5373 <field name="int_field"/>
5374 <field name="foo" optional="hidden"/>
5375 </list>
5376 </field>
5377 </sheet>
5378 </form>
5379 `,
5380 resId: 1,
5381 });
5382 // in readonly mode, the delete action is not available but the optional fields is and the empty lines should cover that col
5383 expect(`tbody td:eq(0)`).toHaveAttribute("colspan", "2");
5384 });
5385
5386 test(`colspan of empty lines is correct in edit with optional fields`, async () => {
5387 Foo._fields.foo_o2m = fields.One2many({ relation: "foo" });
5388
5389 await mountView({
5390 resModel: "foo",
5391 type: "form",
5392 arch: `
5393 <form>
5394 <sheet>
5395 <field name="foo_o2m">
5396 <list editable="bottom">
5397 <field name="int_field"/>
5398 <field name="foo" optional="hidden"/>
5399 </list>
5400 </field>
5401 </sheet>
5402 </form>
5403 `,
5404 resId: 1,
5405 });
5406 // in edit mode, both the delete action and the optional fields are available and the empty lines should cover that col
5407 expect(`tbody td:eq(0)`).toHaveAttribute("colspan", "2");
5408 });
5409
5410 test.tags("desktop");
5411 test(`editable list: updating list state while invisible`, async () => {
5412 Foo._onChanges = {
5413 bar(record) {
5414 record.o2m = [[5], [0, null, { display_name: "Whatever" }]];
5415 },
5416 };
5417
5418 await mountView({
5419 resModel: "foo",
5420 type: "form",
5421 arch: `
5422 <form>
5423 <sheet>
5424 <field name="bar"/>
5425 <notebook>
5426 <page string="Page 1"></page>
5427 <page string="Page 2">
5428 <field name="o2m">
5429 <list editable="bottom">
5430 <field name="display_name"/>
5431 </list>
5432 </field>
5433 </page>
5434 </notebook>
5435 </sheet>
5436 </form>
5437 `,
5438 resId: 1,
5439 });
5440 expect(`.o_field_one2many`).toHaveCount(0);
5441
5442 await contains(`.o_field_boolean input`).click();
5443 expect(`.o_field_one2many`).toHaveCount(0);
5444
5445 await contains(`.nav-item:eq(-1) .nav-link`).click();
5446 expect(`.o_field_one2many`).toHaveCount(1);
5447 expect(`.o_field_one2many .o_data_row:eq(0)`).toHaveText("Whatever");
5448 });
5449
5450 test.tags("desktop");
5451 test(`editable list view, click on m2o dropdown does not close editable row`, async () => {
5452 await mountView({
5453 resModel: "foo",
5454 type: "list",
5455 arch: `<list editable="top"><field name="m2o"/></list>`,
5456 });
5457 await contains(`.o_list_button_add`).click();
5458 expect(`.o_selected_row .o_field_many2one input`).toHaveValue("");
5459
5460 await contains(`.o_selected_row .o_field_many2one input`).click();
5461 expect(`.o_field_many2one .o-autocomplete--dropdown-menu`).toHaveCount(1);
5462
5463 await contains(`.o_field_many2one .o-autocomplete--dropdown-menu .dropdown-item`).click();
5464 expect(`.o_selected_row .o_field_many2one input`).toHaveValue("Value 1");
5465 expect(`.o_selected_row`).toHaveCount(1, { message: "should still have editable row" });
5466 });
5467
5468 test(`fields are translatable in list view`, async () => {
5469 serverState.multiLang = true;
5470 Foo._fields.foo = fields.Char({ translate: true });
5471
5472 installLanguages({
5473 en_US: "English",
5474 fr_BE: "Frenglish",
5475 });
5476
5477 onRpc("foo", "get_field_translations", () => [
5478 [
5479 { lang: "en_US", source: "yop", value: "yop" },
5480 { lang: "fr_BE", source: "yop", value: "valeur français" },
5481 ],
5482 { translation_type: "char", translation_show_source: false },
5483 ]);
5484
5485 await mountView({
5486 resModel: "foo",
5487 type: "list",
5488 arch: `<list editable="top"><field name="foo" required="1"/></list>`,
5489 });
5490 await contains(`.o_data_row .o_data_cell`).click();
5491 expect(`.o_data_row:eq(0)`).toHaveClass("o_selected_row");
5492
5493 await contains(`button.o_field_translate`).click();
5494 expect(`.o_translation_dialog`).toHaveCount(1);
5495 expect(`.o_translation_dialog .translation > input.o_field_char`).toHaveCount(2, {
5496 message: "modal should have 2 languages to translate",
5497 });
5498 });
5499
5500 test.tags("desktop");
5501 test(`long words in text cells should break into smaller lines`, async () => {
5502 Foo._records[0].text = "a";
5503 Foo._records[1].text = "pneumonoultramicroscopicsilicovolcanoconiosis"; // longest english word I could find
5504
5505 await mountView({
5506 resModel: "foo",
5507 type: "list",
5508 arch: `<list><field name="text"/></list>`,
5509 });
5510
5511 // Intentionally set the table width to a small size
5512 queryOne("table").style.width = "100px";
5513 queryOne("th:eq(-1)").style.width = "100px";
5514 const shortText = queryRect(".o_data_row:eq(0) td:eq(-1)").height;
5515 const longText = queryRect(".o_data_row:eq(1) td:eq(-1)").height;
5516 const emptyText = queryRect(".o_data_row:eq(2) td:eq(-1)").height;
5517
5518 expect(shortText).toBe(emptyText, {
5519 message: "Short word should not change the height of the cell",
5520 });
5521 expect(longText).toBeGreaterThan(emptyText, {
5522 message: "Long word should change the height of the cell",
5523 });
5524 });
5525
5526 test(`deleting one record and verify context key`, async () => {
5527 onRpc("unlink", ({ kwargs }) => {
5528 expect.step("unlink");
5529 expect(kwargs.context.ctx_key).toBe("ctx_val");
5530 });
5531
5532 await mountView({
5533 resModel: "foo",
5534 type: "list",
5535 arch: `<list><field name="foo"/></list>`,
5536 actionMenus: {},
5537 context: {
5538 ctx_key: "ctx_val",
5539 },
5540 });
5541 expect(`div.o_control_panel .o_cp_action_menus`).toHaveCount(1);
5542 expect(`tbody td.o_field_cell`).toHaveCount(4, { message: "should have 4 records" });
5543
5544 await clickRecordSelector();
5545 expect(`div.o_control_panel .o_cp_action_menus`).toHaveCount(1);
5546
5547 await contains(`.o_cp_action_menus .dropdown-toggle`).click();
5548 await toggleMenuItem("Delete");
5549 expect(document.body).toHaveClass("modal-open", {
5550 message: "body should have modal-open class",
5551 });
5552
5553 await contains(`.modal footer button.btn-primary`).click();
5554 expect.verifySteps(["unlink"]);
5555 expect(`tbody td.o_field_cell`).toHaveCount(3, { message: "should have 3 records" });
5556 });
5557
5558 test(`custom delete confirmation dialog`, async () => {
5559 const listView = registry.category("views").get("list");
5560 class CautiousController extends listView.Controller {
5561 get deleteConfirmationDialogProps() {
5562 const props = super.deleteConfirmationDialogProps;
5563 props.body = markup`<span class="text-danger">These are the consequences</span>`;
5564 return props;
5565 }
5566 }
5567 registry.category("views").add("caution", {
5568 ...listView,
5569 Controller: CautiousController,
5570 });
5571
5572 await mountView({
5573 resModel: "foo",
5574 type: "list",
5575 arch: `<list js_class="caution"><field name="foo"/></list>`,
5576 actionMenus: {},
5577 });
5578 await clickRecordSelector();
5579 expect(`div.o_control_panel .o_cp_action_menus`).toHaveCount(1);
5580
5581 await toggleActionMenu();
5582 await toggleMenuItem("Delete");
5583 expect(`.modal .text-danger:contains(consequences)`).toHaveCount(1, {
5584 message: "confirmation dialog should have markup and more",
5585 });
5586
5587 await contains(`.modal footer button.btn-secondary`).click();
5588 expect(`tbody tr.o_data_row[data-id]`).toHaveCount(4, {
5589 message: "nothing deleted, 4 records remain",
5590 });
5591 });
5592
5593 test(`deleting record which throws UserError should close confirmation dialog`, async () => {
5594 onRpc("unlink", () => {
5595 throw makeServerError({ message: "Odoo Server Error" });
5596 });
5597
5598 await mountView({
5599 resModel: "foo",
5600 type: "list",
5601 actionMenus: {},
5602 arch: `<list><field name="foo"/></list>`,
5603 });
5604 await clickRecordSelector();
5605 expect(`div.o_control_panel .o_cp_action_menus`).toHaveCount(1);
5606
5607 await toggleActionMenu();
5608 await toggleMenuItem("Delete");
5609 expect(`.modal`).toHaveCount(1, { message: "should have open the confirmation dialog" });
5610
5611 expect.errors(1);
5612
5613 await contains(`.modal footer button.btn-primary`).click();
5614 await waitFor(".modal .modal-title:contains(Invalid Operation)");
5615
5616 expect.verifyErrors(["Odoo Server Error"]);
5617 });
5618
5619 test.tags("desktop");
5620 test(`delete all records matching the domain`, async () => {
5621 Foo._records.push({ id: 5, bar: true, foo: "xxx" });
5622
5623 mockService("notification", {
5624 add() {
5625 expect.step("should not display a notification");
5626 },
5627 });
5628
5629 onRpc("unlink", ({ args }) => {
5630 expect.step("unlink");
5631 expect(args[0]).toEqual([1, 2, 3, 5]);
5632 });
5633
5634 await mountView({
5635 type: "list",
5636 resModel: "foo",
5637 arch: `<list limit="2"><field name="foo"/></list>`,
5638 domain: [["bar", "=", true]],
5639 actionMenus: {},
5640 });
5641 expect(`div.o_control_panel .o_cp_action_menus`).toHaveCount(1);
5642 expect(`tbody td.o_list_record_selector`).toHaveCount(2, { message: "should have 2 records" });
5643
5644 await contains(`thead .o_list_record_selector input`).click();
5645 expect(`div.o_control_panel .o_cp_action_menus`).toHaveCount(1);
5646 expect(`.o_selection_box .o_select_domain`).toHaveCount(1);
5647
5648 await contains(`.o_selection_box .o_select_domain`).click();
5649 await contains(`.o_cp_action_menus .dropdown-toggle`).click();
5650 await toggleMenuItem("Delete");
5651 expect(`.modal`).toHaveCount(1, { message: "a confirm modal should be displayed" });
5652
5653 await contains(`.modal footer button.btn-primary`).click();
5654 expect.verifySteps(["unlink"]);
5655 });
5656
5657 test.tags("desktop");
5658 test(`delete all records matching the domain (limit reached)`, async () => {
5659 Foo._records.push({ id: 5, bar: true, foo: "xxx" });
5660 Foo._records.push({ id: 6, bar: true, foo: "yyy" });
5661
5662 mockService("notification", {
5663 add() {
5664 expect.step("notify");
5665 },
5666 });
5667
5668 patchWithCleanup(session, {
5669 active_ids_limit: 4,
5670 });
5671
5672 onRpc("unlink", ({ args }) => {
5673 expect.step("unlink");
5674 expect(args[0]).toEqual([1, 2, 3, 5]);
5675 });
5676
5677 await mountView({
5678 resModel: "foo",
5679 type: "list",
5680 arch: `<list limit="2"><field name="foo"/></list>`,
5681 domain: [["bar", "=", true]],
5682 actionMenus: {},
5683 });
5684 expect(`div.o_control_panel .o_cp_action_menus`).toHaveCount(1);
5685 expect(`tbody td.o_list_record_selector`).toHaveCount(2, { message: "should have 2 records" });
5686
5687 await contains(`thead .o_list_record_selector input`).click();
5688 expect(`div.o_control_panel .o_cp_action_menus`).toHaveCount(1);
5689 expect(`.o_selection_box .o_select_domain`).toHaveCount(1);
5690
5691 await contains(`.o_selection_box .o_select_domain`).click();
5692 await contains(`.o_cp_action_menus .dropdown-toggle`).click();
5693 await toggleMenuItem("Delete");
5694 expect(`.modal`).toHaveCount(1, { message: "a confirm modal should be displayed" });
5695
5696 await contains(`.modal footer button.btn-primary`).click();
5697 expect.verifySteps(["unlink", "notify"]);
5698 });
5699
5700 test(`duplicate one record`, async () => {
5701 await mountView({
5702 resModel: "foo",
5703 type: "list",
5704 arch: `<list editable="top"><field name="foo"/></list>`,
5705 actionMenus: {},
5706 });
5707
5708 // Initial state: there should be 4 records
5709 expect(`tbody tr`).toHaveCount(4, { message: "should have 4 rows" });
5710
5711 // Duplicate one record
5712 await clickRecordSelector();
5713 await contains(`.o_cp_action_menus .dropdown-toggle`).click();
5714 await toggleMenuItem("Duplicate");
5715
5716 // Final state: there should be 5 records
5717 expect(`tbody tr`).toHaveCount(5, { message: "should have 5 rows" });
5718 });
5719
5720 test(`duplicate all records`, async () => {
5721 await mountView({
5722 resModel: "foo",
5723 type: "list",
5724 arch: `<list editable="top"><field name="foo"/></list>`,
5725 actionMenus: {},
5726 });
5727
5728 // Initial state: there should be 4 records
5729 expect(`tbody tr`).toHaveCount(4, { message: "should have 4 rows" });
5730
5731 // Duplicate all records
5732 await selectAllRecords();
5733 await contains(`.o_cp_action_menus .dropdown-toggle`).click();
5734 await toggleMenuItem("Duplicate");
5735
5736 // A confirmation dialog should appear when duplicating multiple records.
5737 expect(`.modal`).toHaveCount(1);
5738 expect(`.modal-body`).toHaveText(
5739 "Are you sure that you want to duplicate all the selected records?"
5740 );
5741 await contains(`.modal footer button.btn-primary`).click();
5742
5743 // Final state: there should be 8 records
5744 expect(`tbody tr`).toHaveCount(8, { message: "should have 8 rows" });
5745 });
5746
5747 test(`archiving one record`, async () => {
5748 // add active field on foo model and make all records active
5749 Foo._fields.active = fields.Boolean({ default: true });
5750
5751 stepAllNetworkCalls();
5752
5753 await mountView({
5754 resModel: "foo",
5755 type: "list",
5756 actionMenus: {},
5757 arch: `<list><field name="foo"/></list>`,
5758 });
5759 expect(`div.o_control_panel .o_cp_action_menus`).toHaveCount(1);
5760 expect(`tbody tr.o_data_row[data-id]`).toHaveCount(4, { message: "should have 4 records" });
5761
5762 await clickRecordSelector();
5763 expect(`div.o_control_panel .o_cp_action_menus`).toHaveCount(1);
5764 expect.verifySteps([
5765 "/web/webclient/translations",
5766 "/web/webclient/load_menus",
5767 "get_views",
5768 "web_search_read",
5769 "has_group",
5770 ]);
5771
5772 await toggleActionMenu();
5773 await toggleMenuItem("Archive");
5774 expect(`.modal`).toHaveCount(1, { message: "a confirm modal should be displayed" });
5775
5776 await contains(`.modal-footer .btn-secondary`).click();
5777 expect(`tbody tr.o_data_row[data-id]`).toHaveCount(4, {
5778 message: "still should have 4 records",
5779 });
5780
5781 await toggleActionMenu();
5782 await toggleMenuItem("Archive");
5783 expect(`.modal`).toHaveCount(1, { message: "a confirm modal should be displayed" });
5784
5785 await contains(`.modal-footer .btn-primary`).click();
5786 expect(`tbody tr.o_data_row[data-id]`).toHaveCount(3, { message: "should have 3 records" });
5787 expect.verifySteps(["action_archive", "web_search_read"]);
5788 });
5789
5790 test.tags("desktop");
5791 test(`archive all records matching the domain`, async () => {
5792 // add active field on foo model and make all records active
5793 Foo._fields.active = fields.Boolean({ default: true });
5794 Foo._records.push({ id: 5, bar: true, foo: "xxx" });
5795
5796 mockService("notification", {
5797 add() {
5798 expect.step("should not display a notification");
5799 },
5800 });
5801
5802 onRpc("action_archive", ({ args }) => {
5803 expect.step("action_archive");
5804 expect(args[0]).toEqual([1, 2, 3, 5]);
5805 });
5806
5807 await mountView({
5808 resModel: "foo",
5809 type: "list",
5810 arch: `<list limit="2"><field name="foo"/></list>`,
5811 domain: [["bar", "=", true]],
5812 actionMenus: {},
5813 });
5814 expect(`div.o_control_panel .o_cp_action_menus`).toHaveCount(1);
5815 expect(`tbody td.o_list_record_selector`).toHaveCount(2, { message: "should have 2 records" });
5816
5817 await contains(`thead .o_list_record_selector input`).click();
5818 expect(`div.o_control_panel .o_cp_action_menus`).toHaveCount(1);
5819 expect(`.o_selection_box .o_select_domain`).toHaveCount(1);
5820
5821 await contains(`.o_selection_box .o_select_domain`).click();
5822 await contains(`.o_cp_action_menus .dropdown-toggle`).click();
5823 await toggleMenuItem("Archive");
5824 expect(`.modal`).toHaveCount(1, { message: "a confirm modal should be displayed" });
5825
5826 await contains(`.modal-footer .btn-primary`).click();
5827 expect.verifySteps(["action_archive"]);
5828 });
5829
5830 test.tags("desktop");
5831 test(`archive all records matching the domain (limit reached)`, async () => {
5832 // add active field on foo model and make all records active
5833 Foo._fields.active = fields.Boolean({ default: true });
5834 Foo._records.push({ id: 5, bar: true, foo: "xxx" });
5835 Foo._records.push({ id: 6, bar: true, foo: "yyy" });
5836
5837 mockService("notification", {
5838 add() {
5839 expect.step("notify");
5840 },
5841 });
5842
5843 patchWithCleanup(session, {
5844 active_ids_limit: 4,
5845 });
5846
5847 onRpc("action_archive", ({ args }) => {
5848 expect.step("action_archive");
5849 expect(args[0]).toEqual([1, 2, 3, 5]);
5850 });
5851
5852 await mountView({
5853 resModel: "foo",
5854 type: "list",
5855 arch: `<list limit="2"><field name="foo"/></list>`,
5856 domain: [["bar", "=", true]],
5857 actionMenus: {},
5858 });
5859 expect(`div.o_control_panel .o_cp_action_menus`).toHaveCount(1);
5860 expect(`tbody td.o_list_record_selector`).toHaveCount(2, { message: "should have 2 records" });
5861
5862 await contains(`thead .o_list_record_selector input`).click();
5863 expect(`div.o_control_panel .o_cp_action_menus`).toHaveCount(1);
5864 expect(`.o_selection_box .o_select_domain`).toHaveCount(1);
5865
5866 await contains(`.o_selection_box .o_select_domain`).click();
5867 await contains(`.o_cp_action_menus .dropdown-toggle`).click();
5868 await toggleMenuItem("Archive");
5869 expect(`.modal`).toHaveCount(1, { message: "a confirm modal should be displayed" });
5870
5871 await contains(`.modal-footer .btn-primary`).click();
5872 expect.verifySteps(["action_archive", "notify"]);
5873 });
5874
5875 test(`archive/unarchive handles returned action`, async () => {
5876 // add active field on foo model and make all records active
5877 Foo._fields.active = fields.Boolean({ default: true });
5878
5879 Foo._views = {
5880 "list,3": `<list><field name="foo"/></list>`,
5881 "search,9": `
5882 <search>
5883 <filter string="Not Bar" name="not bar" domain="[['bar','=',False]]"/>
5884 </search>
5885 `,
5886 };
5887 Bar._views = {
5888 form: `<form><field name="display_name"/></form>`,
5889 };
5890
5891 defineActions([
5892 {
5893 id: 11,
5894 name: "Action 11",
5895 res_model: "foo",
5896 views: [[3, "list"]],
5897 search_view_id: [9, "search"],
5898 },
5899 ]);
5900
5901 onRpc("foo", "action_archive", ({ parent }) => {
5902 parent();
5903 return {
5904 type: "ir.actions.act_window",
5905 name: "Archive Action",
5906 res_model: "bar",
5907 view_mode: "form",
5908 target: "new",
5909 views: [[false, "form"]],
5910 };
5911 });
5912
5913 await mountWithCleanup(WebClient);
5914 await getService("action").doAction(11);
5915
5916 expect(`tbody tr.o_data_row[data-id]`).toHaveCount(4, { message: "should have 4 records" });
5917
5918 await clickRecordSelector();
5919 expect(`.o_cp_action_menus`).toHaveCount(1, { message: "sidebar should be visible" });
5920
5921 await toggleActionMenu();
5922 await contains(`.o-dropdown--menu .o_menu_item:contains(Archive)`).click();
5923 expect(`.modal`).toHaveCount(1, { message: "a confirm modal should be displayed" });
5924
5925 await contains(`.modal .modal-footer .btn-primary`).click();
5926 expect(`.modal`).toHaveCount(1, { message: "archive action dialog should be displayed" });
5927 expect(`.modal .modal-title`).toHaveText("Archive Action", {
5928 message: "action wizard should have been opened",
5929 });
5930 });
5931
5932 test(`apply custom static action menu (archive)`, async () => {
5933 // add active field on foo model and make all records active
5934 Foo._fields.active = fields.Boolean({ default: true });
5935
5936 const listView = registry.category("views").get("list");
5937 class CustomListController extends listView.Controller {
5938 getStaticActionMenuItems() {
5939 const menuItems = super.getStaticActionMenuItems();
5940 menuItems.archive.callback = () => {
5941 expect.step("customArchive");
5942 };
5943 return menuItems;
5944 }
5945 }
5946 registry.category("views").add("custom_list", {
5947 ...listView,
5948 Controller: CustomListController,
5949 });
5950
5951 await mountView({
5952 resModel: "foo",
5953 type: "list",
5954 arch: `<list js_class="custom_list"><field name="foo"/></list>`,
5955 actionMenus: {},
5956 });
5957 expect(`div.o_control_panel .o_cp_action_menus`).toHaveCount(1);
5958
5959 await clickRecordSelector();
5960 expect(`div.o_control_panel .o_cp_action_menus`).toHaveCount(1);
5961
5962 await toggleActionMenu();
5963 await toggleMenuItem("Archive");
5964 expect.verifySteps(["customArchive"]);
5965 });
5966
5967 test(`add custom static action menu`, async () => {
5968 const listView = registry.category("views").get("list");
5969 class CustomListController extends listView.Controller {
5970 getStaticActionMenuItems() {
5971 const menuItems = super.getStaticActionMenuItems();
5972 menuItems.customAvailable = {
5973 isAvailable: () => true,
5974 description: "Custom Available",
5975 sequence: 35,
5976 callback: () => {
5977 expect.step("Custom Available");
5978 },
5979 };
5980 menuItems.customNotAvailable = {
5981 isAvailable: () => false,
5982 description: "Custom Not Available",
5983 callback: () => {
5984 expect.step("Custom Not Available");
5985 },
5986 };
5987 menuItems.customDefaultAvailable = {
5988 description: "Custom Default Available",
5989 callback: () => {
5990 expect.step("Custom Default Available");
5991 },
5992 };
5993 return menuItems;
5994 }
5995 }
5996 registry.category("views").add("custom_list", {
5997 ...listView,
5998 Controller: CustomListController,
5999 });
6000
6001 await mountView({
6002 resModel: "foo",
6003 type: "list",
6004 arch: `<list js_class="custom_list"><field name="foo"/></list>`,
6005 actionMenus: {},
6006 });
6007 expect(`div.o_control_panel .o_cp_action_menus`).toHaveCount(1);
6008
6009 await clickRecordSelector();
6010 expect(`div.o_control_panel .o_cp_action_menus`).toHaveCount(1);
6011
6012 await toggleActionMenu();
6013 expect(queryAllTexts(`.o-dropdown--menu .dropdown-item`)).toEqual([
6014 "Custom Default Available",
6015 "Export",
6016 "Duplicate",
6017 "Custom Available",
6018 "Delete",
6019 ]);
6020
6021 await toggleMenuItem("Custom Available");
6022 expect.verifySteps(["Custom Available"]);
6023
6024 await toggleActionMenu();
6025 await toggleMenuItem("Custom Default Available");
6026 expect.verifySteps(["Custom Default Available"]);
6027 });
6028
6029 test(`grouped, update the count of the group (and ancestors) when a record is deleted`, async () => {
6030 Foo._records = [
6031 { id: 121, foo: "blip", bar: true },
6032 { id: 122, foo: "blip", bar: true },
6033 { id: 123, foo: "blip", bar: true },
6034 { id: 124, foo: "blip", bar: true },
6035 { id: 125, foo: "blip", bar: false },
6036 { id: 126, foo: "blip", bar: false },
6037 ];
6038 await mountView({
6039 resModel: "foo",
6040 type: "list",
6041 arch: `<list expand="1"><field name="foo"/></list>`,
6042 groupBy: ["foo", "bar"],
6043 actionMenus: {},
6044 });
6045 expect(`.o_group_header:eq(0)`).toHaveText("blip (6)");
6046 expect(`.o_group_header:eq(1)`).toHaveText("No (2)");
6047 expect(`.o_group_header:eq(2)`).toHaveText("Yes (4)");
6048
6049 await contains(`.o_group_header:eq(2)`).click();
6050 expect(`.o_data_row`).toHaveCount(4);
6051
6052 await clickRecordSelector();
6053 await toggleActionMenu();
6054 await toggleMenuItem("Delete");
6055 await contains(`.modal .btn-primary`).click();
6056 expect(`.o_group_header:eq(0)`).toHaveText("blip (5)");
6057 expect(`.o_group_header:eq(2)`).toHaveText("Yes (3)");
6058 });
6059
6060 test(`grouped list, reload aggregates when a record is deleted`, async () => {
6061 Foo._records = [
6062 { id: 121, foo: "blip", int_field: 100 },
6063 { id: 122, foo: "blip", int_field: 300 },
6064 { id: 123, foo: "blip", int_field: 700 },
6065 ];
6066 await mountView({
6067 type: "list",
6068 resModel: "foo",
6069 arch: /*xml*/ `
6070 <list expand="1">
6071 <field name="foo"/>
6072 <field name="int_field"/>
6073 </list>`,
6074 groupBy: ["foo"],
6075 actionMenus: {},
6076 });
6077
6078 expect(".o_group_header .o_list_number").toHaveText("1,100");
6079
6080 await clickRecordSelector();
6081 await toggleActionMenu();
6082 await toggleMenuItem("Delete");
6083 await contains(`.modal-footer .btn-primary`).click();
6084 expect(".o_group_header .o_list_number").toHaveText("1,000");
6085 });
6086
6087 test.tags("desktop");
6088 test(`pager (ungrouped and grouped mode), default limit`, async () => {
6089 onRpc("web_search_read", ({ kwargs }) => {
6090 expect.step("web_search_read");
6091 expect(kwargs.limit).toBe(80, {
6092 message: "default limit should be 80 in List",
6093 });
6094 });
6095 await mountView({
6096 type: "list",
6097 resModel: "foo",
6098 arch: `<list><field name="foo"/><field name="bar"/></list>`,
6099 searchViewArch: `
6100 <search>
6101 <filter name="bar" string="bar" context="{'group_by': 'bar'}"/>
6102 </search>
6103 `,
6104 });
6105 expect.verifySteps(["web_search_read"]);
6106 expect(`div.o_control_panel .o_cp_pager .o_pager`).toHaveCount(1);
6107 expect(`.o_pager_limit`).toHaveText("4");
6108
6109 await toggleSearchBarMenu();
6110 await toggleMenuItem("Bar");
6111 expect(`.o_pager_limit`).toHaveText("2");
6112 });
6113
6114 test.tags("desktop");
6115 test(`pager, ungrouped, with count limit reached`, async () => {
6116 patchWithCleanup(RelationalModel, { DEFAULT_COUNT_LIMIT: 3 });
6117
6118 let expectedCountLimit = 4;
6119 stepAllNetworkCalls();
6120 onRpc("web_search_read", ({ kwargs }) => {
6121 expect(kwargs.count_limit).toBe(expectedCountLimit);
6122 });
6123 onRpc("search_count", ({ kwargs }) => {
6124 expect(kwargs.context.xyz).toBe("abc");
6125 });
6126
6127 await mountView({
6128 resModel: "foo",
6129 type: "list",
6130 arch: `<list limit="2"><field name="foo"/><field name="bar"/></list>`,
6131 context: { xyz: "abc" },
6132 });
6133 expect(`.o_data_row`).toHaveCount(2);
6134 expect(`.o_pager_value`).toHaveText("1-2");
6135 expect(`.o_pager_limit`).toHaveText("3+");
6136 expect.verifySteps([
6137 "/web/webclient/translations",
6138 "/web/webclient/load_menus",
6139 "get_views",
6140 "web_search_read",
6141 "has_group",
6142 ]);
6143
6144 await contains(`.o_pager_limit`).click();
6145 expect(`.o_data_row`).toHaveCount(2);
6146 expect(`.o_pager_value`).toHaveText("1-2");
6147 expect(`.o_pager_limit`).toHaveText("4");
6148 expect.verifySteps(["search_count"]);
6149
6150 expectedCountLimit = undefined;
6151 await contains(`.o_pager_next`).click();
6152 expect.verifySteps(["web_search_read"]);
6153 });
6154
6155 test.tags("desktop");
6156 test(`pager, ungrouped, with count limit reached, click next`, async () => {
6157 patchWithCleanup(RelationalModel, { DEFAULT_COUNT_LIMIT: 3 });
6158
6159 stepAllNetworkCalls();
6160 let expectedCountLimit = 4;
6161 onRpc("web_search_read", ({ kwargs }) => {
6162 expect(kwargs.count_limit).toBe(expectedCountLimit);
6163 });
6164
6165 await mountView({
6166 resModel: "foo",
6167 type: "list",
6168 arch: `<list limit="2"><field name="foo"/><field name="bar"/></list>`,
6169 });
6170 expect(`.o_data_row`).toHaveCount(2);
6171 expect(`.o_pager_value`).toHaveText("1-2");
6172 expect(`.o_pager_limit`).toHaveText("3+");
6173 expect.verifySteps([
6174 "/web/webclient/translations",
6175 "/web/webclient/load_menus",
6176 "get_views",
6177 "web_search_read",
6178 "has_group",
6179 ]);
6180
6181 expectedCountLimit = 5;
6182 await contains(`.o_pager_next`).click();
6183 expect(`.o_data_row`).toHaveCount(2);
6184 expect(`.o_pager_value`).toHaveText("3-4");
6185 expect(`.o_pager_limit`).toHaveText("4");
6186 expect.verifySteps(["web_search_read"]);
6187 });
6188
6189 test.tags("desktop");
6190 test(`pager, ungrouped, with count limit reached, click next (2)`, async () => {
6191 patchWithCleanup(RelationalModel, { DEFAULT_COUNT_LIMIT: 3 });
6192 Foo._records.push({ id: 5, bar: true, foo: "xxx" });
6193
6194 stepAllNetworkCalls();
6195 let expectedCountLimit = 4;
6196 onRpc("web_search_read", ({ kwargs }) => {
6197 expect(kwargs.count_limit).toBe(expectedCountLimit);
6198 });
6199
6200 await mountView({
6201 resModel: "foo",
6202 type: "list",
6203 arch: `<list limit="2"><field name="foo"/><field name="bar"/></list>`,
6204 });
6205 expect(`.o_data_row`).toHaveCount(2);
6206 expect(`.o_pager_value`).toHaveText("1-2");
6207 expect(`.o_pager_limit`).toHaveText("3+");
6208 expect.verifySteps([
6209 "/web/webclient/translations",
6210 "/web/webclient/load_menus",
6211 "get_views",
6212 "web_search_read",
6213 "has_group",
6214 ]);
6215
6216 expectedCountLimit = 5;
6217 await contains(`.o_pager_next`).click();
6218 expect(`.o_data_row`).toHaveCount(2);
6219 expect(`.o_pager_value`).toHaveText("3-4");
6220 expect(`.o_pager_limit`).toHaveText("4+");
6221 expect.verifySteps(["web_search_read"]);
6222
6223 expectedCountLimit = 7;
6224 await contains(`.o_pager_next`).click();
6225 expect(`.o_data_row`).toHaveCount(1);
6226 expect(`.o_pager_value`).toHaveText("5-5");
6227 expect(`.o_pager_limit`).toHaveText("5");
6228 expect.verifySteps(["web_search_read"]);
6229 });
6230
6231 test.tags("desktop");
6232 test(`pager, ungrouped, with count limit reached, click previous`, async () => {
6233 patchWithCleanup(RelationalModel, { DEFAULT_COUNT_LIMIT: 3 });
6234 Foo._records.push({ id: 5, bar: true, foo: "xxx" });
6235
6236 stepAllNetworkCalls();
6237 let expectedCountLimit = 4;
6238 onRpc("web_search_read", ({ kwargs }) => {
6239 expect(kwargs.count_limit).toBe(expectedCountLimit);
6240 });
6241
6242 await mountView({
6243 resModel: "foo",
6244 type: "list",
6245 arch: `<list limit="2"><field name="foo"/><field name="bar"/></list>`,
6246 });
6247 expect(`.o_data_row`).toHaveCount(2);
6248 expect(`.o_pager_value`).toHaveText("1-2");
6249 expect(`.o_pager_limit`).toHaveText("3+");
6250 expect.verifySteps([
6251 "/web/webclient/translations",
6252 "/web/webclient/load_menus",
6253 "get_views",
6254 "web_search_read",
6255 "has_group",
6256 ]);
6257
6258 expectedCountLimit = undefined;
6259 await contains(`.o_pager_previous`).click();
6260 expect(`.o_data_row`).toHaveCount(1);
6261 expect(`.o_pager_value`).toHaveText("5-5");
6262 expect(`.o_pager_limit`).toHaveText("5");
6263 expect.verifySteps(["search_count", "web_search_read"]);
6264 });
6265
6266 test.tags("desktop");
6267 test(`pager, ungrouped, with count limit reached, edit pager`, async () => {
6268 patchWithCleanup(RelationalModel, { DEFAULT_COUNT_LIMIT: 3 });
6269 Foo._records.push({ id: 5, bar: true, foo: "xxx" });
6270
6271 stepAllNetworkCalls();
6272 let expectedCountLimit = 4;
6273 onRpc("web_search_read", ({ kwargs }) => {
6274 expect(kwargs.count_limit).toBe(expectedCountLimit);
6275 });
6276
6277 await mountView({
6278 resModel: "foo",
6279 type: "list",
6280 arch: `<list limit="2"><field name="foo"/><field name="bar"/></list>`,
6281 });
6282 expect(`.o_data_row`).toHaveCount(2);
6283 expect(`.o_pager_value`).toHaveText("1-2");
6284 expect(`.o_pager_limit`).toHaveText("3+");
6285 expect.verifySteps([
6286 "/web/webclient/translations",
6287 "/web/webclient/load_menus",
6288 "get_views",
6289 "web_search_read",
6290 "has_group",
6291 ]);
6292
6293 expectedCountLimit = 5;
6294 await contains(`.o_pager_value`).click();
6295 // FIXME: we have to click out instead of confirming, because somehow if the
6296 // web_search_read calls come back too fast when pressing "Enter", another
6297 // RPC is triggered right after.
6298 await contains(`input.o_pager_value`).edit("2-4", { confirm: "blur" });
6299 expect(`.o_data_row`).toHaveCount(3);
6300 expect(`.o_pager_value`).toHaveText("2-4");
6301 expect(`.o_pager_limit`).toHaveText("4+");
6302 expect.verifySteps(["web_search_read"]);
6303
6304 expectedCountLimit = 15;
6305 await contains(`.o_pager_value`).click();
6306 await contains(`input.o_pager_value`).edit("2-14", { confirm: "blur" });
6307 expect(`.o_data_row`).toHaveCount(4);
6308 expect(`.o_pager_value`).toHaveText("2-5");
6309 expect(`.o_pager_limit`).toHaveText("5");
6310 expect.verifySteps(["web_search_read"]);
6311 });
6312
6313 test.tags("desktop");
6314 test(`pager, ungrouped, with count equals count limit`, async () => {
6315 patchWithCleanup(RelationalModel, { DEFAULT_COUNT_LIMIT: 4 });
6316
6317 stepAllNetworkCalls();
6318 await mountView({
6319 resModel: "foo",
6320 type: "list",
6321 arch: `<list limit="2"><field name="foo"/><field name="bar"/></list>`,
6322 });
6323 expect(`.o_data_row`).toHaveCount(2);
6324 expect(`.o_pager_value`).toHaveText("1-2");
6325 expect(`.o_pager_limit`).toHaveText("4");
6326 expect.verifySteps([
6327 "/web/webclient/translations",
6328 "/web/webclient/load_menus",
6329 "get_views",
6330 "web_search_read",
6331 "has_group",
6332 ]);
6333 });
6334
6335 test.tags("desktop");
6336 test(`pager, ungrouped, reload while fetching count`, async () => {
6337 patchWithCleanup(RelationalModel, { DEFAULT_COUNT_LIMIT: 3 });
6338
6339 stepAllNetworkCalls();
6340 const deferred = new Deferred();
6341 onRpc("search_count", () => deferred);
6342
6343 await mountView({
6344 type: "list",
6345 resModel: "foo",
6346 arch: `<list limit="2"><field name="foo"/><field name="bar"/></list>`,
6347 });
6348 expect(`.o_data_row`).toHaveCount(2);
6349 expect(`.o_pager_value`).toHaveText("1-2");
6350 expect(`.o_pager_limit`).toHaveText("3+");
6351 expect.verifySteps([
6352 "/web/webclient/translations",
6353 "/web/webclient/load_menus",
6354 "get_views",
6355 "web_search_read",
6356 "has_group",
6357 ]);
6358
6359 await contains(`.o_pager_limit`).click();
6360 expect(`.o_pager_value`).toHaveText("1-2");
6361 expect(`.o_pager_limit`).toHaveText("3+");
6362 expect.verifySteps(["search_count"]);
6363
6364 await contains(`.o_searchview_input`).press("enter");
6365 expect(`.o_pager_value`).toHaveText("1-2");
6366 expect(`.o_pager_limit`).toHaveText("3+");
6367 expect.verifySteps(["web_search_read"]);
6368
6369 deferred.resolve();
6370 await animationFrame();
6371 expect(`.o_pager_value`).toHaveText("1-2");
6372 expect(`.o_pager_limit`).toHaveText("3+");
6373 expect.verifySteps([]);
6374 });
6375
6376 test.tags("desktop");
6377 test(`pager, ungrouped, next and fetch count simultaneously`, async () => {
6378 patchWithCleanup(RelationalModel, { DEFAULT_COUNT_LIMIT: 5 });
6379 Foo._records.push({ id: 11, foo: "r11", bar: true });
6380 Foo._records.push({ id: 12, foo: "r12", bar: true });
6381 Foo._records.push({ id: 13, foo: "r13", bar: true });
6382
6383 stepAllNetworkCalls();
6384 let deferred;
6385 onRpc("web_search_read", () => deferred);
6386
6387 await mountView({
6388 resModel: "foo",
6389 type: "list",
6390 arch: `<list limit="2"><field name="foo"/><field name="bar"/></list>`,
6391 });
6392 expect(`.o_data_row`).toHaveCount(2);
6393 expect(`.o_pager_value`).toHaveText("1-2");
6394 expect(`.o_pager_limit`).toHaveText("5+");
6395 expect.verifySteps([
6396 "/web/webclient/translations",
6397 "/web/webclient/load_menus",
6398 "get_views",
6399 "web_search_read",
6400 "has_group",
6401 ]);
6402
6403 deferred = new Deferred();
6404 await contains(`.o_pager_next`).click(); // this request will be pending
6405 expect(`.o_pager_value`).toHaveText("1-2");
6406 expect(`.o_pager_limit`).toHaveText("5+");
6407 // can't fetch count simultaneously as it is temporarily disabled while updating
6408 expect(`.o_pager_limit`).toHaveClass("disabled");
6409 expect.verifySteps(["web_search_read"]);
6410
6411 deferred.resolve();
6412 await animationFrame();
6413 expect(`.o_pager_limit`).not.toHaveClass("disabled");
6414 });
6415
6416 test.tags("desktop");
6417 test(`pager, grouped, with groups count limit reached`, async () => {
6418 patchWithCleanup(RelationalModel, { DEFAULT_COUNT_LIMIT: 3 });
6419 Foo._records.push({ id: 398, foo: "ozfijz" }); // to have 4 groups
6420
6421 await mountView({
6422 resModel: "foo",
6423 type: "list",
6424 arch: `<list groups_limit="2"><field name="foo"/><field name="bar"/></list>`,
6425 groupBy: ["foo"],
6426 });
6427 expect(`.o_group_header`).toHaveCount(2);
6428 expect(`.o_pager_value`).toHaveText("1-2");
6429 expect(`.o_pager_limit`).toHaveText("4");
6430 });
6431
6432 test.tags("desktop");
6433 test(`pager, grouped, with count limit reached`, async () => {
6434 await mountView({
6435 resModel: "foo",
6436 type: "list",
6437 arch: `<list limit="1"><field name="foo"/><field name="bar"/></list>`,
6438 groupBy: ["foo"],
6439 });
6440 expect(`.o_group_header`).toHaveCount(3, { message: "should have 3 groups" });
6441 expect(`.o_group_header:first-of-type .o_group_name`).toHaveCount(1, {
6442 message: "first group should have a name",
6443 });
6444 expect(`.o_group_header:first-of-type .o_pager`).toHaveCount(0, {
6445 message: "pager shouldn't be present until unfolded",
6446 });
6447
6448 // unfold
6449 await contains(`.o_group_header:first-of-type`).click();
6450 expect(`.o_group_header:first-of-type .o_group_name .o_pager`).toHaveCount(1, {
6451 message: "first group should have a pager",
6452 });
6453 expect(`.o_group_header:first-of-type .o_pager_value`).toHaveText("1");
6454 expect(`.o_group_header:first-of-type .o_pager_limit`).toHaveText("2");
6455 });
6456
6457 test.tags("desktop");
6458 test(`multi-level grouped list, pager inside a group`, async () => {
6459 for (const record of Foo._records) {
6460 record.bar = true;
6461 }
6462
6463 Foo._records.forEach((r) => (r.bar = true));
6464 await mountView({
6465 resModel: "foo",
6466 type: "list",
6467 arch: `<list limit="2" groups_limit="3"><field name="foo"/><field name="bar"/></list>`,
6468 groupBy: ["bar", "foo"],
6469 });
6470 expect(`.o_group_header`).toHaveCount(1);
6471
6472 await contains(`.o_group_header`).click();
6473 expect(`.o_group_header`).toHaveCount(4);
6474 expect(`.o_group_header:first-of-type .o_group_name .o_pager`).toHaveCount(0);
6475 });
6476
6477 test.tags("desktop");
6478 test(`multi-level grouped list, pager inside a group, reload`, async () => {
6479 for (const record of Foo._records) {
6480 record.bar = true;
6481 }
6482
6483 await mountView({
6484 resModel: "foo",
6485 type: "list",
6486 arch: `
6487 <list groups_limit="2">
6488 <field name="foo"/>
6489 <field name="int_field"/>
6490 <field name="bar"/>
6491 </list>
6492 `,
6493 groupBy: ["bar", "foo"],
6494 });
6495 expect(`.o_group_header`).toHaveCount(1);
6496
6497 await contains(`.o_group_header`).click();
6498 expect(`.o_group_header`).toHaveCount(3);
6499 expect(`.o_group_header .o_group_name .o_pager`).toHaveCount(1);
6500 expect(getPagerValue(queryFirst(`.o_group_header`))).toEqual([1, 2]);
6501 expect(getPagerLimit(queryFirst(`.o_group_header`))).toBe(3);
6502 expect(queryAllTexts`td.o_list_number`).toEqual(["32", "5", "17"]);
6503
6504 await contains(`.o_list_table thead th[data-name=int_field]`).click();
6505 expect(getPagerValue(queryFirst(`.o_group_header`))).toEqual([1, 2]);
6506 expect(getPagerLimit(queryFirst(`.o_group_header`))).toBe(3);
6507 expect(queryAllTexts`td.o_list_number`).toEqual(["32", "5", "10"]);
6508 });
6509
6510 test.tags("desktop");
6511 test(`count_limit attrs set in arch`, async () => {
6512 stepAllNetworkCalls();
6513 let expectedCountLimit = 4;
6514 onRpc("web_search_read", ({ kwargs }) => {
6515 expect(kwargs.count_limit).toBe(expectedCountLimit);
6516 });
6517
6518 await mountView({
6519 resModel: "foo",
6520 type: "list",
6521 arch: `<list limit="2" count_limit="3"><field name="foo"/><field name="bar"/></list>`,
6522 });
6523 expect(`.o_data_row`).toHaveCount(2);
6524 expect(`.o_pager_value`).toHaveText("1-2");
6525 expect(`.o_pager_limit`).toHaveText("3+");
6526 expect.verifySteps([
6527 "/web/webclient/translations",
6528 "/web/webclient/load_menus",
6529 "get_views",
6530 "web_search_read",
6531 "has_group",
6532 ]);
6533
6534 await contains(`.o_pager_limit`).click();
6535 expect(`.o_data_row`).toHaveCount(2);
6536 expect(`.o_pager_value`).toHaveText("1-2");
6537 expect(`.o_pager_limit`).toHaveText("4");
6538 expect.verifySteps(["search_count"]);
6539
6540 expectedCountLimit = undefined;
6541 await contains(`.o_pager_next`).click();
6542 expect.verifySteps(["web_search_read"]);
6543 });
6544
6545 test.tags("desktop");
6546 test(`pager, grouped, pager limit should be based on the group's count`, async () => {
6547 patchWithCleanup(RelationalModel, { DEFAULT_COUNT_LIMIT: 3 });
6548 Foo._records = [
6549 { id: 121, foo: "blip" },
6550 { id: 122, foo: "blip" },
6551 { id: 123, foo: "blip" },
6552 { id: 124, foo: "blip" },
6553 { id: 125, foo: "blip" },
6554 { id: 126, foo: "blip" },
6555 ];
6556
6557 await mountView({
6558 resModel: "foo",
6559 type: "list",
6560 arch: `<list limit="2"><field name="foo"/><field name="bar"/></list>`,
6561 groupBy: ["foo"],
6562 });
6563
6564 // unfold
6565 await contains(`.o_group_header:first-of-type`).click();
6566 expect(`.o_group_header:first-of-type .o_pager_limit`).toHaveText("6");
6567 });
6568
6569 test.tags("desktop");
6570 test(`pager, grouped, group pager should update after removing a filter`, async () => {
6571 patchWithCleanup(RelationalModel, { DEFAULT_COUNT_LIMIT: 3 });
6572 Foo._records = [
6573 { id: 121, foo: "aaa" },
6574 { id: 122, foo: "blip" },
6575 { id: 123, foo: "blip" },
6576 { id: 124, foo: "blip" },
6577 { id: 125, foo: "blip" },
6578 { id: 126, foo: "blip" },
6579 ];
6580
6581 await mountView({
6582 resModel: "foo",
6583 type: "list",
6584 arch: `<list limit="2"><field name="foo"/><field name="bar"/></list>`,
6585 searchViewArch: `
6586 <search>
6587 <filter name="foo" domain="[('foo','=','aaa')]"/>
6588 <filter name="groupby_foo" context="{'group_by': 'bar'}"/>
6589 </search>
6590 `,
6591 });
6592 await toggleSearchBarMenu();
6593 await toggleMenuItem("Foo");
6594 await toggleMenuItem("Bar");
6595
6596 // expand group
6597 await contains(`th.o_group_name`).click();
6598 expect(`th.o_group_name .o_pager_counter`).toHaveCount(0);
6599
6600 // remove filter
6601 await removeFacet("Foo");
6602 expect(`th.o_group_name:eq(0) .o_pager_counter`).toHaveText("1-2 / 6");
6603 });
6604
6605 test(`grouped, show only limited records when the list view is initially expanded`, async () => {
6606 const forcedDefaultLimit = 3;
6607 patchWithCleanup(RelationalModel, { DEFAULT_LIMIT: forcedDefaultLimit });
6608 Foo._records = [
6609 { id: 121, foo: "blip" },
6610 { id: 122, foo: "blip" },
6611 { id: 123, foo: "blip" },
6612 { id: 124, foo: "blip" },
6613 { id: 125, foo: "blip" },
6614 { id: 126, foo: "blip" },
6615 ];
6616
6617 await mountView({
6618 resModel: "foo",
6619 type: "list",
6620 arch: `<list expand="1"><field name="foo"/></list>`,
6621 groupBy: ["foo"],
6622 });
6623 expect(`.o_data_row`).toHaveCount(forcedDefaultLimit);
6624 });
6625
6626 test(`list keeps offset on switchView`, async () => {
6627 Foo._views = {
6628 "list,99": `<list limit="1"><field name="display_name"/></list>`,
6629 "form,100": `<form><field name="display_name"/></form>`,
6630 };
6631
6632 const offsets = [0, 1, 1];
6633 onRpc("web_search_read", ({ kwargs }) => {
6634 expect.step("web_search_read");
6635 expect(kwargs.offset).toBe(offsets.shift());
6636 });
6637
6638 await mountWithCleanup(WebClient);
6639 await getService("action").doAction({
6640 res_model: "foo",
6641 type: "ir.actions.act_window",
6642 views: [
6643 [99, "list"],
6644 [100, "form"],
6645 ],
6646 });
6647 expect.verifySteps(["web_search_read"]);
6648
6649 await contains(`.o_pager_next`).click();
6650 expect.verifySteps(["web_search_read"]);
6651
6652 await contains(`.o_data_cell`).click();
6653 await contains(`.o_back_button`).click();
6654 expect.verifySteps(["web_search_read"]);
6655 });
6656
6657 test.tags("desktop");
6658 test(`Navigate between the list and kanban view using the command palette`, async () => {
6659 Foo._views = {
6660 list: `<list><field name="display_name"/></list>`,
6661 kanban: `
6662 <kanban class="o_kanban_test">
6663 <templates><t t-name="card">
6664 <field name="foo"/>
6665 </t></templates>
6666 </kanban>
6667 `,
6668 };
6669
6670 await mountWithCleanup(WebClient);
6671 await getService("action").doAction({
6672 res_model: "foo",
6673 type: "ir.actions.act_window",
6674 views: [
6675 [false, "list"],
6676 [false, "kanban"],
6677 ],
6678 });
6679 expect(`.o_cp_switch_buttons`).toHaveCount(1);
6680 expect(`.o_switch_view`).toHaveCount(2);
6681 expect(`.o_list_view`).toHaveCount(1);
6682
6683 await press("control+k");
6684 await animationFrame();
6685 expect(`.o_command_category .o_command:contains(Show Kanban view)`).toHaveCount(1);
6686
6687 await contains(`.o_command:contains(Show Kanban view)`).click();
6688 expect(`.o_kanban_view`).toHaveCount(1);
6689
6690 await press("control+k");
6691 await animationFrame();
6692 expect(`.o_command_category .o_command:contains(Show List view)`).toHaveCount(1);
6693
6694 await contains(`.o_command:contains(Show List view)`).click();
6695 expect(`.o_list_view`).toHaveCount(1);
6696 });
6697
6698 test(`grouped list keeps offset on switchView`, async () => {
6699 Foo._views = {
6700 search: `
6701 <search>
6702 <filter string="IntField" name="groupby" domain="[]" context="{'group_by': 'int_field'}"/>
6703 </search>
6704 `,
6705 "list,99": `<list groups_limit="1"><field name="display_name"/></list>`,
6706 "form,100": `<form><field name="display_name"/></form>`,
6707 };
6708
6709 const offsets = [0, 1, 1];
6710 onRpc("web_read_group", ({ kwargs }) => {
6711 expect.step("web_read_group");
6712 expect(kwargs.offset).toBe(offsets.shift());
6713 });
6714 await mountWithCleanup(WebClient);
6715 await getService("action").doAction({
6716 res_model: "foo",
6717 type: "ir.actions.act_window",
6718 views: [
6719 [99, "list"],
6720 [100, "form"],
6721 ],
6722 context: {
6723 search_default_groupby: true,
6724 },
6725 });
6726 expect(`.o_list_view`).toHaveCount(1);
6727 expect.verifySteps(["web_read_group"]);
6728
6729 await contains(`.o_pager_next`).click();
6730 expect(`.o_data_row`).toHaveCount(0);
6731 expect.verifySteps(["web_read_group"]);
6732
6733 await contains(`.o_group_header`).click();
6734 expect(`.o_data_row`).toHaveCount(1);
6735
6736 await contains(`.o_data_cell`).click();
6737 expect(`.o_form_view`).toHaveCount(1);
6738
6739 await contains(`.o_back_button`).click();
6740 expect(`.o_data_row`).toHaveCount(1);
6741 expect.verifySteps(["web_read_group"]);
6742 });
6743
6744 test(`can sort records when clicking on header`, async () => {
6745 onRpc("web_search_read", () => expect.step("web_search_read"));
6746 await mountView({
6747 resModel: "foo",
6748 type: "list",
6749 arch: `<list><field name="foo"/><field name="bar"/></list>`,
6750 });
6751 expect.verifySteps(["web_search_read"]);
6752 expect(`.o_column_sortable.table-active`).toHaveCount(0);
6753 expect(queryAllTexts(`.o_data_cell.o_list_char`)).toEqual(["yop", "blip", "gnap", "blip"]);
6754
6755 await contains(`thead th:contains(Foo)`).click();
6756 expect(`.o_column_sortable.table-active`).toHaveCount(1);
6757 expect.verifySteps(["web_search_read"]);
6758 expect(queryAllTexts(`.o_data_cell.o_list_char`)).toEqual(["blip", "blip", "gnap", "yop"]);
6759
6760 await contains(`thead th:contains(Foo)`).click();
6761 expect(`.o_column_sortable.table-active`).toHaveCount(1);
6762 expect.verifySteps(["web_search_read"]);
6763 expect(queryAllTexts(`.o_data_cell.o_list_char`)).toEqual(["yop", "gnap", "blip", "blip"]);
6764
6765 // Clicking on a header with a descending order resets the sort to the default from server
6766 await contains(`thead th:contains(Foo)`).click();
6767 expect(`.o_column_sortable.table-active`).toHaveCount(0);
6768 expect.verifySteps(["web_search_read"]);
6769 expect(queryAllTexts(`.o_data_cell.o_list_char`)).toEqual(["yop", "blip", "gnap", "blip"]);
6770 });
6771
6772 test(`do not sort records when clicking on header with nolabel`, async () => {
6773 onRpc("web_search_read", () => expect.step("web_search_read"));
6774 await mountView({
6775 resModel: "foo",
6776 type: "list",
6777 arch: `<list><field name="foo" nolabel="1"/><field name="int_field"/></list>`,
6778 });
6779 expect.verifySteps(["web_search_read"]);
6780 expect(queryAllTexts(`.o_data_cell`)).toEqual([
6781 "yop",
6782 "10",
6783 "blip",
6784 "9",
6785 "gnap",
6786 "17",
6787 "blip",
6788 "-4",
6789 ]);
6790
6791 await contains(`thead th:not(.o_list_record_selector):eq(1)`).click();
6792 expect.verifySteps(["web_search_read"]);
6793 expect(queryAllTexts(`.o_data_cell`)).toEqual([
6794 "blip",
6795 "-4",
6796 "blip",
6797 "9",
6798 "yop",
6799 "10",
6800 "gnap",
6801 "17",
6802 ]);
6803
6804 await contains(`thead th:not(.o_list_record_selector):eq(0)`).click();
6805 expect.verifySteps([]);
6806 expect(queryAllTexts(`.o_data_cell`)).toEqual([
6807 "blip",
6808 "-4",
6809 "blip",
6810 "9",
6811 "yop",
6812 "10",
6813 "gnap",
6814 "17",
6815 ]);
6816 });
6817
6818 test(`use default_order`, async () => {
6819 onRpc("web_search_read", ({ kwargs }) => {
6820 expect.step("web_search_read");
6821 expect(kwargs.order).toBe("foo ASC", {
6822 message: "should correctly set the sort attribute",
6823 });
6824 });
6825
6826 await mountView({
6827 resModel: "foo",
6828 type: "list",
6829 arch: `<list default_order="foo"><field name="foo"/><field name="bar"/></list>`,
6830 });
6831 expect.verifySteps(["web_search_read"]);
6832 expect(queryAllTexts(`.o_data_cell.o_list_char`)).toEqual(["blip", "blip", "gnap", "yop"]);
6833 });
6834
6835 test(`use more complex default_order`, async () => {
6836 onRpc("web_search_read", ({ kwargs }) => {
6837 expect.step("web_search_read");
6838 expect(kwargs.order).toBe("foo ASC, bar DESC, int_field ASC", {
6839 message: "should correctly set the sort attribute",
6840 });
6841 });
6842
6843 await mountView({
6844 resModel: "foo",
6845 type: "list",
6846 arch: `
6847 <list default_order="foo, bar desc, int_field">
6848 <field name="foo"/><field name="bar"/>
6849 </list>
6850 `,
6851 });
6852 expect.verifySteps(["web_search_read"]);
6853 expect(queryAllTexts(`.o_data_cell.o_list_char`)).toEqual(["blip", "blip", "gnap", "yop"]);
6854 });
6855
6856 test(`use default_order on editable tree: sort on save`, async () => {
6857 Foo._records[0].o2m = [1, 3];
6858
6859 await mountView({
6860 resModel: "foo",
6861 type: "form",
6862 arch: `
6863 <form>
6864 <sheet>
6865 <field name="o2m">
6866 <list editable="bottom" default_order="name">
6867 <field name="name"/>
6868 </list>
6869 </field>
6870 </sheet>
6871 </form>
6872 `,
6873 resId: 1,
6874 });
6875 expect(queryAllTexts(`.o_field_x2many_list .o_data_row`)).toEqual(["Value 1", "Value 3"]);
6876
6877 await contains(`.o_field_x2many_list_row_add a`).click();
6878 await contains(`.o_field_widget[name=o2m] .o_field_widget input`).edit("Value 2");
6879 await contains(`.o_form_view`).click();
6880 expect(queryAllTexts(`.o_field_x2many_list .o_data_row`)).toEqual([
6881 "Value 1",
6882 "Value 3",
6883 "Value 2",
6884 ]);
6885
6886 await clickSave();
6887 expect(queryAllTexts(`.o_field_x2many_list .o_data_row`)).toEqual([
6888 "Value 1",
6889 "Value 2",
6890 "Value 3",
6891 ]);
6892 });
6893
6894 test(`use default_order on editable tree: sort on demand`, async () => {
6895 Foo._records[0].o2m = [1, 3];
6896 Bar._fields.name = fields.Char();
6897 Bar._records[0].name = "Value 1";
6898 Bar._records[2].name = "Value 3";
6899
6900 await mountView({
6901 resModel: "foo",
6902 type: "form",
6903 arch: `
6904 <form>
6905 <sheet>
6906 <field name="o2m">
6907 <list editable="bottom" default_order="name">
6908 <field name="name"/>
6909 </list>
6910 </field>
6911 </sheet>
6912 </form>
6913 `,
6914 resId: 1,
6915 });
6916 expect(queryAllTexts(`.o_field_x2many_list .o_data_row`)).toEqual(["Value 1", "Value 3"]);
6917
6918 await contains(`.o_field_x2many_list_row_add a`).click();
6919 await contains(`.o_field_widget[name=o2m] .o_field_widget input`).edit("Value 2");
6920 await contains(`.o_form_view`).click();
6921 expect(queryAllTexts(`.o_field_x2many_list .o_data_row`)).toEqual([
6922 "Value 1",
6923 "Value 3",
6924 "Value 2",
6925 ]);
6926
6927 await contains(`.o_field_widget[name=o2m] .o_column_sortable`).click();
6928 expect(queryAllTexts(`.o_field_x2many_list .o_data_row`)).toEqual([
6929 "Value 1",
6930 "Value 2",
6931 "Value 3",
6932 ]);
6933
6934 await contains(`.o_field_widget[name=o2m] .o_column_sortable`).click();
6935 expect(queryAllTexts(`.o_field_x2many_list .o_data_row`)).toEqual([
6936 "Value 3",
6937 "Value 2",
6938 "Value 1",
6939 ]);
6940 });
6941
6942 test(`use default_order on editable tree: sort on demand in page`, async () => {
6943 Bar._fields.name = fields.Char();
6944
6945 const ids = [];
6946 for (let i = 0; i < 45; i++) {
6947 const id = 4 + i;
6948 ids.push(id);
6949 Bar._records.push({
6950 id: id,
6951 name: "Value " + (id < 10 ? "0" : "") + id,
6952 });
6953 }
6954 Foo._records[0].o2m = ids;
6955
6956 await mountView({
6957 resModel: "foo",
6958 type: "form",
6959 arch: `
6960 <form>
6961 <sheet>
6962 <field name="o2m">
6963 <list editable="bottom" default_order="name">
6964 <field name="name"/>
6965 </list>
6966 </field>
6967 </sheet>
6968 </form>
6969 `,
6970 resId: 1,
6971 });
6972 await contains(`.o_field_widget .o_pager button.o_pager_next`).click();
6973 expect(queryAllTexts(`.o_data_cell`)).toEqual([
6974 "Value 44",
6975 "Value 45",
6976 "Value 46",
6977 "Value 47",
6978 "Value 48",
6979 ]);
6980
6981 await contains(`.o_column_sortable`).click();
6982 expect(queryAllTexts(`.o_data_cell`)).toEqual([
6983 "Value 08",
6984 "Value 07",
6985 "Value 06",
6986 "Value 05",
6987 "Value 04",
6988 ]);
6989 });
6990
6991 test(`can display button in edit mode`, async () => {
6992 await mountView({
6993 resModel: "foo",
6994 type: "list",
6995 arch: `
6996 <list editable="top">
6997 <field name="foo"/>
6998 <button name="notafield" type="object" icon="fa-asterisk" class="o_yeah"/>
6999 </list>
7000 `,
7001 });
7002 expect(`tbody button[name=notafield]`).toHaveCount(4);
7003 expect(`tbody button[name=notafield].o_yeah`).toHaveCount(4, {
7004 message: "class o_yeah should be set on the four button",
7005 });
7006
7007 await contains(`.o_field_cell`).click();
7008 expect(`.o_selected_row button[name=notafield]`).toHaveCount(1);
7009 });
7010
7011 test(`can display a list with a many2many field`, async () => {
7012 stepAllNetworkCalls();
7013 await mountView({
7014 resModel: "foo",
7015 type: "list",
7016 arch: `<list><field name="m2m"/></list>`,
7017 });
7018 expect.verifySteps([
7019 "/web/webclient/translations",
7020 "/web/webclient/load_menus",
7021 "get_views",
7022 "web_search_read",
7023 "has_group",
7024 ]);
7025 expect(queryAllTexts(`.o_data_cell`)).toEqual([
7026 "2 records",
7027 "3 records",
7028 "No records",
7029 "1 record",
7030 ]);
7031 });
7032
7033 test.tags("desktop");
7034 test(`display a tooltip on a field`, async () => {
7035 await mountView({
7036 resModel: "foo",
7037 type: "list",
7038 arch: `
7039 <list>
7040 <field name="foo"/>
7041 <field name="bar" widget="boolean_favorite"/>
7042 </list>
7043 `,
7044 });
7045
7046 await hover(`th[data-name="foo"] div`);
7047 await runAllTimers();
7048 expect(`.o-tooltip .o-tooltip--technical`).toHaveCount(0);
7049 expect(`.o-tooltip`).toHaveCount(1);
7050 expect(`.o-tooltip`).toHaveText("Foo");
7051
7052 serverState.debug = "1";
7053
7054 // it is necessary to rerender the list so tooltips can be properly created
7055 await validateSearch(); // reload view
7056 await hover(`th[data-name="bar"] div`);
7057 await runAllTimers();
7058 expect(`.o-tooltip .o-tooltip--technical`).toHaveCount(1);
7059 expect(`.o-tooltip--technical > li[data-item="widget"]`).toHaveCount(1);
7060 expect(`.o-tooltip--technical > li[data-item="widget"]`).toHaveText(
7061 "Widget:Favorite (boolean_favorite)"
7062 );
7063 expect(`.o-tooltip--technical > li[data-item="label"]`).toHaveCount(1);
7064 expect(`.o-tooltip--technical > li[data-item="label"]`).toHaveText("Label:Bar");
7065 });
7066
7067 test.tags("desktop");
7068 test("field (with help) tooltip in non debug mode", async function () {
7069 Foo._fields.foo.help = "This is a foo field";
7070 await mountView({
7071 type: "list",
7072 resModel: "foo",
7073 arch: `<list><field name="foo"/></list>`,
7074 });
7075 await hover(`th[data-name="foo"] div`);
7076 await runAllTimers();
7077 expect(`.o-tooltip`).toHaveCount(1);
7078 expect(`.o-tooltip`).toHaveText("Foo\nThis is a foo field");
7079 });
7080
7081 test(`support row decoration`, async () => {
7082 await mountView({
7083 resModel: "foo",
7084 type: "list",
7085 arch: `
7086 <list decoration-info="int_field > 5">
7087 <field name="foo"/>
7088 <field name="int_field"/>
7089 </list>
7090 `,
7091 });
7092 expect(`tbody tr.text-info`).toHaveCount(3, {
7093 message: "should have 3 columns with text-info class",
7094 });
7095 expect(`tbody tr`).toHaveCount(4, { message: "should have 4 rows" });
7096 });
7097
7098 test(`support row decoration (with unset numeric values)`, async () => {
7099 Foo._records = [];
7100
7101 await mountView({
7102 resModel: "foo",
7103 type: "list",
7104 arch: `
7105 <list editable="bottom" decoration-danger="int_field &lt; 0">
7106 <field name="int_field"/>
7107 </list>
7108 `,
7109 });
7110
7111 await contains(`.o_list_button_add`).click();
7112 expect(`tr.o_data_row.text-danger`).toHaveCount(0, {
7113 message: "the data row should not have .text-danger decoration (int_field is unset)",
7114 });
7115
7116 await contains(`[name="int_field"] input`).edit("-3");
7117 expect(`tr.o_data_row.text-danger`).toHaveCount(1, {
7118 message: "the data row should have .text-danger decoration (int_field is negative)",
7119 });
7120 });
7121
7122 test(`support row decoration with date`, async () => {
7123 Foo._records[0].datetime = "2017-02-27 12:51:35";
7124
7125 await mountView({
7126 resModel: "foo",
7127 type: "list",
7128 arch: `
7129 <list decoration-info="datetime == '2017-02-27 12:51:35'" decoration-danger="datetime &gt; '2017-02-27 12:51:35' and datetime &lt; '2017-02-27 10:51:35'">
7130 <field name="datetime"/>
7131 <field name="int_field"/>
7132 </list>
7133 `,
7134 });
7135 expect(`tbody tr.text-info`).toHaveCount(1, {
7136 message: "should have 1 columns with text-info class with good datetime",
7137 });
7138 expect(`tbody tr.text-danger`).toHaveCount(0, {
7139 message: "should have 0 columns with text-danger class with wrong timezone datetime",
7140 });
7141 expect(`tbody tr`).toHaveCount(4, { message: "should have 4 rows" });
7142 });
7143
7144 test(`support row decoration (decoration-bf)`, async () => {
7145 await mountView({
7146 resModel: "foo",
7147 type: "list",
7148 arch: `
7149 <list decoration-bf="int_field > 5">
7150 <field name="foo"/>
7151 <field name="int_field"/>
7152 </list>
7153 `,
7154 });
7155 expect(`tbody tr.fw-bold`).toHaveCount(3, {
7156 message: "should have 3 columns with fw-bold class",
7157 });
7158 expect(`tbody tr`).toHaveCount(4, { message: "should have 4 rows" });
7159 });
7160
7161 test(`support row decoration (decoration-it)`, async () => {
7162 await mountView({
7163 resModel: "foo",
7164 type: "list",
7165 arch: `
7166 <list decoration-it="int_field > 5">
7167 <field name="foo"/>
7168 <field name="int_field"/>
7169 </list>
7170 `,
7171 });
7172 expect(`tbody tr.fst-italic`).toHaveCount(3, {
7173 message: "should have 3 columns with fst-italic class",
7174 });
7175 expect(`tbody tr`).toHaveCount(4, { message: "should have 4 rows" });
7176 });
7177
7178 test(`support field decoration`, async () => {
7179 await mountView({
7180 resModel: "foo",
7181 type: "list",
7182 arch: `
7183 <list>
7184 <field name="foo" decoration-danger="int_field > 5"/>
7185 <field name="int_field"/>
7186 </list>
7187 `,
7188 });
7189 expect(`tbody tr`).toHaveCount(4);
7190 expect(`tbody td.o_list_char`).toHaveCount(4);
7191 expect(`tbody td.text-danger`).toHaveCount(3);
7192 expect(`tbody td.o_list_number`).toHaveCount(4);
7193 expect(`tbody td.o_list_number.text-danger`).toHaveCount(0);
7194 });
7195
7196 test(`support field decoration (decoration-bf)`, async () => {
7197 await mountView({
7198 resModel: "foo",
7199 type: "list",
7200 arch: `
7201 <list>
7202 <field name="foo" decoration-bf="int_field > 5"/>
7203 <field name="int_field"/>
7204 </list>
7205 `,
7206 });
7207 expect(`tbody tr`).toHaveCount(4);
7208 expect(`tbody td.o_list_char`).toHaveCount(4);
7209 expect(`tbody td.fw-bold`).toHaveCount(3);
7210 expect(`tbody td.o_list_number`).toHaveCount(4);
7211 expect(`tbody td.o_list_number.fw-bold`).toHaveCount(0);
7212 });
7213
7214 test(`support field decoration (decoration-it)`, async () => {
7215 await mountView({
7216 resModel: "foo",
7217 type: "list",
7218 arch: `
7219 <list>
7220 <field name="foo" decoration-it="int_field > 5"/>
7221 <field name="int_field"/>
7222 </list>
7223 `,
7224 });
7225 expect(`tbody tr`).toHaveCount(4);
7226 expect(`tbody td.o_list_char`).toHaveCount(4);
7227 expect(`tbody td.fst-italic`).toHaveCount(3);
7228 expect(`tbody td.o_list_number`).toHaveCount(4);
7229 expect(`tbody td.o_list_number.fst-italic`).toHaveCount(0);
7230 });
7231
7232 test(`bounce create button when no data and click on empty area`, async () => {
7233 await mountView({
7234 resModel: "foo",
7235 type: "list",
7236 arch: `<list><field name="foo"/></list>`,
7237 noContentHelp: "click to add a record",
7238 searchViewArch: `
7239 <search>
7240 <filter name="Empty List" domain="[('id', '&lt;', 0)]"/>
7241 </search>
7242 `,
7243 });
7244 expect(`.o_view_nocontent`).toHaveCount(0);
7245
7246 await contains(`.o_list_view`).click();
7247 expect(`.o_list_button_add`).not.toHaveClass("o_catch_attention");
7248
7249 await toggleSearchBarMenu();
7250 await toggleMenuItem("Empty List");
7251 expect(`.o_view_nocontent`).toHaveCount(1);
7252
7253 await contains(`.o_list_renderer`).click();
7254 expect(`.o_list_button_add`).toHaveClass("o_catch_attention");
7255 });
7256
7257 test(`no content helper when no data`, async () => {
7258 const records = Foo._records.map((record) => omit(record, "id"));
7259 Foo._records = [];
7260
7261 await mountView({
7262 resModel: "foo",
7263 type: "list",
7264 arch: `<list><field name="foo"/></list>`,
7265 noContentHelp: "click to add a partner",
7266 });
7267 expect(`.o_view_nocontent`).toHaveCount(1, { message: "should display the no content helper" });
7268 expect(`.o_list_view table`).toHaveCount(1, { message: "should have a table in the dom" });
7269 expect(`.o_view_nocontent`).toHaveText("click to add a partner");
7270
7271 MockServer.env["foo"].create(records);
7272 await validateSearch();
7273 expect(`.o_view_nocontent`).toHaveCount(0, {
7274 message: "should not display the no content helper",
7275 });
7276 });
7277
7278 test(`no nocontent helper when no data and no help`, async () => {
7279 Foo._records = [];
7280
7281 await mountView({
7282 resModel: "foo",
7283 type: "list",
7284 arch: `<list><field name="foo"/></list>`,
7285 });
7286 expect(`.o_view_nocontent`).toHaveCount(0, {
7287 message: "should not display the no content helper",
7288 });
7289 expect(`tr.o_data_row`).toHaveCount(0, { message: "should not have any data row" });
7290 expect(`.o_list_view table`).toHaveCount(1, { message: "should have a table in the dom" });
7291 });
7292
7293 test(`empty list with sample data`, async () => {
7294 await mountView({
7295 resModel: "foo",
7296 type: "list",
7297 arch: `
7298 <list sample="1">
7299 <field name="foo"/>
7300 <field name="bar"/>
7301 <field name="int_field"/>
7302 <field name="m2o"/>
7303 <field name="m2m" widget="many2many_tags"/>
7304 <field name="date" options="{'numeric': true}"/>
7305 <field name="datetime" options="{'numeric': true}"/>
7306 </list>
7307 `,
7308 context: { search_default_empty: true },
7309 noContentHelp: "click to add a partner",
7310 searchViewArch: `
7311 <search>
7312 <filter name="empty" domain="[('id', '&lt;', 0)]"/>
7313 <filter name="True Domain" domain="[(1,'=',1)]"/>
7314 <filter name="False Domain" domain="[(1,'=',0)]"/>
7315 </search>
7316 `,
7317 });
7318 expect(`.o_list_view .o_content`).toHaveClass("o_view_sample_data");
7319 expect(`.o_list_table`).toHaveCount(1);
7320 expect(`.o_data_row`).toHaveCount(10);
7321 expect(`.o_nocontent_help`).toHaveCount(1);
7322
7323 // Check list sample data
7324 expect(`.o_data_row .o_data_cell:eq(0)`).toHaveText("", {
7325 message: "Char field should yield an empty element",
7326 });
7327 expect(`.o_data_row .o_data_cell:eq(1) .o-checkbox`).toHaveCount(1, {
7328 message: "Boolean field has been instantiated",
7329 });
7330
7331 const cells = queryAllTexts(`.o_data_row:eq(0) > .o_data_cell`);
7332 expect(isNaN(cells[2])).toBe(false, { message: "Integer value is a number" });
7333 expect(!!cells[3]).toBe(true, { message: "Many2one field is a string" });
7334 expect(cells[4]).not.toHaveLength(0, {
7335 message: "Many2many contains at least one string tag",
7336 });
7337 expect(cells[5]).toMatch(/\d{2}\/\d{2}\/\d{4}/, {
7338 message: "Date field should have the right format",
7339 });
7340 expect(cells[6]).toMatch(/\d{2}\/\d{2}\/\d{4} \d{2}:\d{2}/, {
7341 message: "Datetime field should have the right format",
7342 });
7343
7344 await toggleSearchBarMenu();
7345 await toggleMenuItem("empty");
7346 await toggleMenuItem("False Domain");
7347 expect(`.o_list_view .o_content`).not.toHaveClass("o_view_sample_data");
7348 expect(`.o_list_table`).toHaveCount(1);
7349 expect(`.o_nocontent_help`).toHaveCount(1);
7350
7351 await toggleMenuItem("False Domain");
7352 await toggleMenuItem("True Domain");
7353 expect(`.o_list_view .o_content`).not.toHaveClass("o_view_sample_data");
7354 expect(`.o_list_table`).toHaveCount(1);
7355 expect(`.o_data_row`).toHaveCount(4);
7356 expect(`.o_nocontent_help`).toHaveCount(0);
7357 });
7358
7359 test(`refresh empty list with sample data`, async () => {
7360 Foo._views = {
7361 search: `
7362 <search>
7363 <filter name="empty" domain="[('id', '&lt;', 0)]"/>
7364 </search>
7365 `,
7366 list: `
7367 <list sample="1">
7368 <field name="foo"/>
7369 <field name="bar"/>
7370 <field name="int_field"/>
7371 <field name="m2o"/>
7372 <field name="m2m" widget="many2many_tags"/>
7373 <field name="date"/>
7374 <field name="datetime"/>
7375 </list>
7376 `,
7377 };
7378
7379 await mountWithCleanup(WebClient);
7380 await getService("action").doAction({
7381 res_model: "foo",
7382 type: "ir.actions.act_window",
7383 views: [
7384 [false, "list"],
7385 [false, "kanban"],
7386 ],
7387 context: { search_default_empty: true },
7388 help: '<p class="hello">click to add a partner</p>',
7389 });
7390 expect(`.o_list_view .o_content`).toHaveClass("o_view_sample_data");
7391 expect(`.o_list_table`).toHaveCount(1);
7392 expect(`.o_data_row`).toHaveCount(10);
7393 expect(`.o_nocontent_help`).toHaveCount(1);
7394
7395 const textContent = queryText`.o_list_view table`;
7396 await getService("action").switchView("list");
7397 expect(`.o_list_view .o_content`).toHaveClass("o_view_sample_data");
7398 expect(`.o_list_table`).toHaveCount(1);
7399 expect(`.o_data_row`).toHaveCount(10);
7400 expect(`.o_nocontent_help`).toHaveCount(1);
7401 expect(`.o_list_view table`).toHaveText(textContent);
7402 });
7403
7404 test(`empty list with sample data: toggle optional field`, async () => {
7405 await mountView({
7406 resModel: "foo",
7407 type: "list",
7408 arch: `
7409 <list sample="1">
7410 <field name="foo"/>
7411 <field name="m2o" optional="hide"/>
7412 </list>
7413 `,
7414 domain: Domain.FALSE.toList(),
7415 });
7416 expect(`.o_list_view .o_content`).toHaveClass("o_view_sample_data");
7417 expect(`.o_data_row`).toHaveCount();
7418 expect(`th:not(.o_list_record_selector)`).toHaveCount(2, {
7419 message:
7420 "should have 1 th for selector (desktop only), 1 th for foo and 1 th for optional columns",
7421 });
7422 expect(`table .o_optional_columns_dropdown`).toHaveCount(1);
7423
7424 await contains(`table .o_optional_columns_dropdown .dropdown-toggle`).click();
7425 await contains(`.o-dropdown--menu span.dropdown-item:eq(0) label`).click();
7426 expect(`.o_list_view .o_content`).toHaveClass("o_view_sample_data");
7427 expect(`.o_data_row`).toHaveCount();
7428 expect(`th:not(.o_list_record_selector)`).toHaveCount(3);
7429 });
7430
7431 test.tags("desktop");
7432 test(`empty list with sample data: keyboard navigation`, async () => {
7433 await mountView({
7434 resModel: "foo",
7435 type: "list",
7436 arch: `
7437 <list sample="1">
7438 <field name="foo"/>
7439 <field name="bar"/>
7440 <field name="int_field"/>
7441 </list>`,
7442 domain: Domain.FALSE.toList(),
7443 });
7444
7445 // Check keynav is disabled
7446 expect(`.o_list_view .o_content`).toHaveClass("o_view_sample_data");
7447
7448 // From search bar
7449 expect(`.o_searchview_input`).toBeFocused();
7450
7451 await press("arrowdown");
7452 await animationFrame();
7453 expect(`.o_searchview_input`).toBeFocused();
7454
7455 // From 'Create' button
7456 await pointerDown(".o_list_button_add");
7457 await animationFrame();
7458 expect(`.o_list_button_add`).toBeFocused();
7459
7460 await press("arrowdown");
7461 await animationFrame();
7462 expect(`.o_list_button_add`).toBeFocused();
7463
7464 await press("tab");
7465 await animationFrame();
7466 expect(`.o-tooltip--string`).toHaveCount(0);
7467 });
7468
7469 test(`empty list with sample data: group by date`, async () => {
7470 await mountView({
7471 resModel: "foo",
7472 type: "list",
7473 arch: `
7474 <list sample="1">
7475 <field name="date"/>
7476 </list>`,
7477 domain: Domain.FALSE.toList(),
7478 groupBy: ["date:day"],
7479 });
7480 expect(`.o_list_view .o_view_sample_data`).toHaveCount(1);
7481 expect(`.o_group_header`).toHaveCount();
7482 });
7483
7484 test(`non empty list with sample data`, async () => {
7485 await mountView({
7486 resModel: "foo",
7487 type: "list",
7488 arch: `
7489 <list sample="1">
7490 <field name="foo"/>
7491 <field name="bar"/>
7492 <field name="int_field"/>
7493 </list>
7494 `,
7495 domain: Domain.TRUE.toList(),
7496 context: { search_default_true_domain: true },
7497 searchViewArch: `
7498 <search>
7499 <filter name="true_domain" domain="[(1,'=',1)]"/>
7500 <filter name="false_domain" domain="[(1,'=',0)]"/>
7501 </search>
7502 `,
7503 });
7504 expect(`.o_list_table`).toHaveCount(1);
7505 expect(`.o_data_row`).toHaveCount(4);
7506 expect(`.o_list_view .o_content`).not.toHaveClass("o_view_sample_data");
7507
7508 await toggleSearchBarMenu();
7509 await toggleMenuItem("true_domain");
7510 await toggleMenuItem("false_domain");
7511 expect(`.o_list_table`).toHaveCount(1);
7512 expect(`.o_data_row`).toHaveCount(0);
7513 expect(`.o_list_view .o_content`).not.toHaveClass("o_view_sample_data");
7514 });
7515
7516 test(`click on header in empty list with sample data`, async () => {
7517 await mountView({
7518 resModel: "foo",
7519 type: "list",
7520 arch: `
7521 <list sample="1">
7522 <field name="foo"/>
7523 <field name="bar"/>
7524 <field name="int_field"/>
7525 </list>
7526 `,
7527 domain: Domain.FALSE.toList(),
7528 });
7529 expect(`.o_list_view .o_content`).toHaveClass("o_view_sample_data");
7530 expect(`.o_list_table`).toHaveCount(1);
7531 expect(`.o_data_row`).toHaveCount(10);
7532
7533 const content = queryText`.o_list_view`;
7534 await contains(`tr .o_column_sortable`).click();
7535 expect(`.o_list_view`).toHaveText(content, {
7536 message: "the content should still be the same",
7537 });
7538 });
7539
7540 test(`list grouped by m2o with sample data with more than 5 real groups`, async () => {
7541 Foo._records = [];
7542 onRpc("web_read_group", () => ({
7543 // simulate 6, empty, real groups
7544 groups: [1, 2, 3, 4, 5, 6].map((id) => ({
7545 __count: 0,
7546 __records: [],
7547 m2o: [id, `Value ${id}`],
7548 __extra_domain: [["m2o", "=", id]],
7549 })),
7550 length: 6,
7551 }));
7552
7553 await mountView({
7554 resModel: "foo",
7555 type: "list",
7556 arch: `<list sample="1"><field name="foo"/></list>`,
7557 groupBy: ["m2o"],
7558 });
7559 expect(`.o_list_view .o_content`).toHaveClass("o_view_sample_data");
7560 expect(`.o_list_table`).toHaveCount(1);
7561 expect(`.o_group_header`).toHaveCount(6);
7562 expect(queryAllTexts(`.o_group_header`)).toEqual([
7563 "Value 1 (3)",
7564 "Value 2 (3)",
7565 "Value 3 (3)",
7566 "Value 4 (3)",
7567 "Value 5 (2)",
7568 "Value 6 (2)",
7569 ]);
7570 });
7571
7572 test.tags("desktop");
7573 test(`non empty editable list with sample data: delete all records`, async () => {
7574 await mountView({
7575 resModel: "foo",
7576 type: "list",
7577 arch: `
7578 <list editable="top" sample="1">
7579 <field name="foo"/>
7580 <field name="bar"/>
7581 <field name="int_field"/>
7582 </list>
7583 `,
7584 domain: Domain.TRUE.toList(),
7585 noContentHelp: "click to add a partner",
7586 actionMenus: {},
7587 });
7588
7589 // Initial state: all records displayed
7590 expect(`.o_list_view .o_content`).not.toHaveClass("o_view_sample_data");
7591 expect(`.o_list_table`).toHaveCount(1);
7592 expect(`.o_data_row`).toHaveCount(4);
7593 expect(`.o_nocontent_help`).toHaveCount(0);
7594
7595 // Delete all records
7596 await contains(`thead .o_list_record_selector input`).click();
7597 await contains(`.o_cp_action_menus .dropdown-toggle`).click();
7598 await toggleMenuItem("Delete");
7599 await contains(`.modal-footer .btn-primary`).click();
7600
7601 // Final state: no more sample data, but nocontent helper displayed
7602 expect(`.o_list_view .o_content`).not.toHaveClass("o_view_sample_data");
7603 expect(`.o_list_table`).toHaveCount(1);
7604 expect(`.o_nocontent_help`).toHaveCount(1);
7605 });
7606
7607 test.tags("desktop");
7608 test(`empty editable list with sample data: start create record and cancel`, async () => {
7609 await mountView({
7610 resModel: "foo",
7611 type: "list",
7612 arch: `
7613 <list editable="top" sample="1">
7614 <field name="foo"/>
7615 <field name="bar"/>
7616 <field name="int_field"/>
7617 </list>
7618 `,
7619 domain: Domain.FALSE.toList(),
7620 noContentHelp: "click to add a partner",
7621 });
7622
7623 // Initial state: sample data and nocontent helper displayed
7624 expect(`.o_list_view .o_content`).toHaveClass("o_view_sample_data");
7625 expect(`.o_list_table`).toHaveCount(1);
7626 expect(`.o_data_row`).toHaveCount(10);
7627 expect(`.o_nocontent_help`).toHaveCount(1);
7628
7629 // Start creating a record
7630 await contains(`.o_list_button_add`).click();
7631 expect(`.o_list_view .o_content`).not.toHaveClass("o_view_sample_data");
7632 expect(`.o_data_row`).toHaveCount(1);
7633
7634 // Discard temporary record
7635 await contains(`.o_list_button_discard`).click();
7636
7637 // Final state: there should be no table, but the no content helper
7638 expect(`.o_list_view .o_content`).not.toHaveClass("o_view_sample_data");
7639 expect(`.o_list_table`).toHaveCount(1);
7640 expect(`.o_nocontent_help`).toHaveCount(1);
7641 });
7642
7643 test.tags("desktop");
7644 test(`empty editable list with sample data: create and delete record`, async () => {
7645 await mountView({
7646 resModel: "foo",
7647 type: "list",
7648 arch: `
7649 <list editable="top" sample="1">
7650 <field name="foo"/>
7651 <field name="bar"/>
7652 <field name="int_field"/>
7653 </list>
7654 `,
7655 domain: Domain.FALSE.toList(),
7656 noContentHelp: "click to add a partner",
7657 actionMenus: {},
7658 });
7659
7660 // Initial state: sample data and nocontent helper displayed
7661 expect(`.o_list_view .o_content`).toHaveClass("o_view_sample_data");
7662 expect(`.o_list_table`).toHaveCount(1);
7663 expect(`.o_data_row`).toHaveCount(10);
7664 expect(`.o_nocontent_help`).toHaveCount(1);
7665
7666 // Start creating a record
7667 await contains(`.o_list_button_add`).click();
7668 expect(`.o_list_view .o_content`).not.toHaveClass("o_view_sample_data");
7669 expect(`.o_data_row`).toHaveCount(1);
7670
7671 // Save temporary record
7672 await contains(`.o_list_button_save`).click();
7673 expect(`.o_list_view .o_content`).not.toHaveClass("o_view_sample_data");
7674 expect(`.o_list_table`).toHaveCount(1);
7675 expect(`.o_data_row`).toHaveCount(1);
7676 expect(`.o_nocontent_help`).toHaveCount(0);
7677
7678 // Delete newly created record
7679 await contains(`.o_data_row input`).click();
7680 await contains(`.o_cp_action_menus .dropdown-toggle`).click();
7681 await toggleMenuItem("Delete");
7682 await contains(`.modal-footer .btn-primary`).click();
7683
7684 // Final state: there should be no table, but the no content helper
7685 expect(`.o_list_view .o_content`).not.toHaveClass("o_view_sample_data");
7686 expect(`.o_list_table`).toHaveCount(1);
7687 expect(`.o_nocontent_help`).toHaveCount(1);
7688 });
7689
7690 test.tags("desktop");
7691 test(`empty editable list with sample data: create and duplicate record`, async () => {
7692 await mountView({
7693 resModel: "foo",
7694 type: "list",
7695 arch: `
7696 <list editable="top" sample="1">
7697 <field name="foo"/>
7698 <field name="bar"/>
7699 <field name="int_field"/>
7700 </list>
7701 `,
7702 domain: [["int_field", "=", 0]],
7703 noContentHelp: "click to add a partner",
7704 actionMenus: {},
7705 });
7706
7707 // Initial state: sample data and nocontent helper displayed
7708 expect(`.o_list_view .o_content`).toHaveClass("o_view_sample_data");
7709 expect(`.o_list_table`).toHaveCount(1);
7710 expect(`.o_data_row`).toHaveCount(10);
7711 expect(`.o_nocontent_help`).toHaveCount(1);
7712
7713 // Start creating a record
7714 await contains(`.o_list_button_add`).click();
7715 expect(`.o_list_view .o_content`).not.toHaveClass("o_view_sample_data");
7716 expect(`.o_data_row`).toHaveCount(1);
7717
7718 // Save temporary record
7719 await contains(`.o_list_button_save`).click();
7720 expect(`.o_list_view .o_content`).not.toHaveClass("o_view_sample_data");
7721 expect(`.o_list_table`).toHaveCount(1);
7722 expect(`.o_data_row`).toHaveCount(1);
7723 expect(`.o_nocontent_help`).toHaveCount(0);
7724
7725 // Duplicate newly created record
7726 await contains(`.o_data_row input`).click();
7727 await contains(`.o_cp_action_menus .dropdown-toggle`).click();
7728 await toggleMenuItem("Duplicate");
7729
7730 // Final state: there should be 2 records
7731 expect(`.o_list_view .o_content .o_data_row`).toHaveCount(2, {
7732 message: "there should be 2 records",
7733 });
7734 });
7735
7736 test(`groupby node with a button`, async () => {
7737 stepAllNetworkCalls();
7738
7739 mockService("action", {
7740 doActionButton(params) {
7741 expect.step(params.name);
7742 expect(params.resId).toBe(1, { message: "should call with correct id" });
7743 expect(params.resModel).toBe("res.currency", {
7744 message: "should call with correct model",
7745 });
7746 expect(params.name).toBe("button_method", {
7747 message: "should call correct method",
7748 });
7749 expect(params.type).toBe("object", { message: "should have correct type" });
7750 },
7751 });
7752
7753 await mountView({
7754 resModel: "foo",
7755 type: "list",
7756 arch: `
7757 <list>
7758 <field name="foo"/>
7759 <groupby name="currency_id">
7760 <button string="Button 1" type="object" name="button_method"/>
7761 </groupby>
7762 </list>
7763 `,
7764 });
7765 expect.verifySteps([
7766 "/web/webclient/translations",
7767 "/web/webclient/load_menus",
7768 "get_views",
7769 "web_search_read",
7770 "has_group",
7771 ]);
7772 expect(`thead th:not(.o_list_record_selector)`).toHaveCount(1, {
7773 message: "there should be only one column",
7774 });
7775
7776 await selectGroup("currency_id");
7777 expect.verifySteps(["web_read_group"]);
7778 expect(`.o_group_header`).toHaveCount(2, { message: "there should be 2 group headers" });
7779 expect(`.o_group_header:eq(0) .o_group_buttons`).toHaveCount(0, {
7780 message: "there should be no group button in the header",
7781 });
7782
7783 await contains(`.o_group_header:eq(0)`).click();
7784 expect.verifySteps(["web_search_read"]);
7785 expect(`.o_group_header:eq(0) .o_group_buttons button`).toHaveCount(1);
7786
7787 await contains(`.o_group_header:eq(0) button`).click();
7788 expect.verifySteps(["button_method"]);
7789 });
7790
7791 test(`groupby node with a button when many2one is None`, async () => {
7792 for (const record of Foo._records) {
7793 record.currency_id = false;
7794 }
7795
7796 await mountView({
7797 resModel: "foo",
7798 type: "list",
7799 arch: `
7800 <list default_group_by="currency_id">
7801 <field name="foo"/>
7802 <groupby name="currency_id">
7803 <field name="display_name"/>
7804 <button string="Button 1" type="object" name="button_method"/>
7805 </groupby>
7806 </list>
7807 `,
7808 });
7809 expect(`.o_list_table_grouped`).toHaveCount(1);
7810 expect(`.o_group_header.o_group_open button`).toHaveCount(0);
7811
7812 await contains(`.o_group_header:first-child`).click();
7813 expect(`.o_group_header.o_group_open`).toHaveCount(1);
7814 expect(`.o_group_header .o_group_buttons button`).toHaveCount(0);
7815 });
7816
7817 test(`groupby node with a button in inner groupbys`, async () => {
7818 await mountView({
7819 resModel: "foo",
7820 type: "list",
7821 arch: `
7822 <list>
7823 <field name="foo"/>
7824 <groupby name="currency_id">
7825 <button string="Button 1" type="object" name="button_method"/>
7826 </groupby>
7827 </list>
7828 `,
7829 groupBy: ["bar", "currency_id"],
7830 });
7831 expect(`.o_group_header`).toHaveCount(2, { message: "there should be 2 group headers" });
7832 expect(`.o_group_header .o_group_buttons button`).toHaveCount(0);
7833
7834 await contains(`.o_group_header:eq(0)`).click();
7835 expect(`.o_list_view .o_group_header`).toHaveCount(3);
7836 expect(`.o_group_header .o_group_buttons button`).toHaveCount(0);
7837
7838 await contains(`.o_group_header:eq(1)`).click();
7839 expect(`.o_group_header .o_group_buttons button`).toHaveCount(1);
7840 });
7841
7842 test(`groupby node with a button with modifiers`, async () => {
7843 stepAllNetworkCalls();
7844
7845 await mountView({
7846 type: "list",
7847 resModel: "foo",
7848 arch: `
7849 <list>
7850 <field name="foo"/>
7851 <groupby name="currency_id">
7852 <field name="position"/>
7853 <button string="Button 1" type="object" name="button_method" invisible="position == 'after'"/>
7854 </groupby>
7855 </list>`,
7856 groupBy: ["currency_id"],
7857 });
7858
7859 expect.verifySteps([
7860 "/web/webclient/translations",
7861 "/web/webclient/load_menus",
7862 "get_views",
7863 "web_read_group",
7864 "has_group",
7865 ]);
7866 expect(`.o_group_header .o_group_buttons button`).toHaveCount(0);
7867 expect(`.o_data_row`).toHaveCount(0);
7868
7869 await contains(`.o_group_header:eq(1)`).click();
7870 expect.verifySteps(["web_search_read"]);
7871 expect(`.o_group_header .o_group_buttons button`).toHaveCount(0);
7872 expect(`.o_data_row`).toHaveCount(1);
7873
7874 await contains(`.o_group_header:eq(0)`).click();
7875 expect.verifySteps(["web_search_read"]);
7876 expect(`.o_group_header .o_group_buttons button`).toHaveCount(1);
7877 expect(`.o_data_row`).toHaveCount(4);
7878 });
7879
7880 test(`groupby node with a button with modifiers using a many2one`, async () => {
7881 Currency._fields.m2o = fields.Many2one({ relation: "bar" });
7882 Currency._records[0].m2o = 1;
7883
7884 stepAllNetworkCalls();
7885
7886 await mountView({
7887 resModel: "foo",
7888 type: "list",
7889 arch: `
7890 <list expand="1">
7891 <field name="foo"/>
7892 <groupby name="currency_id">
7893 <field name="m2o"/>
7894 <button string="Button 1" type="object" name="button_method" invisible="not m2o"/>
7895 </groupby>
7896 </list>
7897 `,
7898 groupBy: ["currency_id"],
7899 });
7900 expect(`.o_group_header:eq(0) .o_group_buttons button`).toHaveCount(1);
7901 expect(`.o_group_header:eq(1) .o_group_buttons button`).toHaveCount(0);
7902 expect.verifySteps([
7903 "/web/webclient/translations",
7904 "/web/webclient/load_menus",
7905 "get_views",
7906 "web_read_group",
7907 "has_group",
7908 ]);
7909 });
7910
7911 test(`reload list view with groupby node`, async () => {
7912 await mountView({
7913 resModel: "foo",
7914 type: "list",
7915 arch: `
7916 <list expand="1">
7917 <field name="foo"/>
7918 <groupby name="currency_id">
7919 <field name="position"/>
7920 <button string="Button 1" type="object" name="button_method" invisible="position == 'after'"/>
7921 </groupby>
7922 </list>
7923 `,
7924 groupBy: ["currency_id"],
7925 });
7926 expect(`.o_group_header .o_group_buttons button`).toHaveCount(1);
7927
7928 await validateSearch();
7929 expect(`.o_group_header .o_group_buttons button`).toHaveCount(1);
7930 });
7931
7932 test.tags("desktop");
7933 test(`editable list view with groupby node and modifiers`, async () => {
7934 await mountView({
7935 resModel: "foo",
7936 type: "list",
7937 arch: `
7938 <list expand="1" editable="bottom">
7939 <field name="foo"/>
7940 <groupby name="currency_id">
7941 <field name="position"/>
7942 <button string="Button 1" type="object" name="button_method" invisible="position == 'after'"/>
7943 </groupby>
7944 </list>
7945 `,
7946 groupBy: ["currency_id"],
7947 });
7948 expect(`.o_data_row:eq(0)`).not.toHaveClass("o_selected_row", {
7949 message: "first row should be in readonly mode",
7950 });
7951
7952 await contains(`.o_data_row .o_data_cell`).click();
7953 expect(`.o_data_row:eq(0)`).toHaveClass("o_selected_row", {
7954 message: "the row should be in edit mode",
7955 });
7956
7957 await contains(`.o_data_cell input`).press("escape");
7958 expect(`.o_data_row:eq(0)`).not.toHaveClass("o_selected_row", {
7959 message: "the row should be back in readonly mode",
7960 });
7961 });
7962
7963 test(`groupby node with edit button`, async () => {
7964 mockService("action", {
7965 doAction(action) {
7966 expect.step("doAction");
7967 expect(action).toEqual({
7968 context: { create: false },
7969 res_id: 2,
7970 res_model: "res.currency",
7971 type: "ir.actions.act_window",
7972 views: [[false, "form"]],
7973 });
7974 },
7975 });
7976
7977 await mountView({
7978 resModel: "foo",
7979 type: "list",
7980 arch: `
7981 <list expand="1">
7982 <field name="foo"/>
7983 <groupby name="currency_id">
7984 <button string="Button 1" type="edit" name="edit"/>
7985 </groupby>
7986 </list>
7987 `,
7988 groupBy: ["currency_id"],
7989 });
7990 await contains(`.o_group_header .o_group_buttons button:eq(1)`).click();
7991 expect.verifySteps(["doAction"]);
7992 });
7993
7994 test(`edit button does not trigger fold group`, async () => {
7995 mockService("action", {
7996 doAction(action) {
7997 expect.step("doAction");
7998 expect(action).toEqual({
7999 context: { create: false },
8000 res_id: 1,
8001 res_model: "res.currency",
8002 type: "ir.actions.act_window",
8003 views: [[false, "form"]],
8004 });
8005 },
8006 });
8007 await mountView({
8008 resModel: "foo",
8009 type: "list",
8010 arch: `
8011 <list>
8012 <field name="foo"/>
8013 <groupby name="currency_id">
8014 <button name="edit" type="edit" icon="fa-edit" title="Edit"/>
8015 </groupby>
8016 </list>
8017 `,
8018 groupBy: ["currency_id"],
8019 });
8020 expect(`.o_group_open`).toHaveCount(0);
8021 await contains(`.o_group_header:eq(0)`).click();
8022 expect(`.o_group_open`).toHaveCount(1);
8023 await contains(`.o_group_header .o_group_buttons button:eq(0)`).click();
8024 expect(`.o_group_open`).toHaveCount(1);
8025 expect.verifySteps(["doAction"]);
8026 });
8027
8028 test(`groupby node with subfields, and onchange`, async () => {
8029 Foo._onChanges = {
8030 foo() {},
8031 };
8032
8033 onRpc("onchange", ({ args }) => {
8034 expect.step("onchange");
8035 expect(args[3]).toEqual(
8036 {
8037 currency_id: {
8038 fields: {
8039 display_name: {},
8040 },
8041 },
8042 foo: {},
8043 },
8044 { message: "onchange spec should not follow relation of many2one fields" }
8045 );
8046 });
8047
8048 await mountView({
8049 resModel: "foo",
8050 type: "list",
8051 arch: `
8052 <list editable="bottom" expand="1">
8053 <field name="foo"/>
8054 <field name="currency_id"/>
8055 <groupby name="currency_id">
8056 <field name="position" column_invisible="1"/>
8057 </groupby>
8058 </list>
8059 `,
8060 groupBy: ["currency_id"],
8061 });
8062 await contains(`.o_data_row .o_data_cell`).click();
8063 await contains(`.o_field_widget[name=foo] input`).edit("new value");
8064 expect.verifySteps(["onchange"]);
8065 });
8066
8067 test.tags("desktop");
8068 test(`list view, editable, without data`, async () => {
8069 Foo._records = [];
8070 Foo._fields.date = fields.Date({ default: "2017-02-10" });
8071
8072 onRpc("web_save", () => {
8073 expect.step("web_save");
8074 });
8075
8076 await mountView({
8077 resModel: "foo",
8078 type: "list",
8079 arch: `
8080 <list editable="top">
8081 <field name="foo"/>
8082 <field name="date"/>
8083 <field name="m2o"/>
8084 <button type="object" icon="fa-plus-square" name="method"/>
8085 </list>
8086 `,
8087 noContentHelp: "click to add a partner",
8088 });
8089
8090 expect(`.o_view_nocontent`).toHaveCount(1, {
8091 message: "should have a no content helper displayed",
8092 });
8093 expect(`div.table-responsive`).toHaveCount(1, {
8094 message: "should have a div.table-responsive",
8095 });
8096 expect(`table`).toHaveCount(1, { message: "should have rendered a table" });
8097
8098 await contains(`.o_list_button_add`).click();
8099 expect(`.o_view_nocontent`).toHaveCount(0, {
8100 message: "should not have a no content helper displayed",
8101 });
8102 expect(`tbody tr:eq(0)`).toHaveClass("o_selected_row", {
8103 message: "the date field td should be in edit mode",
8104 });
8105 expect(`tbody tr:eq(0) td:eq(2)`).toHaveText("Feb 10, 2017", {
8106 message: "the date field td should have the default value",
8107 });
8108 expect(`tr.o_selected_row .o_list_record_selector input`).toHaveProperty("disabled", true, {
8109 message: "record selector checkbox should be disabled while the record is not yet created",
8110 });
8111 expect(`.o_list_button button:eq(0)`).toHaveProperty("disabled", false, {
8112 message: "buttons should not be disabled while the record is not yet created",
8113 });
8114
8115 await contains(`.o_list_button_save`).click();
8116 expect(`tbody tr .o_list_record_selector input`).toHaveProperty("disabled", false, {
8117 message: "record selector checkbox should not be disabled once the record is created",
8118 });
8119 expect(`.o_list_button button:eq(0)`).toHaveProperty("disabled", false, {
8120 message: "buttons should not be disabled once the record is created",
8121 });
8122 expect.verifySteps(["web_save"]);
8123 });
8124
8125 test(`list view, editable, with a button`, async () => {
8126 Foo._records = [];
8127
8128 onRpc("web_save", () => {
8129 expect.step("web_save");
8130 });
8131 onRpc("/web/dataset/call_button/*", () => {
8132 expect.step("call_button");
8133 return true;
8134 });
8135
8136 await mountView({
8137 resModel: "foo",
8138 type: "list",
8139 arch: `
8140 <list editable="top">
8141 <field name="foo"/>
8142 <button string="abc" icon="fa-phone" type="object" name="schedule_another_phonecall"/>
8143 </list>
8144 `,
8145 });
8146 await contains(`.o_list_button_add`).click();
8147 expect(`table button i.o_button_icon.fa-phone`).toHaveCount(1, {
8148 message: "should have rendered a button",
8149 });
8150 expect(`table button:eq(0)`).toHaveProperty("disabled", false, {
8151 message: "button should not be disabled when creating the record",
8152 });
8153
8154 await contains(`table button`).click();
8155 // clicking the button should save the record and then execute the action
8156 expect.verifySteps(["web_save", "call_button"]);
8157 });
8158
8159 test(`list view with a button without icon`, async () => {
8160 await mountView({
8161 resModel: "foo",
8162 type: "list",
8163 arch: `
8164 <list editable="top">
8165 <field name="foo"/>
8166 <button string="abc" type="object" name="schedule_another_phonecall"/>
8167 </list>
8168 `,
8169 });
8170 expect(`table button:eq(0)`).toHaveText("abc", {
8171 message: "should have rendered a button with string attribute as label",
8172 });
8173 });
8174
8175 test.tags("desktop");
8176 test(`list view, editable, can discard`, async () => {
8177 await mountView({
8178 resModel: "foo",
8179 type: "list",
8180 arch: `<list editable="top"><field name="foo"/></list>`,
8181 });
8182 expect(`td:not(.o_list_record_selector) input`).toHaveCount(0, {
8183 message: "no input should be in the table",
8184 });
8185 expect(`.o_list_button_discard`).toHaveCount(0);
8186
8187 await contains(`.o_data_cell`).click();
8188 expect(`td:not(.o_list_record_selector) input`).toHaveCount(1, {
8189 message: "first cell should be editable",
8190 });
8191 expect(`.o_list_button_discard`).toHaveCount(1);
8192
8193 await contains(`.o_list_button_discard:not(.dropdown-item)`).click();
8194 expect(`td:not(.o_list_record_selector) input`).toHaveCount(0, {
8195 message: "no input should be in the table",
8196 });
8197 expect(`.o_list_button_discard`).toHaveCount(0);
8198 });
8199
8200 test.tags("desktop");
8201 test(`editable list view, click on the list to save`, async () => {
8202 Foo._records = [];
8203 Foo._fields.date = fields.Date({ default: "2017-02-10" });
8204
8205 onRpc("web_save", () => expect.step("web_save"));
8206 await mountView({
8207 resModel: "foo",
8208 type: "list",
8209 arch: `
8210 <list editable="top">
8211 <field name="foo"/>
8212 <field name="int_field" sum="Sum"/>
8213 </list>
8214 `,
8215 });
8216 await contains(`.o_list_button_add`).click();
8217 await contains(`.o_field_widget[name=foo] input`).edit("new value");
8218 await contains(`.o_list_renderer`).click();
8219 expect.verifySteps(["web_save"]);
8220
8221 await contains(`.o_list_button_add`).click();
8222 await contains(`.o_field_widget[name=foo] input`).edit("new value");
8223 await contains(`tfoot`).click();
8224 expect.verifySteps(["web_save"]);
8225
8226 await contains(`.o_list_button_add`).click();
8227 await contains(`.o_field_widget[name=foo] input`).edit("new value");
8228 await contains(`tbody tr:eq(2) .o_data_cell`).click();
8229 expect.verifySteps(["web_save"]);
8230 });
8231
8232 test.tags("desktop");
8233 test(`editable list view, should refocus date field`, async () => {
8234 mockDate("2017-02-10 12:00:00");
8235
8236 Foo._records = [];
8237
8238 await mountView({
8239 resModel: "foo",
8240 type: "list",
8241 arch: `
8242 <list editable="bottom">
8243 <field name="foo"/>
8244 <field name="date"/>
8245 </list>
8246 `,
8247 });
8248 await contains(`.o_list_button_add`).click();
8249 expect(`.o_field_widget[name=foo] input`).toBeFocused();
8250
8251 await contains(`.o_field_widget[name=date] input`).click();
8252 expect(`.o_field_widget[name=date] input`).toBeFocused();
8253 expect(`.o_datetime_picker`).toHaveCount(1);
8254
8255 await contains(getPickerCell("15")).click();
8256 expect(`.o_datetime_picker`).toHaveCount(0);
8257
8258 // the datetime field is rendered multiple times before `picker.activeInput`
8259 // is reset, and so before the field displays a button instead of the input
8260 await waitFor(`.o_field_widget[name=date] button`);
8261 expect(`.o_field_widget[name=date] button`).toHaveValue("02/15/2017");
8262 expect(`.o_field_widget[name=date] button`).toBeFocused();
8263 });
8264
8265 test(`text field should keep it's selection when clicking on it`, async () => {
8266 Foo._records[0].text = "1234";
8267
8268 await mountView({
8269 resModel: "foo",
8270 type: "list",
8271 arch: `
8272 <list editable="bottom" limit="1">
8273 <field name="text"/>
8274 </list>
8275 `,
8276 });
8277 await contains(`td[name=text]`).click();
8278 expect(window.getSelection().toString()).toBe("1234", {
8279 message: "the entire content should be selected on initial click",
8280 });
8281
8282 Object.assign(queryOne("[name=text] textarea"), {
8283 selectionStart: 0,
8284 selectionEnd: 1,
8285 });
8286
8287 await contains(`[name=text] textarea`).click();
8288 expect(window.getSelection().toString()).toBe("1", {
8289 message: "the selection shouldn't be changed",
8290 });
8291 });
8292
8293 test(`click on a button cell in a list view`, async () => {
8294 Foo._records[0].foo = "bar";
8295
8296 mockService("action", {
8297 doActionButton(action) {
8298 expect.step("doActionButton");
8299 action.onClose();
8300 },
8301 });
8302
8303 await mountView({
8304 resModel: "foo",
8305 type: "list",
8306 arch: `
8307 <list editable="bottom" limit="1">
8308 <field name="foo"/>
8309 <button name="action_do_something" type="object" string="Action"/>
8310 </list>
8311 `,
8312 });
8313 await contains(`.o_data_cell.o_list_button`).click();
8314 expect(window.getSelection().toString()).toBe("bar", {
8315 message: "Focus should have returned to the editable cell without throwing an error",
8316 });
8317 expect(`.o_selected_row`).toHaveCount(1);
8318 expect.verifySteps([]);
8319 });
8320
8321 test(`click on a button in a list view`, async () => {
8322 mockService("action", {
8323 doActionButton(action) {
8324 expect.step("doActionButton");
8325 expect(action.resId).toBe(1, { message: "should call with correct id" });
8326 expect(action.resModel).toBe("foo", { message: "should call with correct model" });
8327 expect(action.name).toBe("button_action", {
8328 message: "should call correct method",
8329 });
8330 expect(action.type).toBe("object", { message: "should have correct type" });
8331 action.onClose();
8332 },
8333 });
8334
8335 stepAllNetworkCalls();
8336
8337 await mountView({
8338 resModel: "foo",
8339 type: "list",
8340 arch: `
8341 <list>
8342 <field name="foo"/>
8343 <button string="a button" name="button_action" icon="fa-car" type="object"/>
8344 </list>
8345 `,
8346 });
8347 expect.verifySteps([
8348 "/web/webclient/translations",
8349 "/web/webclient/load_menus",
8350 "get_views",
8351 "web_search_read",
8352 "has_group",
8353 ]);
8354 expect(`tbody .o_list_button`).toHaveCount(4, {
8355 message: "there should be one button per row",
8356 });
8357 expect(`.o_data_row .o_list_button .o_button_icon.fa.fa-car`).toHaveCount(4);
8358
8359 await contains(`.o_data_row .o_list_button button`).click();
8360 // should have reloaded the view (after the action is complete)
8361 expect.verifySteps(["doActionButton", "web_search_read"]);
8362 });
8363
8364 test("click on a button in a list view on second page", async () => {
8365 onRpc("web_search_read", ({ kwargs }) => {
8366 expect.step(`web_search_read (offset: ${kwargs.offset})`);
8367 });
8368 mockService("action", {
8369 doActionButton: (action) => {
8370 expect.step("doActionButton");
8371 action.onClose();
8372 },
8373 });
8374
8375 await mountView({
8376 resModel: "foo",
8377 type: "list",
8378 arch: `
8379 <list limit="3">
8380 <field name="foo"/>
8381 <button string="a button" name="button_action" icon="fa-car" type="object"/>
8382 </list>
8383 `,
8384 });
8385
8386 expect(".o_data_row").toHaveCount(3);
8387
8388 await pagerNext();
8389 expect(".o_data_row").toHaveCount(1);
8390
8391 await contains(".o_data_row .o_list_button button").click();
8392 expect(".o_data_row").toHaveCount(1);
8393
8394 expect.verifySteps([
8395 "web_search_read (offset: 0)",
8396 "web_search_read (offset: 3)",
8397 "doActionButton",
8398 "web_search_read (offset: 3)",
8399 ]);
8400 });
8401
8402 test.tags("desktop");
8403 test(`invisible attrs in readonly and editable list`, async () => {
8404 await mountView({
8405 resModel: "foo",
8406 type: "list",
8407 arch: `
8408 <list editable="top">
8409 <button string="a button" name="button_action" icon="fa-car" type="object" invisible="id == 1"/>
8410 <field name="int_field"/>
8411 <field name="qux"/>
8412 <field name="foo" invisible="id == 1"/>
8413 </list>
8414 `,
8415 });
8416 expect(`.o_field_cell:eq(2)`).toHaveInnerHTML("");
8417 expect(`.o_data_cell.o_list_button:eq(0)`).toHaveInnerHTML(
8418 `<div class="d-flex flex-wrap gap-1"></div>`
8419 );
8420
8421 // edit first row
8422 await contains(`.o_field_cell`).click();
8423 expect(`.o_field_cell:eq(2)`).toHaveInnerHTML("");
8424 expect(`.o_data_cell.o_list_button:eq(0)`).toHaveInnerHTML(
8425 `<div class="d-flex flex-wrap gap-1"></div>`
8426 );
8427
8428 await contains(`.o_list_button_discard:not(.dropdown-item)`).click();
8429 // click on the invisible field's cell to edit first row
8430 await contains(`.o_field_cell[name=foo]`).click();
8431 expect(`.o_data_row:eq(0)`).toHaveClass("o_selected_row");
8432 });
8433
8434 test.tags("desktop");
8435 test(`monetary fields are properly rendered on desktop`, async () => {
8436 await mountView({
8437 resModel: "foo",
8438 type: "list",
8439 arch: `
8440 <list>
8441 <field name="id"/>
8442 <field name="amount"/>
8443 <field name="currency_id" column_invisible="1"/>
8444 </list>
8445 `,
8446 });
8447 expect(`tbody tr:eq(0) td`).toHaveCount(3, {
8448 message: "currency_id column should not be in the table",
8449 });
8450 expect(`tbody .o_data_row:eq(0) .o_data_cell:nth-child(3)`).toHaveText("1,200.00 €", {
8451 message: "currency_id column should not be in the table",
8452 });
8453 expect(`tbody .o_data_row:eq(1) .o_data_cell:nth-child(3)`).toHaveText("$ 500.00", {
8454 message: "currency_id column should not be in the table",
8455 });
8456 });
8457
8458 test.tags("mobile");
8459 test(`monetary fields are properly rendered on mobile`, async () => {
8460 await mountView({
8461 resModel: "foo",
8462 type: "list",
8463 arch: `
8464 <list>
8465 <field name="id"/>
8466 <field name="amount"/>
8467 <field name="currency_id" column_invisible="1"/>
8468 </list>
8469 `,
8470 });
8471 expect(`tbody tr:eq(0) td`).toHaveCount(2, {
8472 message: "currency_id column should not be in the table",
8473 });
8474 expect(`tbody .o_data_row:eq(0) .o_data_cell:nth-child(2)`).toHaveText("1,200.00 €", {
8475 message: "currency_id column should not be in the table",
8476 });
8477 expect(`tbody .o_data_row:eq(1) .o_data_cell:nth-child(2)`).toHaveText("$ 500.00", {
8478 message: "currency_id column should not be in the table",
8479 });
8480 });
8481
8482 test(`simple list with date and datetime`, async () => {
8483 mockTimeZone(+2);
8484
8485 await mountView({
8486 resModel: "foo",
8487 type: "list",
8488 arch: `<list><field name="date"/><field name="datetime"/></list>`,
8489 });
8490 expect(`.o_data_row .o_data_cell:eq(0)`).toHaveText("Jan 25, 2017", {
8491 message: "should have formatted the date",
8492 });
8493 expect(`.o_data_row .o_data_cell:eq(1)`).toHaveText("Dec 12, 2016, 12:55 PM", {
8494 message: "should have formatted the datetime",
8495 });
8496 });
8497
8498 test(`edit a row by clicking on a readonly field`, async () => {
8499 Foo._fields.foo = fields.Char({ readonly: true });
8500 await mountView({
8501 resModel: "foo",
8502 type: "list",
8503 arch: `<list editable="bottom"><field name="foo"/><field name="int_field"/></list>`,
8504 });
8505
8506 // edit the first row
8507 await contains(`.o_field_cell`).click();
8508 expect(`.o_data_row:eq(0)`).toHaveClass("o_selected_row", {
8509 message: "first row should be selected",
8510 });
8511 expect(`.o_data_row:eq(0)`).toHaveClass("o_selected_row");
8512 expect(`.o_selected_row .o_field_widget[name=foo]`).toHaveClass("o_readonly_modifier");
8513 expect(`.o_selected_row .o_field_widget[name=foo] span`).toHaveText("yop", {
8514 message: "a widget should have been rendered for readonly fields",
8515 });
8516 expect(`.o_selected_row .o_field_widget[name=int_field] input`).toHaveCount(1, {
8517 message: "'int_field' should be editable",
8518 });
8519
8520 // click again on readonly cell of first line: nothing should have changed
8521 await contains(`.o_field_cell`).click();
8522 expect(`.o_data_row:eq(0)`).toHaveClass("o_selected_row");
8523 expect(`.o_selected_row .o_field_widget[name=foo]`).toHaveClass("o_readonly_modifier");
8524 expect(`.o_selected_row .o_field_widget[name=int_field] input`).toHaveCount(1, {
8525 message: "'int_field' should be editable",
8526 });
8527 });
8528
8529 test(`list view with nested groups`, async () => {
8530 Foo._records.push({ id: 5, foo: "blip", int_field: -7, m2o: 1 });
8531 Foo._records.push({ id: 6, foo: "blip", int_field: 5, m2o: 2 });
8532
8533 onRpc("web_read_group", ({ kwargs }) => {
8534 if (kwargs.groupby[0] === "foo") {
8535 // nested web_read_group
8536 // called twice (once when opening the group, once when sorting)
8537 expect(kwargs.domain).toEqual([["m2o", "=", 1]], {
8538 message: "nested web_read_group should be called with correct domain",
8539 });
8540 }
8541 expect.step("web_read_group");
8542 });
8543 onRpc("web_search_read", ({ kwargs }) => {
8544 // called twice (once when opening the group, once when sorting)
8545 expect(kwargs.domain).toEqual(["&", ["m2o", "=", 1], ["foo", "=", "blip"]], {
8546 message: "nested web_search_read should be called with correct domain",
8547 });
8548 expect.step("web_search_read");
8549 });
8550
8551 await mountView({
8552 resModel: "foo",
8553 type: "list",
8554 arch: `<list><field name="id"/><field name="int_field"/></list>`,
8555 groupBy: ["m2o", "foo"],
8556 selectRecord(resId, options) {
8557 expect.step(`switch to form - resId: ${resId}`);
8558 },
8559 });
8560 expect.verifySteps(["web_read_group"]);
8561
8562 // basic rendering tests
8563 expect(`.o_group_header`).toHaveCount(2);
8564 expect(queryAllTexts(`.o_group_name`)).toEqual(["Value 1 (4)", "Value 2 (2)"]);
8565 expect(`.o_group_name .fa-caret-right`).toHaveCount(2);
8566 expect(`.o_group_header:eq(0) span:first`).toHaveStyle({ "--o-list-group-level": "0" });
8567 expect(queryAllTexts(`.o_group_header .o_list_number`)).toEqual(["16", "14"]);
8568
8569 // open the first group
8570 await contains(`.o_group_header:eq(0)`).click();
8571 expect.verifySteps(["web_read_group"]);
8572 expect(queryAllTexts(`.o_group_name`)).toEqual([
8573 "Value 1 (4)",
8574 "blip (2)",
8575 "gnap (1)",
8576 "yop (1)",
8577 "Value 2 (2)",
8578 ]);
8579 expect(`.o_group_name:eq(0) .fa-caret-down`).toHaveCount(1);
8580 expect(`.o_group_header:eq(1) span:first`).toHaveStyle({ "--o-list-group-level": "1" });
8581 expect(queryAllTexts(`.o_group_header .o_list_number`)).toEqual([
8582 "16",
8583 "-11",
8584 "17",
8585 "10",
8586 "14",
8587 ]);
8588
8589 // open subgroup
8590 await contains(`.o_group_header:eq(1)`).click();
8591 expect.verifySteps(["web_search_read"]);
8592 expect(`.o_group_header`).toHaveCount(5);
8593 expect(`.o_data_row`).toHaveCount(2);
8594 expect(queryAllTexts(`.o_data_row .o_data_cell`)).toEqual(["4", "-4", "5", "-7"]);
8595
8596 // open a record (should trigger event 'open_record')
8597 await contains(`.o_data_row .o_data_cell`).click();
8598 expect.verifySteps([`switch to form - resId: 4`]);
8599
8600 // sort by int_field (ASC) and check that open groups are still open
8601 await contains(`.o_list_view thead [data-name='int_field']`).click();
8602 expect.verifySteps(["web_read_group"]);
8603 expect(`.o_group_header`).toHaveCount(5);
8604 expect(`.o_data_row`).toHaveCount(2);
8605 expect(queryAllTexts(`.o_data_row .o_data_cell`)).toEqual(["5", "-7", "4", "-4"]);
8606
8607 // close first level group
8608 await contains(`.o_group_header:eq(1)`).click();
8609 expect.verifySteps([]);
8610 expect(`.o_group_header`).toHaveCount(2);
8611 expect(`.o_group_name .fa-caret-right`).toHaveCount(2);
8612 expect(`.o_data_row`).toHaveCount(0);
8613 });
8614
8615 test(`grouped list on selection field at level 2`, async () => {
8616 Foo._fields.priority = fields.Selection({
8617 selection: [
8618 [1, "Low"],
8619 [2, "Medium"],
8620 [3, "High"],
8621 ],
8622 default: 1,
8623 });
8624 Foo._records.push({
8625 id: 5,
8626 foo: "blip",
8627 int_field: -7,
8628 m2o: 1,
8629 priority: 2,
8630 });
8631 Foo._records.push({
8632 id: 6,
8633 foo: "blip",
8634 int_field: 5,
8635 m2o: 1,
8636 priority: 3,
8637 });
8638
8639 await mountView({
8640 resModel: "foo",
8641 type: "list",
8642 arch: `<list><field name="id"/><field name="int_field"/></list>`,
8643 groupBy: ["m2o", "priority"],
8644 });
8645 expect(`.o_group_header`).toHaveCount(2, { message: "should contain 2 groups at first level" });
8646
8647 // open the first group
8648 await contains(`.o_group_header`).click();
8649 expect(`.o_group_header`).toHaveCount(5, {
8650 message: "should contain 2 groups at first level and 3 groups at second level",
8651 });
8652 expect(queryAllTexts(`.o_group_header .o_group_name`)).toEqual([
8653 "Value 1 (5)",
8654 "Low (3)",
8655 "Medium (1)",
8656 "High (1)",
8657 "Value 2 (1)",
8658 ]);
8659 });
8660
8661 test.tags("desktop");
8662 test(`grouped list with a pager in a group`, async () => {
8663 Foo._records[3].bar = true;
8664
8665 await mountView({
8666 resModel: "foo",
8667 type: "list",
8668 arch: `<list><field name="foo"/><field name="bar"/></list>`,
8669 groupBy: ["bar"],
8670 limit: 3,
8671 });
8672 const headerHeight = queryFirst(`.o_group_header`).offsetHeight;
8673 // basic rendering checks
8674 await contains(`.o_group_header`).click();
8675 expect(queryFirst(`.o_group_header`).offsetHeight).toBe(headerHeight, {
8676 message: "height of group header shouldn't have changed",
8677 });
8678 expect(`.o_group_header th nav`).toHaveClass("o_pager", {
8679 message: "last cell of open group header should have classname 'o_pager'",
8680 });
8681 expect(`.o_group_header .o_pager .o_pager_value`).toHaveText("1-3");
8682 expect(`.o_data_row`).toHaveCount(3);
8683
8684 // go to next page
8685 await contains(`.o_group_header .o_pager button.o_pager_next`).click();
8686 expect(`.o_group_header .o_pager .o_pager_value`).toHaveText("4-4");
8687 expect(`.o_data_row`).toHaveCount(1);
8688 });
8689
8690 test.tags("desktop");
8691 test(`edition: create new line, then discard`, async () => {
8692 await mountView({
8693 resModel: "foo",
8694 type: "list",
8695 arch: `<list editable="bottom"><field name="foo"/><field name="bar"/></list>`,
8696 });
8697 expect(`tr.o_data_row`).toHaveCount(4, { message: "should have 4 records" });
8698 expect(`.o_list_button_add`).toHaveCount(1);
8699 expect(`.o_list_button_discard`).toHaveCount(0);
8700 expect(`.o_list_record_selector input:enabled`).toHaveCount(5);
8701
8702 await contains(`.o_list_button_add`).click();
8703 expect(`.o_list_button_add`).toHaveCount(0);
8704 expect(`.o_list_button_discard`).toHaveCount(1);
8705 expect(`.o_list_record_selector input:enabled`).toHaveCount(0);
8706
8707 await contains(`.o_list_button_discard:not(.dropdown-item)`).click();
8708 expect(`tr.o_data_row`).toHaveCount(4, { message: "should still have 4 records" });
8709 expect(`.o_list_button_add`).toHaveCount(1);
8710 expect(`.o_list_button_discard`).toHaveCount(0);
8711 expect(`.o_list_record_selector input:enabled`).toHaveCount(5);
8712 });
8713
8714 test.tags("desktop");
8715 test(`invisible attrs on fields are re-evaluated on field change on desktop`, async () => {
8716 await mountView({
8717 resModel: "foo",
8718 type: "list",
8719 arch: `
8720 <list editable="top">
8721 <field name="foo" invisible="bar"/>
8722 <field name="bar"/>
8723 </list>
8724 `,
8725 });
8726 expect(queryAllTexts(`.o_data_cell.o_list_char`)).toEqual(["", "", "", "blip"]);
8727
8728 // Make first line editable
8729 await contains(`.o_field_cell`).click();
8730 expect(`.o_selected_row .o_list_char .o_field_widget[name=foo]`).toHaveCount(0);
8731
8732 await contains(`.o_field_widget[name=bar] input`).click();
8733 expect(`.o_selected_row .o_list_char .o_field_widget[name=foo]`).toHaveCount(1);
8734 expect(`.o_list_char input`).toHaveValue("yop");
8735 expect(queryAllTexts(`.o_data_cell.o_list_char`)).toEqual(["", "", "", "blip"]);
8736
8737 await contains(`.o_field_widget[name=bar] input`).click();
8738 expect(`.o_selected_row .o_list_char .o_field_widget[name=foo]`).toHaveCount(0);
8739 expect(queryAllTexts(`.o_data_cell.o_list_char`)).toEqual(["", "", "", "blip"]);
8740
8741 // Reswitch the field to visible and save the row
8742 await contains(`.o_field_widget[name=bar] input`).click();
8743 await contains(`.o_list_button_save`).click();
8744 expect(queryAllTexts(`.o_data_cell.o_list_char`)).toEqual(["yop", "", "", "blip"]);
8745 });
8746
8747 test.tags("mobile");
8748 test(`invisible attrs on fields are re-evaluated on field change on mobile`, async () => {
8749 await mountView({
8750 resModel: "foo",
8751 type: "list",
8752 arch: `
8753 <list editable="top">
8754 <field name="foo" invisible="bar"/>
8755 <field name="bar"/>
8756 </list>
8757 `,
8758 });
8759 expect(queryAllTexts(`.o_data_cell.o_list_char`)).toEqual(["", "", "", "blip"]);
8760
8761 // Make first line editable
8762 await contains(`.o_field_cell`).click();
8763 expect(`.o_selected_row .o_list_char .o_field_widget[name=foo]`).toHaveCount(0);
8764
8765 await contains(`.o_field_widget[name=bar] input`).click();
8766 expect(`.o_selected_row .o_list_char .o_field_widget[name=foo]`).toHaveCount(1);
8767 expect(`.o_list_char input`).toHaveValue("yop");
8768 expect(queryAllTexts(`.o_data_cell.o_list_char`)).toEqual(["", "", "", "blip"]);
8769
8770 await contains(`.o_field_widget[name=bar] input`).click();
8771 expect(`.o_selected_row .o_list_char .o_field_widget[name=foo]`).toHaveCount(0);
8772 expect(queryAllTexts(`.o_data_cell.o_list_char`)).toEqual(["", "", "", "blip"]);
8773
8774 // Reswitch the field to visible and save the row
8775 await contains(`.o_field_widget[name=bar] input`).click();
8776 await contains(`.o_list_button_save`).click();
8777 expect(queryAllTexts(`.o_data_cell.o_list_char`)).toEqual(["yop", "", "", "blip"]);
8778 });
8779
8780 test(`readonly attrs on fields are re-evaluated on field change`, async () => {
8781 await mountView({
8782 resModel: "foo",
8783 type: "list",
8784 arch: `
8785 <list editable="top">
8786 <field name="foo" readonly="bar"/>
8787 <field name="bar"/>
8788 </list>
8789 `,
8790 });
8791
8792 // Make first line editable
8793 await contains(`.o_field_cell`).click();
8794 expect(`.o_selected_row`).toHaveCount(1);
8795 expect(`.o_selected_row .o_field_widget[name=foo] span`).toHaveCount(1);
8796 expect(`.o_selected_row .o_field_widget[name=foo]`).toHaveClass("o_readonly_modifier");
8797
8798 await contains(`.o_field_widget[name=bar] input`).click();
8799 expect(`.o_selected_row .o_field_widget[name=foo] input`).toHaveCount(1);
8800 expect(`.o_selected_row .o_field_widget[name=foo]`).not.toHaveClass("o_readonly_modifier");
8801
8802 await contains(`.o_field_widget[name=bar] input`).click();
8803 expect(`.o_selected_row .o_field_widget[name=foo] span`).toHaveCount(1);
8804 expect(`.o_selected_row .o_field_widget[name=foo]`).toHaveClass("o_readonly_modifier");
8805
8806 await contains(`.o_field_widget[name=bar] input`).click();
8807 expect(`.o_selected_row .o_field_widget[name=foo] input`).toHaveCount(1);
8808 expect(`.o_selected_row .o_field_widget[name=foo]`).not.toHaveClass("o_readonly_modifier");
8809
8810 // Click outside to leave edition mode and make first line editable again
8811 await contains(`.o_control_panel`).click();
8812 expect(`.o_selected_row`).toHaveCount(0);
8813
8814 await contains(`.o_field_cell`).click();
8815 expect(`.o_selected_row`).toHaveCount(1);
8816 expect(`.o_selected_row .o_field_widget[name=foo] input`).toHaveCount(1);
8817 expect(`.o_selected_row .o_field_widget[name=foo]`).not.toHaveClass("o_readonly_modifier");
8818 });
8819
8820 test.tags("desktop");
8821 test(`required attrs on fields are re-evaluated on field change on desktop`, async () => {
8822 await mountView({
8823 resModel: "foo",
8824 type: "list",
8825 arch: `
8826 <list editable="top">
8827 <field name="foo" required="bar"/>
8828 <field name="bar"/>
8829 </list>
8830 `,
8831 });
8832
8833 // Make first line editable
8834 await contains(`.o_field_cell`).click();
8835 expect(`.o_selected_row .o_field_widget[name=foo]`).toHaveClass("o_required_modifier");
8836
8837 await contains(`.o_field_widget[name=bar] input`).click();
8838 expect(`.o_selected_row .o_field_widget[name=foo]`).not.toHaveClass("o_required_modifier");
8839
8840 await contains(`.o_field_widget[name=bar] input`).click();
8841 expect(`.o_selected_row .o_field_widget[name=foo]`).toHaveClass("o_required_modifier");
8842
8843 // Reswitch the field to required and save the row and make first line editable again
8844 await contains(`.o_field_widget[name=bar] input`).click();
8845 expect(`.o_selected_row .o_field_widget[name=foo]`).not.toHaveClass("o_required_modifier");
8846
8847 await contains(`.o_list_button_save`).click();
8848 await contains(`.o_field_cell`).click();
8849 expect(`.o_selected_row .o_field_widget[name=foo]`).not.toHaveClass("o_required_modifier");
8850 });
8851
8852 test.tags("mobile");
8853 test(`required attrs on fields are re-evaluated on field change on mobile`, async () => {
8854 await mountView({
8855 resModel: "foo",
8856 type: "list",
8857 arch: `
8858 <list editable="top">
8859 <field name="foo" required="bar"/>
8860 <field name="bar"/>
8861 </list>
8862 `,
8863 });
8864
8865 // Make first line editable
8866 await contains(`.o_field_cell`).click();
8867 expect(`.o_selected_row .o_field_widget[name=foo]`).toHaveClass("o_required_modifier");
8868
8869 await contains(`.o_field_widget[name=bar] input`).click();
8870 expect(`.o_selected_row .o_field_widget[name=foo]`).not.toHaveClass("o_required_modifier");
8871
8872 await contains(`.o_field_widget[name=bar] input`).click();
8873 expect(`.o_selected_row .o_field_widget[name=foo]`).toHaveClass("o_required_modifier");
8874
8875 // Reswitch the field to required and save the row and make first line editable again
8876 await contains(`.o_field_widget[name=bar] input`).click();
8877 expect(`.o_selected_row .o_field_widget[name=foo]`).not.toHaveClass("o_required_modifier");
8878
8879 await contains(`.o_list_button_save`).click();
8880 await contains(`.o_field_cell`).click();
8881 expect(`.o_selected_row .o_field_widget[name=foo]`).not.toHaveClass("o_required_modifier");
8882 });
8883
8884 test(`modifiers of other x2many rows a re-evaluated when a subrecord is updated`, async () => {
8885 // In an x2many, a change on a subrecord might trigger an onchange on the x2many that
8886 // updates other sub-records than the edited one. For that reason, modifiers must be
8887 // re-evaluated.
8888 Foo._onChanges = {
8889 o2m(record) {
8890 record.o2m = [
8891 [1, 1, { display_name: "Value 1", stage: "open" }],
8892 [1, 2, { display_name: "Value 2", stage: "draft" }],
8893 ];
8894 },
8895 };
8896 Foo._records[0].o2m = [1, 2];
8897 Bar._fields.stage = fields.Selection({
8898 selection: [
8899 ["draft", "Draft"],
8900 ["open", "Open"],
8901 ],
8902 });
8903 Bar._records[0].stage = "draft";
8904 Bar._records[1].stage = "open";
8905
8906 await mountView({
8907 resModel: "foo",
8908 type: "form",
8909 arch: `
8910 <form>
8911 <field name="o2m">
8912 <list editable="top">
8913 <field name="display_name" invisible="stage == 'open'"/>
8914 <field name="stage"/>
8915 </list>
8916 </field>
8917 </form>
8918 `,
8919 resId: 1,
8920 });
8921 expect(queryAllTexts(`.o_field_widget[name=o2m] .o_data_row .o_data_cell:first-child`)).toEqual(
8922 ["Value 1", ""]
8923 );
8924
8925 // Make a change in the list to trigger the onchange
8926 await contains(`.o_field_widget[name=o2m] .o_data_row .o_data_cell:eq(1)`).click();
8927 await editSelectMenu(".o_field_widget[name=o2m] .o_data_row [name=stage] input", {
8928 value: "Open",
8929 });
8930 expect(queryAllTexts(`.o_field_widget[name=o2m] .o_data_row .o_data_cell:first-child`)).toEqual(
8931 ["", "Value 2"]
8932 );
8933 expect(`.o_data_row:eq(1)`).toHaveText("Value 2 Draft", {
8934 message: "the onchange should have been applied",
8935 });
8936 });
8937
8938 test(`leaving unvalid rows in edition`, async () => {
8939 let warnings = 0;
8940 mockService("notification", {
8941 add(message, { type }) {
8942 if (type === "danger") {
8943 warnings++;
8944 }
8945 },
8946 });
8947
8948 await mountView({
8949 resModel: "foo",
8950 type: "list",
8951 arch: `
8952 <list editable="bottom">
8953 <field name="foo" required="1"/>
8954 <field name="bar"/>
8955 </list>
8956 `,
8957 });
8958
8959 // Start first line edition
8960 await contains(`.o_data_cell`).click();
8961
8962 // Remove required foo field value
8963 await contains(`.o_selected_row .o_field_widget[name=foo] input`).edit("", { confirm: false });
8964
8965 // Try starting other line edition
8966 await contains(`.o_data_row:eq(1) .o_data_cell`).click();
8967 expect(`.o_data_row:eq(0)`).toHaveClass("o_selected_row", {
8968 message: "first line should still be in edition as invalid",
8969 });
8970 expect(`.o_selected_row`).toHaveCount(1, { message: "no other line should be in edition" });
8971 expect(`.o_data_row:eq(0) .o_field_invalid input`).toHaveCount(1, {
8972 message: "the required field should be marked as invalid",
8973 });
8974 expect(warnings).toBe(1, { message: "a warning should have been displayed" });
8975 });
8976
8977 test.tags("desktop");
8978 test(`pressing enter on last line of editable list view`, async () => {
8979 stepAllNetworkCalls();
8980
8981 await mountView({
8982 resModel: "foo",
8983 type: "list",
8984 arch: `<list editable="bottom"><field name="foo"/></list>`,
8985 });
8986 expect.verifySteps([
8987 "/web/webclient/translations",
8988 "/web/webclient/load_menus",
8989 "get_views",
8990 "web_search_read",
8991 "has_group",
8992 ]);
8993 expect(`tr.o_data_row`).toHaveCount(4);
8994
8995 // click on 3rd line
8996 await contains(`tr.o_data_row:eq(2) .o_field_cell[name=foo]`).click();
8997 expect(`tr.o_data_row:eq(2)`).toHaveClass("o_selected_row");
8998 expect(`.o_selected_row [name=foo] input`).toBeFocused();
8999
9000 // press enter in input
9001 await press("Enter");
9002 await animationFrame();
9003 expect(`tr.o_data_row:eq(3)`).toHaveClass("o_selected_row");
9004 expect(`.o_selected_row [name=foo] input`).toBeFocused();
9005
9006 // press enter on last row
9007 await press("Enter");
9008 await animationFrame();
9009 expect(`tr.o_data_row`).toHaveCount(5);
9010 expect(`tr.o_data_row:eq(4)`).toHaveClass("o_selected_row");
9011 expect.verifySteps(["onchange"]);
9012 });
9013
9014 test.tags("desktop");
9015 test(`pressing tab on last cell of editable list view`, async () => {
9016 stepAllNetworkCalls();
9017
9018 await mountView({
9019 resModel: "foo",
9020 type: "list",
9021 arch: `<list editable="bottom"><field name="foo"/><field name="int_field"/></list>`,
9022 });
9023 await contains(`.o_data_row:eq(3) .o_data_cell`).click();
9024 expect(`[name=foo] input`).toBeFocused();
9025
9026 //it will not create a new line unless a modification is made
9027 await contains(`[name=foo] input`).edit("blip-changed", { confirm: "tab" });
9028 expect(`[name=int_field] input`).toBeFocused();
9029 await press("Tab");
9030 await animationFrame();
9031 expect(`tr.o_data_row:eq(4)`).toHaveClass("o_selected_row", {
9032 message: "5th row should be selected",
9033 });
9034
9035 await contains(`[name=foo] input`).edit("blip-changed", { confirm: false });
9036 expect(`[name=foo] input`).toBeFocused();
9037 expect.verifySteps([
9038 "/web/webclient/translations",
9039 "/web/webclient/load_menus",
9040 "get_views",
9041 "web_search_read",
9042 "has_group",
9043 "web_save",
9044 "onchange",
9045 ]);
9046 });
9047
9048 test.tags("desktop");
9049 test(`navigation with tab and read completes after default_get`, async () => {
9050 stepAllNetworkCalls();
9051 const onchangePromise = new Deferred();
9052 const readPromise = new Deferred();
9053 onRpc("onchange", () => onchangePromise);
9054 onRpc("web_save", () => readPromise);
9055
9056 await mountView({
9057 resModel: "foo",
9058 type: "list",
9059 arch: `<list editable="bottom"><field name="foo"/><field name="int_field"/></list>`,
9060 });
9061 await contains(`.o_data_row:eq(3) .o_data_cell`).click();
9062 await contains(`.o_selected_row [name='int_field'] input`).edit("1234");
9063
9064 onchangePromise.resolve();
9065 await animationFrame();
9066 expect(`tbody tr.o_data_row`).toHaveCount(4, { message: "should have 4 data rows" });
9067
9068 readPromise.resolve();
9069 await animationFrame();
9070 expect(`tbody tr.o_data_row`).toHaveCount(5, { message: "should have 5 data rows" });
9071 expect(`td:contains(1,234)`).toHaveCount(1, { message: "should have a cell with new value" });
9072
9073 // we trigger a tab to move to the second cell in the current row. this
9074 // operation requires that this.currentRow is properly set in the
9075 // list editable renderer.
9076 await press("Tab");
9077 await animationFrame();
9078 expect(`tr.o_data_row:eq(4)`).toHaveClass("o_selected_row", {
9079 message: "5th row should be selected",
9080 });
9081 expect.verifySteps([
9082 "/web/webclient/translations",
9083 "/web/webclient/load_menus",
9084 "get_views",
9085 "web_search_read",
9086 "has_group",
9087 "web_save",
9088 "onchange",
9089 ]);
9090 });
9091
9092 test(`display toolbar`, async () => {
9093 await mountView({
9094 resModel: "foo",
9095 type: "list",
9096 arch: `<list><field name="foo"/></list>`,
9097 info: {
9098 actionMenus: {
9099 action: [
9100 {
9101 id: 29,
9102 name: "Action event",
9103 },
9104 ],
9105 },
9106 },
9107 });
9108 expect(`div.o_control_panel .o_cp_action_menus`).toHaveCount(1);
9109
9110 await clickRecordSelector();
9111 await toggleActionMenu();
9112 expect(queryAllTexts(`.o-dropdown--menu .dropdown-item`)).toEqual([
9113 "Export",
9114 "Duplicate",
9115 "Delete",
9116 "Action event",
9117 ]);
9118 });
9119
9120 test.tags("desktop");
9121 test(`execute ActionMenus actions on desktop`, async () => {
9122 stepAllNetworkCalls();
9123
9124 mockService("action", {
9125 doAction(id, { additionalContext, onClose }) {
9126 expect.step({ action_id: id, context: additionalContext });
9127 onClose(); // simulate closing of target new action's dialog
9128 },
9129 });
9130
9131 await mountView({
9132 resModel: "foo",
9133 type: "list",
9134 arch: `<list><field name="foo"/></list>`,
9135 info: {
9136 actionMenus: {
9137 action: [
9138 {
9139 id: 44,
9140 name: "Custom Action",
9141 target: "new",
9142 },
9143 ],
9144 print: [],
9145 },
9146 },
9147 actionMenus: {},
9148 });
9149
9150 expect(`div.o_control_panel .o_cp_action_menus`).toHaveCount(1);
9151 expect(`.o_data_row`).toHaveCount(4);
9152 // select all records
9153 await contains(`thead .o_list_record_selector input`).click();
9154 expect(`.o_list_record_selector input:checked`).toHaveCount(5);
9155 expect(`div.o_control_panel .o_cp_action_menus`).toHaveCount(1);
9156
9157 await contains(`.o_cp_action_menus .dropdown-toggle`).click();
9158 await toggleMenuItem("Custom Action");
9159
9160 expect.verifySteps([
9161 "/web/webclient/translations",
9162 "/web/webclient/load_menus",
9163 "get_views",
9164 "web_search_read",
9165 "has_group",
9166 {
9167 action_id: 44,
9168 context: {
9169 lang: "en",
9170 tz: "taht",
9171 uid: 7,
9172 allowed_company_ids: [1],
9173 active_id: 1,
9174 active_ids: [1, 2, 3, 4],
9175 active_model: "foo",
9176 active_domain: [],
9177 },
9178 },
9179 "web_search_read",
9180 ]);
9181 });
9182
9183 test.tags("mobile");
9184 test(`execute ActionMenus actions on mobile`, async () => {
9185 stepAllNetworkCalls();
9186
9187 mockService("action", {
9188 doAction(id, { additionalContext, onClose }) {
9189 expect.step({ action_id: id, context: additionalContext });
9190 onClose(); // simulate closing of target new action's dialog
9191 },
9192 });
9193
9194 await mountView({
9195 resModel: "foo",
9196 type: "list",
9197 arch: `<list><field name="foo"/></list>`,
9198 info: {
9199 actionMenus: {
9200 action: [
9201 {
9202 id: 44,
9203 name: "Custom Action",
9204 type: "ir.actions.act_window",
9205 target: "new",
9206 },
9207 ],
9208 print: [],
9209 },
9210 },
9211 actionMenus: {},
9212 });
9213
9214 expect(`div.o_control_panel .o_cp_action_menus`).toHaveCount(1);
9215 expect(`.o_data_row`).toHaveCount(4);
9216 // select all records
9217 await selectAllRecords();
9218 expect(`.o_data_row.o_data_row_selected`).toHaveCount(4);
9219 expect(`div.o_control_panel .o_cp_action_menus`).toHaveCount(1);
9220
9221 await toggleActionMenu();
9222 await toggleMenuItem("Custom Action");
9223
9224 expect.verifySteps([
9225 "/web/webclient/translations",
9226 "/web/webclient/load_menus",
9227 "get_views",
9228 "web_search_read",
9229 "has_group",
9230 {
9231 action_id: 44,
9232 context: {
9233 lang: "en",
9234 tz: "taht",
9235 uid: 7,
9236 allowed_company_ids: [1],
9237 active_id: 1,
9238 active_ids: [1, 2, 3, 4],
9239 active_model: "foo",
9240 active_domain: [],
9241 },
9242 },
9243 "web_search_read",
9244 ]);
9245 });
9246
9247 test.tags("desktop");
9248 test(`execute ActionMenus actions with correct params (single page) on desktop`, async () => {
9249 mockService("action", {
9250 doAction(id, { additionalContext }) {
9251 expect.step({ action_id: id, context: additionalContext });
9252 },
9253 });
9254
9255 await mountView({
9256 resModel: "foo",
9257 type: "list",
9258 arch: `<list><field name="foo"/></list>`,
9259 info: {
9260 actionMenus: {
9261 action: [
9262 {
9263 id: 44,
9264 name: "Custom Action",
9265 type: "ir.actions.server",
9266 },
9267 ],
9268 print: [],
9269 },
9270 },
9271 actionMenus: {},
9272 searchViewArch: `
9273 <search>
9274 <filter name="bar" domain="[('bar', '=', true)]"/>
9275 </search>
9276 `,
9277 });
9278 expect(`div.o_control_panel .o_cp_action_menus`).toHaveCount(1);
9279 expect(`.o_data_row`).toHaveCount(4);
9280
9281 // select all records
9282 await contains(`thead .o_list_record_selector input`).click();
9283 expect(`.o_list_record_selector input:checked`).toHaveCount(5);
9284 expect(`div.o_control_panel .o_cp_action_menus`).toHaveCount(1);
9285
9286 await contains(`.o_cp_action_menus .dropdown-toggle`).click();
9287 await toggleMenuItem("Custom Action");
9288
9289 // unselect first record (will unselect the thead checkbox as well)
9290 await contains(`.o_data_row .o_list_record_selector input`).click();
9291 expect(`.o_list_record_selector input:checked`).toHaveCount(3);
9292
9293 await contains(`.o_cp_action_menus .dropdown-toggle`).click();
9294 await toggleMenuItem("Custom Action");
9295
9296 // add a domain and select first two records (need to unselect records first)
9297 await contains(`thead .o_list_record_selector input`).click(); // select all
9298 await contains(`thead .o_list_record_selector input`).click(); // unselect all
9299 await toggleSearchBarMenu();
9300 await toggleMenuItem("bar");
9301 expect(`.o_data_row`).toHaveCount(3);
9302 expect(`.o_list_record_selector input:checked`).toHaveCount(0);
9303
9304 await contains(`.o_data_row:eq(0) .o_list_record_selector input`).click();
9305 await contains(`.o_data_row:eq(1) .o_list_record_selector input`).click();
9306 expect(`.o_list_record_selector input:checked`).toHaveCount(2);
9307
9308 await contains(`.o_cp_action_menus .dropdown-toggle`).click();
9309 await toggleMenuItem("Custom Action");
9310 expect.verifySteps([
9311 {
9312 action_id: 44,
9313 context: {
9314 lang: "en",
9315 tz: "taht",
9316 uid: 7,
9317 allowed_company_ids: [1],
9318 active_id: 1,
9319 active_ids: [1, 2, 3, 4],
9320 active_model: "foo",
9321 active_domain: [],
9322 },
9323 },
9324 {
9325 action_id: 44,
9326 context: {
9327 lang: "en",
9328 tz: "taht",
9329 uid: 7,
9330 allowed_company_ids: [1],
9331 active_id: 2,
9332 active_ids: [2, 3, 4],
9333 active_model: "foo",
9334 active_domain: [],
9335 },
9336 },
9337 {
9338 action_id: 44,
9339 context: {
9340 lang: "en",
9341 tz: "taht",
9342 uid: 7,
9343 allowed_company_ids: [1],
9344 active_id: 1,
9345 active_ids: [1, 2],
9346 active_model: "foo",
9347 active_domain: [["bar", "=", true]],
9348 },
9349 },
9350 ]);
9351 });
9352
9353 test.tags("mobile");
9354 test(`execute ActionMenus actions with correct params (single page) on mobile`, async () => {
9355 mockService("action", {
9356 doAction(id, { additionalContext }) {
9357 expect.step({ action_id: id, context: additionalContext });
9358 },
9359 });
9360
9361 await mountView({
9362 resModel: "foo",
9363 type: "list",
9364 arch: `<list><field name="foo"/></list>`,
9365 info: {
9366 actionMenus: {
9367 action: [
9368 {
9369 id: 44,
9370 name: "Custom Action",
9371 type: "ir.actions.server",
9372 },
9373 ],
9374 print: [],
9375 },
9376 },
9377 actionMenus: {},
9378 searchViewArch: `
9379 <search>
9380 <filter name="bar" domain="[('bar', '=', true)]"/>
9381 </search>
9382 `,
9383 });
9384
9385 expect(`div.o_control_panel .o_cp_action_menus`).toHaveCount(1);
9386 expect(`.o_data_row`).toHaveCount(4);
9387
9388 // select all records
9389 await selectAllRecords();
9390 expect(`.o_data_row.o_data_row_selected`).toHaveCount(4);
9391 expect(`div.o_control_panel .o_cp_action_menus`).toHaveCount(1);
9392
9393 await toggleActionMenu();
9394 await toggleMenuItem("Custom Action");
9395
9396 // unselect first record (will unselect the thead checkbox as well)
9397 await clickRecordSelector();
9398 expect(`.o_data_row.o_data_row_selected`).toHaveCount(3);
9399
9400 await toggleActionMenu();
9401 await toggleMenuItem("Custom Action");
9402
9403 // add a domain and select first two records (need to unselect records first)
9404 await selectAllRecords(); // select all
9405 await unselectAllRecords(); // unselect all
9406 await toggleSearchBarMenu();
9407 await toggleMenuItem("bar");
9408 await toggleSearchBarMenu();
9409 expect(`.o_data_row`).toHaveCount(3);
9410 expect(`.o_data_row.o_data_row_selected`).toHaveCount(0);
9411 await contains(`.o_data_row:eq(0)`).drag();
9412 await contains(`.o_data_row:eq(1)`).drag();
9413 expect(`.o_data_row.o_data_row_selected`).toHaveCount(2);
9414
9415 await toggleActionMenu();
9416 await toggleMenuItem("Custom Action");
9417 expect.verifySteps([
9418 {
9419 action_id: 44,
9420 context: {
9421 lang: "en",
9422 tz: "taht",
9423 uid: 7,
9424 allowed_company_ids: [1],
9425 active_id: 1,
9426 active_ids: [1, 2, 3, 4],
9427 active_model: "foo",
9428 active_domain: [],
9429 },
9430 },
9431 {
9432 action_id: 44,
9433 context: {
9434 lang: "en",
9435 tz: "taht",
9436 uid: 7,
9437 allowed_company_ids: [1],
9438 active_id: 2,
9439 active_ids: [2, 3, 4],
9440 active_model: "foo",
9441 active_domain: [],
9442 },
9443 },
9444 {
9445 action_id: 44,
9446 context: {
9447 lang: "en",
9448 tz: "taht",
9449 uid: 7,
9450 allowed_company_ids: [1],
9451 active_id: 1,
9452 active_ids: [1, 2],
9453 active_model: "foo",
9454 active_domain: [["bar", "=", true]],
9455 },
9456 },
9457 ]);
9458 });
9459
9460 test.tags("desktop");
9461 test(`execute ActionMenus actions with correct params (multi pages)`, async () => {
9462 mockService("action", {
9463 doAction(id, { additionalContext }) {
9464 expect.step({ action_id: id, context: additionalContext });
9465 },
9466 });
9467
9468 await mountView({
9469 resModel: "foo",
9470 type: "list",
9471 arch: `<list limit="2"><field name="foo"/></list>`,
9472 info: {
9473 actionMenus: {
9474 action: [
9475 {
9476 id: 44,
9477 name: "Custom Action",
9478 type: "ir.actions.server",
9479 },
9480 ],
9481 print: [],
9482 },
9483 },
9484 actionMenus: {},
9485 searchViewArch: `
9486 <search>
9487 <filter name="bar" domain="[('bar', '=', true)]"/>
9488 </search>
9489 `,
9490 });
9491 expect(`div.o_control_panel .o_cp_action_menus`).toHaveCount(1);
9492 expect(`.o_data_row`).toHaveCount(2);
9493
9494 // select all records
9495 await contains(`thead .o_list_record_selector input`).click();
9496 expect(`.o_list_record_selector input:checked`).toHaveCount(3);
9497 expect(`.o_selection_box .o_select_domain`).toHaveCount(1);
9498 expect(`div.o_control_panel .o_cp_action_menus`).toHaveCount(1);
9499
9500 await contains(`.o_cp_action_menus .dropdown-toggle`).click();
9501 await toggleMenuItem("Custom Action");
9502
9503 // select all domain
9504 await contains(`.o_selection_box .o_select_domain`).click();
9505 expect(`.o_list_record_selector input:checked`).toHaveCount(3);
9506
9507 await contains(`.o_cp_action_menus .dropdown-toggle`).click();
9508 await toggleMenuItem("Custom Action");
9509
9510 // add a domain (need to unselect records first)
9511 await contains(`thead .o_list_record_selector input`).click();
9512 await toggleSearchBarMenu();
9513 await toggleMenuItem("bar");
9514 expect(`.o_selection_box .o_select_domain`).toHaveCount(0);
9515
9516 // select all domain
9517 await contains(`thead .o_list_record_selector input`).click();
9518 await contains(`.o_selection_box .o_select_domain`).click();
9519 expect(`.o_list_record_selector input:checked`).toHaveCount(3);
9520 expect(`.o_selection_box .o_select_domain`).toHaveCount(0);
9521
9522 await contains(`.o_cp_action_menus .dropdown-toggle`).click();
9523 await toggleMenuItem("Custom Action");
9524 expect.verifySteps([
9525 {
9526 action_id: 44,
9527 context: {
9528 lang: "en",
9529 tz: "taht",
9530 uid: 7,
9531 allowed_company_ids: [1],
9532 active_id: 1,
9533 active_ids: [1, 2],
9534 active_model: "foo",
9535 active_domain: [],
9536 },
9537 },
9538 {
9539 action_id: 44,
9540 context: {
9541 lang: "en",
9542 tz: "taht",
9543 uid: 7,
9544 allowed_company_ids: [1],
9545 active_id: 1,
9546 active_ids: [1, 2, 3, 4],
9547 active_model: "foo",
9548 active_domain: [],
9549 },
9550 },
9551 {
9552 action_id: 44,
9553 context: {
9554 lang: "en",
9555 tz: "taht",
9556 uid: 7,
9557 allowed_company_ids: [1],
9558 active_id: 1,
9559 active_ids: [1, 2, 3],
9560 active_model: "foo",
9561 active_domain: [["bar", "=", true]],
9562 },
9563 },
9564 ]);
9565 });
9566
9567 test.tags("desktop");
9568 test(`edit list line after line deletion`, async () => {
9569 await mountView({
9570 resModel: "foo",
9571 type: "list",
9572 arch: `<list editable="top"><field name="foo"/><field name="int_field"/></list>`,
9573 });
9574 await contains(`.o_data_row:eq(2) .o_data_cell`).click();
9575 expect(`.o_data_row:eq(2)`).toHaveClass("o_selected_row");
9576
9577 await contains(`.o_list_button_discard`).click();
9578 await contains(`.o_list_button_add`).click();
9579 expect(`.o_data_row:eq(0)`).toHaveClass("o_selected_row");
9580
9581 await contains(`.o_list_button_discard`).click();
9582 expect(`.o_selected_row`).toHaveCount(0, { message: "no row should be selected" });
9583
9584 await contains(`.o_data_row:eq(2) .o_data_cell`).click();
9585 expect(`.o_data_row:eq(2)`).toHaveClass("o_selected_row");
9586 expect(`.o_selected_row`).toHaveCount(1, { message: "no other row should be selected" });
9587 });
9588
9589 test.tags("desktop");
9590 test(`pressing TAB in editable list with several fields`, async () => {
9591 await mountView({
9592 resModel: "foo",
9593 type: "list",
9594 arch: `
9595 <list editable="bottom">
9596 <field name="foo"/>
9597 <field name="int_field"/>
9598 </list>
9599 `,
9600 });
9601 await contains(`.o_data_cell`).click();
9602 expect(`.o_data_row:eq(0)`).toHaveClass("o_selected_row");
9603 expect(`.o_data_row:eq(0) .o_data_cell:eq(0) input`).toBeFocused();
9604
9605 // Press 'Tab' -> should go to next cell (still in first row)
9606 await press("Tab");
9607 await animationFrame();
9608 expect(`.o_data_row:eq(0)`).toHaveClass("o_selected_row");
9609 expect(`.o_data_row:eq(0) .o_data_cell:eq(1) input`).toBeFocused();
9610
9611 // Press 'Tab' -> should go to next line (first cell)
9612 await press("Tab");
9613 await animationFrame();
9614 expect(`.o_data_row:eq(1)`).toHaveClass("o_selected_row");
9615 expect(`.o_data_row:eq(1) .o_data_cell:eq(0) input`).toBeFocused();
9616 });
9617
9618 test.tags("desktop");
9619 test(`pressing SHIFT-TAB in editable list with several fields`, async () => {
9620 await mountView({
9621 resModel: "foo",
9622 type: "list",
9623 arch: `
9624 <list editable="bottom">
9625 <field name="foo"/>
9626 <field name="int_field"/>
9627 </list>
9628 `,
9629 });
9630 await contains(`.o_data_row:eq(1) .o_data_cell`).click();
9631 expect(`.o_data_row:eq(1)`).toHaveClass("o_selected_row");
9632 expect(`.o_data_row:eq(1) .o_data_cell:eq(0) input`).toBeFocused();
9633
9634 await press("shift+Tab");
9635 await animationFrame();
9636 expect(`.o_data_row:eq(0)`).toHaveClass("o_selected_row");
9637 expect(`.o_data_row:eq(0) .o_data_cell:eq(1) input`).toBeFocused();
9638
9639 await press("shift+Tab");
9640 await animationFrame();
9641 expect(`.o_data_row:eq(0)`).toHaveClass("o_selected_row");
9642 expect(`.o_data_row:eq(0) .o_data_cell:eq(0) input`).toBeFocused();
9643 });
9644
9645 test.tags("desktop");
9646 test(`navigation with tab and readonly field (no modification)`, async () => {
9647 // This test makes sure that if we have 2 cells in a row, the first in
9648 // edit mode, and the second one readonly, then if we press TAB when the
9649 // focus is on the first, then the focus skip the readonly cells and
9650 // directly goes to the next line instead.
9651 await mountView({
9652 resModel: "foo",
9653 type: "list",
9654 arch: `
9655 <list editable="bottom">
9656 <field name="foo"/>
9657 <field name="int_field" readonly="1"/>
9658 </list>
9659 `,
9660 });
9661
9662 // Pass the first row in edition.
9663 await contains(`.o_data_row:eq(0) [name=foo]`).click();
9664 expect(`.o_selected_row`).toHaveCount(1);
9665 expect(`.o_data_row:eq(0)`).toHaveClass("o_selected_row");
9666 expect(`.o_data_row:eq(0) [name=foo] input`).toBeFocused();
9667
9668 // Pressing Tab should skip the readonly field and directly go to the next row.
9669 await press("Tab");
9670 await animationFrame();
9671 expect(`.o_selected_row`).toHaveCount(1);
9672 expect(`.o_data_row:eq(1)`).toHaveClass("o_selected_row");
9673 expect(`.o_data_row:eq(1) [name=foo] input`).toBeFocused();
9674
9675 // We do it again.
9676 await press("Tab");
9677 await animationFrame();
9678 expect(`.o_selected_row`).toHaveCount(1);
9679 expect(`.o_data_row:eq(2)`).toHaveClass("o_selected_row");
9680 expect(`.o_data_row:eq(2) [name=foo] input`).toBeFocused();
9681 });
9682
9683 test.tags("desktop");
9684 test(`navigation with tab and readonly field (with modification)`, async () => {
9685 // This test makes sure that if we have 2 cells in a row, the first in
9686 // edit mode, and the second one readonly, then if we press TAB when the
9687 // focus is on the first, then the focus skips the readonly cells and
9688 // directly goes to the next line instead.
9689 await mountView({
9690 resModel: "foo",
9691 type: "list",
9692 arch: `
9693 <list editable="bottom">
9694 <field name="foo"/>
9695 <field name="int_field" readonly="1"/>
9696 </list>
9697 `,
9698 });
9699
9700 // Pass the first row in edition.
9701 await contains(`.o_data_row:eq(0) [name=foo]`).click();
9702 expect(`.o_selected_row`).toHaveCount(1);
9703 expect(`.o_data_row:eq(0)`).toHaveClass("o_selected_row");
9704 expect(`.o_data_row:eq(0) [name=foo] input`).toBeFocused();
9705
9706 // Modity the cell content, validate with tab
9707 await contains(`.o_data_row:eq(0) [name=foo] input`).edit("blip-changed", { confirm: "tab" });
9708 expect(`.o_selected_row`).toHaveCount(1);
9709 expect(`.o_data_row:eq(1)`).toHaveClass("o_selected_row");
9710 expect(`.o_data_row:eq(1) [name=foo] input`).toBeFocused();
9711
9712 // Press tab again.
9713 await press("Tab");
9714 await animationFrame();
9715 expect(`.o_selected_row`).toHaveCount(1);
9716 expect(`.o_data_row:eq(2)`).toHaveClass("o_selected_row");
9717 expect(`.o_data_row:eq(2) [name=foo] input`).toBeFocused();
9718 });
9719
9720 test.tags("desktop");
9721 test(`navigation with tab on a list with create="0"`, async () => {
9722 await mountView({
9723 resModel: "foo",
9724 type: "list",
9725 arch: `
9726 <list editable="bottom" create="0">
9727 <field name="foo"/>
9728 </list>
9729 `,
9730 });
9731 expect(`.o_data_row`).toHaveCount(4, { message: "the list should contain 4 rows" });
9732
9733 await contains(`.o_data_row:eq(2) .o_data_cell`).click();
9734 expect(`.o_data_row:eq(2)`).toHaveClass("o_selected_row", {
9735 message: "third row should be in edition",
9736 });
9737
9738 // Fill the cell and press tab
9739 await contains(`.o_selected_row .o_data_cell input`).edit("11", { confirm: "tab" });
9740 expect(`.o_data_row:eq(3)`).toHaveClass("o_selected_row", {
9741 message: "fourth row should be in edition",
9742 });
9743
9744 // Press 'Tab' -> should go back to first line as the create action isn't available
9745 await press("Tab");
9746 await animationFrame();
9747 expect(`.o_data_row:eq(0)`).toHaveClass("o_selected_row", {
9748 message: "first row should be in edition",
9749 });
9750 });
9751
9752 test.tags("desktop");
9753 test(`navigation with tab on a one2many list with create="0"`, async () => {
9754 Foo._records[0].o2m = [1, 2];
9755 Bar._fields.name = fields.Char();
9756
9757 await mountView({
9758 resModel: "foo",
9759 type: "form",
9760 arch: `
9761 <form>
9762 <sheet>
9763 <field name="o2m">
9764 <list editable="bottom" create="0">
9765 <field name="name"/>
9766 </list>
9767 </field>
9768 <field name="int_field"/>
9769 </sheet>
9770 </form>
9771 `,
9772 resId: 1,
9773 });
9774 expect(`.o_field_widget[name=o2m] .o_data_row`).toHaveCount(2);
9775
9776 await contains(`.o_field_widget[name=o2m] .o_data_row:eq(0) .o_data_cell[name=name]`).click();
9777 expect(`.o_field_widget[name=o2m] .o_data_row:eq(0)`).toHaveClass("o_selected_row");
9778 expect(`.o_selected_row`).toHaveCount(1);
9779 expect(`.o_selected_row [name=name] input`).toBeFocused();
9780
9781 // Press 'Tab' -> should go to next line
9782 await press("Tab");
9783 await animationFrame();
9784 expect(`.o_field_widget[name=o2m] .o_data_row:eq(1)`).toHaveClass("o_selected_row");
9785 expect(`.o_selected_row`).toHaveCount(1);
9786 expect(`.o_selected_row [name=name] input`).toBeFocused();
9787
9788 // Pressing 'Tab' -> should use default behavior and thus get out of
9789 // the one to many and go to the next field of the form
9790 await press("Tab");
9791 await animationFrame();
9792 expect(`.o_field_widget[name=int_field] input`).toBeFocused();
9793 });
9794
9795 test.tags("desktop");
9796 test(`edition, then navigation with tab (with a readonly field)`, async () => {
9797 // This test makes sure that if we have 2 cells in a row, the first in
9798 // edit mode, and the second one readonly, then if we edit and press TAB,
9799 // (before debounce), the save operation is properly done (before
9800 // selecting the next row)
9801 stepAllNetworkCalls();
9802
9803 await mountView({
9804 resModel: "foo",
9805 type: "list",
9806 arch: `
9807 <list editable="bottom">
9808 <field name="foo"/>
9809 <field name="int_field" readonly="1"/>
9810 </list>
9811 `,
9812 });
9813
9814 // click on first dataRow and press TAB
9815 await contains(`.o_data_row .o_data_cell`).click();
9816 await contains(`.o_selected_row [name='foo'] input`).edit("new value");
9817 await press("Tab");
9818 await animationFrame();
9819 expect(`tbody tr:eq(0) td:contains(new value)`).toHaveCount(1, {
9820 message: "should have the new value visible in dom",
9821 });
9822 expect.verifySteps([
9823 "/web/webclient/translations",
9824 "/web/webclient/load_menus",
9825 "get_views",
9826 "web_search_read",
9827 "has_group",
9828 "web_save",
9829 ]);
9830 });
9831
9832 test(`edition, then navigation with tab (with a readonly field and onchange)`, async () => {
9833 // This test makes sure that if we have a read-only cell in a row, in
9834 // case the keyboard navigation move over it and there a unsaved changes
9835 // (which will trigger an onchange), the focus of the next activable
9836 // field will not crash
9837 Bar._fields.o2m = fields.One2many({
9838 relation: "foo",
9839 });
9840 Bar._onChanges = {
9841 o2m() {},
9842 };
9843 Bar._records[0].o2m = [1, 4];
9844
9845 onRpc("onchange", ({ model }) => {
9846 expect.step(`onchange:${model}`);
9847 });
9848
9849 await mountView({
9850 resModel: "bar",
9851 type: "form",
9852 arch: `
9853 <form>
9854 <group>
9855 <field name="display_name"/>
9856 <field name="o2m">
9857 <list editable="bottom">
9858 <field name="foo"/>
9859 <field name="date" readonly="1"/>
9860 <field name="int_field"/>
9861 </list>
9862 </field>
9863 </group>
9864 </form>
9865 `,
9866 resId: 1,
9867 });
9868 await contains(`.o_data_cell`).click();
9869 expect(`.o_data_cell[name=foo] input`).toBeFocused();
9870
9871 await contains(`.o_data_cell[name=foo] input`).edit("new value", { confirm: "tab" });
9872 expect(`.o_data_cell[name=int_field] input`).toBeFocused();
9873 expect.verifySteps(["onchange:bar"]);
9874 });
9875
9876 test.tags("desktop");
9877 test(`pressing SHIFT-TAB in editable list with a readonly field`, async () => {
9878 await mountView({
9879 resModel: "foo",
9880 type: "list",
9881 arch: `
9882 <list editable="bottom">
9883 <field name="foo"/>
9884 <field name="int_field" readonly="1"/>
9885 <field name="qux"/>
9886 </list>
9887 `,
9888 });
9889 await contains(`.o_data_row:eq(1) [name=qux]`).click();
9890 expect(`.o_data_row:eq(1)`).toHaveClass("o_selected_row");
9891 expect(`.o_data_row:eq(1) [name=qux] input`).toBeFocused();
9892
9893 await press("shift+Tab");
9894 await animationFrame();
9895 expect(`.o_data_row:eq(1)`).toHaveClass("o_selected_row");
9896 expect(`.o_data_row:eq(1) [name=foo] input`).toBeFocused();
9897 });
9898
9899 test.tags("desktop");
9900 test(`pressing SHIFT-TAB in editable list with a readonly field in first column`, async () => {
9901 await mountView({
9902 resModel: "foo",
9903 type: "list",
9904 arch: `
9905 <list editable="bottom">
9906 <field name="int_field" readonly="1"/>
9907 <field name="foo"/>
9908 <field name="qux"/>
9909 </list>
9910 `,
9911 });
9912 await contains(`.o_data_row:eq(1) .o_data_cell`).click();
9913 expect(`.o_data_row:eq(1)`).toHaveClass("o_selected_row");
9914 expect(`.o_data_row:eq(1) [name=foo] input`).toBeFocused();
9915
9916 await press("shift+Tab");
9917 await animationFrame();
9918 expect(`.o_data_row:eq(0)`).toHaveClass("o_selected_row");
9919 expect(`.o_data_row [name=qux] input`).toBeFocused();
9920 });
9921
9922 test.tags("desktop");
9923 test(`pressing SHIFT-TAB in editable list with a readonly field in last column`, async () => {
9924 await mountView({
9925 resModel: "foo",
9926 type: "list",
9927 arch: `
9928 <list editable="bottom">
9929 <field name="int_field"/>
9930 <field name="foo"/>
9931 <field name="qux" readonly="1"/>
9932 </list>
9933 `,
9934 });
9935 await contains(`.o_data_row:eq(1) .o_data_cell`).click();
9936 expect(`.o_data_row:eq(1)`).toHaveClass("o_selected_row");
9937 expect(`.o_data_row:eq(1) [name=int_field] input`).toBeFocused();
9938
9939 await press("shift+Tab");
9940 await animationFrame();
9941 expect(`.o_data_row:eq(0)`).toHaveClass("o_selected_row");
9942 expect(`.o_data_row [name=foo] input`).toBeFocused();
9943 });
9944
9945 test.tags("desktop");
9946 test(`skip invisible fields when navigating list view with TAB`, async () => {
9947 await mountView({
9948 resModel: "foo",
9949 type: "list",
9950 arch: `
9951 <list editable="bottom">
9952 <field name="foo"/>
9953 <field name="bar" column_invisible="1"/>
9954 <field name="int_field"/>
9955 </list>
9956 `,
9957 resId: 1,
9958 });
9959 await contains(`.o_data_row:eq(0) .o_field_cell[name=foo]`).click();
9960 expect(`.o_data_row:eq(0) .o_field_cell[name=foo] input`).toBeFocused();
9961
9962 await press("Tab");
9963 await animationFrame();
9964 expect(`.o_data_row:eq(0) .o_field_cell[name=int_field] input`).toBeFocused();
9965 });
9966
9967 test.tags("desktop");
9968 test(`skip buttons when navigating list view with TAB (end)`, async () => {
9969 await mountView({
9970 resModel: "foo",
9971 type: "list",
9972 arch: `
9973 <list editable="bottom">
9974 <field name="foo"/>
9975 <button name="kikou" string="Kikou" type="object"/>
9976 </list>
9977 `,
9978 resId: 1,
9979 });
9980 await contains(`.o_data_row:eq(2) [name=foo]`).click();
9981 expect(`.o_data_row:eq(2) [name=foo] input`).toBeFocused();
9982
9983 await press("Tab");
9984 await animationFrame();
9985 expect(`.o_data_row:eq(3) [name=foo] input`).toBeFocused();
9986 });
9987
9988 test.tags("desktop");
9989 test(`skip buttons when navigating list view with TAB (middle)`, async () => {
9990 await mountView({
9991 resModel: "foo",
9992 type: "list",
9993 arch: `
9994 <list editable="bottom">
9995 <button name="kikou" string="Kikou" type="object"/>
9996 <field name="foo"/>
9997 <button name="kikou" string="Kikou" type="object"/>
9998 <field name="int_field"/>
9999 </list>
10000 `,
10001 resId: 1,
10002 });
10003 await contains(`.o_data_row:eq(2) [name=foo]`).click();
10004 expect(`.o_data_row:eq(2) [name=foo] input`).toBeFocused();
10005
10006 await press("Tab");
10007 await animationFrame();
10008 expect(`.o_data_row:eq(2) [name=int_field] input`).toBeFocused();
10009 });
10010
10011 test.tags("desktop");
10012 test(`navigation: not moving down with keydown`, async () => {
10013 await mountView({
10014 resModel: "foo",
10015 type: "list",
10016 arch: `<list editable="bottom"><field name="foo"/></list>`,
10017 });
10018 await contains(`.o_field_cell[name=foo]`).click();
10019 expect(`.o_data_row:eq(0)`).toHaveClass("o_selected_row");
10020
10021 await press("arrowdown");
10022 await animationFrame();
10023 expect(`.o_data_row:eq(0)`).toHaveClass("o_selected_row");
10024 });
10025
10026 test.tags("desktop");
10027 test(`navigation: moving right with keydown from text field does not move the focus`, async () => {
10028 Foo._fields.foo = fields.Text();
10029
10030 await mountView({
10031 resModel: "foo",
10032 type: "list",
10033 arch: `
10034 <list editable="bottom">
10035 <field name="foo"/>
10036 <field name="bar"/>
10037 </list>
10038 `,
10039 });
10040 await contains(`.o_field_cell[name=foo]`).click();
10041 expect(`.o_field_widget[name=foo] textarea`).toBeFocused();
10042 const textarea = queryOne(".o_field_widget[name=foo] textarea");
10043 expect(textarea.selectionStart).toBe(0);
10044 expect(textarea.selectionEnd).toBe(3);
10045
10046 await press("arrowright");
10047 await animationFrame();
10048 expect(`.o_field_widget[name=foo] textarea`).toBeFocused();
10049 expect(textarea.selectionStart).toBe(3);
10050 expect(textarea.selectionEnd).toBe(3);
10051
10052 await press("arrowright");
10053 await animationFrame();
10054 expect(`.o_field_widget[name=foo] textarea`).toBeFocused();
10055 expect(textarea.selectionStart).toBe(3);
10056 expect(textarea.selectionEnd).toBe(3);
10057 });
10058
10059 test.tags("desktop");
10060 test(`discarding changes in a row properly updates the rendering`, async () => {
10061 await mountView({
10062 resModel: "foo",
10063 type: "list",
10064 arch: `<list editable="top"><field name="foo"/></list>`,
10065 });
10066 expect(`.o_field_cell:eq(0)`).toHaveText("yop", { message: "first cell should contain 'yop'" });
10067
10068 await contains(`.o_field_cell`).click();
10069 await contains(`.o_field_widget[name=foo] input`).edit("hello", { confirm: false });
10070 await contains(`.o_list_button_discard:not(.dropdown-item)`).click();
10071 expect(`.modal`).toHaveCount(0, { message: "should be no modal to ask for discard" });
10072 expect(`.o_field_cell:eq(0)`).toHaveText("yop", {
10073 message: "first cell should still contain 'yop'",
10074 });
10075 });
10076
10077 test(`numbers in list are right-aligned`, async () => {
10078 await mountView({
10079 resModel: "foo",
10080 type: "list",
10081 arch: `
10082 <list editable="top">
10083 <field name="foo"/>
10084 <field name="qux"/>
10085 <field name="amount" widget="monetary"/>
10086 <field name="currency_id" column_invisible="1"/>
10087 </list>
10088 `,
10089 });
10090
10091 const nbCellRight = queryAll(`.o_data_row:eq(0) > .o_data_cell`).filter(
10092 (el) => window.getComputedStyle(el).textAlign === "right"
10093 ).length;
10094 expect(nbCellRight).toBe(2, { message: "there should be two right-aligned cells" });
10095
10096 await contains(`.o_data_cell`).click();
10097 const nbInputRight = queryAll(`.o_data_row:eq(0) > .o_data_cell input`).filter(
10098 (el) => window.getComputedStyle(el).textAlign === "right"
10099 ).length;
10100 expect(nbInputRight).toBe(2, { message: "there should be two right-aligned input" });
10101 });
10102
10103 test.tags("desktop");
10104 test(`grouped list with another grouped list parent, click unfold`, async () => {
10105 Bar._fields.cornichon = fields.Char();
10106 const rec = Bar._records[0];
10107 // create records to have the search more button
10108 const newRecs = [];
10109 for (let i = 0; i < 8; i++) {
10110 newRecs.push({ ...rec, id: i + 1, cornichon: "extra fin" });
10111 }
10112 Bar._records = newRecs;
10113 Bar._views = {
10114 list: `<list><field name="cornichon"/></list>`,
10115 search: `
10116 <search>
10117 <filter context="{'group_by': 'cornichon'}" string="cornichon"/>
10118 </search>
10119 `,
10120 };
10121
10122 await mountView({
10123 resModel: "foo",
10124 type: "list",
10125 arch: `<list editable="top"><field name="foo"/><field name="m2o"/></list>`,
10126 searchViewArch: `
10127 <search>
10128 <filter name="bar" string="bar" context="{'group_by': 'bar'}"/>
10129 </search>
10130 `,
10131 });
10132 await toggleSearchBarMenu();
10133 await toggleMenuItem("bar");
10134 await toggleMenuItem("bar");
10135
10136 await contains(`.o_data_cell`).click();
10137 await contains(`.o_field_widget[name=m2o] input`).click();
10138 await contains(`.o-autocomplete--dropdown-item:contains(Search more...)`).click();
10139 expect(`.modal-content`).toHaveCount(1);
10140 expect(`.modal-content .o_group_name`).toHaveCount(0, { message: "list in modal not grouped" });
10141
10142 await contains(`.modal .o_searchview_dropdown_toggler`).click();
10143 await toggleMenuItem("cornichon");
10144 await contains(`.o_group_header`).click();
10145 expect(`.modal-content .o_group_open`).toHaveCount(1);
10146 });
10147
10148 test(`field values are escaped`, async () => {
10149 const value = "<script>throw Error();</script>";
10150
10151 Foo._records[0].foo = value;
10152
10153 await mountView({
10154 resModel: "foo",
10155 type: "list",
10156 arch: `<list editable="top"><field name="foo"/></list>`,
10157 });
10158 expect(`.o_data_cell:eq(0)`).toHaveText(value, {
10159 message: "value should have been escaped",
10160 });
10161 });
10162
10163 test.tags("desktop");
10164 test(`pressing ESC discard the current line changes`, async () => {
10165 await mountView({
10166 resModel: "foo",
10167 type: "list",
10168 arch: `<list editable="top"><field name="foo"/></list>`,
10169 });
10170 await contains(`.o_list_button_add`).click();
10171 expect(`tr.o_data_row`).toHaveCount(5, { message: "should currently adding a 5th data row" });
10172
10173 await press("escape");
10174 await animationFrame();
10175 expect(`tr.o_data_row`).toHaveCount(4, { message: "should have only 4 data row after escape" });
10176 expect(`tr.o_data_row.o_selected_row`).toHaveCount(0, {
10177 message: "no rows should be selected",
10178 });
10179 expect(`.o_list_button_save`).toHaveCount(0, { message: "should not have a save button" });
10180 });
10181
10182 test.tags("desktop");
10183 test(`pressing ESC discard the current line changes (with required)`, async () => {
10184 await mountView({
10185 resModel: "foo",
10186 type: "list",
10187 arch: `<list editable="top"><field name="foo" required="1"/></list>`,
10188 });
10189 await contains(`.o_list_button_add`).click();
10190 expect(`tr.o_data_row`).toHaveCount(5, { message: "should currently adding a 5th data row" });
10191
10192 await press("escape");
10193 await animationFrame();
10194 expect(`tr.o_data_row`).toHaveCount(4, { message: "should have only 4 data row after escape" });
10195 expect(`tr.o_data_row.o_selected_row`).toHaveCount(0, {
10196 message: "no rows should be selected",
10197 });
10198 expect(`.o_list_button_save`).toHaveCount(0, { message: "should not have a save button" });
10199 });
10200
10201 test(`field with password attribute`, async () => {
10202 await mountView({
10203 resModel: "foo",
10204 type: "list",
10205 arch: `<list><field name="foo" password="True"/></list>`,
10206 });
10207 expect(queryAllTexts(`.o_data_row .o_data_cell`)).toEqual(["***", "****", "****", "****"]);
10208 });
10209
10210 test(`list with handle widget`, async () => {
10211 onRpc("web_search_read", ({ kwargs }) => {
10212 expect.step(`web_search_read: order: ${kwargs.order}`);
10213 });
10214 onRpc("web_resequence", ({ args, kwargs }) => {
10215 expect.step(["web_resequence", args[0], kwargs.field_name, kwargs.offset]);
10216 });
10217
10218 await mountView({
10219 resModel: "foo",
10220 type: "list",
10221 arch: `
10222 <list>
10223 <field name="int_field" widget="handle"/>
10224 <field name="amount" widget="float" digits="[5,0]"/>
10225 </list>
10226 `,
10227 });
10228 expect.verifySteps(["web_search_read: order: int_field ASC, id ASC"]);
10229 expect(`.o_data_row:eq(0) [name='amount']`).toHaveText("0", {
10230 message: "default fourth record should have amount 0",
10231 });
10232 expect(`.o_data_row:eq(1) [name='amount']`).toHaveText("500", {
10233 message: "default second record should have amount 500",
10234 });
10235 expect(`.o_data_row:eq(2) [name='amount']`).toHaveText("1,200", {
10236 message: "default first record should have amount 1,200",
10237 });
10238 expect(`.o_data_row:eq(3) [name='amount']`).toHaveText("300", {
10239 message: "default third record should have amount 300",
10240 });
10241
10242 // Drag and drop the fourth line in second position
10243 await contains(`tbody tr:eq(3) .o_handle_cell`).dragAndDrop(queryFirst(`tbody tr:eq(1)`));
10244 expect.verifySteps([["web_resequence", [3, 2, 1], "int_field", 9]]);
10245 expect(`.o_data_row:eq(0) [name='amount']`).toHaveText("0", {
10246 message: "new second record should have amount 0",
10247 });
10248 expect(`.o_data_row:eq(1) [name='amount']`).toHaveText("300", {
10249 message: "new fourth record should have amount 300",
10250 });
10251 expect(`.o_data_row:eq(2) [name='amount']`).toHaveText("500", {
10252 message: "new third record should have amount 500",
10253 });
10254 expect(`.o_data_row:eq(3) [name='amount']`).toHaveText("1,200", {
10255 message: "new first record should have amount 1,200",
10256 });
10257 });
10258
10259 test(`result of consecutive resequences is correctly sorted`, async () => {
10260 // we want the data to be minimal to have a minimal test
10261 class MyFoo extends models.Model {
10262 int_field = fields.Integer();
10263
10264 _records = [
10265 { id: 1, int_field: 11 },
10266 { id: 2, int_field: 12 },
10267 { id: 3, int_field: 13 },
10268 { id: 4, int_field: 14 },
10269 ];
10270 }
10271 defineModels([MyFoo]);
10272
10273 const kwargs = makeKwArgs({
10274 context: {
10275 lang: "en",
10276 tz: "taht",
10277 uid: 7,
10278 allowed_company_ids: [1],
10279 },
10280 specification: { int_field: {} },
10281 field_name: "int_field",
10282 });
10283
10284 onRpc("my.foo", "web_resequence", ({ args, kwargs }) => {
10285 expect.step({ args, kwargs });
10286 });
10287
10288 await mountView({
10289 resModel: "my.foo",
10290 type: "list",
10291 arch: `
10292 <list>
10293 <field name="int_field" widget="handle"/>
10294 <field name="id"/>
10295 </list>
10296 `,
10297 });
10298 expect(queryAllTexts(`tbody tr td[name=id]`)).toEqual(["1", "2", "3", "4"], {
10299 message: "default should be sorted by id",
10300 });
10301
10302 await contains(`.o_list_view tbody tr:eq(3) .o_handle_cell`).dragAndDrop(
10303 ".o_list_view tbody tr:eq(2)"
10304 );
10305 expect.verifySteps([{ args: [[4, 3]], kwargs: { ...kwargs, offset: 13 } }]);
10306 expect(queryAllTexts(`tbody tr td[name=id]`)).toEqual(["1", "2", "4", "3"], {
10307 message: "the int_field (sequence) should have been correctly updated",
10308 });
10309
10310 await contains(`.o_list_view tbody tr:eq(2) .o_handle_cell`).dragAndDrop(
10311 ".o_list_view tbody tr:eq(1)"
10312 );
10313 expect.verifySteps([{ args: [[4, 2]], kwargs: { ...kwargs, offset: 12 } }]);
10314 expect(queryAllTexts(`tbody tr td[name=id]`)).toEqual(["1", "4", "2", "3"], {
10315 message: "the int_field (sequence) should have been correctly updated",
10316 });
10317
10318 await contains(`.o_list_view tbody tr:eq(1) .o_handle_cell`).dragAndDrop(
10319 ".o_list_view tbody tr:eq(2)"
10320 );
10321 expect.verifySteps([{ args: [[2, 4]], kwargs: { ...kwargs, offset: 12 } }]);
10322 expect(queryAllTexts(`tbody tr td[name=id]`)).toEqual(["1", "2", "4", "3"], {
10323 message: "the int_field (sequence) should have been correctly updated",
10324 });
10325
10326 await contains(`.o_list_view tbody tr:eq(2) .o_handle_cell`).dragAndDrop(
10327 ".o_list_view tbody tr:eq(1)"
10328 );
10329 expect.verifySteps([{ args: [[4, 2]], kwargs: { ...kwargs, offset: 12 } }]);
10330 expect(queryAllTexts(`tbody tr td[name=id]`)).toEqual(["1", "4", "2", "3"], {
10331 message: "the int_field (sequence) should have been correctly updated",
10332 });
10333 });
10334
10335 test("resequence with NULL values", async () => {
10336 mockService("action", {
10337 doActionButton(params) {
10338 params.onClose();
10339 },
10340 });
10341 // we want the data to be minimal to have a minimal test
10342 class MyFoo extends models.Model {
10343 int_field = fields.Integer();
10344
10345 _records = [
10346 { id: 1, int_field: 1 },
10347 { id: 2 },
10348 { id: 3, int_field: 3 },
10349 { id: 4, int_field: 2 },
10350 ];
10351 }
10352 defineModels([MyFoo]);
10353
10354 const serverValues = {
10355 1: 1,
10356 2: false,
10357 3: 3,
10358 4: 2,
10359 };
10360
10361 onRpc("web_search_read", function ({ parent }) {
10362 const res = parent();
10363 const getServerValue = (record) =>
10364 serverValues[record.id] === false ? Number.MAX_SAFE_INTEGER : serverValues[record.id];
10365
10366 // when sorted, NULL values are last
10367 res.records.sort((a, b) => getServerValue(a) - getServerValue(b));
10368 return res;
10369 });
10370
10371 onRpc("web_resequence", ({ args }) => {
10372 for (let i = 0; i < args[0].length; i++) {
10373 serverValues[args[0][i]] = i;
10374 }
10375 });
10376
10377 await mountView({
10378 type: "list",
10379 resModel: "my.foo",
10380 arch: `<list default_order="int_field">
10381 <field name="int_field" widget="handle"/>
10382 <field name="id"/>
10383 <button name="reload" class="reload" string="Confirm" type="object"/>
10384 </list>`,
10385 });
10386
10387 expect(queryAllTexts(".o_field_cell[name=id]")).toEqual(["1", "4", "3", "2"]);
10388
10389 await contains("tbody tr:nth-child(4) .o_handle_cell").dragAndDrop("tbody tr:nth-child(3)");
10390 expect(queryAllTexts(".o_field_cell[name=id]")).toEqual(["1", "4", "2", "3"]);
10391
10392 await contains("button.reload").click();
10393 expect(queryAllTexts(".o_field_cell[name=id]")).toEqual(["1", "4", "2", "3"]);
10394 });
10395
10396 test("resequence with only NULL values", async () => {
10397 mockService("action", {
10398 doActionButton(params) {
10399 params.onClose();
10400 },
10401 });
10402 // we want the data to be minimal to have a minimal test
10403 class MyFoo extends models.Model {
10404 int_field = fields.Integer();
10405
10406 _records = [{ id: 1 }, { id: 2 }, { id: 3 }];
10407 }
10408 defineModels([MyFoo]);
10409
10410 const serverValues = {
10411 1: false,
10412 2: false,
10413 3: false,
10414 };
10415
10416 onRpc("web_search_read", function ({ parent }) {
10417 const res = parent();
10418 const getServerValue = (record) =>
10419 serverValues[record.id] === false ? Number.MAX_SAFE_INTEGER : serverValues[record.id];
10420
10421 // when sorted, NULL values are last
10422 res.records.sort((a, b) => getServerValue(a) - getServerValue(b));
10423 return res;
10424 });
10425
10426 onRpc("web_resequence", ({ args }) => {
10427 for (let i = 0; i < args[0].length; i++) {
10428 serverValues[args[0][i]] = i;
10429 }
10430 });
10431
10432 await mountView({
10433 type: "list",
10434 resModel: "my.foo",
10435 arch: `<list default_order="int_field">
10436 <field name="int_field" widget="handle"/>
10437 <field name="id"/>
10438 <button name="reload" class="reload" string="Confirm" type="object"/>
10439 </list>`,
10440 });
10441
10442 expect(queryAllTexts(".o_field_cell[name=id]")).toEqual(["1", "2", "3"]);
10443
10444 await contains("tbody tr:nth-child(3) .o_handle_cell").dragAndDrop("tbody tr:nth-child(2)");
10445 expect(queryAllTexts(".o_field_cell[name=id]")).toEqual(["1", "3", "2"]);
10446
10447 await contains("button.reload").click();
10448 expect(queryAllTexts(".o_field_cell[name=id]")).toEqual(["1", "3", "2"]);
10449 });
10450
10451 test.tags("desktop");
10452 test(`editable list with handle widget`, async () => {
10453 // resequence makes sense on a sequence field, not on arbitrary fields
10454 Foo._records[0].int_field = 0;
10455 Foo._records[1].int_field = 1;
10456 Foo._records[2].int_field = 2;
10457 Foo._records[3].int_field = 3;
10458
10459 onRpc("web_resequence", ({ args, kwargs }) => {
10460 expect.step(["web_resequence", args[0], kwargs.field_name, kwargs.offset]);
10461 });
10462
10463 await mountView({
10464 resModel: "foo",
10465 type: "list",
10466 arch: `
10467 <list editable="top" default_order="int_field">
10468 <field name="int_field" widget="handle"/>
10469 <field name="amount" widget="float" digits="[5,0]"/>
10470 </list>
10471 `,
10472 });
10473 expect(`tbody tr:eq(0) td:last`).toHaveText("1,200", {
10474 message: "default first record should have amount 1,200",
10475 });
10476 expect(`tbody tr:eq(1) td:last`).toHaveText("500", {
10477 message: "default second record should have amount 500",
10478 });
10479 expect(`tbody tr:eq(2) td:last`).toHaveText("300", {
10480 message: "default third record should have amount 300",
10481 });
10482 expect(`tbody tr:eq(3) td:last`).toHaveText("0", {
10483 message: "default fourth record should have amount 0",
10484 });
10485
10486 await contains(`tbody tr:eq(1) div[name='amount']`).click();
10487 await contains(`tbody tr:eq(1) div[name='amount'] input`).edit(600, { confirm: false });
10488 // Drag and drop the fourth line in second position
10489 // TODO JUM: PRHOOT the events
10490 const { drop, moveTo } = await contains(`tbody tr:eq(3) .o_handle_cell`).drag();
10491 await moveTo(`tbody tr:eq(1)`);
10492 await drop(document.body);
10493 expect.verifySteps([["web_resequence", [4, 2, 3], "int_field", 1]]);
10494 expect(`tbody tr:eq(0) td:last`).toHaveText("1,200", {
10495 message: "new first record should have amount 1,200",
10496 });
10497 expect(`tbody tr:eq(1) td:last`).toHaveText("0", {
10498 message: "new second record should have amount 0",
10499 });
10500 expect(`tbody tr:eq(2) td:last`).toHaveText("600", {
10501 message: "new third record should have amount 500",
10502 });
10503 expect(`tbody tr:eq(3) td:last`).toHaveText("300", {
10504 message: "new fourth record should have amount 300",
10505 });
10506
10507 await contains(`tbody tr:eq(1) div[name='amount']`).click();
10508 expect(`tbody tr:eq(1) td:last input`).toHaveValue("0", {
10509 message: "the edited record should be the good one",
10510 });
10511 });
10512
10513 test.tags("desktop");
10514 test(`editable grouped list with handle widget`, async () => {
10515 // resequence makes sense on a sequence field, not on arbitrary fields
10516 Foo._records[0].int_field = 0;
10517 Foo._records[0].currency_id = 1;
10518 Foo._records[1].int_field = 1;
10519 Foo._records[2].int_field = 2;
10520 Foo._records[3].int_field = 3;
10521
10522 onRpc("web_resequence", ({ args, kwargs }) => {
10523 expect.step(["web_resequence", args[0], kwargs.field_name, kwargs.offset]);
10524 });
10525 onRpc("web_save", ({ args }) => {
10526 expect.step(["web_save", args[0]]);
10527 });
10528
10529 await mountView({
10530 resModel: "foo",
10531 type: "list",
10532 arch: `
10533 <list editable="top" default_order="int_field">
10534 <field name="int_field" widget="handle"/>
10535 <field name="amount" widget="float" digits="[5,0]"/>
10536 </list>
10537 `,
10538 groupBy: ["bar"],
10539 });
10540 expect(`.o_group_header`).toHaveCount(2);
10541 await contains(`.o_group_header:first`).click();
10542 await contains(`.o_group_header:last`).click();
10543 expect(`.o_group_header:first`).toHaveText("No (1)\n 0");
10544 expect(`.o_group_header:last`).toHaveText("Yes (3)\n 2,000");
10545 expect(`tbody .o_data_row:eq(0) td:eq(-2)`).toHaveText("0", {
10546 message: "default fourth record should have amount 0",
10547 });
10548 expect(`tbody .o_data_row:eq(1) td:eq(-2)`).toHaveText("1,200", {
10549 message: "default first record should have amount 1,200",
10550 });
10551 expect(`tbody .o_data_row:eq(2) td:eq(-2)`).toHaveText("500", {
10552 message: "default second record should have amount 500",
10553 });
10554 expect(`tbody .o_data_row:eq(3) td:eq(-2)`).toHaveText("300", {
10555 message: "default third record should have amount 300",
10556 });
10557
10558 // Drag and drop the fourth line in second position
10559 await contains(`tbody .o_data_row:eq(3) .o_handle_cell`).dragAndDrop(
10560 queryFirst(`tbody tr:eq(1)`)
10561 );
10562 expect.verifySteps([
10563 ["web_save", [3]],
10564 ["web_resequence", [3], "int_field", 2],
10565 ]);
10566 // Aggregates are not updated, todo later?
10567 expect(`.o_group_header:first`).toHaveText("No (2)\n 0");
10568 expect(`.o_group_header:last`).toHaveText("Yes (2)\n 2,000");
10569 expect(`tbody .o_data_row:eq(0) td:eq(-2)`).toHaveText("300", {
10570 message: "new first record should have amount 300",
10571 });
10572 expect(`tbody .o_data_row:eq(1) td:eq(-2)`).toHaveText("0", {
10573 message: "new second record should have amount 0",
10574 });
10575 expect(`tbody .o_data_row:eq(2) td:eq(-2)`).toHaveText("1,200", {
10576 message: "new third record should have amount 1,200",
10577 });
10578 expect(`tbody .o_data_row:eq(3) td:eq(-2)`).toHaveText("500", {
10579 message: "new fourth record should have amount 500",
10580 });
10581
10582 await contains(`tbody .o_data_row:eq(0) div[name='amount']`).click();
10583 expect(`tbody .o_data_row:eq(0) td:eq(-2) input`).toHaveValue("300", {
10584 message: "the edited record should be the good one",
10585 });
10586 });
10587
10588 test(`editable grouped list with handle widget (group by date)`, async () => {
10589 await mountView({
10590 resModel: "foo",
10591 type: "list",
10592 arch: `
10593 <list editable="top" default_order="int_field">
10594 <field name="int_field" widget="handle"/>
10595 <field name="amount" widget="float" digits="[5,0]"/>
10596 </list>
10597 `,
10598 groupBy: ["date"],
10599 });
10600 expect(`.o_group_header`).toHaveCount(2);
10601 await contains(`.o_group_header:first`).click();
10602 await contains(`.o_group_header:last`).click();
10603 expect(`.o_group_header:first`).toHaveText("January 2017 (1)\n 1,200");
10604 expect(`.o_group_header:last`).toHaveText("None (3)\n 800");
10605 expect(`.o_field_handle:first span`).not.toBeEnabled();
10606 });
10607
10608 test(`editable grouped list with handle widget (multiple group by)`, async () => {
10609 await mountView({
10610 resModel: "foo",
10611 type: "list",
10612 arch: `
10613 <list editable="top" default_order="int_field">
10614 <field name="int_field" widget="handle"/>
10615 <field name="amount" widget="float" digits="[5,0]"/>
10616 </list>
10617 `,
10618 groupBy: ["bar", "foo"],
10619 });
10620 expect(`.o_group_header`).toHaveCount(2);
10621 await contains(`.o_group_header:first`).click();
10622 await contains(`.o_group_header:eq(1)`).click(); // sub group
10623 expect(`.o_group_header:first`).toHaveText("No (1)\n 0");
10624 expect(`.o_group_header:eq(1)`).toHaveText("blip (1)\n 0");
10625 expect(`.o_field_handle:first span`).not.toBeEnabled();
10626 });
10627
10628 test(`editable target, handle widget locks and unlocks on sort`, async () => {
10629 // resequence makes sense on a sequence field, not on arbitrary fields
10630 Foo._records[0].int_field = 0;
10631 Foo._records[1].int_field = 1;
10632 Foo._records[2].int_field = 2;
10633 Foo._records[3].int_field = 3;
10634
10635 await mountView({
10636 resModel: "foo",
10637 type: "list",
10638 arch: `
10639 <list editable="top" default_order="int_field">
10640 <field name="int_field" widget="handle"/>
10641 <field name="amount" widget="float"/>
10642 </list>
10643 `,
10644 });
10645 expect(`.o_row_handle.o_disabled`).toHaveCount(0);
10646 expect(queryAllTexts(`tbody div[name=amount]`)).toEqual(
10647 ["1,200.00", "500.00", "300.00", "0.00"],
10648 {
10649 message: "default should be sorted by int_field",
10650 }
10651 );
10652
10653 // Drag and drop the fourth line in second position
10654 await contains(`tbody tr:eq(3) .o_row_handle`).dragAndDrop(`tbody tr:eq(1)`);
10655 // Handle should be unlocked at this point
10656 expect(queryAllTexts(`tbody div[name=amount]`)).toEqual(
10657 ["1,200.00", "0.00", "500.00", "300.00"],
10658 {
10659 message: "drag and drop should have succeeded, as the handle is unlocked",
10660 }
10661 );
10662
10663 // Sorting by a field different for int_field should lock the handle
10664 await contains(`.o_column_sortable:eq(1)`).click();
10665 expect(queryAllTexts(`tbody div[name=amount]`)).toEqual(
10666 ["0.00", "300.00", "500.00", "1,200.00"],
10667 {
10668 message: "should have been sorted by amount",
10669 }
10670 );
10671 expect(`.o_row_handle.o_disabled`).toHaveCount(4, {
10672 message: "handle fields should now be readonly and therefore disabled",
10673 });
10674
10675 // Drag and drop the fourth line in second position (not)
10676 await contains(`tbody tr:eq(3) .o_row_handle`).dragAndDrop(`tbody tr:eq(1)`);
10677 expect(queryAllTexts(`tbody div[name=amount]`)).toEqual(
10678 ["0.00", "300.00", "500.00", "1,200.00"],
10679 {
10680 message: "drag and drop should have failed as the handle is locked",
10681 }
10682 );
10683
10684 // Sorting by int_field should unlock the handle
10685 await contains(`.o_column_sortable`).click();
10686 expect(queryAllTexts(`tbody div[name=amount]`)).toEqual(
10687 ["1,200.00", "0.00", "500.00", "300.00"],
10688 {
10689 message: "records should be ordered as per the previous resequence",
10690 }
10691 );
10692 expect(`.o_row_handle.o_disabled`).toHaveCount(0);
10693
10694 // Drag and drop the fourth line in second position
10695 await contains(`tbody tr:eq(3) .o_row_handle`).dragAndDrop(`tbody tr:eq(1)`);
10696 expect(queryAllTexts(`tbody div[name=amount]`)).toEqual(
10697 ["1,200.00", "300.00", "0.00", "500.00"],
10698 {
10699 message: "drag and drop should have worked as the handle is unlocked",
10700 }
10701 );
10702 });
10703
10704 test.tags("desktop");
10705 test(`editable list with handle widget with slow network`, async () => {
10706 // resequence makes sense on a sequence field, not on arbitrary fields
10707 Foo._records[0].int_field = 0;
10708 Foo._records[1].int_field = 1;
10709 Foo._records[2].int_field = 2;
10710 Foo._records[3].int_field = 3;
10711
10712 const deferred = new Deferred();
10713 onRpc("web_resequence", async ({ args, kwargs }) => {
10714 expect.step(["web_resequence", args[0], kwargs.field_name, kwargs.offset]);
10715 await deferred;
10716 });
10717
10718 await mountView({
10719 resModel: "foo",
10720 type: "list",
10721 arch: `
10722 <list editable="top">
10723 <field name="int_field" widget="handle"/>
10724 <field name="amount" widget="float" digits="[5,0]"/>
10725 </list>
10726 `,
10727 });
10728 expect(queryAllTexts(`.o_data_cell[name=amount]`)).toEqual(["1,200", "500", "300", "0"]);
10729
10730 // drag and drop the fourth line in second position
10731 await contains(`tbody tr:eq(3) .o_handle_cell`).dragAndDrop(`tbody tr:eq(1)`);
10732 expect.verifySteps([["web_resequence", [4, 2, 3], "int_field", 1]]);
10733
10734 // edit moved row before the end of resequence
10735 await contains(`tbody tr:eq(3) .o_field_widget[name='amount']`).click();
10736 await animationFrame();
10737 expect(`tbody tr:eq(3) td:eq(2) input`).toHaveCount(0, {
10738 message: "shouldn't edit the line before resequence",
10739 });
10740
10741 deferred.resolve();
10742 await animationFrame();
10743 expect(`tbody tr:eq(3) td:eq(2) input`).toHaveCount(1, {
10744 message: "should edit the line after resequence",
10745 });
10746 expect(`tbody tr:eq(3) td:eq(2) input`).toHaveValue("300", {
10747 message: "fourth record should have amount 300",
10748 });
10749
10750 await contains(`.o_data_row [name='amount'] input`).edit("301", { confirm: false });
10751 await contains(`tbody tr:eq(0) .o_field_widget[name='amount']`).click();
10752 await contains(`.o_list_button_save`).click();
10753 expect(queryAllTexts(`.o_data_cell[name=amount]`)).toEqual(["1,200", "0", "500", "301"]);
10754
10755 await contains(`tbody tr:eq(3) .o_field_widget[name='amount']`).click();
10756 expect(`tbody tr:eq(3) td:eq(2) input`).toHaveValue("301", {
10757 message: "fourth record should have amount 301",
10758 });
10759 });
10760
10761 test(`multiple clicks on Add do not create invalid rows`, async () => {
10762 Foo._onChanges = {
10763 m2o() {},
10764 };
10765
10766 const deferred = new Deferred();
10767 onRpc("onchange", () => deferred);
10768
10769 await mountView({
10770 resModel: "foo",
10771 type: "list",
10772 arch: `<list editable="top"><field name="m2o" required="1"/></list>`,
10773 });
10774 expect(`.o_data_row`).toHaveCount(4, { message: "should contain 4 records" });
10775
10776 // click on Add and delay the onchange (check that the button is correctly disabled)
10777 await contains(`.o_list_button_add`).click();
10778 expect(`.o_list_button_add`).toHaveProperty("disabled", true);
10779
10780 deferred.resolve();
10781 await animationFrame();
10782 expect(`.o_data_row`).toHaveCount(5, { message: "only one record should have been created" });
10783 });
10784
10785 test(`reference field rendering`, async () => {
10786 Foo._records.push({
10787 id: 5,
10788 reference: "res.currency,2",
10789 });
10790
10791 await mountView({
10792 resModel: "foo",
10793 type: "list",
10794 arch: `<list><field name="reference"/></list>`,
10795 });
10796 expect(queryAllTexts(`.o_data_cell`)).toEqual(["Value 1", "USD", "EUR", "", "EUR"]);
10797 });
10798
10799 test(`reference field batched in grouped list`, async () => {
10800 Foo._records = [
10801 // group 1
10802 { id: 1, foo: "1", reference: "bar,1" },
10803 { id: 2, foo: "1", reference: "bar,2" },
10804 { id: 3, foo: "1", reference: "res.currency,1" },
10805 //group 2
10806 { id: 4, foo: "2", reference: "bar,2" },
10807 { id: 5, foo: "2", reference: "bar,3" },
10808 ];
10809
10810 stepAllNetworkCalls();
10811
10812 await mountView({
10813 resModel: "foo",
10814 type: "list",
10815 arch: `
10816 <list expand="1">
10817 <field name="foo" column_invisible="1"/>
10818 <field name="reference"/>
10819 </list>
10820 `,
10821 groupBy: ["foo"],
10822 });
10823 expect.verifySteps([
10824 "/web/webclient/translations",
10825 "/web/webclient/load_menus",
10826 "get_views",
10827 "web_read_group",
10828 "has_group",
10829 ]);
10830 expect(`.o_group_header`).toHaveCount(2);
10831 expect(queryAllTexts(`.o_data_cell`)).toEqual([
10832 "Value 1",
10833 "Value 2",
10834 "USD",
10835 "Value 2",
10836 "Value 3",
10837 ]);
10838 });
10839
10840 test.tags("desktop");
10841 test(`multi edit in view grouped by field not in view`, async () => {
10842 Foo._records = [
10843 // group 1
10844 { id: 1, foo: "1", m2o: 1 },
10845 { id: 3, foo: "2", m2o: 1 },
10846 //group 2
10847 { id: 2, foo: "1", m2o: 2 },
10848 { id: 4, foo: "2", m2o: 2 },
10849 // group 3
10850 { id: 5, foo: "2", m2o: 3 },
10851 ];
10852
10853 await mountView({
10854 resModel: "foo",
10855 type: "list",
10856 arch: `<list expand="1" multi_edit="1"><field name="foo"/></list>`,
10857 groupBy: ["m2o"],
10858 });
10859
10860 // Select items from the first group
10861 await contains(`.o_data_row:eq(0) .o_list_record_selector input`).click();
10862 await contains(`.o_data_row:eq(1) .o_list_record_selector input`).click();
10863 await contains(`.o_list_char`).click();
10864 await contains(`.o_data_row [name=foo] input`).edit("test");
10865 expect(`.modal`).toHaveCount(1);
10866
10867 await contains(`.modal .modal-footer .btn-primary`).click();
10868 expect(`.modal`).toHaveCount(0);
10869 expect(queryAllTexts(`.o_data_cell`)).toEqual(["test", "test", "1", "2", "2"]);
10870 });
10871
10872 test.tags("desktop");
10873 test(`multi edit reference field batched in grouped list`, async () => {
10874 Foo._records = [
10875 // group 1
10876 { id: 1, foo: "1", reference: "bar,1" },
10877 { id: 2, foo: "1", reference: "bar,2" },
10878 //group 2
10879 { id: 3, foo: "2", reference: "res.currency,1" },
10880 { id: 4, foo: "2", reference: "bar,2" },
10881 { id: 5, foo: "2", reference: "bar,3" },
10882 ];
10883
10884 stepAllNetworkCalls();
10885 onRpc("web_save", ({ args }) => {
10886 expect(args).toEqual([[1, 2, 3], { bar: true }]);
10887 });
10888
10889 // Field boolean_toggle just to simplify the test flow
10890 await mountView({
10891 type: "list",
10892 resModel: "foo",
10893 arch: `
10894 <list expand="1" multi_edit="1">
10895 <field name="foo" column_invisible="1"/>
10896 <field name="bar" widget="boolean_toggle"/>
10897 <field name="reference"/>
10898 </list>
10899 `,
10900 groupBy: ["foo"],
10901 });
10902 expect.verifySteps([
10903 "/web/webclient/translations",
10904 "/web/webclient/load_menus",
10905 "get_views",
10906 "web_read_group",
10907 "has_group",
10908 ]);
10909 await contains(`.o_data_row .o_list_record_selector input:eq(0)`).click();
10910 await contains(`.o_data_row .o_list_record_selector input:eq(1)`).click();
10911 await contains(`.o_data_row .o_list_record_selector input:eq(2)`).click();
10912 await contains(`.o_data_row .o_field_boolean input`).click();
10913 expect(`.modal`).toHaveCount(1);
10914
10915 await contains(`.modal .modal-footer .btn-primary`).click();
10916 expect(`.modal`).toHaveCount(0);
10917 expect.verifySteps(["web_save"]);
10918 expect(`.o_group_header`).toHaveCount(2);
10919 expect(queryAllTexts(`.o_data_cell[name=reference]`)).toEqual([
10920 "Value 1",
10921 "Value 2",
10922 "USD",
10923 "Value 2",
10924 "Value 3",
10925 ]);
10926 });
10927
10928 test.tags("desktop");
10929 test(`multi edit field with daterange widget`, async () => {
10930 mockTimeZone(+6);
10931
10932 class Daterange extends models.Model {
10933 date_start = fields.Date();
10934 date_end = fields.Date();
10935
10936 _records = [
10937 {
10938 id: 1,
10939 date_start: "2017-01-25",
10940 date_end: "2017-01-26",
10941 },
10942 {
10943 id: 2,
10944 date_start: "2017-01-02",
10945 date_end: "2017-01-03",
10946 },
10947 ];
10948 }
10949 defineModels([Daterange]);
10950
10951 onRpc("web_save", ({ args }) => {
10952 expect.step("web_save");
10953 expect(args).toEqual([[1, 2], { date_start: "2017-01-16", date_end: "2017-02-12" }]);
10954 });
10955
10956 await mountView({
10957 resModel: "daterange",
10958 type: "list",
10959 arch: `
10960 <list multi_edit="1">
10961 <field name="date_start" widget="daterange" options="{'end_date_field': 'date_end'}"/>
10962 </list>
10963 `,
10964 });
10965 await contains(`.o_list_record_selector input`).click();
10966 await contains(`.o_data_row .o_data_cell`).click(); // edit first row
10967 await contains(`.o_data_row .o_data_cell .o_field_daterange input`).click();
10968
10969 // change dates range
10970 await contains(getPickerCell("16")).click();
10971 await contains("button.o_next").click();
10972 await contains(getPickerCell("12")).click();
10973
10974 // Apply the changes
10975 await contains(`.o_list_view`).click();
10976
10977 expect(`.modal`).toHaveCount(1, {
10978 message: "The confirm dialog should appear to confirm the multi edition.",
10979 });
10980 expect(queryAllTexts(`.modal-body .o_modal_changes td`)).toEqual([
10981 "Field:",
10982 "Date start",
10983 "Update to:",
10984 "Jan 16, 2017\nFeb 12, 2017",
10985 "Field:",
10986 "Date end",
10987 "Update to:",
10988 "Feb 12, 2017",
10989 ]);
10990
10991 // Valid the confirm dialog
10992 await contains(`.modal .btn-primary`).click();
10993 expect(`.modal`).toHaveCount(0);
10994 expect.verifySteps(["web_save"]);
10995 });
10996
10997 test.tags("desktop");
10998 test(`multi edit field with daterange widget (edition without using the picker)`, async () => {
10999 mockTimeZone(+6);
11000
11001 class Daterange extends models.Model {
11002 date_start = fields.Date();
11003 date_end = fields.Date();
11004
11005 _records = [
11006 {
11007 id: 1,
11008 date_start: "2017-01-25",
11009 date_end: "2017-01-26",
11010 },
11011 {
11012 id: 2,
11013 date_start: "2017-01-02",
11014 date_end: "2017-01-03",
11015 },
11016 ];
11017 }
11018 defineModels([Daterange]);
11019
11020 onRpc("web_save", ({ args }) => {
11021 expect.step("web_save");
11022 expect(args).toEqual([[1, 2], { date_start: "2016-04-01" }]);
11023 });
11024
11025 await mountView({
11026 resModel: "daterange",
11027 type: "list",
11028 arch: `
11029 <list multi_edit="1">
11030 <field name="date_start" widget="daterange" options="{'end_date_field': 'date_end'}"/>
11031 </list>
11032 `,
11033 });
11034
11035 // Test manually edit the date without using the daterange picker
11036 await contains(`.o_list_record_selector input`).click();
11037 await contains(`.o_data_row .o_data_cell`).click(); // edit first row
11038
11039 // Change the date in the first datetime
11040 await contains(
11041 `.o_data_row .o_data_cell .o_field_daterange[name='date_start'] input[data-field='date_start']`
11042 ).edit("2016-04-01 11:00:00", { confirm: "enter" });
11043 expect(`.modal`).toHaveCount(1, {
11044 message: "The confirm dialog should appear to confirm the multi edition.",
11045 });
11046 expect(queryAllTexts(`.modal-body .o_modal_changes td`)).toEqual([
11047 "Field:",
11048 "Date start",
11049 "Update to:",
11050 "Apr 1, 2016\nJan 26, 2017",
11051 ]);
11052
11053 // Valid the confirm dialog
11054 await contains(`.modal .btn-primary`).click();
11055 expect(`.modal`).toHaveCount(0);
11056 expect.verifySteps(["web_save"]);
11057 });
11058
11059 test(`list daterange with start date and empty end date`, async () => {
11060 Foo._fields.date_end = fields.Date();
11061
11062 await mountView({
11063 resModel: "foo",
11064 type: "list",
11065 arch: `
11066 <list>
11067 <field name="date" widget="daterange" options="{'end_date_field': 'date_end'}"/>
11068 </list>
11069 `,
11070 });
11071 expect(queryAllTexts(`.o_data_row:eq(0) .o_field_widget[name=date] span`)).toEqual([
11072 "Jan 25, 2017",
11073 "",
11074 ]);
11075 });
11076
11077 test(`list daterange with empty start date and end date`, async () => {
11078 Foo._fields.date_end = fields.Date();
11079 Foo._records[0].date_end = Foo._records[0].date;
11080 Foo._records[0].date = false;
11081
11082 await mountView({
11083 resModel: "foo",
11084 type: "list",
11085 arch: `
11086 <list>
11087 <field name="date" widget="daterange" options="{'end_date_field': 'date_end'}"/>
11088 </list>
11089 `,
11090 });
11091 expect(queryAllTexts(`.o_data_row:eq(0) .o_field_widget[name=date] span`)).toEqual([
11092 "Jan 25, 2017",
11093 ]);
11094 });
11095
11096 test(`list daterange in form: open/close picker`, async () => {
11097 Foo._fields.foo_o2m = fields.One2many({ relation: "foo" });
11098 Foo._fields.date_end = fields.Date();
11099
11100 await mountView({
11101 resModel: "foo",
11102 type: "form",
11103 arch: `
11104 <form>
11105 <sheet>
11106 <field name="foo_o2m">
11107 <list editable="bottom">
11108 <field name="date" widget="daterange" options="{'end_date_field': 'date_end', 'always_range': '1'}"/>
11109 </list>
11110 </field>
11111 </sheet>
11112 </form>
11113 `,
11114 resId: 1,
11115 });
11116
11117 await contains(`.o_field_x2many_list_row_add a`).click();
11118 await contains(".o_field_daterange[name=date]").click();
11119 await animationFrame();
11120 await animationFrame();
11121 expect(".o_datetime_picker").toBeDisplayed();
11122 expect("input[data-field=date]").toBeFocused();
11123
11124 await contains(getPickerCell("15")).click();
11125 await contains(getPickerCell("20")).click();
11126
11127 // Close picker
11128 await pointerDown(`.o_view_controller`);
11129 await animationFrame();
11130 expect(".o_datetime_picker").toHaveCount(0);
11131
11132 // Wait to check if the picker is still closed
11133 await animationFrame();
11134 await animationFrame();
11135 expect(".o_datetime_picker").toHaveCount(0);
11136 });
11137
11138 test.tags("desktop");
11139 test(`editable list view: contexts are correctly sent`, async () => {
11140 serverState.userContext = { someKey: "some value" };
11141
11142 onRpc(({ method, kwargs }) => {
11143 if (method === "web_search_read" || method === "web_save") {
11144 expect.step(method);
11145 const context = kwargs.context;
11146 expect(context.active_field).toBe(2, { message: "context should be correct" });
11147 expect(context.someKey).toBe("some value", {
11148 message: "context should be correct",
11149 });
11150 }
11151 });
11152
11153 await mountView({
11154 resModel: "foo",
11155 type: "list",
11156 arch: `<list editable="top"><field name="foo"/></list>`,
11157 context: { active_field: 2 },
11158 });
11159 expect.verifySteps(["web_search_read"]);
11160
11161 await contains(`.o_data_cell`).click();
11162 await contains(`.o_field_widget[name=foo] input`).edit("abc", { confirm: false });
11163 await contains(`.o_list_button_save`).click();
11164 expect.verifySteps(["web_save"]);
11165 });
11166
11167 test.tags("desktop");
11168 test(`editable list view: contexts with multiple edit`, async () => {
11169 serverState.userContext = { someKey: "some value" };
11170
11171 onRpc("web_save", ({ args, kwargs }) => {
11172 expect.step("web_save");
11173 const context = kwargs.context;
11174 expect(context.active_field).toBe(2, { message: "context should be correct" });
11175 expect(context.someKey).toBe("some value", {
11176 message: "context should be correct",
11177 });
11178 });
11179
11180 await mountView({
11181 resModel: "foo",
11182 type: "list",
11183 arch: `<list multi_edit="1"><field name="foo"/></list>`,
11184 context: { active_field: 2 },
11185 });
11186 // Uses the main selector to select all lines.
11187 await contains(`.o_list_record_selector input`).click();
11188 await contains(`.o_data_row .o_data_cell`).click();
11189
11190 // Edits first record then confirms changes.
11191 await contains(`.o_data_row [name=foo] input`).edit("legion");
11192 await contains(`.modal-dialog button.btn-primary`).click();
11193 expect.verifySteps(["web_save"]);
11194 });
11195
11196 test.tags("desktop");
11197 test(`list view editable and multi editable: click on row with selected records`, async () => {
11198 await mountView({
11199 resModel: "foo",
11200 type: "list",
11201 arch: `<list editable="top" multi_edit="1"><field name="foo"/></list>`,
11202 });
11203
11204 // Select first record
11205 await contains(`.o_data_row .o_list_record_selector input`).click();
11206 expect(".o_data_row_selected").toHaveCount(1);
11207 // Click on a cell of the second record
11208 await contains(`.o_data_row:eq(1) .o_data_cell`).click();
11209 expect(".o_data_row_selected").toHaveCount(2);
11210 });
11211
11212 test.tags("desktop");
11213 test(`editable list view: non dirty record with required fields`, async () => {
11214 await mountView({
11215 resModel: "foo",
11216 type: "list",
11217 arch: `
11218 <list editable="top">
11219 <field name="foo" required="1"/>
11220 <field name="int_field"/>
11221 </list>
11222 `,
11223 });
11224 expect(`.o_data_row`).toHaveCount(4);
11225
11226 await contains(`.o_list_button_add`).click();
11227 expect(`.o_data_row`).toHaveCount(5);
11228 expect(`.o_selected_row`).toHaveCount(1);
11229
11230 // do not change anything and then click outside should discard record
11231 await contains(`.o_list_view`).click();
11232 expect(`.o_data_row`).toHaveCount(4);
11233 expect(`.o_selected_row`).toHaveCount(0);
11234
11235 await contains(`.o_list_button_add`).click();
11236 expect(`.o_data_row`).toHaveCount(5);
11237 expect(`.o_selected_row`).toHaveCount(1);
11238
11239 // do not change anything and then click save button should not allow to discard record
11240 await contains(`.o_list_button_save`).click();
11241 expect(`.o_data_row`).toHaveCount(5);
11242 expect(`.o_selected_row`).toHaveCount(1);
11243
11244 // selecting some other row should discard non dirty record
11245 await contains(`.o_data_row:eq(1) .o_data_cell`).click();
11246 expect(`.o_data_row`).toHaveCount(4);
11247 expect(`.o_selected_row`).toHaveCount(1);
11248
11249 // click somewhere else to discard currently selected row
11250 await contains(`.o_list_view`).click();
11251 expect(`.o_data_row`).toHaveCount(4);
11252 expect(`.o_selected_row`).toHaveCount(0);
11253
11254 await contains(`.o_list_button_add`).click();
11255 expect(`.o_data_row`).toHaveCount(5);
11256 expect(`.o_selected_row`).toHaveCount(1);
11257
11258 // do not change anything and press Enter key should not allow to discard record
11259 await press("Enter");
11260 await animationFrame();
11261 expect(`.o_selected_row`).toHaveCount(1);
11262
11263 // discard row and create new record and keep required field empty and click anywhere
11264 await contains(`.o_list_button_discard:not(.dropdown-item)`).click();
11265 await contains(`.o_list_button_add`).click();
11266 expect(`.o_selected_row`).toHaveCount(1, { message: "row should be selected" });
11267
11268 await contains(`.o_selected_row [name=int_field] input`).edit("123", { confirm: false });
11269 await contains(`.o_list_view`).click();
11270 expect(`.o_selected_row`).toHaveCount(1, { message: "row should still be in edition" });
11271 });
11272
11273 test.tags("desktop");
11274 test(`editable list view: multi edition`, async () => {
11275 stepAllNetworkCalls();
11276 onRpc("web_save", ({ args, kwargs }) => {
11277 if (args[0].length) {
11278 expect(args).toEqual([[1, 2], { int_field: 666 }], {
11279 message: "should write on multi records",
11280 });
11281 expect.step("conditional web_read");
11282 expect(kwargs.specification).toEqual({ foo: {}, int_field: {} });
11283 }
11284 });
11285
11286 await mountView({
11287 resModel: "foo",
11288 type: "list",
11289 arch: `
11290 <list editable="bottom" multi_edit="1">
11291 <field name="foo"/>
11292 <field name="int_field"/>
11293 </list>
11294 `,
11295 });
11296 expect.verifySteps([
11297 "/web/webclient/translations",
11298 "/web/webclient/load_menus",
11299 "get_views",
11300 "web_search_read",
11301 "has_group",
11302 ]);
11303
11304 // select two records
11305 await contains(`.o_data_row:eq(0) .o_list_record_selector input`).click();
11306 await contains(`.o_data_row:eq(1) .o_list_record_selector input`).click();
11307
11308 // edit a line without modifying a field
11309 await contains(`.o_data_row:eq(0) .o_data_cell:eq(0)`).click();
11310 expect(`.o_data_row:eq(0)`).toHaveClass("o_selected_row");
11311
11312 await contains(`.o_list_view`).click();
11313 expect(`.o_selected_row`).toHaveCount(0);
11314
11315 // create a record and edit its value
11316 await contains(`.o_list_button_add`).click();
11317 expect.verifySteps(["onchange"]);
11318
11319 await contains(`.o_selected_row [name=int_field] input`).edit("123", { confirm: false });
11320 expect(`.modal`).toHaveCount(0);
11321
11322 await contains(`.o_list_button_save`).click();
11323 expect.verifySteps(["web_save"]);
11324
11325 // edit a field
11326 await contains(`.o_data_row:eq(0) [name=int_field]`).click();
11327 await contains(`.o_data_row:eq(0) [name=int_field] input`).edit("666");
11328 expect(`.modal`).toHaveCount(1);
11329
11330 await contains(`.modal .btn.btn-secondary`).click();
11331 expect(`.o_list_record_selector input:checked`).toHaveCount(2);
11332 expect(queryAllTexts(`.o_data_row:eq(0) .o_data_cell`)).toEqual(["yop", "10"]);
11333 expect(`.o_data_row:eq(0) .o_data_cell[name=int_field]`).toBeFocused();
11334
11335 await contains(`.o_data_row:eq(0) .o_data_cell:eq(1)`).click();
11336 await contains(`.o_data_row [name=int_field] input`).edit("666");
11337 expect(".modal-body").toHaveText(/update 2 records/, {
11338 message: "the number of records should be correctly displayed",
11339 });
11340
11341 await contains(`.modal .btn-primary`).click();
11342 expect(`.o_data_cell input.o_field_widget`).toHaveCount(0, {
11343 message: "no field should be editable anymore",
11344 });
11345 // discard selection
11346 await contains(`.o_unselect_all`).click();
11347 expect(`.o_list_record_selector input:checked`).toHaveCount(0, {
11348 message: "no record should be selected anymore",
11349 });
11350 expect.verifySteps(["web_save", "conditional web_read"]);
11351 expect(queryAllTexts(`.o_data_row:eq(0) .o_data_cell`)).toEqual(["yop", "666"], {
11352 message: "the first row should be updated",
11353 });
11354 expect(queryAllTexts(`.o_data_row:eq(1) .o_data_cell`)).toEqual(["blip", "666"], {
11355 message: "the second row should be updated",
11356 });
11357 expect(`.o_data_cell input.o_field_widget`).toHaveCount(0, {
11358 message: "no field should be editable anymore",
11359 });
11360 });
11361
11362 test.tags("desktop");
11363 test(`editable list view: multi edit a field with string attr`, async () => {
11364 await mountView({
11365 resModel: "foo",
11366 type: "list",
11367 arch: `
11368 <list multi_edit="1">
11369 <field name="foo" string="Custom Label"/>
11370 <field name="int_field"/>
11371 </list>
11372 `,
11373 });
11374
11375 // select two records
11376 await contains(`.o_data_row:eq(0) .o_list_record_selector input`).click();
11377 await contains(`.o_data_row:eq(1) .o_list_record_selector input`).click();
11378
11379 // edit foo
11380 await contains(`.o_data_row:eq(0) .o_data_cell:eq(0)`).click();
11381 await contains(`.o_data_row [name=foo] input`).edit("new value");
11382 expect(`.modal`).toHaveCount(1);
11383 expect(queryAllTexts(`.modal-body .o_modal_changes td`)).toEqual([
11384 "Field:",
11385 "Custom Label",
11386 "Update to:",
11387 "new value",
11388 ]);
11389 });
11390
11391 test(`create in multi editable list`, async () => {
11392 await mountView({
11393 resModel: "foo",
11394 type: "list",
11395 arch: `
11396 <list multi_edit="1">
11397 <field name="foo"/>
11398 <field name="int_field"/>
11399 </list>
11400 `,
11401 createRecord() {
11402 expect.step("createRecord");
11403 },
11404 });
11405
11406 // click on CREATE (should trigger a switch_view)
11407 await contains(`.o_list_button_add`).click();
11408 expect.verifySteps(["createRecord"]);
11409 });
11410
11411 test.tags("desktop");
11412 test(`editable list view: multi edition cannot call onchanges`, async () => {
11413 Foo._onChanges = {
11414 foo(record) {
11415 record.int_field = record.foo.length;
11416 },
11417 };
11418
11419 stepAllNetworkCalls();
11420 onRpc("web_save", function ({ args }) {
11421 for (const record of this.env["foo"].browse(args[0])) {
11422 record.int_field = args[1].foo.length;
11423 }
11424 });
11425
11426 await mountView({
11427 resModel: "foo",
11428 type: "list",
11429 arch: `
11430 <list multi_edit="1">
11431 <field name="foo"/>
11432 <field name="int_field"/>
11433 </list>
11434 `,
11435 });
11436 expect.verifySteps([
11437 "/web/webclient/translations",
11438 "/web/webclient/load_menus",
11439 "get_views",
11440 "web_search_read",
11441 "has_group",
11442 ]);
11443
11444 // select and edit a single record
11445 await contains(`.o_data_row:eq(0) .o_list_record_selector input`).click();
11446 await contains(`.o_data_row:eq(0) .o_data_cell:eq(0)`).click();
11447 await contains(`.o_data_row [name=foo] input`).edit("hi");
11448 expect(`.modal`).toHaveCount(0);
11449 expect(queryAllTexts(`.o_data_row:eq(0) .o_data_cell`)).toEqual(["hi", "2"]);
11450 expect(queryAllTexts(`.o_data_row:eq(1) .o_data_cell`)).toEqual(["blip", "9"]);
11451 expect.verifySteps(["web_save"]);
11452 // select the second record (the first one is still selected)
11453 expect(`.o_list_record_selector input:checked`).toHaveCount(1, {
11454 message: "Record should be still selected",
11455 });
11456
11457 await contains(`.o_data_row:eq(1) .o_list_record_selector input`).click();
11458 // edit foo, first row
11459 await contains(`.o_data_row:eq(0) .o_data_cell:eq(0)`).click();
11460 await contains(`.o_data_row [name=foo] input`).edit("hello");
11461 expect(`.modal`).toHaveCount(1); // save dialog
11462
11463 await contains(`.modal .btn-primary`).click();
11464 expect(queryAllTexts(`.o_data_row:eq(0) .o_data_cell`)).toEqual(["hello", "5"]);
11465 expect(queryAllTexts(`.o_data_row:eq(1) .o_data_cell`)).toEqual(["hello", "5"]);
11466 // should not perform the onchange in multi edition
11467 expect.verifySteps(["web_save"]);
11468 });
11469
11470 test.tags("desktop");
11471 test(`editable list view: multi edition error and cancellation handling`, async () => {
11472 await mountView({
11473 resModel: "foo",
11474 type: "list",
11475 arch: `
11476 <list multi_edit="1">
11477 <field name="foo" required="1"/>
11478 <field name="int_field"/>
11479 </list>
11480 `,
11481 });
11482 expect(`.o_list_record_selector input:enabled`).toHaveCount(5);
11483
11484 // select two records
11485 await contains(`.o_data_row:eq(0) .o_list_record_selector input`).click();
11486 await contains(`.o_data_row:eq(1) .o_list_record_selector input`).click();
11487
11488 // edit a line and cancel
11489 await contains(`.o_data_row:eq(0) .o_data_cell:eq(0)`).click();
11490 expect(`.o_list_record_selector input:enabled`).toHaveCount(0);
11491 await contains(`.o_selected_row [name=foo] input`).edit("abc");
11492 await contains(`.modal .btn.btn-secondary`).click();
11493 expect(queryAllTexts(`.o_data_row:eq(0) .o_data_cell`)).toEqual(["yop", "10"], {
11494 message: "first cell should have discarded any change",
11495 });
11496 expect(`.o_list_record_selector input:enabled`).toHaveCount(5);
11497
11498 // edit a line with an invalid format type
11499 await contains(`.o_data_row:eq(0) .o_data_cell:eq(1)`).click();
11500 expect(`.o_list_record_selector input:enabled`).toHaveCount(0);
11501
11502 await contains(`.o_selected_row [name=int_field] input`).edit("hahaha", { confirm: "blur" });
11503 expect(`.o_notification`).toHaveCount(1);
11504 await contains(`.o_notification_close`).click();
11505 expect(queryAllTexts(`.o_data_row:eq(0) .o_data_cell`)).toEqual(["yop", "10"], {
11506 message: "changes should be discarded",
11507 });
11508 expect(`.o_list_record_selector input:enabled`).toHaveCount(5);
11509
11510 // edit a line with an invalid value
11511 await contains(`.o_data_row:eq(0) .o_data_cell:eq(0)`).click();
11512 expect(`.o_list_record_selector input:enabled`).toHaveCount(0);
11513
11514 await contains(`.o_selected_row [name=foo] input`).edit("", { confirm: false });
11515 await contains(`.o_control_panel`).click();
11516 expect(`.o_notification`).toHaveCount(1);
11517 expect(queryAllTexts(`.o_data_row:eq(0) .o_data_cell`)).toEqual(["yop", "10"], {
11518 message: "changes should be discarded",
11519 });
11520 expect(`.o_list_record_selector input:enabled`).toHaveCount(5);
11521 });
11522
11523 test.tags("desktop");
11524 test(`multi edition: many2many_tags in many2many field`, async () => {
11525 for (let i = 4; i <= 10; i++) {
11526 Bar._records.push({ id: i, name: "Value" + i });
11527 }
11528 Bar._views = {
11529 list: `<list><field name="name"/></list>`,
11530 };
11531
11532 await mountView({
11533 resModel: "foo",
11534 type: "list",
11535 arch: `<list multi_edit="1"><field name="m2m" widget="many2many_tags"/></list>`,
11536 });
11537
11538 expect(`.o_list_record_selector input:enabled`).toHaveCount(5);
11539
11540 // select two records and enter edit mode
11541 await contains(`.o_data_row:eq(0) .o_list_record_selector input`).click();
11542 await contains(`.o_data_row:eq(1) .o_list_record_selector input`).click();
11543 await contains(`.o_data_row:eq(0) .o_data_cell:eq(0)`).click();
11544 await contains(`.o_field_widget[name=m2m] input`).click();
11545 await contains(`.o-autocomplete--dropdown-item:contains(Search more...)`).click();
11546 expect(`.modal`).toHaveCount(1, { message: "should have open the modal" });
11547
11548 await contains(`.modal .o_data_row:eq(2) .o_field_cell`).click();
11549 expect(`.modal [role='alert']`).toHaveCount(1, {
11550 message: "should have open the confirmation modal",
11551 });
11552 expect(`.modal .o_field_many2many_tags .badge`).toHaveCount(1);
11553 expect(`.modal .o_field_many2many_tags .badge:eq(0)`).toHaveText("Value 3", {
11554 message: "should have display_name in badge",
11555 });
11556 });
11557
11558 test.tags("desktop");
11559 test(`multi edition: set a numeric field to 0`, async () => {
11560 await mountView({
11561 resModel: "foo",
11562 type: "list",
11563 arch: `
11564 <list multi_edit="1">
11565 <field name="foo"/>
11566 <field name="int_field"/>
11567 </list>
11568 `,
11569 });
11570
11571 expect(queryAllTexts(`.o_data_cell`)).toEqual([
11572 "yop",
11573 "10",
11574 "blip",
11575 "9",
11576 "gnap",
11577 "17",
11578 "blip",
11579 "-4",
11580 ]);
11581 await contains(`.o_list_record_selector`).click();
11582 expect(".o_data_row_selected").toHaveCount(4);
11583
11584 await contains(`.o_data_row:eq(0) .o_data_cell:eq(1)`).click();
11585 await contains(`.o_field_widget[name=int_field] input`).edit("0");
11586 expect(`.o_dialog`).toHaveCount(1);
11587 expect(`.modal-body`).toHaveText(`Are you sure you want to update 4 records?
11588
11589 Field: Int field
11590 Update to: 0
11591 Use the operators "+=", "-=", "*=" and "/=" to update the current value.
11592 For example, if the value is "1" and you enter "+=2", it will be updated to "3".`);
11593 await contains(`.o_dialog footer .btn-primary`).click();
11594 expect(queryAllTexts(`.o_data_cell`)).toEqual([
11595 "yop",
11596 "0",
11597 "blip",
11598 "0",
11599 "gnap",
11600 "0",
11601 "blip",
11602 "0",
11603 ]);
11604 });
11605
11606 test.tags("desktop");
11607 test(`multi edition: many2many_tags field: link a record`, async () => {
11608 stepAllNetworkCalls();
11609 await mountView({
11610 resModel: "foo",
11611 type: "list",
11612 arch: `
11613 <list multi_edit="1">
11614 <field name="foo"/>
11615 <field name="m2m" widget="many2many_tags"/>
11616 </list>
11617 `,
11618 });
11619
11620 expect(queryAllTexts(`.o_data_cell`)).toEqual([
11621 "yop",
11622 "Value 1\nValue 2",
11623 "blip",
11624 "Value 1\nValue 2\nValue 3",
11625 "gnap",
11626 "",
11627 "blip",
11628 "Value 1",
11629 ]);
11630 await contains(`.o_list_record_selector`).click();
11631 expect(".o_data_row_selected").toHaveCount(4);
11632
11633 await contains(`.o_data_row:eq(0) .o_data_cell:eq(1)`).click();
11634 await contains(`.o_field_widget[name=m2m] input`).click();
11635 await contains(`.o-autocomplete--dropdown-item:contains(Value 3)`).click();
11636 expect(`.o_dialog`).toHaveCount(1);
11637 expect(`.modal-body`).toHaveText(`Are you sure you want to update 4 records?
11638
11639 Field: M2m
11640 Add: \nValue 3`);
11641
11642 await contains(`.o_dialog footer .btn-primary`).click();
11643 expect.verifySteps([
11644 "/web/webclient/translations",
11645 "/web/webclient/load_menus",
11646 "get_views",
11647 "web_search_read",
11648 "has_group",
11649 "web_name_search",
11650 "web_read", // we want only one web_read, not one by selected record
11651 "web_save",
11652 ]);
11653 expect(queryAllTexts(`.o_data_cell`)).toEqual([
11654 "yop",
11655 "Value 1\nValue 2\nValue 3",
11656 "blip",
11657 "Value 1\nValue 2\nValue 3",
11658 "gnap",
11659 "Value 3",
11660 "blip",
11661 "Value 1\nValue 3",
11662 ]);
11663 });
11664
11665 test.tags("desktop");
11666 test(`multi edition: many2many field required field`, async () => {
11667 onRpc("web_save", ({ args }) => {
11668 expect.step("web_save");
11669 // can't write on record 4 as it would make it invalid
11670 expect(args[0]).toEqual([1, 2, 3]);
11671 expect(args[1]).toEqual({ m2m: [[3, 1]] });
11672 });
11673 await mountView({
11674 resModel: "foo",
11675 type: "list",
11676 arch: `
11677 <list multi_edit="1">
11678 <field name="foo"/>
11679 <field name="m2m" widget="many2many_tags" required="foo == 'blip'"/>
11680 </list>
11681 `,
11682 });
11683
11684 await contains(`.o_list_record_selector`).click();
11685 expect(".o_data_row_selected").toHaveCount(4);
11686
11687 await contains(`.o_data_row:eq(0) .o_data_cell:eq(1)`).click();
11688 await contains(`.o_field_widget[name=m2m] .o_tag:contains(Value 1) .o_delete`).click();
11689 expect(`.o_dialog`).toHaveCount(1);
11690 expect(`.modal-body`).toHaveText(`Among the 4 selected records, 3 are valid for this update.
11691 Are you sure you want to update 3 records?
11692
11693 Field: M2m
11694 Remove: \nValue 1`);
11695
11696 await contains(`.o_dialog footer .btn-primary`).click();
11697 expect.verifySteps(["web_save"]);
11698 });
11699
11700 test.tags("desktop");
11701 test(`multi edition: many2many field required field (edit another field)`, async () => {
11702 onRpc("web_save", ({ args }) => {
11703 expect.step("web_save");
11704 // can't write on record 3 as it would make it invalid
11705 expect(args[0]).toEqual([1, 2, 4]);
11706 expect(args[1]).toEqual({ foo: "force required" });
11707 });
11708 await mountView({
11709 resModel: "foo",
11710 type: "list",
11711 arch: `
11712 <list multi_edit="1">
11713 <field name="foo"/>
11714 <field name="m2m" widget="many2many_tags" required="foo == 'force required'"/>
11715 </list>
11716 `,
11717 });
11718
11719 await contains(`.o_list_record_selector`).click();
11720 expect(".o_data_row_selected").toHaveCount(4);
11721
11722 await contains(`.o_data_row:eq(0) .o_data_cell:eq(0)`).click();
11723 await contains(`.o_data_row:eq(0) .o_field_widget[name=foo] input`).edit("force required");
11724 expect(`.o_dialog`).toHaveCount(1);
11725 expect(`.modal-body`).toHaveText(`Among the 4 selected records, 3 are valid for this update.
11726 Are you sure you want to update 3 records?
11727
11728 Field: Foo
11729 Update to: force required`);
11730
11731 await contains(`.o_dialog footer .btn-primary`).click();
11732 expect.verifySteps(["web_save"]);
11733 });
11734
11735 test.tags("desktop");
11736 test(`multi edition: many2many field required field (edited field is invalid)`, async () => {
11737 onRpc("web_save", ({ args }) => {
11738 expect.step("web_save");
11739 // can't write on record 4 as it would make it invalid
11740 expect(args[0]).toEqual([1, 2, 3]);
11741 expect(args[1]).toEqual({ m2m: [[3, 1]] });
11742 });
11743 await mountView({
11744 resModel: "foo",
11745 type: "list",
11746 arch: `
11747 <list multi_edit="1">
11748 <field name="foo"/>
11749 <field name="m2m" widget="many2many_tags" required="foo == 'blip'"/>
11750 </list>
11751 `,
11752 });
11753
11754 await contains(`.o_list_record_selector`).click();
11755 expect(".o_data_row_selected").toHaveCount(4);
11756 expect(`.o_data_row:eq(3) .o_data_cell:eq(1) .o_tag`).toHaveCount(1);
11757
11758 await contains(`.o_data_row:eq(3) .o_data_cell:eq(1)`).click(); // edit last row
11759 await contains(`.o_field_widget[name=m2m] .o_tag:contains(Value 1) .o_delete`).click();
11760 expect(`.o_data_row:eq(3) .o_data_cell:eq(1) .o_tag`).toHaveCount(1); // still there
11761 expect(`.o_dialog`).toHaveCount(1);
11762 expect(`.modal-body`).toHaveText(`Among the 4 selected records, 3 are valid for this update.
11763 Are you sure you want to update 3 records?
11764
11765 Field: M2m
11766 Remove: \nValue 1`);
11767
11768 await contains(`.o_dialog footer .btn-primary`).click();
11769 expect.verifySteps(["web_save"]);
11770 });
11771
11772 test.tags("desktop");
11773 test(`multi edition: many2many field in grouped list`, async () => {
11774 await mountView({
11775 resModel: "foo",
11776 type: "list",
11777 arch: `
11778 <list multi_edit="1">
11779 <field name="foo"/>
11780 <field name="m2m" widget="many2many_tags"/>
11781 </list>
11782 `,
11783 groupBy: ["m2m"],
11784 });
11785 await contains(`.o_group_header:eq(1)`).click();
11786 await contains(`.o_group_header:eq(2)`).click(); // open Value 2 group
11787 await contains(`.o_data_row:eq(0) .o_list_record_selector input`).click();
11788 await contains(`.o_data_row:eq(0) .o_data_cell:eq(1)`).click();
11789 await contains(`.o_field_widget[name=m2m] input`).click();
11790 await contains(`.o-autocomplete--dropdown-item:contains(Value 3)`).click();
11791 expect(`.o_data_row:eq(0) .o_data_cell:eq(1)`).toHaveText("Value 1\nValue 2\nValue 3", {
11792 message: "should have a right value in many2many field",
11793 });
11794 expect(`.o_data_row:eq(2) .o_data_cell:eq(1)`).toHaveText("Value 1\nValue 2\nValue 3", {
11795 message: "should have same value in many2many field on all other records with same res_id",
11796 });
11797 });
11798
11799 test.tags("desktop");
11800 test(`editable list view: multi edition of many2one: set same value`, async () => {
11801 onRpc("web_save", ({ args }) => {
11802 expect.step("web_save");
11803 expect(args).toEqual([[1, 2, 3, 4], { m2o: 2 }], {
11804 message: "should force write value on all selected records",
11805 });
11806 });
11807 await mountView({
11808 resModel: "foo",
11809 type: "list",
11810 arch: `
11811 <list multi_edit="1">
11812 <field name="foo"/>
11813 <field name="m2o"/>
11814 </list>
11815 `,
11816 });
11817 expect(queryAllTexts(`.o_list_many2one`)).toEqual(["Value 1", "Value 2", "Value 1", "Value 1"]);
11818
11819 // select all records (the first one has value 1 for m2o)
11820 await contains(`.o_list_record_selector input`).click();
11821
11822 // set m2o to 1 in first record
11823 await contains(`.o_data_row .o_data_cell`).click();
11824 await contains(`.o_data_row [name=m2o] input`).fill("Value 2", { confirm: false });
11825 await runAllTimers();
11826 await contains(`.o-autocomplete--dropdown-item:contains(Value 2)`).click();
11827 expect(`.modal`).toHaveCount(1);
11828
11829 await contains(`.modal .modal-footer .btn-primary`).click();
11830 expect(queryAllTexts(`.o_list_many2one`)).toEqual(["Value 2", "Value 2", "Value 2", "Value 2"]);
11831 expect.verifySteps(["web_save"]);
11832 });
11833
11834 test.tags("desktop");
11835 test(`editable list view: clicking on "Discard changes" in multi edition`, async () => {
11836 await mountView({
11837 resModel: "foo",
11838 type: "list",
11839 arch: `
11840 <list editable="top" multi_edit="1">
11841 <field name="foo"/>
11842 </list>
11843 `,
11844 });
11845
11846 // select two records
11847 await contains(`.o_data_row:eq(0) .o_list_record_selector input`).check();
11848 await contains(`.o_data_row:eq(1) .o_list_record_selector input`).check();
11849 await contains(`.o_data_row:eq(0) .o_data_cell:eq(0)`).click();
11850 await contains(`.o_data_row [name=foo] input`).edit("oof", { confirm: "blur" });
11851
11852 await clickModalButton({ text: "Cancel" });
11853
11854 expect(`.modal`).toHaveCount(0, { message: "should not open modal" });
11855 expect(`.o_data_row:eq(0) .o_data_cell:eq(0)`).toHaveText("yop");
11856 });
11857
11858 test.tags("desktop");
11859 test(`discard has to wait for changes in each field in multi edit`, async () => {
11860 const def = new Deferred();
11861
11862 class CustomField extends Component {
11863 static template = xml`<input t-ref="input" t-att-value="value" t-on-blur="onBlur" t-on-input="onInput"/>`;
11864 static props = {
11865 ...standardFieldProps,
11866 };
11867
11868 setup() {
11869 this.input = useRef("input");
11870 useBus(this.props.record.model.bus, "NEED_LOCAL_CHANGES", ({ detail }) =>
11871 detail.proms.push(this.updateValue())
11872 );
11873 }
11874
11875 get value() {
11876 return this.props.record.data[this.props.name];
11877 }
11878
11879 async updateValue() {
11880 if (!this.isDirty) {
11881 return;
11882 }
11883 const value = this.input.el.value;
11884 await def;
11885 await this.props.record.update({ [this.props.name]: `update value: ${value}` });
11886 }
11887
11888 onBlur() {
11889 return this.updateValue();
11890 }
11891
11892 onInput() {
11893 this.isDirty = true;
11894 this.props.record.model.bus.trigger("FIELD_IS_DIRTY", true);
11895 }
11896 }
11897 registry.category("fields").add("custom", { component: CustomField });
11898
11899 await mountView({
11900 resModel: "foo",
11901 type: "list",
11902 arch: `
11903 <list editable="top" multi_edit="1">
11904 <field name="foo" widget="custom"/>
11905 </list>
11906 `,
11907 });
11908
11909 // select two records
11910 await contains(`.o_data_row:eq(0) .o_list_record_selector input`).click();
11911 await contains(`.o_data_row:eq(1) .o_list_record_selector input`).click();
11912 await contains(`.o_data_row:eq(0) .o_data_cell`).click();
11913 await contains(`.o_data_row .o_data_cell input`).edit("oof", { confirm: false });
11914 await contains(`.o_list_button_discard`).click();
11915 expect(`.modal`).toHaveCount(0);
11916 expect(`.o_data_row:eq(0) .o_data_cell input`).toHaveValue("oof");
11917
11918 def.resolve();
11919 await animationFrame();
11920 expect(`.modal`).toHaveCount(0);
11921 expect(`.o_data_row:eq(0) .o_data_cell input`).toHaveValue("yop");
11922 });
11923
11924 test.tags("desktop");
11925 test(`editable list view: mousedown on "Discard", mouseup somewhere else (no multi-edit)`, async () => {
11926 stepAllNetworkCalls();
11927
11928 await mountView({
11929 resModel: "foo",
11930 type: "list",
11931 arch: `
11932 <list editable="top">
11933 <field name="foo"/>
11934 </list>
11935 `,
11936 });
11937
11938 await contains(`.o_data_row:eq(0) .o_data_cell:eq(0)`).click();
11939 await contains(`.o_data_row [name=foo] input`).edit("oof", { confirm: false });
11940 await pointerDown(`.o_list_button_discard`);
11941 await pointerUp(".o_control_panel");
11942 await animationFrame();
11943 expect(`.modal`).toHaveCount(0, { message: "should not open modal" });
11944 expect(queryAllTexts(`.o_data_cell`)).toEqual(["oof", "blip", "gnap", "blip"]);
11945 expect.verifySteps([
11946 "/web/webclient/translations",
11947 "/web/webclient/load_menus",
11948 "get_views",
11949 "web_search_read",
11950 "has_group",
11951 "web_save",
11952 ]);
11953 });
11954
11955 test.tags("desktop");
11956 test(`multi edit list view: mousedown on "Discard" with invalid field`, async () => {
11957 await mountView({
11958 resModel: "foo",
11959 type: "list",
11960 arch: `
11961 <list multi_edit="1">
11962 <field name="int_field"/>
11963 </list>
11964 `,
11965 });
11966 expect(`.o_data_row:eq(0) .o_data_cell`).toHaveText("10");
11967
11968 // select two records
11969 await contains(`.o_data_row:eq(0) .o_list_record_selector input`).click();
11970 await contains(`.o_data_row:eq(1) .o_list_record_selector input`).click();
11971
11972 // edit the numeric field with an invalid value
11973 await contains(`.o_data_row:eq(0) .o_data_cell`).click();
11974 await contains(`.o_data_row:eq(0) .o_data_cell input`).edit("oof", { confirm: false });
11975
11976 // mousedown on Discard and then mouseup also on Discard
11977 await contains(`.o_list_button_discard`).click();
11978 expect(`.o_notification`).toHaveCount(0);
11979 expect(`.o_data_row:eq(0) .o_data_cell`).toHaveText("10");
11980
11981 // edit again with an invalid value
11982 await contains(`.o_data_row:eq(0) .o_data_cell`).click();
11983 await contains(`.o_data_row:eq(0) .o_data_cell input`).edit("oof2", { confirm: false });
11984
11985 // mousedown on Discard (simulate a mousemove) and mouseup somewhere else
11986 await pointerDown(".o_list_button_discard");
11987 await animationFrame();
11988 expect(`.o_notification`).toHaveCount(0);
11989
11990 await pointerUp(".o_control_panel");
11991 await animationFrame();
11992 // FIXME: Hoot incorrectly triggers"change" events *after* the blur instead of
11993 // *before*, causing the internals of the list controller/renderer to dispatch
11994 // 2 notifications.
11995 expect(`.o_notification`).toHaveCount(2);
11996 expect(`.o_data_row:eq(0) .o_data_cell`).toHaveText("10");
11997 });
11998
11999 test.tags("desktop");
12000 test(`editable list view (multi edition): mousedown on 'Discard', but mouseup somewhere else`, async () => {
12001 await mountView({
12002 resModel: "foo",
12003 type: "list",
12004 arch: `<list multi_edit="1"><field name="foo"/></list>`,
12005 });
12006
12007 // select two records
12008 await contains(`.o_data_row:eq(0) .o_list_record_selector input`).click();
12009 await contains(`.o_data_row:eq(1) .o_list_record_selector input`).click();
12010 await contains(`.o_data_row:eq(0) .o_data_cell`).click();
12011 await contains(`.o_data_row [name=foo] input`).fill("oof", { confirm: false });
12012 await pointerDown(".o_list_button_discard");
12013 await animationFrame();
12014 await pointerUp(".o_control_panel");
12015 await animationFrame();
12016 expect(`.modal-header`).toHaveText("Confirmation", {
12017 message: "Modal should ask to save changes",
12018 });
12019 });
12020
12021 test.tags("desktop");
12022 test(`editable list view (multi edition): writable fields in readonly (force save)`, async () => {
12023 stepAllNetworkCalls();
12024 onRpc("web_save", ({ args }) => {
12025 expect(args).toEqual([[1, 3], { bar: false }]);
12026 });
12027
12028 // boolean toogle widget allows for writing on the record even in readonly mode
12029 await mountView({
12030 resModel: "foo",
12031 type: "list",
12032 arch: `
12033 <list multi_edit="1">
12034 <field name="bar" widget="boolean_toggle"/>
12035 </list>
12036 `,
12037 });
12038 expect.verifySteps([
12039 "/web/webclient/translations",
12040 "/web/webclient/load_menus",
12041 "get_views",
12042 "web_search_read",
12043 "has_group",
12044 ]);
12045 // select two records
12046 await contains(`.o_data_row:eq(0) .o_list_record_selector input`).click();
12047 await contains(`.o_data_row:eq(2) .o_list_record_selector input`).click();
12048 await contains(`.o_data_row:eq(0) .o_boolean_toggle input`).click();
12049 expect(`.modal-header`).toHaveText("Confirmation");
12050
12051 await contains(`.modal .btn-primary`).click();
12052 expect.verifySteps(["web_save"]);
12053 });
12054
12055 test.tags("desktop");
12056 test(`editable list view: multi edition with readonly modifiers`, async () => {
12057 onRpc("web_save", ({ args }) => {
12058 expect.step("web_save");
12059 expect(args).toEqual([[1, 2], { int_field: 666 }], {
12060 message: "should only write on the valid records",
12061 });
12062 });
12063
12064 await mountView({
12065 resModel: "foo",
12066 type: "list",
12067 arch: `
12068 <list multi_edit="1">
12069 <field name="id"/>
12070 <field name="foo"/>
12071 <field name="int_field" readonly="id > 2"/>
12072 </list>
12073 `,
12074 });
12075 // select all records
12076 await contains(`.o_list_record_selector input`).click();
12077 await contains(`.o_data_row .o_data_cell:eq(1)`).click();
12078 await contains(`.o_data_row [name=int_field] input`).edit("666");
12079
12080 expect(`.modal-body main p`)
12081 .toHaveText(`Among the 4 selected records, 2 are valid for this update.
12082 Are you sure you want to update 2 records?`);
12083 expect(`.modal-body main .o_modal_changes`).toHaveText(`Field: Int field
12084 Update to: 666`);
12085 expect(queryOne(".modal .o_modal_changes .o_field_widget").parentNode.style.pointerEvents).toBe(
12086 "none",
12087 { message: "pointer events should be deactivated on the demo widget" }
12088 );
12089
12090 await contains(`.modal .btn-primary`).click();
12091 expect.verifySteps(["web_save"]);
12092 expect(queryAllTexts(`.o_data_row:eq(0) .o_data_cell`)).toEqual(["1", "yop", "666"], {
12093 message: "the first row should be updated",
12094 });
12095 expect(queryAllTexts(`.o_data_row:eq(1) .o_data_cell`)).toEqual(["2", "blip", "666"], {
12096 message: "the second row should be updated",
12097 });
12098 });
12099
12100 test.tags("desktop");
12101 test(`editable list view: multi edition when the domain is selected`, async () => {
12102 await mountView({
12103 resModel: "foo",
12104 type: "list",
12105 arch: `
12106 <list multi_edit="1" limit="2">
12107 <field name="id"/>
12108 <field name="int_field"/>
12109 </list>
12110 `,
12111 });
12112
12113 // select all records, and then select all domain
12114 await contains(`.o_list_record_selector input`).click();
12115 await contains(`.o_selection_box .o_select_domain`).click();
12116
12117 // edit a field
12118 await contains(`.o_data_row .o_data_cell:eq(1)`).click();
12119 await contains(`.o_data_row [name=int_field] input`).edit("666");
12120 expect(`.modal-body`).toHaveText(
12121 /This update will only consider the records of the current page./
12122 );
12123 });
12124
12125 test.tags("desktop");
12126 test(`editable list view: many2one with readonly modifier`, async () => {
12127 await mountView({
12128 resModel: "foo",
12129 type: "list",
12130 arch: `
12131 <list editable="top">
12132 <field name="m2o" readonly="1"/>
12133 <field name="foo"/>
12134 </list>
12135 `,
12136 });
12137
12138 // edit a field
12139 await contains(`.o_data_row .o_data_cell`).click();
12140 expect(`.o_data_row:eq(0) .o_data_cell:eq(0) div[name=m2o] a`).toHaveCount(1);
12141 expect(`.o_data_row .o_data_cell:eq(1) input`).toBeFocused({
12142 message: "focus should go to the char input",
12143 });
12144 });
12145
12146 test.tags("desktop");
12147 test(`editable list view: multi edition server error handling`, async () => {
12148 onRpc("web_save", () => {
12149 throw makeServerError();
12150 });
12151
12152 await mountView({
12153 resModel: "foo",
12154 type: "list",
12155 arch: `<list multi_edit="1"><field name="foo" required="1"/></list>`,
12156 });
12157
12158 // select two records
12159 await contains(`.o_data_row:eq(0) .o_list_record_selector input`).click();
12160 await contains(`.o_data_row:eq(1) .o_list_record_selector input`).click();
12161
12162 // edit a line and confirm
12163 await contains(`.o_data_row:eq(0) .o_data_cell:eq(0)`).click();
12164 await contains(`.o_selected_row [name=foo] input`).edit("abc");
12165 await contains(`.o_list_view`).click();
12166
12167 expect.errors(1);
12168 await contains(`.modal .btn-primary`).click();
12169 expect.verifyErrors(["RPC_ERROR"]);
12170
12171 expect(`.o_data_row:eq(0) .o_data_cell`).toHaveText("yop", {
12172 message: "first cell should have discarded any change",
12173 });
12174 expect(`.o_data_row:eq(1) .o_data_cell`).toHaveText("blip", {
12175 message: "second selected record should not have changed",
12176 });
12177 expect(`.o_data_cell input.o_field_widget`).toHaveCount(0, {
12178 message: "no field should be editable anymore",
12179 });
12180 });
12181
12182 test.tags("desktop");
12183 test(`editable readonly list view: navigation`, async () => {
12184 await mountView({
12185 resModel: "foo",
12186 type: "list",
12187 arch: `
12188 <list multi_edit="1">
12189 <field name="foo"/>
12190 <field name="int_field"/>
12191 </list>
12192 `,
12193 selectRecord(resId) {
12194 expect.step(`resId: ${resId}`);
12195 },
12196 });
12197 expect(`.o_searchview_input`).toBeFocused();
12198
12199 // ArrowDown two times must get to the checkbox selector of first data row
12200 await press("ArrowDown");
12201 await press("ArrowDown");
12202 await animationFrame();
12203 expect(`.o_data_row:eq(0) .o_list_record_selector input`).toBeFocused();
12204
12205 // select the second record
12206 await press("ArrowDown");
12207 await animationFrame();
12208 expect(`.o_data_row:eq(1) .o_list_record_selector input`).toBeFocused();
12209 expect(`.o_data_row:eq(1) .o_list_record_selector input`).not.toBeChecked();
12210
12211 await press("space");
12212 await animationFrame();
12213 expect(`.o_data_row:eq(1) .o_list_record_selector input`).toBeFocused();
12214 expect(`.o_data_row:eq(1) .o_list_record_selector input`).toBeChecked();
12215
12216 // select the fourth record
12217 await press("ArrowDown");
12218 await press("ArrowDown");
12219 await animationFrame();
12220 expect(`.o_data_row:eq(3) .o_list_record_selector input`).toBeFocused();
12221 expect(`.o_data_row:eq(3) .o_list_record_selector input`).not.toBeChecked();
12222
12223 await press("space");
12224 await animationFrame();
12225 expect(`.o_data_row:eq(3) .o_list_record_selector input`).toBeFocused();
12226 expect(`.o_data_row:eq(3) .o_list_record_selector input`).toBeChecked();
12227
12228 // toggle a row mode
12229 await press("ArrowUp");
12230 await press("ArrowUp");
12231 await press("ArrowRight");
12232 await animationFrame();
12233 expect(`.o_data_row:eq(1) [name=foo]`).toBeFocused();
12234
12235 await press("Enter");
12236 await animationFrame();
12237 expect(`.o_selected_row`).toHaveCount(1);
12238 expect(`.o_data_row:eq(1)`).toHaveClass("o_selected_row");
12239 expect(`.o_data_row:eq(1) [name=foo] input`).toBeFocused();
12240
12241 // Keyboard navigation only interracts with selected elements
12242 await press("Enter");
12243 await animationFrame();
12244 expect(`.o_selected_row`).toHaveCount(1);
12245 expect(`.o_data_row:eq(3)`).toHaveClass("o_selected_row");
12246 expect(`.o_data_row:eq(3) [name=foo] input`).toBeFocused();
12247
12248 await press("Tab"); // go to 4th row int_field
12249 await press("Tab"); // go to 2nd row foo field
12250 await animationFrame();
12251 expect(`.o_selected_row`).toHaveCount(1);
12252 expect(`.o_data_row:eq(1)`).toHaveClass("o_selected_row");
12253 expect(`.o_data_row:eq(1) [name=foo] input`).toBeFocused();
12254
12255 await press("Tab"); // go to 2nd row int_field
12256 await press("Tab"); // go to 4th row foo field
12257 await animationFrame();
12258 expect(`.o_selected_row`).toHaveCount(1);
12259 expect(`.o_data_row:eq(3)`).toHaveClass("o_selected_row");
12260 expect(`.o_data_row:eq(3) [name=foo] input`).toBeFocused();
12261
12262 await press("Shift+Tab"); // go to 2nd row int_field
12263 await animationFrame();
12264 expect(`.o_selected_row`).toHaveCount(1);
12265 expect(`.o_data_row:eq(1)`).toHaveClass("o_selected_row");
12266 expect(`.o_data_row:eq(1) [name=int_field] input`).toBeFocused();
12267
12268 await press("Shift+Tab"); // go to 2nd row foo field
12269 await press("Shift+Tab"); // go to 4th row int_field field
12270 await animationFrame();
12271 expect(`.o_selected_row`).toHaveCount(1);
12272 expect(`.o_data_row:eq(3)`).toHaveClass("o_selected_row");
12273 expect(`.o_data_row:eq(3) [name=int_field] input`).toBeFocused();
12274
12275 // Clicking on an unselected row while a row is being edited will leave the edition
12276 await contains(`.o_data_row:eq(2) [name=foo]`).click();
12277 expect(`.o_selected_row`).toHaveCount(0);
12278
12279 // Clicking on an unselected record while no row is being edited will select it
12280 expect(`.o_data_row_selected`).toHaveCount(2);
12281 await contains(`.o_data_row:eq(2) [name=foo]`).click();
12282 expect(`.o_data_row_selected`).toHaveCount(3);
12283 expect.verifySteps([]);
12284 });
12285
12286 test.tags("desktop");
12287 test(`editable list view: multi edition: edit and validate last row`, async () => {
12288 await mountView({
12289 resModel: "foo",
12290 type: "list",
12291 arch: `
12292 <list multi_edit="1">
12293 <field name="foo"/>
12294 <field name="int_field"/>
12295 </list>
12296 `,
12297 });
12298 expect(`.o_data_row`).toHaveCount(4);
12299 await contains(`.o_list_view .o_list_record_selector input`).click();
12300
12301 await contains(`.o_data_row:eq(-1) [name=int_field]`).click();
12302 await contains(`.o_data_row:eq(-1) [name=int_field] input`).fill("7", { confirm: "Enter" });
12303 expect(`.modal`).toHaveCount(1);
12304
12305 await contains(`.modal .btn-primary`).click();
12306 expect(`.o_data_row`).toHaveCount(4);
12307 });
12308
12309 test.tags("desktop");
12310 test(`editable readonly list view: navigation in grouped list`, async () => {
12311 await mountView({
12312 resModel: "foo",
12313 type: "list",
12314 arch: `<list multi_edit="1"><field name="foo"/></list>`,
12315 groupBy: ["bar"],
12316 selectRecord(resId) {
12317 expect.step(`resId: ${resId}`);
12318 },
12319 });
12320
12321 // Open both groups
12322 expect(`.o_group_header`).toHaveCount(2);
12323 await contains(`.o_group_header:eq(0)`).click();
12324 await contains(`.o_group_header:eq(1)`).click();
12325
12326 // select 2 records
12327 expect(`.o_data_row`).toHaveCount(4);
12328 await contains(`.o_data_row:eq(0) .o_list_record_selector input`).click();
12329 await contains(`.o_data_row:eq(2) .o_list_record_selector input`).click();
12330
12331 // toggle a row mode
12332 await contains(`.o_data_row:eq(0) [name=foo]`).click();
12333 expect(`.o_selected_row`).toHaveCount(1);
12334 expect(`.o_data_row:eq(0)`).toHaveClass("o_selected_row");
12335 expect(`.o_data_row:eq(0) [name=foo] input`).toBeFocused();
12336
12337 // Keyboard navigation only interracts with selected elements
12338 await press("Enter");
12339 await animationFrame();
12340 expect(`.o_selected_row`).toHaveCount(1);
12341 expect(`.o_data_row:eq(2)`).toHaveClass("o_selected_row");
12342 expect(`.o_data_row:eq(2) [name=foo] input`).toBeFocused();
12343
12344 await press("Tab");
12345 await animationFrame();
12346 expect(`.o_selected_row`).toHaveCount(1);
12347 expect(`.o_data_row:eq(0)`).toHaveClass("o_selected_row");
12348 expect(`.o_data_row:eq(0) [name=foo] input`).toBeFocused();
12349
12350 await press("Tab");
12351 await animationFrame();
12352 expect(`.o_selected_row`).toHaveCount(1);
12353 expect(`.o_data_row:eq(2)`).toHaveClass("o_selected_row");
12354 expect(`.o_data_row:eq(2) [name=foo] input`).toBeFocused();
12355
12356 // Click on a non selected row
12357 await contains(`.o_data_row:eq(3) [name=foo]`).click();
12358 expect(`.o_selected_row`).toHaveCount(0);
12359
12360 // Click again should select the clicked record
12361 expect(`.o_data_row_selected`).toHaveCount(2);
12362 await contains(`.o_data_row:eq(3) [name=foo]`).click();
12363 expect(`.o_data_row_selected`).toHaveCount(3);
12364 expect.verifySteps([]);
12365 });
12366
12367 test.tags("desktop");
12368 test(`editable readonly list view: single edition does not behave like a multi-edition`, async () => {
12369 await mountView({
12370 resModel: "foo",
12371 type: "list",
12372 arch: `<list multi_edit="1"><field name="foo" required="1"/></list>`,
12373 });
12374
12375 // select a record
12376 await contains(`.o_data_row:eq(0) .o_list_record_selector input`).click();
12377 // edit a field (invalid input)
12378 await contains(`.o_data_row:eq(0) .o_data_cell:eq(0)`).click();
12379 await clear({ confirm: "blur" });
12380 await animationFrame();
12381 expect(`.o_notification`).toHaveCount(1);
12382 await contains(`.o_notification_close`).click();
12383
12384 // edit a field
12385 await contains(`.o_data_row:eq(0) .o_data_cell:eq(0)`).click();
12386 await contains(`.o_data_row [name=foo] input`).edit("bar");
12387 expect(`.o_notification`).toHaveCount(0);
12388 expect(`.o_data_row:eq(0) .o_data_cell`).toHaveText("bar", {
12389 message: "the first row should be updated",
12390 });
12391 });
12392
12393 test.tags("desktop");
12394 test(`non editable list view: multi edition`, async () => {
12395 stepAllNetworkCalls();
12396 onRpc("web_save", ({ args, kwargs }) => {
12397 if (args[0].length) {
12398 expect(args).toEqual([[1, 2], { int_field: 666 }], {
12399 message: "should write on multi records",
12400 });
12401 expect.step("conditional web_read");
12402 expect(kwargs.specification).toEqual({ foo: {}, int_field: {} });
12403 }
12404 });
12405
12406 await mountView({
12407 resModel: "foo",
12408 type: "list",
12409 arch: `
12410 <list multi_edit="1">
12411 <field name="foo"/>
12412 <field name="int_field"/>
12413 </list>
12414 `,
12415 });
12416 expect.verifySteps([
12417 "/web/webclient/translations",
12418 "/web/webclient/load_menus",
12419 "get_views",
12420 "web_search_read",
12421 "has_group",
12422 ]);
12423
12424 // select two records
12425 await contains(`.o_data_row:eq(0) .o_list_record_selector input`).click();
12426 await contains(`.o_data_row:eq(1) .o_list_record_selector input`).click();
12427
12428 // edit a field
12429 await contains(`.o_data_row:eq(0) .o_data_cell:eq(1)`).click();
12430 await contains(`.o_data_row [name=int_field] input`).edit("666");
12431 await contains(`.o_data_row:eq(0) .o_data_cell:eq(0)`).click();
12432 expect(`.modal`).toHaveCount(1, { message: "modal appears when switching cells" });
12433
12434 await contains(`.modal .btn-secondary`).click();
12435 expect(queryAllTexts(`.o_data_row:eq(0) .o_data_cell`)).toEqual(["yop", "10"], {
12436 message: "changes have been discarded and row is back to readonly",
12437 });
12438
12439 await contains(`.o_data_row:eq(0) .o_data_cell:eq(1)`).click();
12440 await contains(`.o_data_row [name=int_field] input`).edit("666");
12441 expect(`.modal`).toHaveCount(1);
12442 expect(".modal").toHaveText(/update 2 records/, {
12443 message: "the number of records should be correctly displayed",
12444 });
12445
12446 await contains(`.modal .btn-primary`).click();
12447 expect.verifySteps(["web_save", "conditional web_read"]);
12448 expect(queryAllTexts(`.o_data_row:eq(0) .o_data_cell`)).toEqual(["yop", "666"], {
12449 message: "the first row should be updated",
12450 });
12451 expect(queryAllTexts(`.o_data_row:eq(1) .o_data_cell`)).toEqual(["blip", "666"], {
12452 message: "the second row should be updated",
12453 });
12454 expect(`.o_data_cell input.o_field_widget`).toHaveCount(0, {
12455 message: "no field should be editable anymore",
12456 });
12457 });
12458
12459 test.tags("desktop");
12460 test(`editable list view: m2m tags in grouped list`, async () => {
12461 await mountView({
12462 resModel: "foo",
12463 type: "list",
12464 arch: `
12465 <list editable="top" multi_edit="1">
12466 <field name="bar"/>
12467 <field name="m2m" widget="many2many_tags"/>
12468 </list>
12469 `,
12470 groupBy: ["bar"],
12471 });
12472
12473 // Opens first group
12474 await contains(`.o_group_header:eq(1)`).click();
12475 expect(queryAllTexts(`td.o_many2many_tags_cell`)).toEqual([
12476 "Value 1\nValue 2",
12477 "Value 1\nValue 2\nValue 3",
12478 "",
12479 ]);
12480
12481 await contains(`thead .o_list_record_selector input`).click();
12482 await contains(`.o_data_row .o_field_many2many_tags`).click();
12483 await contains(`.o_selected_row .o_field_many2many_tags .o_delete`).click();
12484 await contains(`.modal .btn-primary`).click();
12485 expect(queryAllTexts(`td.o_many2many_tags_cell`)).toEqual(["Value 2", "Value 2\nValue 3", ""]);
12486 });
12487
12488 test.tags("desktop");
12489 test(`editable list: edit many2one from external link`, async () => {
12490 Bar._views = {
12491 form: `<form><field name="name"/></form>`,
12492 };
12493
12494 onRpc("get_formview_id", () => false);
12495
12496 await mountViewInDialog({
12497 resModel: "foo",
12498 type: "list",
12499 arch: `<list editable="top" multi_edit="1"><field name="m2o"/></list>`,
12500 });
12501 expect(`.o_dialog .o_list_view`).toHaveCount(1);
12502 expect(`.o_selected_row`).toHaveCount(0);
12503
12504 await contains(`thead .o_list_record_selector input`).click();
12505 await contains(`.o_data_row .o_data_cell`).click();
12506 expect(`.o_selected_row`).toHaveCount(1, { message: "in edit mode" });
12507
12508 await contains(`.o_external_button`).click();
12509 // Clicking somewhere on the form dialog should not close it
12510 // and should not leave edit mode
12511 expect(`.modal[role='dialog']`).toHaveCount(2);
12512
12513 await contains(`.modal[role='dialog']`).click();
12514 expect(`.modal[role='dialog']`).toHaveCount(2);
12515 expect(`.o_selected_row`).toHaveCount(1, { message: "in edit mode" });
12516
12517 // Change the M2O value in the Form dialog (will open a confirmation dialog)
12518 await contains(`.modal:eq(1) input`).edit("OOF");
12519 await contains(`.modal:eq(1) .o_form_button_save`).click();
12520 expect(`.modal[role='dialog']`).toHaveCount(3);
12521 expect(`.modal:eq(2) .o_field_widget[name=m2o]`).toHaveText("OOF", {
12522 message: "Value of the m2o should be updated in the confirmation dialog",
12523 });
12524
12525 // Close the confirmation dialog
12526 await contains(`.modal:eq(2) .btn-primary`).click();
12527 expect(`.o_data_cell:eq(0)`).toHaveText("OOF", {
12528 message: "Value of the m2o should be updated in the list",
12529 });
12530 });
12531
12532 test.tags("desktop");
12533 test(`editable list with fields with readonly modifier`, async () => {
12534 await mountView({
12535 resModel: "foo",
12536 type: "list",
12537 arch: `
12538 <list editable="top">
12539 <field name="bar"/>
12540 <field name="foo" readonly="bar"/>
12541 <field name="m2o" readonly="not bar"/>
12542 <field name="int_field"/>
12543 </list>
12544 `,
12545 });
12546
12547 await contains(`.o_list_button_add`).click();
12548 expect(`.o_selected_row`).toHaveCount(1);
12549 expect(`.o_selected_row .o_field_boolean input`).not.toBeChecked();
12550 expect(`.o_selected_row .o_field_char`).not.toHaveClass("o_readonly_modifier");
12551 expect(`.o_selected_row .o_field_many2one`).toHaveClass("o_readonly_modifier");
12552
12553 await contains(`.o_selected_row .o_field_boolean input`).click();
12554 expect(`.o_selected_row .o_field_boolean input`).toBeChecked();
12555 expect(`.o_selected_row .o_field_char`).toHaveClass("o_readonly_modifier");
12556 expect(`.o_selected_row .o_field_many2one`).not.toHaveClass("o_readonly_modifier");
12557
12558 await contains(`.o_selected_row .o_field_many2one`).click();
12559 expect(`.o_selected_row .o_field_many2one input`).toBeFocused();
12560 });
12561
12562 test.tags("desktop");
12563 test(`editable form alongside html field: click out to unselect the row`, async () => {
12564 Bar._fields.name = fields.Char();
12565
12566 await mountView({
12567 resModel: "foo",
12568 type: "form",
12569 arch: `
12570 <form>
12571 <field name="text" widget="html"/>
12572 <field name="o2m">
12573 <list editable="bottom">
12574 <field name="name"/>
12575 </list>
12576 </field>
12577 </form>
12578 `,
12579 });
12580 expect(`.o_data_row`).toHaveCount(0);
12581
12582 await contains(`.o_field_x2many_list_row_add a`).click();
12583 expect(`.o_data_row`).toHaveCount(1);
12584 expect(`.o_data_row`).toHaveClass("o_selected_row");
12585
12586 await contains(`[name=o2m] .o_field_x2many .o_selected_row [name=name] input`).edit(
12587 "new value"
12588 );
12589 // click outside to unselect the row
12590 await contains(`.o_form_view`).click();
12591 expect(`.o_data_row`).toHaveCount(1);
12592 expect(`.o_data_row`).not.toHaveClass("o_selected_row");
12593 });
12594
12595 test(`list grouped by date:month`, async () => {
12596 await mountView({
12597 resModel: "foo",
12598 type: "list",
12599 arch: `<list><field name="date"/></list>`,
12600 groupBy: ["date:month"],
12601 });
12602 expect(queryAllTexts(`.o_group_header`)).toEqual(["January 2017 (1)", "None (3)"], {
12603 message: "the group names should be correct",
12604 });
12605 });
12606
12607 test(`grouped list edition with boolean_favorite widget`, async () => {
12608 onRpc("web_save", ({ args }) => {
12609 expect.step("web_save");
12610 expect(args[1]).toEqual({ bar: false }, { message: "should write the correct value" });
12611 });
12612 await mountView({
12613 resModel: "foo",
12614 type: "list",
12615 arch: `<list><field name="bar" widget="boolean_favorite"/></list>`,
12616 groupBy: ["m2o"],
12617 });
12618
12619 await contains(`.o_group_header`).click();
12620 expect(`.o_data_row:eq(0) .fa-star`).toHaveCount(1, {
12621 message: "boolean value of the first record should be true",
12622 });
12623
12624 await contains(".o_data_row:eq(0) .fa-star", { visible: false }).click();
12625 expect.verifySteps(["web_save"]);
12626 expect(`.o_data_row:eq(0) .fa-star-o`).toHaveCount(1, {
12627 message: "boolean value of the first record should have been updated",
12628 });
12629 });
12630
12631 test(`grouped list view, indentation for empty group`, async () => {
12632 Foo._fields.priority = fields.Selection({
12633 selection: [
12634 [1, "Low"],
12635 [2, "Medium"],
12636 [3, "High"],
12637 ],
12638 default: 1,
12639 });
12640 Foo._records.push({
12641 id: 5,
12642 foo: "blip",
12643 int_field: -7,
12644 m2o: 1,
12645 priority: 2,
12646 });
12647 Foo._records.push({
12648 id: 6,
12649 foo: "blip",
12650 int_field: 5,
12651 m2o: 1,
12652 priority: 3,
12653 });
12654
12655 onRpc("web_read_group", ({ kwargs }) => {
12656 // Override of the web_read_group to display the row even if there is no record in it,
12657 // to mock the behavihour of some fields e.g stage_id on the sale order.
12658 if (kwargs.groupby[0] === "m2o") {
12659 return {
12660 groups: [
12661 {
12662 id: 8,
12663 m2o: [1, "Value 1"],
12664 m2o_count: 0,
12665 },
12666 {
12667 id: 2,
12668 m2o: [2, "Value 2"],
12669 m2o_count: 1,
12670 },
12671 ],
12672 length: 1,
12673 };
12674 }
12675 });
12676
12677 await mountView({
12678 resModel: "foo",
12679 type: "list",
12680 arch: `<list><field name="id"/></list>`,
12681 groupBy: ["priority", "m2o"],
12682 });
12683
12684 // open the first group
12685 await contains(`.o_group_header`).click();
12686 expect(`tr:nth-child(1) th.o_group_name span.o_group_caret`).toHaveCount(1, {
12687 message: "There should be an element creating the indentation for the subgroup.",
12688 });
12689 expect(`tr:nth-child(1) th.o_group_name span.o_group_caret`).toHaveStyle(
12690 { "--o-list-group-level": "0" },
12691 {
12692 message:
12693 "The element creating the indentation should have a group level to use for margin css calculation.",
12694 }
12695 );
12696 });
12697
12698 test.tags("desktop");
12699 test(`use the limit attribute in arch`, async () => {
12700 onRpc("web_search_read", ({ kwargs }) => {
12701 expect.step("web_search_read");
12702 expect(kwargs.limit).toBe(2, {
12703 message: "should use the correct limit value",
12704 });
12705 });
12706
12707 await mountView({
12708 resModel: "foo",
12709 type: "list",
12710 arch: `<list limit="2"><field name="foo"/></list>`,
12711 });
12712 expect.verifySteps(["web_search_read"]);
12713 expect(getPagerValue()).toEqual([1, 2]);
12714 expect(getPagerLimit()).toBe(4);
12715 expect(`.o_data_row`).toHaveCount(2, { message: "should display 2 data rows" });
12716 });
12717
12718 test(`concurrent reloads finishing in inverse order`, async () => {
12719 let blockSearchRead = false;
12720 const deferred = new Deferred();
12721 onRpc("web_search_read", () => {
12722 if (blockSearchRead) {
12723 return deferred;
12724 }
12725 });
12726
12727 await mountView({
12728 resModel: "foo",
12729 type: "list",
12730 arch: `<list><field name="foo"/></list>`,
12731 searchViewArch: `
12732 <search>
12733 <filter name="yop" domain="[('foo', '=', 'yop')]"/>
12734 </search>
12735 `,
12736 });
12737 expect(`.o_list_view .o_data_row`).toHaveCount(4, {
12738 message: "list view should contain 4 records",
12739 });
12740
12741 // reload with a domain (this request is blocked)
12742 blockSearchRead = true;
12743 // list.reload({ domain: [["foo", "=", "yop"]] });
12744 await toggleSearchBarMenu();
12745 await toggleMenuItem("yop");
12746 expect(`.o_list_view .o_data_row`).toHaveCount(4, {
12747 message: "list view should still contain 4 records (search_read being blocked)",
12748 });
12749
12750 // reload without the domain
12751 blockSearchRead = false;
12752 await toggleMenuItem("yop");
12753 expect(`.o_list_view .o_data_row`).toHaveCount(4, {
12754 message: "list view should still contain 4 records",
12755 });
12756
12757 // unblock the RPC
12758 deferred.resolve();
12759 await animationFrame();
12760 expect(`.o_list_view .o_data_row`).toHaveCount(4, {
12761 message: "list view should still contain 4 records",
12762 });
12763 });
12764
12765 test.tags("desktop");
12766 test(`list view move to previous page when all records from last page deleted`, async () => {
12767 let checkSearchRead = false;
12768 onRpc("web_search_read", ({ kwargs }) => {
12769 if (checkSearchRead) {
12770 expect.step(`web_search_read (limit: ${kwargs.limit}, offset: ${kwargs.offset})`);
12771 }
12772 });
12773 await mountView({
12774 resModel: "foo",
12775 type: "list",
12776 arch: `<list limit="3"><field name="display_name"/></list>`,
12777 actionMenus: {},
12778 });
12779 expect(getPagerValue()).toEqual([1, 3]);
12780 expect(getPagerLimit()).toBe(4);
12781
12782 // move to next page
12783 await pagerNext();
12784 expect(getPagerValue()).toEqual([4, 4]);
12785 expect(getPagerLimit()).toBe(4);
12786
12787 // delete a record
12788 await contains(`tbody .o_data_row td.o_list_record_selector input`).click();
12789 checkSearchRead = true;
12790
12791 await contains(`.o_cp_action_menus .dropdown-toggle`).click();
12792 await contains(`.o-dropdown--menu .o_menu_item:contains(Delete)`).click();
12793 await contains(`.modal button.btn-primary`).click();
12794 expect(getPagerValue()).toEqual([1, 3]);
12795 expect(getPagerLimit()).toBe(3);
12796 expect.verifySteps([
12797 "web_search_read (limit: 3, offset: 3)",
12798 "web_search_read (limit: 3, offset: 0)",
12799 ]);
12800 });
12801
12802 test.tags("desktop");
12803 test(`grouped list view move to previous page of group when all records from last page deleted`, async () => {
12804 onRpc("web_search_read", ({ kwargs }) => {
12805 expect.step(`web_search_read ${kwargs.limit} - ${kwargs.offset}`);
12806 });
12807 await mountView({
12808 resModel: "foo",
12809 type: "list",
12810 arch: `<list limit="2"><field name="display_name"/></list>`,
12811 actionMenus: {},
12812 groupBy: ["m2o"],
12813 });
12814 expect(`th:contains(Value 1 (3))`).toHaveCount(1, {
12815 message: "Value 1 should contain 3 records",
12816 });
12817 expect(`th:contains(Value 2 (1))`).toHaveCount(1, {
12818 message: "Value 2 should contain 1 record",
12819 });
12820
12821 await contains(`.o_group_header:eq(0)`).click();
12822 expect(getPagerValue(queryFirst(`.o_group_header`))).toEqual([1, 2]);
12823 expect(getPagerLimit(queryFirst(`.o_group_header`))).toBe(3);
12824 expect.verifySteps(["web_search_read 2 - 0"]);
12825
12826 // move to next page
12827 await pagerNext(queryFirst(`.o_group_header`));
12828 expect(getPagerValue(queryFirst(`.o_group_header`))).toEqual([3, 3]);
12829 expect(getPagerLimit(queryFirst(`.o_group_header`))).toBe(3);
12830 expect.verifySteps(["web_search_read 2 - 2"]);
12831
12832 // delete a record
12833 await contains(`.o_data_row .o_list_record_selector input`).click();
12834 await contains(`.o_cp_action_menus .dropdown-toggle`).click();
12835 await contains(`.dropdown-item:contains(Delete)`).click();
12836 await contains(`.modal .btn-primary`).click();
12837 expect(`th.o_group_name:eq(0) .o_pager_counter`).toHaveCount(0);
12838 expect(`.o_data_row`).toHaveCount(2);
12839 });
12840
12841 test.tags("desktop");
12842 test(`grouped list view move to previous page of group when all records from last page deleted with more pages`, async () => {
12843 Foo._records.push({ id: 6, foo: "foo", m2o: 1 });
12844 Foo._records.push({ id: 7, foo: "foo", m2o: 1 });
12845 onRpc("web_search_read", ({ kwargs }) => {
12846 expect.step(`web_search_read ${kwargs.limit} - ${kwargs.offset}`);
12847 });
12848 await mountView({
12849 resModel: "foo",
12850 type: "list",
12851 arch: `<list limit="2"><field name="display_name"/></list>`,
12852 actionMenus: {},
12853 groupBy: ["m2o"],
12854 });
12855 expect(`th:contains(Value 1 (5))`).toHaveCount(1, {
12856 message: "Value 1 should contain 3 records",
12857 });
12858 expect(`th:contains(Value 2 (1))`).toHaveCount(1, {
12859 message: "Value 2 should contain 1 record",
12860 });
12861 await contains(`.o_group_header:eq(0)`).click();
12862 expect(getPagerValue(queryFirst(`.o_group_header`))).toEqual([1, 2]);
12863 expect(getPagerLimit(queryFirst(`.o_group_header`))).toBe(5);
12864 expect.verifySteps(["web_search_read 2 - 0"]);
12865
12866 // move to next page
12867 await pagerNext(queryFirst(`.o_group_header`));
12868 await pagerNext(queryFirst(`.o_group_header`));
12869 expect(getPagerValue(queryFirst(`.o_group_header`))).toEqual([5, 5]);
12870 expect(getPagerLimit(queryFirst(`.o_group_header`))).toBe(5);
12871 expect.verifySteps(["web_search_read 2 - 2", "web_search_read 2 - 4"]);
12872
12873 // delete a record
12874 await contains(`.o_data_row .o_list_record_selector input`).click();
12875 await contains(`.o_cp_action_menus .dropdown-toggle`).click();
12876 await contains(`.dropdown-item:contains(Delete)`).click();
12877 await contains(`.modal .btn-primary`).click();
12878 expect(`th.o_group_name:eq(0) .o_pager_counter`).toHaveCount(1);
12879 expect(`.o_data_row`).toHaveCount(2);
12880 });
12881
12882 test.tags("desktop");
12883 test(`grouped list view move to next page when all records from the current page deleted`, async () => {
12884 Foo._records = [1, 2, 3, 4, 5, 6]
12885 .map((i) => ({
12886 id: i,
12887 foo: `yop${i}`,
12888 m2o: 1,
12889 }))
12890 .concat([{ id: 7, foo: "blip", m2o: 2 }]);
12891
12892 await mountView({
12893 resModel: "foo",
12894 type: "list",
12895 arch: `<list limit="2"><field name="foo"/></list>`,
12896 actionMenus: {},
12897 groupBy: ["m2o"],
12898 });
12899 expect(`tr.o_group_header:eq(0) th:eq(0)`).toHaveText("Value 1 (6)");
12900 expect(`tr.o_group_header:eq(1) th:eq(0)`).toHaveText("Value 2 (1)");
12901
12902 const firstGroup = queryFirst(`tr.o_group_header:eq(0)`);
12903 await contains(firstGroup).click();
12904 expect(getPagerValue(firstGroup)).toEqual([1, 2]);
12905 expect(getPagerLimit(firstGroup)).toBe(6);
12906
12907 // delete all records from current page
12908 await contains(`thead .o_list_record_selector input`).click();
12909 await contains(`.o_cp_action_menus .dropdown-toggle`).click();
12910 await contains(`.dropdown-item:contains(Delete)`).click();
12911 await contains(`.modal .btn-primary`).click();
12912 expect(`.o_group_header:eq(0) .o_group_name`).toHaveText(`Value 1 (4)\n1-2 / 4`);
12913 expect(queryAllTexts(`.o_data_row`)).toEqual(["yop3", "yop4"]);
12914 });
12915
12916 test.tags("desktop");
12917 test(`list view move to previous page when all records from last page archive/unarchived`, async () => {
12918 // add active field on foo model and make all records active
12919 Foo._fields.active = fields.Boolean({ default: true });
12920
12921 await mountView({
12922 resModel: "foo",
12923 type: "list",
12924 arch: `<list limit="3"><field name="display_name"/></list>`,
12925 actionMenus: {},
12926 });
12927 expect(`.o_pager_counter`).toHaveText("1-3 / 4", {
12928 message: "should have 2 pages and current page should be first page",
12929 });
12930 expect(`tbody td.o_list_record_selector`).toHaveCount(3, {
12931 message: "should have 3 records",
12932 });
12933
12934 // move to next page
12935 await contains(`.o_pager_next`).click();
12936 expect(`.o_pager_counter`).toHaveText("4-4 / 4", {
12937 message: "should be on second page",
12938 });
12939 expect(`tbody td.o_list_record_selector`).toHaveCount(1, {
12940 message: "should have 1 records",
12941 });
12942 expect(`.o_control_panel_actions .o_cp_action_menus`).toHaveCount(0, {
12943 message: "sidebar should not be available",
12944 });
12945
12946 await contains(`tbody .o_data_row:eq(0) td.o_list_record_selector:eq(0) input`).click();
12947 expect(`.o_control_panel_actions .o_cp_action_menus`).toHaveCount(1, {
12948 message: "sidebar should be available",
12949 });
12950
12951 // archive all records of current page
12952 await contains(`.o_cp_action_menus .dropdown-toggle`).click();
12953 await toggleMenuItem("Archive");
12954 expect(`.modal`).toHaveCount(1, { message: "a confirm modal should be displayed" });
12955
12956 await contains(`.modal-footer .btn-primary`).click();
12957 expect(`tbody td.o_list_record_selector`).toHaveCount(3, {
12958 message: "should have 3 records",
12959 });
12960 expect(queryFirst(`.o_pager_counter`)).toHaveText("1-3 / 3", {
12961 message: "should have 1 page only",
12962 });
12963 });
12964
12965 test.tags("desktop");
12966 test(`list should ask to scroll to top on page changes`, async () => {
12967 // add records to be able to scroll
12968 for (let i = 5; i < 55; i++) {
12969 Foo._records.push({ id: i, foo: "foo" });
12970 }
12971 patchWithCleanup(ListController.prototype, {
12972 onPageChangeScroll() {
12973 super.onPageChangeScroll(...arguments);
12974 expect.step("scroll");
12975 },
12976 });
12977
12978 await mountView({
12979 resModel: "foo",
12980 type: "list",
12981 arch: `<list limit="3"><field name="display_name"/></list>`,
12982 });
12983 // switch pages (should ask to scroll)
12984 await pagerNext();
12985 await pagerPrevious();
12986 // should ask to scroll when switching pages
12987 expect.verifySteps(["scroll", "scroll"]);
12988
12989 // change the limit (should not ask to scroll)
12990 await contains(`.o_pager_value`).click();
12991 await contains(`.o_pager_value`).edit("1-25");
12992 await animationFrame();
12993 expect(getPagerValue()).toEqual([1, 25]);
12994 // should not ask to scroll when changing the limit
12995 expect.verifySteps([]);
12996
12997 await contains(".o_list_renderer").scroll({ top: 250 });
12998 expect(".o_list_renderer").toHaveProperty("scrollTop", 250);
12999
13000 // switch pages again (should still ask to scroll)
13001 await pagerNext();
13002 // this is still working after a limit change
13003 expect.verifySteps(["scroll"]);
13004 // Should effectively reset the scroll position
13005 expect(".o_list_renderer").toHaveProperty("scrollTop", 0);
13006 });
13007
13008 test.tags("desktop");
13009 test(`list with handle field, override default_get, bottom when inline`, async () => {
13010 Foo._fields.int_field = fields.Integer({ default: 10 });
13011
13012 await mountView({
13013 resModel: "foo",
13014 type: "list",
13015 arch: `
13016 <list editable="bottom" default_order="int_field">
13017 <field name="int_field" widget="handle"/>
13018 <field name="foo"/>
13019 </list>
13020 `,
13021 });
13022 // starting condition
13023 expect(queryAllTexts(`.o_data_cell.o_list_char`)).toEqual(["blip", "blip", "yop", "gnap"]);
13024
13025 // click add a new line
13026 // save the record
13027 // check line is at the correct place
13028 await contains(`.o_list_button_add`).click();
13029 await contains(`[name=foo] input`).edit("ninja", { confirm: false });
13030 await contains(`.o_list_button_save`).click();
13031 await contains(`.o_list_button_add`).click();
13032 expect(queryAllTexts(`.o_data_cell.o_list_char`)).toEqual([
13033 "blip",
13034 "blip",
13035 "yop",
13036 "gnap",
13037 "ninja",
13038 "",
13039 ]);
13040 });
13041
13042 test.tags("desktop");
13043 test(`create record on list with modifiers depending on id`, async () => {
13044 await mountView({
13045 resModel: "foo",
13046 type: "list",
13047 arch: `
13048 <list editable="top">
13049 <field name="id" column_invisible="1"/>
13050 <field name="foo" readonly="id"/>
13051 <field name="int_field" invisible="id"/>
13052 </list>
13053 `,
13054 });
13055 // add a new record
13056 await contains(`.o_list_button_add`).click();
13057 // modifiers should be evaluted to false
13058 expect(`.o_selected_row`).toHaveCount(1);
13059 expect(`.o_selected_row [name=foo].o_field_widget`).not.toHaveClass("o_readonly_modifier");
13060 expect(`.o_selected_row div[name=int_field]`).toHaveCount(1);
13061
13062 // set a value and save
13063 await contains(`.o_selected_row [name=foo] input`).edit("some value");
13064 await contains(`.o_list_button_save`).click();
13065 // int_field should not be displayed
13066 expect(`.o_data_row .o_data_cell:eq(1)`).toHaveText("");
13067
13068 // edit again the just created record
13069 await contains(`.o_data_row .o_data_cell`).click();
13070 expect(`.o_selected_row`).toHaveCount(1);
13071 // modifiers should be evaluated to true
13072 expect(`.o_selected_row .o_field_widget[name=foo]`).toHaveClass("o_readonly_modifier");
13073 expect(`.o_selected_row div[name=int_field]`).toHaveCount(0);
13074 });
13075
13076 test(`readonly boolean in editable list is readonly`, async () => {
13077 await mountView({
13078 resModel: "foo",
13079 type: "list",
13080 arch: `
13081 <list editable="bottom">
13082 <field name="foo"/>
13083 <field name="bar" readonly="foo != 'yop'"/>
13084 </list>
13085 `,
13086 });
13087 await contains(`.o_data_row:eq(1) .o_data_cell`).click();
13088 expect(`.o_data_row:eq(1) [name=bar] input`).not.toBeEnabled();
13089 expect(`.o_data_row:eq(1) [name=bar] input`).toBeChecked();
13090
13091 await contains(`.o_data_row:eq(1) [name=bar] div`).click();
13092 expect(`.o_data_row:eq(1) [name=bar] input`).toBeChecked();
13093 expect(`.o_data_row:eq(1) input[type=text]`).toBeFocused();
13094
13095 // clicking on enabled checkbox with active row toggles check mark
13096 await contains(`.o_data_row:eq(0) .o_data_cell:eq(0)`).click();
13097 expect(`.o_data_row:eq(0) [name=bar] input`).toBeEnabled();
13098 expect(`.o_data_row:eq(0) [name=bar] input`).toBeChecked();
13099
13100 await contains(`.o_data_row:eq(0) div[name=bar] div`).click();
13101 expect(`.o_data_row:eq(0) [name=bar] input`).not.toBeChecked();
13102 expect(`.o_data_row:eq(0) [name=bar] input[type=checkbox]`).toBeFocused();
13103 });
13104
13105 test(`grouped list with groups_limit attribute`, async () => {
13106 stepAllNetworkCalls();
13107
13108 await mountView({
13109 resModel: "foo",
13110 type: "list",
13111 arch: `<list groups_limit="3"><field name="foo"/></list>`,
13112 groupBy: ["int_field"],
13113 });
13114 expect(`.o_group_header`).toHaveCount(3); // page 1
13115 expect(`.o_data_row`).toHaveCount(0);
13116 expect(`.o_pager`).toHaveCount(1); // has a pager
13117
13118 await pagerNext(); // switch to page 2
13119 expect(`.o_group_header`).toHaveCount(1); // page 2
13120 expect(`.o_data_row`).toHaveCount(0);
13121 expect.verifySteps([
13122 "/web/webclient/translations",
13123 "/web/webclient/load_menus",
13124 "get_views",
13125 "web_read_group", // web_read_group page 1
13126 "has_group",
13127 "web_read_group", // web_read_group page 2
13128 ]);
13129 });
13130
13131 test.tags("desktop");
13132 test(`ungrouped list with groups_limit attribute, then group`, async () => {
13133 await mountView({
13134 resModel: "foo",
13135 type: "list",
13136 arch: `<list groups_limit="3"><field name="foo"/></list>`,
13137 searchViewArch: `
13138 <search>
13139 <filter name="int_field" string="GroupBy IntField" context="{'group_by': 'int_field'}"/>
13140 </search>
13141 `,
13142 });
13143 expect(`.o_data_row`).toHaveCount(4);
13144
13145 // add a custom group in searchview groupby
13146 await toggleSearchBarMenu();
13147 await toggleMenuItem("GroupBy IntField");
13148 expect(`.o_group_header`).toHaveCount(3);
13149 expect(`.o_pager_value`).toHaveText("1-3", {
13150 message: "pager should be correct",
13151 });
13152 expect(`.o_pager_limit`).toHaveText("4");
13153 });
13154
13155 test.tags("desktop");
13156 test(`grouped list with groups_limit attribute, then ungroup`, async () => {
13157 await mountView({
13158 resModel: "foo",
13159 type: "list",
13160 arch: `<list groups_limit="3"><field name="foo"/></list>`,
13161 irFilters: [
13162 {
13163 context: "{'group_by': ['int_field']}",
13164 domain: "[]",
13165 id: 8,
13166 is_default: true,
13167 name: "GroupBy IntField",
13168 sort: "[]",
13169 user_ids: [2],
13170 },
13171 ],
13172 });
13173 expect(`.o_group_header`).toHaveCount(3);
13174 expect(`.o_pager_value`).toHaveText("1-3", {
13175 message: "pager should be correct",
13176 });
13177 expect(`.o_pager_limit`).toHaveText("4");
13178
13179 // remove groupby
13180 await removeFacet("GroupBy IntField");
13181 expect(`.o_data_row`).toHaveCount(4);
13182 });
13183
13184 test.tags("desktop");
13185 test(`multi level grouped list with groups_limit attribute`, async () => {
13186 for (let i = 50; i < 55; i++) {
13187 Foo._records.push({ id: i, foo: "foo", int_field: i });
13188 }
13189 await mountView({
13190 resModel: "foo",
13191 type: "list",
13192 arch: `<list groups_limit="3"><field name="foo"/></list>`,
13193 groupBy: ["foo", "int_field"],
13194 });
13195 expect(`.o_group_header`).toHaveCount(3);
13196 expect(`.o_pager_value`).toHaveText("1-3", {
13197 message: "pager should be correct",
13198 });
13199 expect(`.o_pager_limit`).toHaveText("4");
13200 expect(queryAllTexts(`.o_group_header`)).toEqual(["blip (2)", "foo (5)", "gnap (1)"]);
13201
13202 // open foo group
13203 await contains(`.o_group_header:eq(1)`).click();
13204 expect(`.o_group_header`).toHaveCount(6);
13205 expect(queryAllTexts(`.o_group_header`)).toEqual([
13206 "blip (2)",
13207 "foo (5)\n1-3 / 5",
13208 "50 (1)",
13209 "51 (1)",
13210 "52 (1)",
13211 "gnap (1)",
13212 ]);
13213 });
13214
13215 test(`grouped list with expand attribute`, async () => {
13216 stepAllNetworkCalls();
13217
13218 await mountView({
13219 resModel: "foo",
13220 type: "list",
13221 arch: `<list expand="1"><field name="foo"/></list>`,
13222 groupBy: ["bar"],
13223 });
13224 expect(`.o_group_header`).toHaveCount(2);
13225 expect(`.o_data_row`).toHaveCount(4);
13226 expect(queryAllTexts(`.o_data_cell`)).toEqual(["blip", "yop", "blip", "gnap"]);
13227 expect.verifySteps([
13228 "/web/webclient/translations",
13229 "/web/webclient/load_menus",
13230 "get_views",
13231 "web_read_group",
13232 "has_group",
13233 ]);
13234 });
13235
13236 test(`grouped list with dynamic expand attribute (eval true)`, async () => {
13237 await mountView({
13238 resModel: "foo",
13239 type: "list",
13240 arch: `<list expand="context.get('expand', False)"><field name="foo"/></list>`,
13241 groupBy: ["bar"],
13242 context: {
13243 expand: true,
13244 },
13245 });
13246 expect(`.o_group_header`).toHaveCount(2);
13247 expect(`.o_data_row`).toHaveCount(4);
13248 });
13249
13250 test(`grouped list with dynamic expand attribute (eval false)`, async () => {
13251 await mountView({
13252 resModel: "foo",
13253 type: "list",
13254 arch: `<list expand="context.get('expand', False)"><field name="foo"/></list>`,
13255 groupBy: ["bar"],
13256 context: {
13257 expand: false,
13258 },
13259 });
13260 expect(`.o_group_header`).toHaveCount(2);
13261 expect(`.o_data_row`).toHaveCount(0);
13262 });
13263
13264 test(`grouped list (two levels) with expand attribute`, async () => {
13265 stepAllNetworkCalls();
13266
13267 // the expand attribute only opens the first level groups
13268 await mountView({
13269 resModel: "foo",
13270 type: "list",
13271 arch: `<list expand="1"><field name="foo"/></list>`,
13272 groupBy: ["bar", "int_field"],
13273 });
13274 expect(`.o_group_header`).toHaveCount(6);
13275 expect.verifySteps([
13276 "/web/webclient/translations",
13277 "/web/webclient/load_menus",
13278 "get_views",
13279 "web_read_group", // global
13280 "has_group",
13281 ]);
13282 });
13283
13284 test.tags("desktop");
13285 test(`grouped lists with expand attribute and a lot of groups`, async () => {
13286 for (let i = 0; i < 15; i++) {
13287 Foo._records.push({ foo: "record " + i, int_field: i });
13288 }
13289
13290 onRpc("web_read_group", () => {
13291 expect.step("web_read_group");
13292 });
13293 await mountView({
13294 resModel: "foo",
13295 type: "list",
13296 arch: `<list expand="1"><field name="foo"/></list>`,
13297 groupBy: ["int_field"],
13298 });
13299 expect(`.o_group_header`).toHaveCount(10); // page 1
13300 expect(`.o_data_row`).toHaveCount(10); // two groups contains two records
13301 expect(`.o_pager`).toHaveCount(1); // has a pager
13302 expect(queryAllTexts(`.o_group_name`)).toEqual([
13303 "-4 (1)",
13304 "0 (1)",
13305 "1 (1)",
13306 "2 (1)",
13307 "3 (1)",
13308 "4 (1)",
13309 "5 (1)",
13310 "6 (1)",
13311 "7 (1)",
13312 "8 (1)",
13313 ]);
13314
13315 await pagerNext(); // switch to page 2
13316 expect(`.o_group_header`).toHaveCount(7); // page 2
13317 expect(`.o_data_row`).toHaveCount(9); // two groups contains two records
13318 expect(queryAllTexts(`.o_group_name`)).toEqual([
13319 "9 (2)",
13320 "10 (2)",
13321 "11 (1)",
13322 "12 (1)",
13323 "13 (1)",
13324 "14 (1)",
13325 "17 (1)",
13326 ]);
13327 expect.verifySteps([
13328 "web_read_group", // web_read_group page 1
13329 "web_read_group", // web_read_group page 2
13330 ]);
13331 });
13332
13333 test.tags("desktop");
13334 test(`add filter in a grouped list with a pager`, async () => {
13335 defineActions([
13336 {
13337 id: 11,
13338 name: "Action 11",
13339 res_model: "foo",
13340 views: [[3, "list"]],
13341 search_view_id: [9, "search"],
13342 context: { group_by: ["int_field"] },
13343 },
13344 ]);
13345
13346 Foo._views = {
13347 "list,3": `<list groups_limit="3"><field name="foo"/></list>`,
13348 "search,9": `
13349 <search>
13350 <filter string="Not Bar" name="not bar" domain="[['bar','=',False]]"/>
13351 </search>
13352 `,
13353 };
13354
13355 onRpc("web_read_group", ({ kwargs }) => {
13356 expect.step({ domain: kwargs.domain, offset: kwargs.offset });
13357 });
13358
13359 await mountWithCleanup(WebClient);
13360 await getService("action").doAction(11);
13361 expect(`.o_list_view`).toHaveCount(1);
13362 expect(getPagerValue()).toEqual([1, 3]);
13363 expect(`.o_group_header`).toHaveCount(3); // page 1
13364
13365 await pagerNext();
13366 expect(getPagerValue()).toEqual([4, 4]);
13367 expect(`.o_group_header`).toHaveCount(1); // page 2
13368
13369 // toggle a filter -> there should be only one group left (on page 1)
13370 await toggleSearchBarMenu();
13371 await toggleMenuItem("Not Bar");
13372 expect(getPagerValue()).toEqual([1, 1]);
13373 expect(`.o_group_header`).toHaveCount(1); // page 1
13374 expect.verifySteps([
13375 { domain: [], offset: 0 },
13376 { domain: [], offset: 3 },
13377 { domain: [["bar", "=", false]], offset: 0 },
13378 ]);
13379 });
13380
13381 test.tags("desktop");
13382 test(`grouped list: have a group with pager, then apply filter`, async () => {
13383 await mountView({
13384 resModel: "foo",
13385 type: "list",
13386 arch: `<list limit="2"><field name="foo"/></list>`,
13387 searchViewArch: `
13388 <search>
13389 <filter name="Some Filter" domain="[('foo', '=', 'gnap')]"/>
13390 </search>
13391 `,
13392 groupBy: ["bar"],
13393 });
13394 expect(`.o_data_row`).toHaveCount(0);
13395 expect(`.o_group_header`).toHaveCount(2);
13396
13397 await contains(`.o_group_header:eq(1)`).click();
13398 expect(`.o_data_row`).toHaveCount(2);
13399 expect(`.o_group_header .o_pager:first`).toHaveText("1-2 / 3");
13400
13401 await contains(`.o_group_header .o_pager_next`).click();
13402 expect(`.o_data_row`).toHaveCount(1);
13403 expect(`.o_group_header .o_pager:first`).toHaveText("3-3 / 3");
13404
13405 await toggleSearchBarMenu();
13406 await toggleMenuItem("Some Filter");
13407 expect(`.o_data_row`).toHaveCount(1);
13408 expect(`.o_group_header`).toHaveCount(1);
13409 expect(`.o_group_header .o_pager`).toHaveCount(0);
13410 });
13411
13412 test(`editable grouped lists`, async () => {
13413 await mountView({
13414 resModel: "foo",
13415 type: "list",
13416 arch: `<list editable="top"><field name="foo"/><field name="bar"/></list>`,
13417 searchViewArch: `
13418 <search>
13419 <filter name="bar" string="bar" context="{'group_by': 'bar'}"/>
13420 </search>
13421 `,
13422 });
13423 await toggleSearchBarMenu();
13424 await toggleMenuItem("bar");
13425 await contains(`.o_group_header`).click();
13426 // enter edition (grouped case)
13427 await contains(`.o_data_cell`).click();
13428 expect(`.o_selected_row`).toHaveCount(1);
13429
13430 // click on the body should leave the edition
13431 await contains(`.o_list_view`).click();
13432 expect(`.o_selected_row`).toHaveCount(0);
13433
13434 // reload without groupBy
13435 await toggleSearchBarMenu();
13436 await toggleMenuItem("bar");
13437
13438 // enter edition (ungrouped case)
13439 await contains(`.o_data_cell`).click();
13440 expect(`.o_selected_row`).toHaveCount(1);
13441
13442 // click on the body should leave the edition
13443 await contains(`.o_list_view`).click();
13444 expect(`.o_selected_row`).toHaveCount(0);
13445 });
13446
13447 test(`grouped lists are editable (ungrouped first)`, async () => {
13448 await mountView({
13449 resModel: "foo",
13450 type: "list",
13451 arch: `<list editable="top"><field name="foo"/><field name="bar"/></list>`,
13452 searchViewArch: `
13453 <search>
13454 <filter name="bar" string="bar" context="{'group_by': 'bar'}"/>
13455 </search>
13456 `,
13457 });
13458 // enter edition (ungrouped case)
13459 await contains(`.o_data_cell`).click();
13460 expect(`.o_selected_row`).toHaveCount(1);
13461
13462 // reload with a groupby
13463 await toggleSearchBarMenu();
13464 await toggleMenuItem("bar");
13465
13466 // open first group
13467 await contains(`.o_group_header`).click();
13468
13469 // enter edition (grouped case)
13470 await contains(`.o_data_cell`).click();
13471 expect(`.o_selected_row`).toHaveCount(1);
13472 });
13473
13474 test(`char field edition in editable grouped list`, async () => {
13475 await mountView({
13476 resModel: "foo",
13477 type: "list",
13478 arch: `<list editable="bottom"><field name="foo"/><field name="bar"/></list>`,
13479 groupBy: ["bar"],
13480 });
13481 await contains(`.o_group_header`).click();
13482 await contains(`.o_data_cell`).click();
13483 await contains(`.o_selected_row .o_data_cell [name=foo] input`).edit("pla");
13484 await contains(`.o_list_button_save`).click();
13485 expect(MockServer.env["foo"].browse(4)[0].foo).toBe("pla", {
13486 message: "the edition should have been properly saved",
13487 });
13488 expect(`.o_data_row:eq(0):contains(pla)`).toHaveCount(1);
13489 });
13490
13491 test(`control panel buttons in editable grouped list views`, async () => {
13492 await mountView({
13493 resModel: "foo",
13494 type: "list",
13495 arch: `<list editable="top"><field name="foo"/><field name="bar"/></list>`,
13496 searchViewArch: `
13497 <search>
13498 <filter name="bar" string="bar" context="{'group_by': 'bar'}"/>
13499 </search>
13500 `,
13501 });
13502 expect(`.o_list_button_add`).toHaveCount(1);
13503
13504 // reload with a groupby
13505 await toggleSearchBarMenu();
13506 await toggleMenuItem("bar");
13507 expect(`.o_list_button_add`).toHaveCount(1);
13508
13509 // reload without groupby
13510 await toggleMenuItem("bar");
13511 expect(`.o_list_button_add`).toHaveCount(1);
13512 });
13513
13514 test(`control panel buttons in multi editable grouped list views`, async () => {
13515 await mountView({
13516 resModel: "foo",
13517 type: "list",
13518 groupBy: ["foo"],
13519 arch: `
13520 <list multi_edit="1">
13521 <field name="foo"/>
13522 <field name="int_field"/>
13523 </list>
13524 `,
13525 });
13526 expect(`.o_data_row`).toHaveCount(0, { message: "all groups should be closed" });
13527 expect(`.o_list_button_add`).toHaveCount(1, {
13528 message: "should have a visible Create button",
13529 });
13530
13531 await contains(`.o_group_header`).click();
13532 expect(`.o_data_row`).toHaveCount(2, { message: "first group should be opened" });
13533 expect(`.o_list_button_add`).toHaveCount(1, {
13534 message: "should have a visible Create button",
13535 });
13536
13537 await clickRecordSelector();
13538 expect(`.o_data_row:eq(0)`).toHaveClass("o_data_row_selected", {
13539 message: "should have selected first record",
13540 });
13541 expect(`.o_list_button_add`).toHaveCount(1, {
13542 message: "should have a visible Create button",
13543 });
13544
13545 await contains(`.o_group_header:eq(-1)`).click();
13546 expect(`.o_data_row`).toHaveCount(3, { message: "two groups should be opened" });
13547 expect(`.o_list_button_add`).toHaveCount(1, {
13548 message: "should have a visible Create button",
13549 });
13550 });
13551
13552 test.tags("desktop");
13553 test(`edit a line and discard it in grouped editable`, async () => {
13554 await mountView({
13555 resModel: "foo",
13556 type: "list",
13557 arch: `<list editable="top"><field name="foo"/><field name="int_field"/></list>`,
13558 groupBy: ["bar"],
13559 });
13560 await contains(`.o_group_header:nth-child(2)`).click();
13561 await contains(`.o_data_row:nth-child(5) .o_data_cell:nth-child(2)`).click();
13562 expect(`.o_selected_row`).toHaveCount(1);
13563 expect(`.o_data_row:nth-child(5)`).toHaveClass("o_selected_row");
13564
13565 await contains(`.o_list_button_discard`).click();
13566 await contains(`.o_data_row:nth-child(3) .o_data_cell:nth-child(2)`).click();
13567 expect(`.o_selected_row`).toHaveCount(1);
13568 expect(`.o_data_row:nth-child(3)`).toHaveClass("o_selected_row");
13569
13570 await contains(`.o_list_button_discard`).click();
13571 expect(`.o_selected_row`).toHaveCount(0);
13572
13573 await contains(`.o_data_row:nth-child(5) .o_data_cell:nth-child(2)`).click();
13574 expect(`.o_selected_row`).toHaveCount(1);
13575 expect(`.o_data_row:nth-child(5)`).toHaveClass("o_selected_row");
13576 });
13577
13578 test.tags("desktop");
13579 test(`add and discard a record in a multi-level grouped list view`, async () => {
13580 await mountView({
13581 resModel: "foo",
13582 type: "list",
13583 arch: `<list editable="top"><field name="foo" required="1"/></list>`,
13584 groupBy: ["foo", "bar"],
13585 });
13586 // unfold first subgroup
13587 await contains(`.o_group_header`).click();
13588 await contains(`.o_group_header:eq(1)`).click();
13589 expect(`.o_group_header:eq(0)`).toHaveClass("o_group_open");
13590 expect(`.o_group_header:eq(1)`).toHaveClass("o_group_open");
13591 expect(`.o_data_row`).toHaveCount(1);
13592
13593 // add a record to first subgroup
13594 await contains(`.o_group_field_row_add a`).click();
13595 expect(`.o_data_row`).toHaveCount(2);
13596
13597 // discard
13598 await contains(`.o_list_button_discard`).click();
13599 expect(`.o_data_row`).toHaveCount(1);
13600 });
13601
13602 test.tags("desktop");
13603 test(`pressing ESC in editable grouped list should discard the current line changes`, async () => {
13604 // This test is wrong, there's a bug in list view when pressing "Escape".
13605 // The row becomes readonly but the value is not reset.
13606
13607 await mountView({
13608 resModel: "foo",
13609 type: "list",
13610 arch: `<list editable="top"><field name="foo"/><field name="bar"/></list>`,
13611 groupBy: ["bar"],
13612 });
13613 await contains(`.o_group_header:eq(1)`).click();
13614 expect(`tr.o_data_row`).toHaveCount(3);
13615
13616 await contains(`.o_data_cell`).click();
13617 // update foo field of edited row
13618 await contains(`.o_data_cell [name=foo] input`).edit("new_value", { confirm: false });
13619 expect(`.o_data_cell [name=foo] input`).toBeFocused();
13620
13621 // discard by pressing ESC
13622 await press("Escape");
13623 await animationFrame();
13624 expect(`.modal`).toHaveCount(0);
13625 expect(`tbody tr td:contains(yop)`).toHaveCount(1);
13626 expect(`tr.o_data_row`).toHaveCount(3);
13627 expect(`tr.o_data_row.o_selected_row`).toHaveCount(0);
13628 expect(`.o_list_button_save`).not.toHaveCount();
13629 });
13630
13631 test.tags("desktop");
13632 test(`pressing TAB in editable="bottom" grouped list`, async () => {
13633 await mountView({
13634 resModel: "foo",
13635 type: "list",
13636 arch: `<list editable="bottom"><field name="foo"/></list>`,
13637 groupBy: ["bar"],
13638 });
13639 // open two groups
13640 await contains(`.o_group_header:eq(0)`).click();
13641 expect(`.o_data_row`).toHaveCount(1, { message: "first group contains 1 row" });
13642
13643 await contains(`.o_group_header:eq(1)`).click();
13644 expect(`.o_data_row`).toHaveCount(4, { message: "second group contains 3 rows" });
13645
13646 await contains(`.o_data_cell`).click();
13647 expect(`.o_data_row:eq(0)`).toHaveClass("o_selected_row");
13648
13649 // Press 'Tab' -> should go to first line of second group
13650 await press("Tab");
13651 await animationFrame();
13652 expect(`.o_data_row:eq(1)`).toHaveClass("o_selected_row");
13653
13654 // Press 'Tab' -> should go to next line (still in second group)
13655 await press("Tab");
13656 await animationFrame();
13657 expect(`.o_data_row:eq(2)`).toHaveClass("o_selected_row");
13658
13659 // Press 'Tab' -> should go to next line (still in second group)
13660 await press("Tab");
13661 await animationFrame();
13662 expect(`.o_data_row:eq(3)`).toHaveClass("o_selected_row");
13663
13664 // Press 'Tab' -> should go back to first line of first group
13665 await press("Tab");
13666 await animationFrame();
13667 expect(`.o_data_row:eq(0)`).toHaveClass("o_selected_row");
13668 });
13669
13670 test.tags("desktop");
13671 test(`pressing TAB in editable="top" grouped list`, async () => {
13672 await mountView({
13673 resModel: "foo",
13674 type: "list",
13675 arch: `
13676 <list editable="top">
13677 <field name="foo"/>
13678 </list>
13679 `,
13680 groupBy: ["bar"],
13681 });
13682
13683 // open two groups
13684 await contains(`.o_group_header`).click();
13685 expect(`.o_data_row`).toHaveCount(1);
13686
13687 await contains(`.o_group_header:eq(-1)`).click();
13688 expect(`.o_data_row`).toHaveCount(4);
13689
13690 await contains(`.o_data_cell`).click();
13691 expect(`.o_data_row:eq(0)`).toHaveClass("o_selected_row");
13692
13693 await press("Tab");
13694 await animationFrame();
13695 expect(`.o_data_row:eq(1)`).toHaveClass("o_selected_row");
13696
13697 await press("Tab");
13698 await animationFrame();
13699 expect(`.o_data_row:eq(2)`).toHaveClass("o_selected_row");
13700
13701 await press("Tab");
13702 await animationFrame();
13703 expect(`.o_data_row:eq(3)`).toHaveClass("o_selected_row");
13704 });
13705
13706 test.tags("desktop");
13707 test(`pressing TAB in editable grouped list with create=0`, async () => {
13708 await mountView({
13709 resModel: "foo",
13710 type: "list",
13711 arch: `<list editable="bottom" create="0"><field name="foo"/></list>`,
13712 groupBy: ["bar"],
13713 });
13714
13715 // open two groups
13716 await contains(`.o_group_header:eq(0)`).click();
13717 expect(`.o_data_row`).toHaveCount(1, { message: "first group contains 1 rows" });
13718
13719 await contains(`.o_group_header:eq(1)`).click();
13720 expect(`.o_data_row`).toHaveCount(4, { message: "first group contains 3 row" });
13721
13722 await contains(`.o_data_cell`).click();
13723 expect(`.o_data_row:eq(0)`).toHaveClass("o_selected_row");
13724
13725 // Press 'Tab' -> should go to the second group
13726 await press("Tab");
13727 await animationFrame();
13728 expect(`.o_data_row:eq(1)`).toHaveClass("o_selected_row");
13729
13730 // Press 'Tab' -> should go to next line (still in second group)
13731 await press("Tab");
13732 await animationFrame();
13733 expect(`.o_data_row:eq(2)`).toHaveClass("o_selected_row");
13734
13735 // Press 'Tab' -> should go to next line (still in second group)
13736 await press("Tab");
13737 await animationFrame();
13738 expect(`.o_data_row:eq(3)`).toHaveClass("o_selected_row");
13739
13740 // Press 'Tab' -> should go back to first line of first group
13741 await press("Tab");
13742 await animationFrame();
13743 expect(`.o_data_row:eq(0)`).toHaveClass("o_selected_row");
13744 });
13745
13746 test.tags("desktop");
13747 test(`pressing SHIFT-TAB in editable="bottom" grouped list`, async () => {
13748 Foo._records[2].bar = false;
13749
13750 await mountView({
13751 resModel: "foo",
13752 type: "list",
13753 arch: `
13754 <list editable="bottom">
13755 <field name="foo" required="1"/>
13756 </list>
13757 `,
13758 groupBy: ["bar"],
13759 });
13760 await contains(`.o_group_header`).click();
13761 expect(`.o_data_row`).toHaveCount(2);
13762
13763 await contains(`.o_group_header:eq(-1)`).click();
13764 expect(`.o_data_row`).toHaveCount(4);
13765
13766 // navigate inside a group
13767 await contains(`.o_data_row:eq(1) .o_data_cell`).click();
13768 expect(`.o_data_row:eq(1)`).toHaveClass("o_selected_row");
13769
13770 await press("shift+Tab");
13771 await animationFrame();
13772 expect(`.o_data_row:eq(0)`).toHaveClass("o_selected_row");
13773 expect(`.o_data_row:eq(1)`).not.toHaveClass("o_selected_row");
13774
13775 // navigate between groups
13776 await contains(`.o_data_row:eq(2) .o_data_cell`).click();
13777 expect(`.o_data_row:eq(2)`).toHaveClass("o_selected_row");
13778
13779 await press("shift+Tab");
13780 await animationFrame();
13781 expect(`.o_data_row:eq(1)`).toHaveClass("o_selected_row");
13782 });
13783
13784 test.tags("desktop");
13785 test(`pressing SHIFT-TAB in editable="top" grouped list`, async () => {
13786 Foo._records[2].bar = false;
13787
13788 await mountView({
13789 resModel: "foo",
13790 type: "list",
13791 arch: `
13792 <list editable="top">
13793 <field name="foo" required="1"/>
13794 </list>
13795 `,
13796 groupBy: ["bar"],
13797 });
13798 await contains(`.o_group_header`).click();
13799 expect(`.o_data_row`).toHaveCount(2);
13800
13801 await contains(`.o_group_header:eq(-1)`).click();
13802 expect(`.o_data_row`).toHaveCount(4);
13803
13804 // navigate inside a group
13805 await contains(`.o_data_row:eq(1) .o_data_cell`).click();
13806 expect(`.o_data_row:eq(1)`).toHaveClass("o_selected_row");
13807
13808 await press("shift+Tab");
13809 await animationFrame();
13810 expect(`.o_data_row:eq(0)`).toHaveClass("o_selected_row");
13811 expect(`.o_data_row:eq(1)`).not.toHaveClass("o_selected_row");
13812
13813 // navigate between groups
13814 await contains(`.o_data_row:eq(2) .o_data_cell`).click();
13815 expect(`.o_data_row:eq(2)`).toHaveClass("o_selected_row");
13816
13817 await press("shift+Tab");
13818 await animationFrame();
13819 expect(`.o_data_row:eq(1)`).toHaveClass("o_selected_row");
13820 });
13821
13822 test.tags("desktop");
13823 test(`pressing SHIFT-TAB in editable grouped list with create="0"`, async () => {
13824 Foo._records[2].bar = false;
13825
13826 await mountView({
13827 resModel: "foo",
13828 type: "list",
13829 arch: `
13830 <list editable="top" create="0">
13831 <field name="foo" required="1"/>
13832 </list>
13833 `,
13834 groupBy: ["bar"],
13835 });
13836 await contains(`.o_group_header`).click();
13837 expect(`.o_data_row`).toHaveCount(2);
13838
13839 await contains(`.o_group_header:eq(-1)`).click();
13840 expect(`.o_data_row`).toHaveCount(4);
13841
13842 // navigate inside a group
13843 await contains(`.o_data_row:eq(1) .o_data_cell`).click();
13844 expect(`.o_data_row:eq(1)`).toHaveClass("o_selected_row");
13845
13846 await press("shift+Tab");
13847 await animationFrame();
13848 expect(`.o_data_row:eq(0)`).toHaveClass("o_selected_row");
13849 expect(`.o_data_row:eq(1)`).not.toHaveClass("o_selected_row");
13850
13851 // navigate between groups
13852 await contains(`.o_data_row:eq(2) .o_data_cell`).click();
13853 expect(`.o_data_row:eq(2)`).toHaveClass("o_selected_row");
13854
13855 await press("shift+Tab");
13856 await animationFrame();
13857 expect(`.o_data_row:eq(1)`).toHaveClass("o_selected_row");
13858 });
13859
13860 test(`editing then pressing TAB in editable grouped list`, async () => {
13861 stepAllNetworkCalls();
13862
13863 await mountView({
13864 resModel: "foo",
13865 type: "list",
13866 arch: `<list editable="bottom"><field name="foo"/></list>`,
13867 groupBy: ["bar"],
13868 });
13869
13870 // open two groups
13871 await contains(`.o_group_header:eq(0)`).click();
13872 expect(`.o_data_row`).toHaveCount(1, { message: "first group contains 1 row" });
13873
13874 await contains(`.o_group_header:eq(1)`).click();
13875 expect(`.o_data_row`).toHaveCount(4, { message: "second group contains 3 rows" });
13876
13877 // select and edit last row of first group
13878 await contains(`.o_data_row:eq(0) .o_data_cell`).click();
13879 expect(`.o_data_row:eq(0)`).toHaveClass("o_selected_row");
13880
13881 await edit("new value", { confirm: "tab" });
13882 await animationFrame();
13883 expect(`.o_data_row`).toHaveCount(5);
13884 expect(`.o_data_row:eq(1)`).toHaveClass("o_selected_row");
13885
13886 // fill foo field for the new record and press 'tab' -> should create another record
13887 // FIXME: input field hook calls update, but in a mutex -> .dirty is not set when we call applyCellKeydownEditModeGroup
13888 await edit("new record", { confirm: "tab" });
13889 await animationFrame();
13890 expect(`.o_data_row`).toHaveCount(6);
13891 expect(`.o_data_row:eq(2)`).toHaveClass("o_selected_row");
13892
13893 // leave this new row empty and press tab -> should discard the new record and move to the
13894 // next group
13895 await press("tab");
13896 await animationFrame();
13897 expect(`.o_data_row`).toHaveCount(5);
13898 expect(`.o_data_row:eq(2)`).toHaveClass("o_selected_row");
13899 expect.verifySteps([
13900 "/web/webclient/translations",
13901 "/web/webclient/load_menus",
13902 "get_views",
13903 "web_read_group",
13904 "has_group",
13905 "web_search_read",
13906 "web_search_read",
13907 "web_save",
13908 "onchange",
13909 "web_save",
13910 "onchange",
13911 ]);
13912 });
13913
13914 test(`editing then pressing TAB (with a readonly field) in grouped list`, async () => {
13915 Foo._records[0].bar = false;
13916
13917 stepAllNetworkCalls();
13918
13919 await mountView({
13920 resModel: "foo",
13921 type: "list",
13922 arch: `
13923 <list editable="bottom">
13924 <field name="foo"/>
13925 <field name="int_field" readonly="1"/>
13926 </list>
13927 `,
13928 groupBy: ["bar"],
13929 });
13930 await contains(`.o_group_header`).click();
13931 await contains(`.o_data_row [name=foo]`).click();
13932 await contains(`.o_selected_row [name=foo] input`).edit("new value", { confirm: "tab" });
13933 expect(`.o_data_row:eq(0) [name=foo]`).toHaveText("new value");
13934 expect(`.o_data_row:eq(1) [name=foo] input`).toBeFocused();
13935 expect.verifySteps([
13936 "/web/webclient/translations",
13937 "/web/webclient/load_menus",
13938 "get_views",
13939 "web_read_group",
13940 "has_group",
13941 "web_search_read",
13942 "web_save",
13943 ]);
13944 });
13945
13946 test.tags("desktop");
13947 test(`pressing ENTER in editable="bottom" grouped list view`, async () => {
13948 stepAllNetworkCalls();
13949
13950 await mountView({
13951 resModel: "foo",
13952 type: "list",
13953 arch: `<list editable="bottom"><field name="foo"/></list>`,
13954 groupBy: ["bar"],
13955 });
13956 await contains(`.o_group_header:eq(0)`).click(); // open first group
13957 await contains(`.o_group_header:eq(1)`).click(); // open second group
13958 expect(`tr.o_data_row`).toHaveCount(4);
13959
13960 await contains(`.o_data_row:eq(2) .o_data_cell`).click();
13961 expect(`tr.o_data_row:eq(2)`).toHaveClass("o_selected_row");
13962
13963 // press enter in input should move to next record
13964 await press("Enter");
13965 await animationFrame();
13966 expect(`tr.o_data_row:eq(3)`).toHaveClass("o_selected_row");
13967 expect(`tr.o_data_row:eq(2)`).not.toHaveClass("o_selected_row");
13968
13969 // press enter on last row should create a new record
13970 await press("Enter");
13971 await animationFrame();
13972 expect(`tr.o_data_row`).toHaveCount(5);
13973 expect(`tr.o_data_row:eq(4)`).toHaveClass("o_selected_row");
13974 expect.verifySteps([
13975 "/web/webclient/translations",
13976 "/web/webclient/load_menus",
13977 "get_views",
13978 "web_read_group",
13979 "has_group",
13980 "web_search_read",
13981 "web_search_read",
13982 "onchange",
13983 ]);
13984 });
13985
13986 test.tags("desktop");
13987 test(`pressing ENTER in editable="top" grouped list view`, async () => {
13988 Foo._records[2].bar = false;
13989
13990 stepAllNetworkCalls();
13991
13992 await mountView({
13993 resModel: "foo",
13994 type: "list",
13995 arch: `<list editable="top"><field name="foo"/></list>`,
13996 groupBy: ["bar"],
13997 });
13998 await contains(`.o_group_header`).click();
13999 await contains(`.o_group_header:eq(-1)`).click();
14000 expect(`tr.o_data_row`).toHaveCount(4);
14001
14002 await contains(`.o_data_row .o_data_cell`).click();
14003 expect(`.o_data_row:eq(0)`).toHaveClass("o_selected_row");
14004
14005 await press("Enter");
14006 await animationFrame();
14007 expect(`.o_data_row:eq(1)`).toHaveClass("o_selected_row");
14008
14009 await press("Enter");
14010 await animationFrame();
14011 expect(`.o_data_row:eq(2)`).toHaveClass("o_selected_row");
14012 expect.verifySteps([
14013 "/web/webclient/translations",
14014 "/web/webclient/load_menus",
14015 "get_views",
14016 "web_read_group",
14017 "has_group",
14018 "web_search_read",
14019 "web_search_read",
14020 ]);
14021 });
14022
14023 test.tags("desktop");
14024 test(`pressing ENTER in editable grouped list view with create=0`, async () => {
14025 stepAllNetworkCalls();
14026
14027 await mountView({
14028 resModel: "foo",
14029 type: "list",
14030 arch: `<list editable="bottom" create="0"><field name="foo"/></list>`,
14031 groupBy: ["bar"],
14032 });
14033 expect(`.o_group_header`).toHaveCount(2);
14034 expect(`.o_data_row`).toHaveCount(0);
14035 expect.verifySteps([
14036 "/web/webclient/translations",
14037 "/web/webclient/load_menus",
14038 "get_views",
14039 "web_read_group",
14040 "has_group",
14041 ]);
14042
14043 // Open group headers
14044 await contains(`.o_group_header:eq(0)`).click();
14045 await contains(`.o_group_header:eq(1)`).click();
14046 expect(`.o_data_row`).toHaveCount(4);
14047 expect(`.o_selected_row`).toHaveCount(0);
14048 expect.verifySteps(["web_search_read", "web_search_read"]);
14049
14050 // Click on first data row
14051 await contains(`.o_data_row:eq(0) [name=foo]`).click();
14052 expect(`.o_selected_row`).toHaveCount(1);
14053 expect(`.o_data_row:eq(0)`).toHaveClass("o_selected_row");
14054 expect(`.o_data_row:eq(0) [name=foo] input`).toBeFocused();
14055
14056 // Press enter in input should move to next record, even if record is in another group
14057 await press("Enter");
14058 await animationFrame();
14059 expect(`.o_selected_row`).toHaveCount(1);
14060 expect(`.o_data_row:eq(1)`).toHaveClass("o_selected_row");
14061 expect(`.o_data_row:eq(1) [name=foo] input`).toBeFocused();
14062
14063 // Press enter in input should move to next record
14064 await press("Enter");
14065 await animationFrame();
14066 expect(`.o_selected_row`).toHaveCount(1);
14067 expect(`.o_data_row:eq(2)`).toHaveClass("o_selected_row");
14068 expect(`.o_data_row:eq(2) [name=foo] input`).toBeFocused();
14069
14070 // Once again
14071 await press("Enter");
14072 await animationFrame();
14073 expect(`.o_selected_row`).toHaveCount(1);
14074 expect(`.o_data_row:eq(3)`).toHaveClass("o_selected_row");
14075 expect(`.o_data_row:eq(3) [name=foo] input`).toBeFocused();
14076
14077 // Once again on the last data row should cycle to the first data row
14078 await press("Enter");
14079 await animationFrame();
14080 expect(`.o_selected_row`).toHaveCount(1);
14081 expect(`.o_data_row:eq(0)`).toHaveClass("o_selected_row");
14082 expect(`.o_data_row:eq(0) [name=foo] input`).toBeFocused();
14083 expect.verifySteps([]);
14084 });
14085
14086 test.tags("desktop");
14087 test(`cell-level keyboard navigation in non-editable list`, async () => {
14088 await mountView({
14089 resModel: "foo",
14090 type: "list",
14091 arch: `<list><field name="foo" required="1"/></list>`,
14092 selectRecord(resId) {
14093 expect.step(`resId: ${resId}`);
14094 },
14095 });
14096 expect(`.o_searchview_input`).toBeFocused();
14097
14098 await press("ArrowDown");
14099 await animationFrame();
14100 expect(`thead .o_list_record_selector input`).toBeFocused();
14101
14102 await press("ArrowUp");
14103 await animationFrame();
14104 expect(`.o_searchview_input`).toBeFocused();
14105
14106 await press("ArrowDown");
14107 await press("ArrowDown");
14108 await animationFrame();
14109 expect(`tbody tr:eq(0) .o_list_record_selector input`).toBeFocused();
14110
14111 await press("ArrowRight");
14112 await animationFrame();
14113 expect(`tbody tr:eq(0) .o_field_cell[name=foo]`).toBeFocused();
14114 expect(`tbody tr:eq(0) .o_field_cell[name=foo]`).toHaveText("yop");
14115
14116 await press("ArrowRight");
14117 await animationFrame();
14118 expect(`tbody tr:eq(0) .o_field_cell[name=foo]`).toBeFocused();
14119
14120 await press("ArrowDown");
14121 await animationFrame();
14122 expect(`tbody tr:eq(1) .o_field_cell[name=foo]`).toBeFocused();
14123 expect(`tbody tr:eq(1) .o_field_cell[name=foo]`).toHaveText("blip");
14124
14125 await press("ArrowDown");
14126 await animationFrame();
14127 expect(`tbody tr:eq(2) .o_field_cell[name=foo]`).toBeFocused();
14128 expect(`tbody tr:eq(2) .o_field_cell[name=foo]`).toHaveText("gnap");
14129
14130 await press("ArrowDown");
14131 await animationFrame();
14132 expect(`tbody tr:eq(3) .o_field_cell[name=foo]`).toBeFocused();
14133 expect(`tbody tr:eq(3) .o_field_cell[name=foo]`).toHaveText("blip");
14134
14135 await press("ArrowDown");
14136 await animationFrame();
14137 expect(`tbody tr:eq(3) .o_field_cell[name=foo]`).toBeFocused();
14138 expect(`tbody tr:eq(3) .o_field_cell[name=foo]`).toHaveText("blip");
14139
14140 await press("ArrowRight");
14141 await animationFrame();
14142 expect(`tbody tr:eq(3) .o_field_cell[name=foo]`).toBeFocused();
14143 expect(`tbody tr:eq(3) .o_field_cell[name=foo]`).toHaveText("blip");
14144
14145 await press("ArrowLeft");
14146 await animationFrame();
14147 expect(`tbody tr:eq(3) .o_list_record_selector input`).toBeFocused();
14148
14149 await press("ArrowLeft");
14150 await animationFrame();
14151 expect(`tbody tr:eq(3) .o_list_record_selector input`).toBeFocused();
14152
14153 await press("ArrowUp");
14154 await press("ArrowRight");
14155 await animationFrame();
14156 expect(`tbody tr:eq(2) .o_field_cell[name=foo]`).toBeFocused();
14157 expect(`tbody tr:eq(2) .o_field_cell[name=foo]`).toHaveText("gnap");
14158
14159 await press("Enter");
14160 await animationFrame();
14161 expect.verifySteps(["resId: 3"]);
14162 });
14163
14164 test.tags("desktop");
14165 test(`keyboard navigation from last cell in editable list`, async () => {
14166 await mountView({
14167 resModel: "foo",
14168 type: "list",
14169 arch: `
14170 <list editable="bottom">
14171 <field name="foo"/>
14172 <field name="int_field"/>
14173 </list>
14174 `,
14175 });
14176 // Click on last cell
14177 await contains(`.o_data_row:eq(-1) [name=int_field]`).click();
14178 expect(`.o_data_row:eq(-1) [name=int_field] input`).toBeFocused();
14179
14180 // Tab should focus the first field of first row
14181 await press("Tab");
14182 await animationFrame();
14183 expect(`.o_data_row:eq(0) [name=foo] input`).toBeFocused();
14184
14185 // Shift+Tab should focus back the last field of last row
14186 await press("Shift+Tab");
14187 await animationFrame();
14188 expect(`.o_data_row:eq(-1) [name=int_field] input`).toBeFocused();
14189 // Enter should add a new row at the bottom
14190 expect(`.o_data_row`).toHaveCount(4);
14191
14192 await press("Enter");
14193 await animationFrame();
14194 expect(`.o_data_row`).toHaveCount(5);
14195 expect(`.o_data_row:eq(-1) [name=foo] input`).toBeFocused();
14196
14197 // Enter should discard the edited row as it is pristine + get to first row
14198 await press("Enter");
14199 await animationFrame();
14200 expect(`.o_data_row`).toHaveCount(4);
14201 expect(`.o_data_row:eq(0) [name=foo] input`).toBeFocused();
14202
14203 // Click on last cell
14204 await contains(`.o_data_row:eq(-1) [name=int_field]`).click();
14205 expect(`.o_data_row:eq(-1) [name=int_field] input`).toBeFocused();
14206
14207 // Enter should add a new row at the bottom
14208 await press("Enter");
14209 await animationFrame();
14210 expect(`.o_data_row`).toHaveCount(5);
14211
14212 // Edit the row and press enter: should add a new row
14213 await contains(`.o_data_row:eq(-1) [name=foo] input`).edit("blork", { confirm: "enter" });
14214 expect(`.o_data_row`).toHaveCount(6);
14215 expect(`.o_data_row:eq(-1) [name=foo] input`).toBeFocused();
14216
14217 // Escape should discard the added row as it is pristine + view should go into readonly mode
14218 await press("Escape");
14219 await animationFrame();
14220 expect(`.o_data_row`).toHaveCount(5);
14221 expect(`.o_selected_row`).toHaveCount(0);
14222 });
14223
14224 test.tags("desktop");
14225 test(`keyboard navigation from last cell in editable grouped list`, async () => {
14226 await mountView({
14227 resModel: "foo",
14228 type: "list",
14229 arch: `
14230 <list editable="bottom">
14231 <field name="foo"/>
14232 <field name="int_field"/>
14233 </list>
14234 `,
14235 groupBy: ["bar"],
14236 });
14237 expect(`.o_data_row`).toHaveCount(0);
14238 expect(`.o_group_header`).toHaveCount(2);
14239
14240 // Open first and second groups
14241 await contains(`.o_group_header:eq(0)`).click();
14242 await contains(`.o_group_header:eq(1)`).click();
14243 expect(`.o_data_row`).toHaveCount(4);
14244
14245 // Click on last cell
14246 await contains(`.o_data_row:eq(3) [name=int_field]`).click();
14247 expect(`.o_data_row:eq(3) [name=int_field] input`).toBeFocused();
14248
14249 // Tab should focus the first field of first data row
14250 await press("Tab");
14251 await animationFrame();
14252 expect(`.o_data_row:eq(0) [name=foo] input`).toBeFocused();
14253
14254 // Shift+Tab should focus back the last field of last row
14255 await press("Shift+Tab");
14256 await animationFrame();
14257 expect(`.o_data_row:eq(3) [name=int_field] input`).toBeFocused();
14258
14259 // Enter should add a new row at the bottom
14260 await press("Enter");
14261 await animationFrame();
14262 expect(`.o_data_row`).toHaveCount(5);
14263 expect(`.o_data_row:eq(4) [name=foo] input`).toBeFocused();
14264
14265 // Enter should discard the edited row as it is pristine + get to first row
14266 await press("Enter");
14267 await animationFrame();
14268 expect(`.o_data_row`).toHaveCount(4);
14269 expect(`.o_data_row:eq(0) [name=foo] input`).toBeFocused();
14270
14271 // Click on last cell
14272 await contains(`.o_data_row:eq(3) [name=int_field]`).click();
14273 expect(`.o_data_row:eq(3) [name=int_field] input`).toBeFocused();
14274
14275 // Enter should add a new row at the bottom
14276 await press("Enter");
14277 await animationFrame();
14278 expect(`.o_data_row`).toHaveCount(5);
14279 expect(`.o_data_row:eq(4) [name=foo] input`).toBeFocused();
14280
14281 // Edit the row and press enter: should add a new row
14282 await contains(`.o_data_row:eq(4) [name=foo] input`).edit("blork", { confirm: "enter" });
14283 expect(`.o_data_row`).toHaveCount(6);
14284 expect(`.o_data_row:eq(5) [name=foo] input`).toBeFocused();
14285
14286 // Escape should discard the added row as it is pristine + view should go into readonly mode
14287 await press("Escape");
14288 await animationFrame();
14289 expect(`.o_data_row`).toHaveCount(5);
14290 expect(`.o_selected_row`).toHaveCount(0);
14291
14292 // Click on last data row of first group
14293 expect(`.o_group_header:eq(0)`).toHaveText("No (1)\n -4");
14294 await contains(`.o_data_row:eq(0) [name=foo]`).click();
14295 expect(`.o_data_row:eq(0) [name=foo] input`).toBeFocused();
14296
14297 // Enter should add a new row in the first group
14298 await press("Enter");
14299 await animationFrame();
14300 expect(`.o_data_row`).toHaveCount(6);
14301 expect(`.o_group_header:eq(0)`).toHaveText("No (2)\n -4");
14302
14303 // Enter should discard the edited row as it is pristine + get to next data row
14304 await press("Enter");
14305 await animationFrame();
14306 expect(`.o_data_row`).toHaveCount(5);
14307 expect(`.o_group_header:eq(0)`).toHaveText("No (1)\n -4");
14308 expect(`.o_data_row:eq(1) [name=foo] input`).toBeFocused();
14309
14310 // Shift+Tab should focus back the last field of first row
14311 await press("Shift+Tab");
14312 await animationFrame();
14313 expect(`.o_data_row:eq(0) [name=int_field] input`).toBeFocused();
14314
14315 // Enter should add a new row in the first group
14316 await press("Enter");
14317 await animationFrame();
14318 expect(`.o_data_row`).toHaveCount(6);
14319 expect(`.o_group_header:eq(0)`).toHaveText("No (2)\n -4");
14320
14321 // Edit the row and press enter: should add a new row
14322 await contains(`.o_data_row:eq(1) [name=foo] input`).edit("zzapp", { confirm: "enter" });
14323 expect(`.o_data_row`).toHaveCount(7);
14324 expect(`.o_group_header:eq(0)`).toHaveText("No (3)\n -4");
14325 expect(`.o_data_row:eq(2) [name=foo] input`).toBeFocused();
14326 });
14327
14328 test.tags("desktop");
14329 test(`keyboard navigation from last cell in multi-edit list`, async () => {
14330 await mountView({
14331 resModel: "foo",
14332 type: "list",
14333 arch: `
14334 <list editable="bottom">
14335 <field name="foo"/>
14336 <field name="int_field"/>
14337 </list>
14338 `,
14339 groupBy: ["bar"],
14340 });
14341 expect(`.o_data_row`).toHaveCount(0);
14342 expect(`.o_group_header`).toHaveCount(2);
14343
14344 // Open first and second groups
14345 await contains(`.o_group_header:eq(0)`).click();
14346 await contains(`.o_group_header:eq(1)`).click();
14347 expect(`.o_data_row`).toHaveCount(4);
14348
14349 // Click on last cell
14350 await contains(`.o_data_row:eq(3) [name=int_field]`).click();
14351 expect(`.o_data_row:eq(3) [name=int_field] input`).toBeFocused();
14352
14353 // Tab should focus the first field of first data row
14354 await press("Tab");
14355 await animationFrame();
14356 expect(`.o_data_row:eq(0) [name=foo] input`).toBeFocused();
14357
14358 // Shift+Tab should focus back the last field of last row
14359 await press("Shift+Tab");
14360 await animationFrame();
14361 expect(`.o_data_row:eq(3) [name=int_field] input`).toBeFocused();
14362
14363 // Enter should add a new row at the bottom
14364 await press("Enter");
14365 await animationFrame();
14366 expect(`.o_data_row`).toHaveCount(5);
14367 expect(`.o_data_row:eq(4) [name=foo] input`).toBeFocused();
14368
14369 // Enter should discard the edited row as it is pristine + get to first row
14370 await press("Enter");
14371 await animationFrame();
14372 expect(`.o_data_row`).toHaveCount(4);
14373 expect(`.o_data_row:eq(0) [name=foo] input`).toBeFocused();
14374
14375 // Click on last cell
14376 await contains(`.o_data_row:eq(3) [name=int_field]`).click();
14377 expect(`.o_data_row:eq(3) [name=int_field] input`).toBeFocused();
14378
14379 // Enter should add a new row at the bottom
14380 await press("Enter");
14381 await animationFrame();
14382 expect(`.o_data_row`).toHaveCount(5);
14383 expect(`.o_data_row:eq(4) [name=foo] input`).toBeFocused();
14384
14385 // Edit the row and press enter: should add a new row
14386 await contains(`.o_data_row:eq(4) [name=foo] input`).edit("blork", { confirm: "enter" });
14387 expect(`.o_data_row`).toHaveCount(6);
14388 expect(`.o_data_row:eq(5) [name=foo] input`).toBeFocused();
14389
14390 // Escape should discard the added row as it is pristine + view should go into readonly mode
14391 await press("Escape");
14392 await animationFrame();
14393 expect(`.o_data_row`).toHaveCount(5);
14394 expect(`.o_selected_row`).toHaveCount(0);
14395 expect(`.o_group_header:eq(0)`).toHaveText("No (1)\n -4");
14396
14397 // Click on last data row of first group
14398 await contains(`.o_data_row:eq(0) [name=foo]`).click();
14399 expect(`.o_data_row:eq(0) [name=foo] input`).toBeFocused();
14400
14401 // Enter should add a new row in the first group
14402 await press("Enter");
14403 await animationFrame();
14404 expect(`.o_data_row`).toHaveCount(6);
14405 expect(`.o_group_header:eq(0)`).toHaveText("No (2)\n -4");
14406
14407 // Enter should discard the edited row as it is pristine + get to next data row
14408 await press("Enter");
14409 await animationFrame();
14410 expect(`.o_data_row`).toHaveCount(5);
14411 expect(`.o_group_header:eq(0)`).toHaveText("No (1)\n -4");
14412 expect(`.o_data_row:eq(1) [name=foo] input`).toBeFocused();
14413
14414 // Shift+Tab should focus back the last field of first row
14415 await press("Shift+Tab");
14416 await animationFrame();
14417 expect(`.o_data_row:eq(0) [name=int_field] input`).toBeFocused();
14418
14419 // Enter should add a new row in the first group
14420 await press("Enter");
14421 await animationFrame();
14422 expect(`.o_data_row`).toHaveCount(6);
14423 expect(`.o_group_header:eq(0)`).toHaveText("No (2)\n -4");
14424
14425 // Edit the row and press enter: should add a new row
14426 expect(`.o_data_row:eq(1) [name=foo] input`).toBeFocused();
14427 await contains(`.o_data_row:eq(1) [name=foo] input`).edit("zzapp", { confirm: "enter" });
14428 expect(`.o_data_row`).toHaveCount(7);
14429 expect(`.o_group_header:eq(0)`).toHaveText("No (3)\n -4");
14430 expect(`.o_data_row:eq(2) [name=foo] input`).toBeFocused();
14431 });
14432
14433 test.tags("desktop");
14434 test(`keyboard navigation with date range`, async () => {
14435 Foo._fields.date_end = fields.Date();
14436 Foo._records[0].date_end = "2017-01-26";
14437
14438 await mountView({
14439 resModel: "foo",
14440 type: "list",
14441 arch: `
14442 <list editable="bottom">
14443 <field name="foo"/>
14444 <field name="date" widget="daterange" options="{'end_date_field': 'date_end'}"/>
14445 <field name="int_field"/>
14446 </list>
14447 `,
14448 });
14449 await contains(`.o_data_row:eq(0) [name=foo]`).click();
14450 expect(`.o_data_row:eq(0) [name=foo] input`).toBeFocused();
14451
14452 await press("Tab");
14453 await animationFrame();
14454 expect(".o_data_row:eq(0) [name=date] input").toBeFocused();
14455
14456 await press("Tab");
14457 await animationFrame();
14458 expect(".o_data_row:eq(0) [name=date] input").toBeFocused();
14459
14460 await press("Tab");
14461 await animationFrame();
14462 expect(`.o_data_row:eq(0) [name=int_field] input`).toBeFocused();
14463 });
14464
14465 test.tags("desktop");
14466 test(`keyboard navigation with Many2One field`, async () => {
14467 await mountView({
14468 resModel: "foo",
14469 type: "list",
14470 arch: `
14471 <list editable="bottom">
14472 <field name="foo"/>
14473 <field name="m2o"/>
14474 <field name="int_field"/>
14475 </list>
14476 `,
14477 });
14478 await contains(`.o_data_row:eq(0) [name=foo]`).click();
14479 expect(`.o_data_row:eq(0) [name=foo] input`).toBeFocused();
14480
14481 await press("Tab");
14482 await animationFrame();
14483 expect(`.o_data_row:eq(0) [name=m2o] input`).toBeFocused();
14484
14485 await press("Tab");
14486 await animationFrame();
14487 expect(`.o_data_row:eq(0) [name=int_field] input`).toBeFocused();
14488 });
14489
14490 test.tags("desktop");
14491 test(`multi-edit records with ENTER does not crash`, async () => {
14492 const deferred = new Deferred();
14493 onRpc("write", () => deferred);
14494
14495 await mountView({
14496 resModel: "foo",
14497 type: "list",
14498 arch: `
14499 <list multi_edit="1">
14500 <field name="foo"/>
14501 <field name="int_field"/>
14502 </list>
14503 `,
14504 });
14505
14506 await contains(`.o_data_row:eq(1) .o_list_record_selector input`).click();
14507 await contains(`.o_data_row:eq(2) .o_list_record_selector input`).click();
14508 await contains(`.o_data_row:eq(1) .o_data_cell[name=int_field]`).click();
14509 expect(`.o_selected_row`).toHaveCount(1);
14510 expect(`.o_data_row:eq(1) [name=int_field] input`).toBeFocused();
14511
14512 await contains(`.o_data_row:eq(1) [name=int_field] input`).edit("234", { confirm: "enter" });
14513 expect(`.o_dialog`).toHaveCount(1); // confirmation dialog
14514
14515 await contains(`.o_dialog .modal-footer .btn-primary`).click();
14516 deferred.resolve();
14517 await animationFrame();
14518 expect(queryAllTexts(`.o_data_cell.o_list_number`)).toEqual(["10", "234", "234", "-4"]);
14519 expect(`.o_dialog`).toHaveCount(0); // no more confirmation dialog, no error dialog
14520 });
14521
14522 test(`editable grouped list: adding a second record pass the first in readonly`, async () => {
14523 await mountView({
14524 type: "list",
14525 resModel: "foo",
14526 arch: `
14527 <list editable="bottom">
14528 <field name="foo"/>
14529 </list>`,
14530 groupBy: ["bar"],
14531 });
14532
14533 expect(`.o_data_row`).toHaveCount(0);
14534 expect(`.o_group_header`).toHaveCount(2);
14535
14536 // Open first and second groups
14537 await contains(`.o_group_header:eq(0)`).click();
14538 await contains(`.o_group_header:eq(1)`).click();
14539 expect(`.o_data_row`).toHaveCount(4);
14540 expect(`.o_group_header:eq(0)`).toHaveText("No (1)");
14541 expect(`.o_group_header:eq(1)`).toHaveText("Yes (3)");
14542
14543 // add a row in first group
14544 await contains(`.o_group_field_row_add:eq(0) a`).click();
14545 expect(`.o_selected_row`).toHaveCount(1);
14546 expect(`.o_data_row`).toHaveCount(5);
14547 expect(`.o_group_header:eq(0)`).toHaveText("No (2)");
14548 expect(`.o_data_row:eq(1) [name=foo] input`).toBeFocused();
14549
14550 // add a row in second group
14551 await contains(`.o_group_field_row_add:eq(1) a`).click();
14552 expect(`.o_selected_row`).toHaveCount(1);
14553 expect(`.o_data_row`).toHaveCount(5);
14554 expect(`.o_group_header:eq(1)`).toHaveText("Yes (4)");
14555 expect(`.o_group_header:eq(0)`).toHaveText("No (1)");
14556 expect(`.o_data_row:eq(4) [name=foo] input`).toBeFocused();
14557 });
14558
14559 test(`removing a groupby while adding a line from list`, async () => {
14560 await mountView({
14561 type: "list",
14562 resModel: "foo",
14563 arch: `
14564 <list multi_edit="1" editable="bottom">
14565 <field name="display_name"/>
14566 <field name="foo"/>
14567 </list>`,
14568 searchViewArch: `
14569 <search>
14570 <field name="foo"/>
14571 <group expand="1" string="Group By">
14572 <filter name="groupby_foo" context="{'group_by': 'foo'}"/>
14573 </group>
14574 </search>`,
14575 });
14576
14577 await toggleSearchBarMenu();
14578 await toggleMenuItem("Foo");
14579
14580 // expand group
14581 await contains(`th.o_group_name`).click();
14582 expect(`.o_selected_row`).toHaveCount(0);
14583 await contains(`td.o_group_field_row_add a`).click();
14584 expect(`.o_selected_row`).toHaveCount(1);
14585 await contains(`.o_searchview_facet .o_facet_remove`).click();
14586 expect(`.o_selected_row`).toHaveCount(0);
14587 });
14588
14589 test.tags("desktop");
14590 test("cell-level keyboard navigation in editable grouped list", async () => {
14591 Foo._records[0].bar = false;
14592 Foo._records[1].bar = false;
14593 Foo._records[2].bar = false;
14594 Foo._records[3].bar = true;
14595
14596 await mountView({
14597 resModel: "foo",
14598 type: "list",
14599 arch: `
14600 <list editable="bottom">
14601 <field name="foo" required="1"/>
14602 </list>
14603 `,
14604 groupBy: ["bar"],
14605 });
14606
14607 await contains(`.o_group_name`).click();
14608 await contains(`.o_data_row:eq(1) .o_data_cell[name=foo]`).click();
14609
14610 expect(`.o_data_row:eq(1)`).toHaveClass("o_selected_row");
14611
14612 await contains(`.o_data_row:eq(1) .o_data_cell[name=foo] input`).click();
14613 await edit("blipbloup", { confirm: false });
14614 await press("escape");
14615 await animationFrame();
14616
14617 expect(`.modal`).toHaveCount(0);
14618 expect(`.o_data_row:eq(1)`).not.toHaveClass("o_selected_row");
14619 expect(`.o_data_row:eq(1) .o_data_cell[name=foo]`).toBeFocused();
14620 expect(`.o_data_row:eq(1) .o_data_cell[name=foo]`).toHaveText("blip");
14621
14622 await press("ArrowLeft");
14623
14624 expect(`.o_data_row:eq(1) input[type=checkbox]`).toBeFocused();
14625
14626 await press("ArrowUp");
14627 await press("ArrowRight");
14628
14629 expect(`.o_data_row:eq(0) .o_data_cell[name=foo]`).toBeFocused();
14630
14631 await press("Enter");
14632 await animationFrame();
14633
14634 expect(`.o_data_row:eq(0)`).toHaveClass("o_selected_row");
14635
14636 await edit("Zipadeedoodah", { confirm: "enter" });
14637 await animationFrame();
14638
14639 expect(`.o_data_row:eq(0)`).not.toHaveClass("o_selected_row");
14640 expect(`.o_data_row:eq(0) .o_data_cell[name=foo]`).toHaveText("Zipadeedoodah");
14641 expect(`.o_data_row:eq(1) .o_data_cell[name=foo] .o_input`).toHaveValue("blip");
14642 expect(`.o_data_row:eq(1) .o_data_cell[name=foo] .o_input`).toBeFocused();
14643
14644 await press("ArrowUp");
14645 await press("ArrowRight");
14646 await animationFrame();
14647
14648 expect(`.o_data_row:eq(1) .o_data_cell[name=foo] .o_input`).toBeFocused();
14649 expect(`.o_data_row:eq(1) .o_data_cell[name=foo] .o_input`).toHaveValue("blip");
14650
14651 await press("ArrowDown");
14652 await press("ArrowLeft");
14653 await animationFrame();
14654
14655 expect(`.o_data_row:eq(1) .o_data_cell[name=foo] .o_input`).toBeFocused();
14656 expect(`.o_data_row:eq(1) .o_data_cell[name=foo] .o_input`).toHaveValue("blip");
14657
14658 await press("Escape");
14659 await animationFrame();
14660
14661 expect(`.o_data_row:eq(1) .o_data_cell[name=foo]`).toBeFocused();
14662
14663 await press("ArrowDown");
14664 await press("ArrowDown");
14665
14666 expect(`.o_group_field_row_add a`).toBeFocused();
14667
14668 await press("ArrowDown");
14669
14670 expect(`.o_group_name:eq(1)`).toBeFocused();
14671 expect(`.o_data_row`).toHaveCount(3);
14672
14673 await press("Enter");
14674 await animationFrame();
14675
14676 expect(`.o_data_row`).toHaveCount(4);
14677 expect(`.o_group_name:eq(1)`).toBeFocused();
14678
14679 await press("ArrowDown");
14680
14681 expect(`.o_data_row:eq(3) [name=foo]`).toBeFocused();
14682
14683 await press("ArrowDown");
14684
14685 expect(`.o_group_field_row_add:eq(1) a`).toBeFocused();
14686
14687 await press("ArrowDown");
14688
14689 expect(`.o_group_field_row_add:eq(1) a`).toBeFocused();
14690
14691 // default Enter on a A tag
14692 await press("Enter");
14693 await animationFrame();
14694 await click(`.o_group_field_row_add a:eq(1)`);
14695 await animationFrame();
14696
14697 expect(`.o_data_row:eq(4) [name=foo] input`).toBeFocused();
14698
14699 await click(`.o_data_row:eq(4) [name=foo] input`);
14700 await edit("cheateur arrete de cheater", { confirm: "enter" });
14701 await animationFrame();
14702
14703 expect(`.o_data_row`).toHaveCount(6);
14704
14705 await press("Escape");
14706 await animationFrame();
14707
14708 expect(`.o_group_field_row_add:eq(1) a`).toBeFocused();
14709
14710 // come back to the top
14711 for (let i = 0; i < 9; i++) {
14712 await press("ArrowUp");
14713 }
14714
14715 expect(`thead th:eq(1)`).toBeFocused();
14716
14717 await press("ArrowLeft");
14718
14719 expect(`thead th.o_list_record_selector input`).toBeFocused();
14720
14721 await press("ArrowDown");
14722 await press("ArrowDown");
14723 await press("ArrowRight");
14724
14725 expect(`.o_data_row:eq(0) .o_data_cell[name=foo]`).toBeFocused();
14726
14727 await press("ArrowUp");
14728
14729 expect(`.o_group_header:eq(0) .o_group_name`).toBeFocused();
14730 expect(`.o_data_row`).toHaveCount(5);
14731
14732 await press("Enter");
14733 await animationFrame();
14734
14735 expect(`.o_data_row`).toHaveCount(2);
14736 expect(`.o_group_header:eq(0) .o_group_name`).toBeFocused();
14737
14738 await press("ArrowRight");
14739 await animationFrame();
14740
14741 expect(`.o_data_row`).toHaveCount(5);
14742 expect(`.o_group_header:eq(0) .o_group_name`).toBeFocused();
14743
14744 await press("ArrowRight");
14745 await animationFrame();
14746
14747 expect(`.o_data_row`).toHaveCount(5);
14748 expect(`.o_group_header:eq(0) .o_group_name`).toBeFocused();
14749
14750 await press("ArrowLeft");
14751 await animationFrame();
14752
14753 expect(`.o_data_row`).toHaveCount(2);
14754 expect(`.o_group_header:eq(0) .o_group_name`).toBeFocused();
14755
14756 await press("ArrowLeft");
14757 await animationFrame();
14758
14759 expect(`.o_data_row`).toHaveCount(2);
14760 expect(`.o_group_header:eq(0) .o_group_name`).toBeFocused();
14761
14762 await press("ArrowDown");
14763
14764 expect(`.o_group_header:eq(1) .o_group_name`).toBeFocused();
14765
14766 await press("ArrowDown");
14767
14768 expect(`.o_data_row:eq(0) .o_data_cell[name=foo]`).toBeFocused();
14769
14770 await press("ArrowDown");
14771
14772 expect(`.o_data_row:eq(1) .o_data_cell[name=foo]`).toBeFocused();
14773
14774 await press("ArrowDown");
14775
14776 expect(`.o_group_field_row_add a`).toBeFocused();
14777
14778 await press("ArrowUp");
14779
14780 expect(`.o_data_row:eq(1) .o_data_cell[name=foo]`).toBeFocused();
14781
14782 await press("ArrowUp");
14783
14784 expect(`.o_data_row:eq(0) .o_data_cell[name=foo]`).toBeFocused();
14785 });
14786
14787 test.tags("desktop");
14788 test(`execute group header button with keyboard navigation`, async () => {
14789 mockService("action", {
14790 doActionButton: ({ name }) => {
14791 expect.step(name);
14792 },
14793 });
14794
14795 await mountView({
14796 resModel: "foo",
14797 type: "list",
14798 arch: `
14799 <list>
14800 <field name="foo"/>
14801 <groupby name="m2o">
14802 <button type="object" name="some_method" string="Do this"/>
14803 </groupby>
14804 </list>
14805 `,
14806 groupBy: ["m2o"],
14807 });
14808 expect(`.o_data_row`).toHaveCount(0);
14809
14810 // focus create button as a starting point
14811 expect(`.o_list_button_add`).toHaveCount(1);
14812
14813 queryFirst(`.o_list_button_add`).focus();
14814 expect(`.o_list_button_add`).toBeFocused();
14815
14816 await press("ArrowDown");
14817 await animationFrame();
14818 expect(`thead th.o_list_record_selector input`).toBeFocused();
14819
14820 await press("ArrowDown");
14821 await animationFrame();
14822 expect(`.o_group_header:nth-child(1) .o_group_name`).toBeFocused();
14823
14824 // unfold first group
14825 await press("Enter");
14826 await animationFrame();
14827 expect(`.o_data_row`).toHaveCount(3);
14828 expect(`.o_group_header:nth-child(1) .o_group_name`).toBeFocused();
14829
14830 // move to first record of opened group
14831 await press("ArrowDown");
14832 await animationFrame();
14833 expect(`tbody tr:nth-child(2) td:nth-child(1) input`).toBeFocused();
14834
14835 // move back to the group header
14836 await press("ArrowUp");
14837 await animationFrame();
14838 expect(`.o_group_header:nth-child(1) .o_group_name`).toBeFocused();
14839
14840 // fold the group
14841 await press("Enter");
14842 await animationFrame();
14843 expect(`.o_data_row`).toHaveCount(0);
14844 expect(`.o_group_header:nth-child(1) .o_group_name`).toBeFocused();
14845
14846 // unfold the group
14847 await press("Enter");
14848 await animationFrame();
14849 expect(`.o_data_row`).toHaveCount(3);
14850 expect(`.o_group_header:nth-child(1) .o_group_name`).toBeFocused();
14851
14852 // tab to the group header button
14853 await press("Tab");
14854 await animationFrame();
14855 expect(`.o_group_header .o_group_buttons button:eq(0)`).toBeFocused();
14856
14857 // click on the button by pressing enter
14858 expect.verifySteps([]);
14859 await press("Enter");
14860 await animationFrame();
14861 expect(`.o_data_row`).toHaveCount(3);
14862 expect.verifySteps(["some_method"]);
14863 });
14864
14865 test.tags("desktop");
14866 test(`add a new row in grouped editable="top" list`, async () => {
14867 await mountView({
14868 resModel: "foo",
14869 type: "list",
14870 arch: `<list editable="top"><field name="foo" required="1"/></list>`,
14871 groupBy: ["bar"],
14872 });
14873
14874 await contains(`.o_group_header`).click(); // open group "No"
14875 await contains(`.o_group_field_row_add a`).click(); // add a new row
14876 expect(`.o_data_row:eq(0)`).toHaveClass("o_selected_row");
14877 expect(`.o_selected_row [name=foo] input`).toBeFocused({
14878 message: "The first input of the line should have the focus",
14879 });
14880 expect(`.o_data_row`).toHaveCount(2);
14881
14882 await contains(`.o_list_button_discard`).click();
14883 await contains(`.o_group_header:eq(1)`).click();
14884 expect(`.o_data_row`).toHaveCount(4);
14885
14886 await contains(`.o_group_field_row_add a:eq(1)`).click(); // create row in second group "Yes"
14887 expect(`.o_group_name:eq(1)`).toHaveText("Yes (4)", {
14888 message: "group should have correct name and count",
14889 });
14890 expect(`.o_data_row`).toHaveCount(5);
14891 expect(`.o_data_row:eq(1)`).toHaveClass("o_selected_row");
14892
14893 await contains(`.o_selected_row [name=foo] input`).edit("pla", { confirm: false });
14894 await contains(`.o_list_button_save`).click();
14895 expect(`.o_data_row`).toHaveCount(5);
14896 });
14897
14898 test.tags("desktop");
14899 test(`add a new row in grouped editable="bottom" list`, async () => {
14900 await mountView({
14901 resModel: "foo",
14902 type: "list",
14903 arch: `<list editable="bottom"><field name="foo" required="1"/></list>`,
14904 groupBy: ["bar"],
14905 });
14906 await contains(`.o_group_header`).click(); // open group "No"
14907 await contains(`.o_group_field_row_add a`).click(); // add a new row
14908 expect(`.o_data_row:eq(1)`).toHaveClass("o_selected_row");
14909 expect(`.o_data_row`).toHaveCount(2);
14910
14911 await contains(`.o_list_button_discard`).click();
14912 await contains(`.o_group_header:eq(1)`).click();
14913 expect(`.o_data_row`).toHaveCount(4);
14914
14915 await contains(`.o_group_field_row_add a:eq(1)`).click(); // create row in second group "Yes"
14916 expect(`.o_data_row:eq(4)`).toHaveClass("o_selected_row");
14917
14918 await contains(`.o_selected_row [name=foo] input`).edit("pla", { confirm: false });
14919 await contains(`.o_list_button_save`).click();
14920 expect(`.o_data_row`).toHaveCount(5);
14921 });
14922
14923 test("editable grouped list: fold group with edited row", async () => {
14924 await mountView({
14925 resModel: "foo",
14926 type: "list",
14927 arch: '<list editable="top"><field name="foo"/></list>',
14928 groupBy: ["bar"],
14929 });
14930
14931 await contains(".o_group_header").click();
14932 expect(".o_data_row .o_data_cell").toHaveText("blip");
14933 await contains(".o_data_row .o_data_cell").click();
14934 await contains(".o_selected_row [name=foo] input").edit("some change");
14935 await contains(".o_group_header").click();
14936 await contains(".o_group_header").click();
14937 expect(".o_data_row .o_data_cell").toHaveText("some change");
14938 });
14939
14940 test("editable grouped list: add row with edited row", async () => {
14941 await mountView({
14942 resModel: "foo",
14943 type: "list",
14944 arch: '<list editable="bottom"><field name="foo"/></list>',
14945 groupBy: ["bar"],
14946 });
14947
14948 await contains(".o_group_header").click();
14949 expect(".o_data_row").toHaveCount(1);
14950 await contains(".o_data_row .o_data_cell").click();
14951 await contains(".o_selected_row [name=foo] input").edit("some change");
14952 await contains(".o_group_field_row_add a").click();
14953 expect(".o_data_row").toHaveCount(2);
14954 expect(".o_data_row:first .o_data_cell").toHaveText("some change");
14955 });
14956
14957 test.tags("desktop");
14958 test(`add and discard a line through keyboard navigation without crashing`, async () => {
14959 await mountView({
14960 resModel: "foo",
14961 type: "list",
14962 arch: `<list editable="bottom"><field name="foo" required="1"/></list>`,
14963 groupBy: ["bar"],
14964 });
14965
14966 // open the last group
14967 await contains(`.o_group_header:eq(-1)`).click();
14968 expect(`.o_data_row`).toHaveCount(3);
14969
14970 // Can trigger ENTER on "Add a line" link ?
14971 expect(`.o_group_field_row_add a`).toHaveCount(1);
14972
14973 queryFirst(`.o_group_field_row_add a`).focus();
14974 expect(`.o_group_field_row_add a`).toBeFocused();
14975 await press("Enter");
14976 await animationFrame();
14977 expect(`.o_data_row`).toHaveCount(4);
14978
14979 await contains(`.o_list_button_discard`).click();
14980 // At this point, a crash manager should appear if no proper link targetting
14981 expect(`.o_data_row`).toHaveCount(3);
14982 });
14983
14984 test.tags("desktop");
14985 test(`discard an invalid row in a list`, async () => {
14986 await mountView({
14987 resModel: "foo",
14988 type: "list",
14989 arch: `<list editable="top"><field name="foo" required="1"/></list>`,
14990 });
14991
14992 await contains(`.o_data_cell`).click();
14993 expect(`.o_field_invalid`).toHaveCount(0);
14994 expect(`.o_selected_row`).toHaveCount(1);
14995
14996 await contains(`[name=foo] input`).edit("");
14997 await contains(`.o_list_view`).click();
14998 expect(`.o_field_invalid`).toHaveCount(1);
14999 expect(`.o_selected_row`).toHaveCount(1);
15000 expect(`[name=foo] input`).toHaveValue("");
15001
15002 await contains(`.o_list_button_discard`).click();
15003 expect(`.o_field_invalid`).toHaveCount(0);
15004 expect(`.o_selected_row`).toHaveCount(0);
15005 expect(`[name='foo']:eq(0)`).toHaveText("yop");
15006 });
15007
15008 test(`editable grouped list with create="0"`, async () => {
15009 await mountView({
15010 resModel: "foo",
15011 type: "list",
15012 arch: `<list editable="top" create="0"><field name="foo" required="1"/></list>`,
15013 groupBy: ["bar"],
15014 });
15015
15016 await contains(`.o_group_header`).click(); // open group
15017 expect(`.o_group_field_row_add a`).toHaveCount(0, {
15018 message: "Add a line should not be available in readonly",
15019 });
15020 });
15021
15022 test(`add a new row in (selection) grouped editable list`, async () => {
15023 Foo._fields.priority = fields.Selection({
15024 selection: [
15025 [1, "Low"],
15026 [2, "Medium"],
15027 [3, "High"],
15028 ],
15029 default: 1,
15030 });
15031 Foo._records.push({
15032 id: 5,
15033 foo: "blip",
15034 int_field: -7,
15035 m2o: 1,
15036 priority: 2,
15037 });
15038 Foo._records.push({
15039 id: 6,
15040 foo: "blip",
15041 int_field: 5,
15042 m2o: 1,
15043 priority: 3,
15044 });
15045
15046 onRpc("onchange", ({ kwargs }) => expect.step(kwargs.context.default_priority.toString()));
15047 await mountView({
15048 resModel: "foo",
15049 type: "list",
15050 arch: `
15051 <list editable="top">
15052 <field name="foo"/>
15053 <field name="priority"/>
15054 <field name="m2o"/>
15055 </list>
15056 `,
15057 groupBy: ["priority"],
15058 });
15059 await contains(`.o_group_header`).click(); // open group
15060 await contains(`.o_group_field_row_add a`).click(); // add a new row
15061 await contains(`[name=foo] input`).edit("xyz", { confirm: false }); // make record dirty
15062 await contains(`.o_list_view`).click(); // unselect row
15063 expect.verifySteps(["1"]);
15064 expect(`.o_data_row .o_data_cell:eq(1)`).toHaveText("Low", {
15065 message: "should have a column name with a value from the groupby",
15066 });
15067
15068 await contains(`.o_group_header:eq(1)`).click();
15069 await contains(`.o_group_field_row_add a:eq(1)`).click(); // create row in second group
15070 await contains(`.o_list_view`).click(); // unselect row
15071 expect(`.o_data_row:eq(5) .o_data_cell:eq(1)`).toHaveText("Medium", {
15072 message: "should have a column name with a value from the groupby",
15073 });
15074 expect.verifySteps(["2"]);
15075 });
15076
15077 test(`add a new row in (m2o) grouped editable list`, async () => {
15078 onRpc("onchange", ({ kwargs }) => {
15079 expect.step(kwargs.context.default_m2o.toString());
15080 });
15081
15082 await mountView({
15083 resModel: "foo",
15084 type: "list",
15085 arch: `
15086 <list editable="top">
15087 <field name="foo"/>
15088 <field name="m2o"/>
15089 </list>
15090 `,
15091 groupBy: ["m2o"],
15092 });
15093 await contains(`.o_group_header`).click(); // open group
15094 await contains(`.o_group_field_row_add a`).click(); // add a new row
15095 await contains(`.o_list_view`).click(); // unselect row
15096 expect(`.o_data_row:eq(0) .o_data_cell:eq(1)`).toHaveText("Value 1", {
15097 message: "should have a column name with a value from the groupby",
15098 });
15099 expect.verifySteps(["1"]);
15100
15101 await contains(`.o_group_header:eq(1)`).click();
15102 await contains(`.o_group_field_row_add a:eq(1)`).click(); // create row in second group
15103 await contains(`.o_list_view`).click(); // unselect row
15104 expect(`.o_data_row:eq(3) .o_data_cell:eq(1)`).toHaveText("Value 2", {
15105 message: "should have a column name with a value from the groupby",
15106 });
15107 expect.verifySteps(["2"]);
15108 });
15109
15110 test(`list view with optional fields rendering`, async () => {
15111 defineParams({ lang_parameters: { direction: "ltr" } });
15112
15113 await mountView({
15114 resModel: "foo",
15115 type: "list",
15116 arch: `
15117 <list>
15118 <field name="foo"/>
15119 <field name="m2o" optional="hide"/>
15120 <field name="amount"/>
15121 <field name="reference" optional="hide"/>
15122 </list>
15123 `,
15124 });
15125 expect(`th:not(.o_list_record_selector)`).toHaveCount(3, {
15126 message: "should have 4 th, 1 for selector, 2 for columns and 1 for optional columns",
15127 });
15128 expect(`tbody tr:first > td:not(.o_list_record_selector)`).toHaveCount(3, {
15129 message: "should have 4 td, 1 for selector, 2 for columns and 1 for optional columns",
15130 });
15131 expect(`table .o_optional_columns_dropdown`).toHaveCount(1, {
15132 message: "should have the optional columns dropdown toggle inside the table",
15133 });
15134 expect(`table > thead > tr > th:eq(-1) .o_optional_columns_dropdown`).toHaveCount(1, {
15135 message: "The optional fields toggler is in the last header column",
15136 });
15137
15138 // optional fields
15139 await contains(`table .o_optional_columns_dropdown .dropdown-toggle`).click();
15140 expect(`.o-dropdown--menu span.dropdown-item`).toHaveCount(2, {
15141 message: "dropdown have 2 optional field foo with checked and bar with unchecked",
15142 });
15143
15144 // enable optional field
15145 await contains(`.o-dropdown--menu span.dropdown-item:eq(0)`).click();
15146 expect(`th:not(.o_list_record_selector)`).toHaveCount(4, {
15147 message:
15148 "should have 1 th for checkbox (desktop only), 3 th for columns, 1 th for optional columns",
15149 });
15150 expect(`tbody tr:first > td:not(.o_list_record_selector)`).toHaveCount(4, {
15151 message:
15152 "should have 1 td for checkbox (desktop only), 3 td for columns, 1 td for optional columns",
15153 });
15154 expect(`th[data-name=m2o]`).toHaveCount(1);
15155 expect(queryAllTexts(`.o-dropdown--menu span.dropdown-item`)).toEqual(["M2o", "Reference"]);
15156 expect(`.o-dropdown--menu span.dropdown-item [name=m2o]`).toBeChecked();
15157
15158 await contains(`.o-dropdown--menu span.dropdown-item [name=m2o]`).click();
15159 expect(`th:not(.o_list_record_selector)`).toHaveCount(3, {
15160 message:
15161 "should have 1 th for checkbox (desktop only), 2 th for columns, 1 th for optional columns",
15162 });
15163 expect(`tbody tr:first > td:not(.o_list_record_selector)`).toHaveCount(3, {
15164 message:
15165 "should have 1 td for checkbox (desktop only), 2 td for columns, 1 td for optional columns",
15166 });
15167 expect(`th[data-name=m2o]`).toHaveCount(0);
15168 expect(`.o-dropdown--menu span.dropdown-item [name=m2o]`).not.toBeChecked();
15169 });
15170
15171 test(`list view with optional fields rendering in RTL mode`, async () => {
15172 defineParams({
15173 lang_parameters: {
15174 direction: "rtl",
15175 },
15176 });
15177
15178 await mountView({
15179 resModel: "foo",
15180 type: "list",
15181 arch: `
15182 <list>
15183 <field name="foo"/>
15184 <field name="m2o" optional="hide"/>
15185 <field name="amount"/>
15186 <field name="reference" optional="hide"/>
15187 </list>
15188 `,
15189 });
15190 expect(`table .o_optional_columns_dropdown`).toHaveCount(1, {
15191 message: "should have the optional columns dropdown toggle inside the table",
15192 });
15193 expect(`table > thead > tr > th:eq(-1) .o_optional_columns_dropdown`).toHaveCount(1, {
15194 message: "The optional fields toggler is in the last header column",
15195 });
15196 });
15197
15198 test.tags("desktop");
15199 test(`optional fields do not disappear even after listview reload`, async () => {
15200 await mountView({
15201 resModel: "foo",
15202 type: "list",
15203 arch: `
15204 <list>
15205 <field name="foo"/>
15206 <field name="m2o" optional="hide"/>
15207 <field name="amount"/>
15208 <field name="reference" optional="hide"/>
15209 </list>
15210 `,
15211 });
15212 expect(`th`).toHaveCount(4, {
15213 message: "should have 3 th, 1 for selector, 2 for columns, 1 for optional columns",
15214 });
15215
15216 // enable optional field
15217 await contains(`table .o_optional_columns_dropdown .dropdown-toggle`).click();
15218 expect(`.o-dropdown--menu span.dropdown-item:eq(0) input`).not.toBeChecked();
15219
15220 await contains(`.o-dropdown--menu span.dropdown-item:eq(0)`).click();
15221 expect(`th`).toHaveCount(5, {
15222 message: "should have 5 th 1 for selector, 3 for columns, 1 for optional columns",
15223 });
15224 expect(`th[data-name=m2o]`).toHaveCount(1);
15225
15226 await contains(`tbody .o_list_record_selector input`).click();
15227 expect(`.o_selection_box`).toHaveCount(1);
15228
15229 await contains(`.o_pager_value`).click();
15230 await contains(`input.o_pager_value`).edit("1-4");
15231 expect(`.o_selection_box`).toHaveCount(0);
15232 expect(`th`).toHaveCount(5, {
15233 message:
15234 "should have 5 th 1 for selector, 3 for columns, 1 for optional columns ever after listview reload",
15235 });
15236 expect(`th[data-name=m2o]`).toHaveCount(1);
15237
15238 await contains(`table .o_optional_columns_dropdown .dropdown-toggle`).click();
15239 expect(`.o-dropdown--menu span.dropdown-item:eq(0) input`).toBeChecked();
15240 });
15241
15242 test(`optional fields is shown only if enabled`, async () => {
15243 defineActions([
15244 {
15245 id: 1,
15246 name: "Currency Action 1",
15247 res_model: "foo",
15248 views: [[1, "list"]],
15249 },
15250 ]);
15251
15252 Foo._views = {
15253 "list,1": `
15254 <list>
15255 <field name="currency_id" optional="show"/>
15256 <field name="display_name" optional="show"/>
15257 </list>
15258 `,
15259 };
15260
15261 await mountWithCleanup(WebClient);
15262 await getService("action").doAction(1);
15263 expect(`th:not(.o_list_record_selector)`).toHaveCount(3, {
15264 message: "should have 4 th, 1 for selector, 2 for columns, 1 for optional columns",
15265 });
15266
15267 // disable optional field
15268 await contains(`table .o_optional_columns_dropdown .dropdown-toggle`).click();
15269 await contains(`.o-dropdown--menu span.dropdown-item:eq(0)`).click();
15270 expect(`th:not(.o_list_record_selector)`).toHaveCount(2, {
15271 message: "should have 1 for selector (desktop only), 1 for columns, 1 for optional columns",
15272 });
15273
15274 await getService("action").doAction(1);
15275 expect(`th:not(.o_list_record_selector)`).toHaveCount(2, {
15276 message:
15277 "should have 1 for selector (desktop only)), 1 for columns, 1 for optional columns ever after listview reload",
15278 });
15279 });
15280
15281 test.tags("desktop");
15282 test(`selection is kept when optional fields are toggled`, async () => {
15283 await mountView({
15284 resModel: "foo",
15285 type: "list",
15286 arch: `
15287 <list>
15288 <field name="foo"/>
15289 <field name="m2o" optional="hide"/>
15290 </list>
15291 `,
15292 });
15293 expect(`th`).toHaveCount(3);
15294
15295 // select a record
15296 await contains(`.o_data_row .o_list_record_selector input`).click();
15297 expect(`.o_list_record_selector input:checked`).toHaveCount(1);
15298
15299 // add an optional field
15300 await contains(`table .o_optional_columns_dropdown .dropdown-toggle`).click();
15301 await contains(`.o-dropdown--menu span.dropdown-item:eq(0) label`).click();
15302 expect(`th`).toHaveCount(4);
15303 expect(`.o_list_record_selector input:checked`).toHaveCount(1);
15304
15305 // select all records
15306 await contains(`thead .o_list_record_selector input`).click();
15307 expect(`.o_list_record_selector input:checked`).toHaveCount(5);
15308
15309 // remove an optional field
15310 await contains(`table .o_optional_columns_dropdown .dropdown-toggle`).click();
15311 await contains(`.o-dropdown--menu span.dropdown-item:eq(0) label`).click();
15312 expect(`th`).toHaveCount(3);
15313 expect(`.o_list_record_selector input:checked`).toHaveCount(5);
15314 });
15315
15316 test(`list view with optional fields and async rendering`, async () => {
15317 const deferred = new Deferred();
15318 const charField = registry.category("fields").get("char");
15319 class AsyncCharField extends charField.component {
15320 setup() {
15321 super.setup();
15322 onWillStart(() => {
15323 expect.step("onWillStart");
15324 return deferred;
15325 });
15326 }
15327 }
15328 registry.category("fields").add("asyncwidget", { component: AsyncCharField });
15329
15330 await mountView({
15331 resModel: "foo",
15332 type: "list",
15333 arch: `
15334 <list>
15335 <field name="m2o"/>
15336 <field name="foo" widget="asyncwidget" optional="hide"/>
15337 </list>
15338 `,
15339 });
15340 expect(`th:not(.o_list_record_selector)`).toHaveCount(2);
15341 expect(`.o_optional_columns_dropdown .show`).toHaveCount(0);
15342
15343 // add an optional field (we click on the label on purpose, as it will trigger
15344 // a second event on the input)
15345 await contains(`table .o_optional_columns_dropdown .dropdown-toggle`).click();
15346 expect(`.o_optional_columns_dropdown .show`).toHaveCount(1);
15347 expect(`.o-dropdown--menu input:checked`).toHaveCount(0);
15348
15349 await contains(`.o-dropdown--menu span.dropdown-item:eq(0) label`).click();
15350 expect(`th:not(.o_list_record_selector)`).toHaveCount(2);
15351 expect(`.o_optional_columns_dropdown .show`).toHaveCount(1);
15352 expect(`.o-dropdown--menu input:checked`).toHaveCount(1);
15353 expect.verifySteps(["onWillStart", "onWillStart", "onWillStart", "onWillStart"]); // 4 rows
15354
15355 deferred.resolve();
15356 await animationFrame();
15357 expect(`th:not(.o_list_record_selector)`).toHaveCount(3);
15358 expect(`.o_optional_columns_dropdown .show`).toHaveCount(1);
15359 expect(`.o-dropdown--menu input:checked`).toHaveCount(1);
15360 });
15361
15362 test.tags("desktop");
15363 test(`change the viewType of the current action`, async () => {
15364 defineActions([
15365 {
15366 id: 1,
15367 name: "Partners Action 1",
15368 res_model: "foo",
15369 views: [[1, "kanban"]],
15370 },
15371 {
15372 id: 2,
15373 name: "Partners",
15374 res_model: "foo",
15375 views: [
15376 [false, "list"],
15377 [1, "kanban"],
15378 ],
15379 },
15380 ]);
15381
15382 Foo._views = {
15383 "kanban,1": `
15384 <kanban>
15385 <templates>
15386 <t t-name="card">
15387 <field name="foo"/>
15388 </t>
15389 </templates>
15390 </kanban>
15391 `,
15392 list: `
15393 <list limit="3">
15394 <field name="foo"/>
15395 <field name="m2o" optional="hide"/>
15396 <field name="o2m" optional="show"/>
15397 </list>
15398 `,
15399 search: `<search><field name="foo" string="Foo"/></search>`,
15400 };
15401
15402 await mountWithCleanup(WebClient);
15403 await getService("action").doAction(2);
15404 expect(`.o_list_view`).toHaveCount(1, { message: "should have rendered a list view" });
15405 expect(`th:not(.o_list_record_selector)`).toHaveCount(3, {
15406 message:
15407 "should have 1 th for selector (desktop only), 2 for fields, 1 for optional columns)",
15408 });
15409
15410 // enable optional field
15411 await contains(`table .o_optional_columns_dropdown_toggle`).click();
15412 expect(`.o-dropdown--menu span.dropdown-item [name=m2o]`).not.toBeChecked();
15413 expect(`.o-dropdown--menu span.dropdown-item [name=o2m]`).toBeChecked();
15414
15415 await contains(`.o-dropdown--menu span.dropdown-item`).click();
15416 expect(`th:not(.o_list_record_selector)`).toHaveCount(4, {
15417 message:
15418 "should have 1 th for selector (desktop only), 3 for fields, 1 for optional columns)",
15419 });
15420 expect(`th[data-name=m2o]`).toHaveCount(1);
15421
15422 // switch to kanban view
15423 await switchView("kanban");
15424 expect(`.o_list_view`).toHaveCount(0, { message: "should not display the list view anymore" });
15425 expect(`.o_kanban_view`).toHaveCount(1, { message: "should have switched to the kanban view" });
15426
15427 // switch back to list view
15428 await switchView("list");
15429 expect(`.o_kanban_view`).toHaveCount(0, {
15430 message: "should not display the kanban view anymoe",
15431 });
15432 expect(`.o_list_view`).toHaveCount(1, { message: "should display the list view" });
15433 expect(`th:not(.o_list_record_selector)`).toHaveCount(4, {
15434 message:
15435 "should have 1 th for selector (desktop only), 3 for fields, 1 for optional columns)",
15436 });
15437 expect(`th[data-name=m2o]`).toHaveCount(1);
15438 expect(`th[data-name=o2m]`).toHaveCount(1);
15439
15440 // disable optional field
15441 await contains(`table .o_optional_columns_dropdown_toggle`).click();
15442 expect(`.o-dropdown--menu span.dropdown-item [name=m2o]`).toBeChecked();
15443 expect(`.o-dropdown--menu span.dropdown-item [name=o2m]`).toBeChecked();
15444
15445 await contains(`.o-dropdown--menu span.dropdown-item input:eq(1)`).click();
15446 expect(`.o-dropdown--menu span.dropdown-item [name=m2o]`).toBeChecked();
15447 expect(`.o-dropdown--menu span.dropdown-item [name=o2m]`).not.toBeChecked();
15448 expect(`th:not(.o_list_record_selector)`).toHaveCount(3, {
15449 message:
15450 "should have 1 th for selector (desktop only), 2 for fields, 1 for optional columns)",
15451 });
15452
15453 await getService("action").doAction(1);
15454 expect(`.o_list_view`).toHaveCount(0, { message: "should not display the list view anymore" });
15455 expect(`.o_kanban_view`).toHaveCount(1, { message: "should have switched to the kanban view" });
15456
15457 await getService("action").doAction(2);
15458 expect(`.o_kanban_view`).toHaveCount(0, { message: "should not havethe kanban view anymoe" });
15459 expect(`.o_list_view`).toHaveCount(1, { message: "should display the list view" });
15460
15461 await contains(`table .o_optional_columns_dropdown_toggle`).click();
15462 expect(`th:not(.o_list_record_selector)`).toHaveCount(3, {
15463 message:
15464 "should have 1 th for selector (desktop only), 2 for fields, 1 for optional columns)",
15465 });
15466 expect(`.o-dropdown--menu span.dropdown-item [name=m2o]`).toBeChecked();
15467 expect(`.o-dropdown--menu span.dropdown-item [name=o2m]`).not.toBeChecked();
15468 });
15469
15470 test(`list view with optional fields rendering and local storage mock`, async () => {
15471 let forceLocalStorage = true;
15472 patchWithCleanup(localStorage, {
15473 getItem(key) {
15474 if (key.startsWith("optional_fields")) {
15475 expect.step(["getItem", key]);
15476 if (forceLocalStorage) {
15477 return "m2o";
15478 }
15479 }
15480 return super.getItem(...arguments);
15481 },
15482 setItem(key, value) {
15483 if (key.startsWith("optional_fields")) {
15484 expect.step(["setItem " + key, value]);
15485 }
15486 super.setItem(...arguments);
15487 },
15488 });
15489
15490 await mountView({
15491 resModel: "foo",
15492 type: "list",
15493 arch: `
15494 <list>
15495 <field name="foo"/>
15496 <field name="m2o" optional="hide"/>
15497 <field name="reference" optional="show"/>
15498 </list>
15499 `,
15500 viewId: 42,
15501 });
15502
15503 const localStorageKey = "optional_fields,foo,list,42,foo,m2o,reference";
15504 expect.verifySteps([["getItem", localStorageKey]]);
15505 expect(`th:not(.o_list_record_selector)`).toHaveCount(3, {
15506 message: "should have 1 for selector (desktop only), 2 for columns, 1 for optional columns",
15507 });
15508 expect(`th[data-name=m2o]`).toHaveCount(1);
15509 expect(`th[data-name=reference]`).toHaveCount(0);
15510
15511 // optional fields
15512 await contains(`table .o_optional_columns_dropdown button`).click();
15513 expect(`.o-dropdown--menu span.dropdown-item`).toHaveCount(2, {
15514 message: "dropdown have 2 optional fields",
15515 });
15516
15517 forceLocalStorage = false;
15518 // enable optional field
15519 await contains(`.o-dropdown--menu span.dropdown-item:eq(1) input`).click();
15520 // Only a setItem since the list view maintains its own internal state of toggled
15521 // optional columns.
15522 expect.verifySteps([
15523 [`setItem ${localStorageKey}`, ["m2o", "reference"]],
15524 ["getItem", "optional_fields,foo,list,42,foo,m2o,reference"],
15525 ]);
15526 expect(`th:not(.o_list_record_selector)`).toHaveCount(4, {
15527 message: "should have 1 for checkbox (desktop only), 3 for columns, 1 for optional columns",
15528 });
15529 expect(`th[data-name=m2o]`).toHaveCount(1);
15530 expect(`th[data-name=reference]`).toHaveCount(1);
15531 });
15532
15533 test(`list view with optional fields from local storage being the empty array`, async () => {
15534 patchWithCleanup(localStorage, {
15535 getItem(key) {
15536 if (key.startsWith("optional_fields")) {
15537 expect.step(["getItem", key]);
15538 }
15539 return super.getItem(...arguments);
15540 },
15541 setItem(key, value) {
15542 if (key.startsWith("optional_fields")) {
15543 expect.step(["setItem " + key, value]);
15544 }
15545 super.setItem(...arguments);
15546 },
15547 });
15548
15549 const verifyHeaders = (namedHeaders) => {
15550 expect(`.o_list_table thead th:not(.o_list_record_selector)`).toHaveCount(
15551 namedHeaders.length + 1
15552 );
15553 expect(`.o_list_table thead th:last`).toHaveClass("o_list_actions_header");
15554 for (let i = 0; i < namedHeaders.length; i++) {
15555 expect(`.o_list_table thead th:not(.o_list_record_selector):eq(${i})`).toHaveAttribute(
15556 "data-name",
15557 namedHeaders[i],
15558 { message: `header at index ${i} is ${namedHeaders[i]}` }
15559 );
15560 }
15561 };
15562
15563 defineActions([
15564 {
15565 id: 1,
15566 name: "Action 1",
15567 res_model: "foo",
15568 views: [[42, "list"]],
15569 search_view_id: [1, "search"],
15570 },
15571 ]);
15572
15573 Foo._views = {
15574 "search,1": `<search/>`,
15575 "list,42": `
15576 <list>
15577 <field name="foo"/>
15578 <field name="m2o" optional="hide"/>
15579 <field name="reference" optional="show"/>
15580 </list>
15581 `,
15582 };
15583
15584 const localStorageKey = "optional_fields,foo,list,42,foo,m2o,reference";
15585 await mountWithCleanup(WebClient);
15586 await getService("action").doAction(1);
15587
15588 // verify initialization
15589 expect.verifySteps([["getItem", localStorageKey]]);
15590 verifyHeaders(["foo", "reference"]);
15591 // open optional columns headers dropdown
15592 await contains(`table .o_optional_columns_dropdown button`).click();
15593 expect(`.o-dropdown--menu span.dropdown-item`).toHaveCount(2, {
15594 message: "dropdown has 2 optional column headers",
15595 });
15596 // disable optional field "reference" (no optional column enabled)
15597 await contains(`.o-dropdown--menu span.dropdown-item input:eq(1)`).click();
15598 expect.verifySteps([
15599 [`setItem ${localStorageKey}`, []],
15600 ["getItem", "optional_fields,foo,list,42,foo,m2o,reference"],
15601 ]);
15602 verifyHeaders(["foo"]);
15603 // mount again to ensure that active optional columns will not be reset while empty
15604 await getService("action").doAction(1);
15605 expect.verifySteps([["getItem", localStorageKey]]);
15606 verifyHeaders(["foo"]);
15607 });
15608
15609 test.tags("desktop");
15610 test(`quickcreate in a many2one in a list`, async () => {
15611 await mountView({
15612 resModel: "foo",
15613 type: "list",
15614 arch: `<list editable="top"><field name="m2o"/></list>`,
15615 });
15616 await contains(`.o_data_row .o_data_cell`).click();
15617 await contains(`.o_data_row .o_data_cell input`).edit("aaa", { confirm: false });
15618 await runAllTimers();
15619 await press("tab");
15620 await animationFrame();
15621 expect(`.o_data_cell:eq(0)`).toHaveText("aaa");
15622 });
15623
15624 test(`float field render with digits attribute on listview`, async () => {
15625 await mountView({
15626 resModel: "foo",
15627 type: "list",
15628 arch: `<list><field name="foo"/><field name="qux" digits="[12,6]"/></list>`,
15629 });
15630 expect(`td.o_list_number:eq(0)`).toHaveText("0.400000", {
15631 message: "should contain 6 digits decimal precision",
15632 });
15633 });
15634
15635 test(`enter edition in editable list with multi_edit = 0`, async () => {
15636 await mountView({
15637 resModel: "foo",
15638 type: "list",
15639 arch: `<list editable="top" multi_edit="0"><field name="int_field"/></list>`,
15640 });
15641
15642 // click on int_field cell of first row
15643 await contains(`.o_data_row .o_data_cell`).click();
15644 expect(`.o_selected_row .o_field_widget[name=int_field] input`).toBeFocused();
15645 });
15646
15647 test(`enter edition in editable list with multi_edit = 1`, async () => {
15648 await mountView({
15649 resModel: "foo",
15650 type: "list",
15651 arch: `
15652 <list editable="top" multi_edit="1">
15653 <field name="int_field"/>
15654 </list>
15655 `,
15656 });
15657
15658 // click on int_field cell of first row
15659 await contains(`.o_data_row .o_data_cell`).click();
15660 expect(`.o_selected_row .o_field_widget[name=int_field] input:eq(0)`).toBeFocused();
15661 });
15662
15663 test(`continue creating new lines in editable=top on keyboard nav`, async () => {
15664 await mountView({
15665 resModel: "foo",
15666 type: "list",
15667 arch: `<list editable="top"><field name="int_field"/></list>`,
15668 });
15669
15670 const initialRowCount = queryAll(`.o_data_cell[name=int_field]`).length;
15671
15672 // click on int_field cell of first row
15673 await contains(`.o_list_button_add`).click();
15674 await contains(`.o_data_cell[name=int_field] input`).edit("1", { confirm: "tab" });
15675 await contains(`.o_data_cell[name=int_field] input`).edit("2", { confirm: "enter" });
15676
15677 // 3 new rows: the two created ("1" and "2", and a new still in edit mode)
15678 expect(`.o_data_cell[name=int_field]`).toHaveCount(initialRowCount + 3);
15679 });
15680
15681 test(`Date in evaluation context works with date field`, async () => {
15682 mockDate("1997-01-09 12:00:00");
15683
15684 Foo._fields.birthday = fields.Date();
15685 Foo._records[0].birthday = "1997-01-08";
15686 Foo._records[1].birthday = "1997-01-09";
15687 Foo._records[2].birthday = "1997-01-10";
15688
15689 await mountView({
15690 resModel: "foo",
15691 type: "list",
15692 arch: `
15693 <list>
15694 <field name="birthday" decoration-danger="birthday > today"/>
15695 </list>
15696 `,
15697 });
15698 expect(`.o_data_row .text-danger`).toHaveCount(1);
15699 });
15700
15701 test(`Datetime in evaluation context works with datetime field`, async () => {
15702 mockDate("1997-01-09 12:00:00");
15703
15704 /**
15705 * Returns "1997-01-DD HH:MM:00" with D, H and M holding current UTC values
15706 * from patched date + (deltaMinutes) minutes.
15707 * This is done to allow testing from any timezone since UTC values are
15708 * calculated with the offset of the current browser.
15709 */
15710 function dateStringDelta(deltaMinutes) {
15711 return luxon.DateTime.now().plus({ minutes: deltaMinutes }).toSQL({ includeZone: false });
15712 }
15713
15714 // "datetime" field may collide with "datetime" object in context
15715 Foo._fields.birthday = fields.Datetime();
15716 Foo._records[0].birthday = dateStringDelta(-120);
15717 Foo._records[1].birthday = dateStringDelta(0);
15718 Foo._records[2].birthday = dateStringDelta(+120);
15719
15720 await mountView({
15721 resModel: "foo",
15722 type: "list",
15723 arch: `
15724 <list>
15725 <field name="birthday" decoration-danger="birthday > now"/>
15726 </list>
15727 `,
15728 });
15729 expect(`.o_data_row .text-danger`).toHaveCount(1);
15730 });
15731
15732 test(`Auto save: add a record and leave action`, async () => {
15733 defineActions([
15734 {
15735 id: 1,
15736 name: "Action 1",
15737 res_model: "foo",
15738 views: [[2, "list"]],
15739 search_view_id: [1, "search"],
15740 },
15741 {
15742 id: 2,
15743 name: "Action 2",
15744 res_model: "foo",
15745 views: [[3, "list"]],
15746 search_view_id: [1, "search"],
15747 },
15748 ]);
15749 Foo._views = {
15750 "search,1": `<search/>`,
15751 "list,2": `<list editable="top"><field name="foo"/></list>`,
15752 "list,3": `<list editable="top"><field name="foo"/></list>`,
15753 };
15754
15755 await mountWithCleanup(WebClient);
15756 await getService("action").doAction(1);
15757 expect(queryAllTexts(`.o_data_cell`)).toEqual(["yop", "blip", "gnap", "blip"]);
15758 expect(`.o_data_row`).toHaveCount(4);
15759
15760 await contains(`.o_list_button_add`).click();
15761 await contains(`.o_data_cell [name=foo] input`).edit("test");
15762 // change action and come back
15763 await getService("action").doAction(2);
15764 await getService("action").doAction(1, { clearBreadcrumbs: true });
15765 expect(queryAllTexts(`.o_data_cell`)).toEqual(["yop", "blip", "gnap", "blip", "test"]);
15766 expect(`.o_data_row`).toHaveCount(5);
15767 });
15768
15769 test(`Auto save: create a new record without modifying it and leave action`, async () => {
15770 Foo._fields.foo = fields.Char({ required: true });
15771
15772 defineActions([
15773 {
15774 id: 1,
15775 name: "Action 1",
15776 res_model: "foo",
15777 views: [[2, "list"]],
15778 search_view_id: [1, "search"],
15779 },
15780 {
15781 id: 2,
15782 name: "Action 2",
15783 res_model: "foo",
15784 views: [[3, "list"]],
15785 search_view_id: [1, "search"],
15786 },
15787 ]);
15788 Foo._views = {
15789 "search,1": `<search/>`,
15790 "list,2": `<list editable="top"><field name="foo"/></list>`,
15791 "list,3": `<list editable="top"><field name="foo"/></list>`,
15792 };
15793
15794 await mountWithCleanup(WebClient);
15795 await getService("action").doAction(1);
15796 expect(queryAllTexts(`.o_data_cell`)).toEqual(["yop", "blip", "gnap", "blip"]);
15797 expect(`.o_data_row`).toHaveCount(4);
15798
15799 await contains(`.o_list_button_add`).click();
15800 expect(`.o_data_row`).toHaveCount(5);
15801
15802 // change action and come back
15803 await getService("action").doAction(2);
15804 await getService("action").doAction(1, { clearBreadcrumbs: true });
15805 expect(queryAllTexts(`.o_data_cell`)).toEqual(["yop", "blip", "gnap", "blip"]);
15806 expect(`.o_data_row`).toHaveCount(4);
15807 });
15808
15809 test(`Auto save: modify a record and leave action`, async () => {
15810 defineActions([
15811 {
15812 id: 1,
15813 name: "Action 1",
15814 res_model: "foo",
15815 views: [[2, "list"]],
15816 search_view_id: [1, "search"],
15817 },
15818 {
15819 id: 2,
15820 name: "Action 2",
15821 res_model: "foo",
15822 views: [[3, "list"]],
15823 search_view_id: [1, "search"],
15824 },
15825 ]);
15826 Foo._views = {
15827 "search,1": `<search/>`,
15828 "list,2": `<list editable="top"><field name="foo"/></list>`,
15829 "list,3": `<list editable="top"><field name="foo"/></list>`,
15830 };
15831
15832 await mountWithCleanup(WebClient);
15833 await getService("action").doAction(1);
15834 expect(queryAllTexts(`.o_data_cell`)).toEqual(["yop", "blip", "gnap", "blip"]);
15835
15836 await contains(`.o_data_cell`).click();
15837 await contains(`.o_data_cell [name=foo] input`).edit("test");
15838 // change action and come back
15839 await getService("action").doAction(2);
15840 await getService("action").doAction(1, { clearBreadcrumbs: true });
15841 expect(queryAllTexts(`.o_data_cell`)).toEqual(["test", "blip", "gnap", "blip"]);
15842 });
15843
15844 test(`Auto save: modify a record and leave action (reject)`, async () => {
15845 defineActions([
15846 {
15847 id: 1,
15848 name: "Action 1",
15849 res_model: "foo",
15850 views: [[2, "list"]],
15851 search_view_id: [1, "search"],
15852 },
15853 {
15854 id: 2,
15855 name: "Action 2",
15856 res_model: "foo",
15857 views: [[3, "list"]],
15858 search_view_id: [1, "search"],
15859 },
15860 ]);
15861 Foo._views = {
15862 "search,1": `<search/>`,
15863 "list,2": `<list editable="top"><field name="foo" required="1"/></list>`,
15864 "list,3": `<list editable="top"><field name="foo"/></list>`,
15865 };
15866
15867 mockService("notification", {
15868 add(message, _) {
15869 expect.step(message);
15870 },
15871 });
15872
15873 await mountWithCleanup(WebClient);
15874 await getService("action").doAction(1);
15875 expect(queryAllTexts(`.o_data_cell`)).toEqual(["yop", "blip", "gnap", "blip"]);
15876
15877 await contains(`.o_data_cell`).click();
15878 await contains(`.o_data_cell [name=foo] input`).edit("", { confirm: false });
15879 getService("action").doAction(2);
15880 await animationFrame();
15881 expect(queryAllTexts(`.o_data_cell`)).toEqual(["", "blip", "gnap", "blip"]);
15882 expect(`.o_selected_row .o_field_widget[name=foo]`).toHaveClass("o_field_invalid");
15883 expect(`.o_data_row`).toHaveCount(4);
15884 expect.verifySteps(["Missing required fields"]);
15885 });
15886
15887 test(`Auto save: add a record and change page`, async () => {
15888 await mountView({
15889 resModel: "foo",
15890 type: "list",
15891 arch: `
15892 <list editable="top" limit="3">
15893 <field name="foo"/>
15894 </list>
15895 `,
15896 });
15897 expect(queryAllTexts(`.o_data_cell`)).toEqual(["yop", "blip", "gnap"]);
15898
15899 await contains(`.o_list_button_add`).click();
15900 await contains(`.o_data_cell [name=foo] input`).edit("test", { confirm: false });
15901 await pagerNext();
15902 expect(queryAllTexts(`.o_data_cell`)).toEqual(["blip", "test"]);
15903
15904 await pagerPrevious();
15905 expect(queryAllTexts(`.o_data_cell`)).toEqual(["yop", "blip", "gnap"]);
15906 });
15907
15908 test(`Auto save: modify a record and change page`, async () => {
15909 await mountView({
15910 resModel: "foo",
15911 type: "list",
15912 arch: `
15913 <list editable="top" limit="3">
15914 <field name="foo"/>
15915 </list>
15916 `,
15917 });
15918 expect(queryAllTexts(`.o_data_cell`)).toEqual(["yop", "blip", "gnap"]);
15919
15920 await contains(`.o_data_cell`).click();
15921 await contains(`.o_data_cell input`).edit("test");
15922 await pagerNext();
15923 expect(queryAllTexts(`.o_data_cell`)).toEqual(["blip"]);
15924
15925 await pagerPrevious();
15926 expect(queryAllTexts(`.o_data_cell`)).toEqual(["test", "blip", "gnap"]);
15927 });
15928
15929 test(`Auto save: modify a record and change page (reject)`, async () => {
15930 await mountView({
15931 resModel: "foo",
15932 type: "list",
15933 arch: `
15934 <list editable="top" limit="3">
15935 <field name="foo" required="1"/>
15936 </list>
15937 `,
15938 });
15939 expect(queryAllTexts(`.o_data_cell`)).toEqual(["yop", "blip", "gnap"]);
15940
15941 await contains(`.o_data_cell`).click();
15942 await contains(`.o_data_cell input`).edit("", { confirm: false });
15943 await pagerNext();
15944 expect(`.o_selected_row .o_field_widget[name=foo]`).toHaveClass("o_field_invalid");
15945 expect(queryAllTexts(`.o_data_cell`)).toEqual(["", "blip", "gnap"]);
15946 });
15947
15948 test(`Auto save: save on closing tab/browser`, async () => {
15949 onRpc("foo", "web_save", ({ args }) => {
15950 expect.step("save"); // should be called
15951 expect(args).toEqual([[1], { foo: "test" }]);
15952 });
15953
15954 await mountView({
15955 resModel: "foo",
15956 type: "list",
15957 arch: `<list editable="top"><field name="foo"/></list>`,
15958 });
15959 await contains(`.o_data_cell`).click();
15960 await contains(`.o_data_cell [name=foo] input`).edit("test");
15961
15962 const [event] = await unload();
15963 await animationFrame();
15964 expect(event.defaultPrevented).toBe(false);
15965 expect.verifySteps(["save"]);
15966 });
15967
15968 test(`Auto save: save on closing tab/browser (pending changes)`, async () => {
15969 onRpc("foo", "web_save", ({ args }) => {
15970 expect.step("web_save");
15971 expect(args).toEqual([[1], { foo: "test" }]);
15972 });
15973
15974 await mountView({
15975 resModel: "foo",
15976 type: "list",
15977 arch: `<list editable="top"><field name="foo"/></list>`,
15978 });
15979 await contains(`.o_data_cell`).click();
15980 await contains(`.o_data_cell [name=foo] input`).edit("test", { confirm: false });
15981
15982 await unload();
15983 await animationFrame();
15984 expect.verifySteps(["web_save"]);
15985 });
15986
15987 test(`Auto save: save on closing tab/browser (invalid field)`, async () => {
15988 onRpc("foo", "web_save", () => {
15989 expect.step("save"); // should not be called
15990 });
15991
15992 await mountView({
15993 resModel: "foo",
15994 type: "list",
15995 arch: `<list editable="top"><field name="foo" required="1"/></list>`,
15996 });
15997 await contains(`.o_data_cell`).click();
15998 await contains(`.o_data_cell [name=foo] input`).edit("");
15999
16000 const [event] = await unload();
16001 await animationFrame();
16002 // should not save because of invalid field
16003 expect.verifySteps([]);
16004 expect(event.defaultPrevented).toBe(true);
16005 });
16006
16007 test(`Auto save: save on closing tab/browser (onchanges + pending changes)`, async () => {
16008 Foo._onChanges = {
16009 int_field(record) {
16010 record.foo = `${record.int_field}`;
16011 },
16012 };
16013
16014 const deferred = new Deferred();
16015 onRpc("foo", "onchange", () => deferred);
16016 onRpc("foo", "web_save", ({ args }) => {
16017 expect.step("web_save");
16018 expect(args).toEqual([[1], { int_field: 2021 }]);
16019 });
16020
16021 await mountView({
16022 resModel: "foo",
16023 type: "list",
16024 arch: `
16025 <list editable="top">
16026 <field name="foo"/>
16027 <field name="int_field"/>
16028 </list>
16029 `,
16030 });
16031 await contains(`.o_data_cell`).click();
16032 await contains(`.o_data_cell [name="int_field"] input`).edit("2021", { confirm: "blur" });
16033
16034 await unload();
16035 await animationFrame();
16036 expect.verifySteps(["web_save"]);
16037 });
16038
16039 test(`Auto save: save on closing tab/browser (onchanges)`, async () => {
16040 Foo._onChanges = {
16041 int_field(record) {
16042 record.foo = `${record.int_field}`;
16043 },
16044 };
16045
16046 const deferred = new Deferred();
16047 onRpc("foo", "onchange", () => deferred);
16048 onRpc("foo", "web_save", ({ args }) => {
16049 expect.step("web_save");
16050 expect(args).toEqual([[1], { foo: "test", int_field: 2021 }]);
16051 });
16052
16053 await mountView({
16054 resModel: "foo",
16055 type: "list",
16056 arch: `
16057 <list editable="top">
16058 <field name="foo"/>
16059 <field name="int_field"/>
16060 </list>
16061 `,
16062 });
16063 await contains(`.o_data_cell`).click();
16064 await contains(`.o_data_cell [name="int_field"] input`).edit("2021", { confirm: false });
16065 await contains(`.o_data_cell [name="foo"] input`).edit("test", { confirm: "blur" });
16066
16067 await unload();
16068 await animationFrame();
16069 expect.verifySteps(["web_save"]);
16070 });
16071
16072 test.tags("desktop");
16073 test(`edition, then navigation with tab (with a readonly re-evaluated field and onchange)`, async () => {
16074 // This test makes sure that if we have a cell in a row that will become
16075 // read-only after editing another cell, in case the keyboard navigation
16076 // move over it before it becomes read-only and there are unsaved changes
16077 // (which will trigger an onchange), the focus of the next activable
16078 // field will not crash
16079 Bar._onChanges = {
16080 o2m() {},
16081 };
16082 Bar._fields.o2m = fields.One2many({ relation: "foo" });
16083 Bar._records[0].o2m = [1, 4];
16084
16085 onRpc("onchange", ({ model }) => {
16086 expect.step(`onchange:${model}`);
16087 });
16088
16089 await mountView({
16090 resModel: "bar",
16091 type: "form",
16092 arch: `
16093 <form>
16094 <group>
16095 <field name="display_name"/>
16096 <field name="o2m">
16097 <list editable="bottom">
16098 <field name="foo"/>
16099 <field name="date" readonly="foo != 'yop'"/>
16100 <field name="int_field"/>
16101 </list>
16102 </field>
16103 </group>
16104 </form>
16105 `,
16106 resId: 1,
16107 });
16108 await contains(`.o_data_cell`).click();
16109 expect(`.o_data_cell[name=foo] input`).toBeFocused();
16110
16111 await contains(`.o_data_cell[name=foo] input`).edit("new value", { confirm: "tab" });
16112 expect(`.o_data_cell[name=date] input`).toHaveCount(0);
16113 expect.verifySteps(["onchange:bar"]);
16114 });
16115
16116 test(`selecting a row after another one containing a table within an html field should be the correct one`, async () => {
16117 Foo._fields.html = fields.Html();
16118 Foo._records[0].html = `
16119 <table class="table table-bordered">
16120 <tbody>
16121 <tr>
16122 <td><br></td>
16123 <td><br></td>
16124 </tr>
16125 <tr>
16126 <td><br></td>
16127 <td><br></td>
16128 </tr>
16129 </tbody>
16130 </table>
16131 `;
16132
16133 await mountView({
16134 resModel: "foo",
16135 type: "list",
16136 arch: `<list editable="top" multi_edit="1"><field name="html"/></list>`,
16137 });
16138 await contains(`.o_data_row:eq(1) .o_data_cell`).click();
16139 expect(`.o_list_table > tbody > tr:eq(1)`).toHaveClass("o_selected_row");
16140 });
16141
16142 test(`archive/unarchive not available on active readonly models`, async () => {
16143 Foo._fields.active = fields.Boolean({ default: true, readonly: true });
16144
16145 await mountView({
16146 resModel: "foo",
16147 type: "list",
16148 arch: `<list limit="3"><field name="display_name"/></list>`,
16149 actionMenus: {},
16150 });
16151 await clickRecordSelector();
16152 expect(`.o_cp_action_menus`).toHaveCount(1, { message: "sidebar should be available" });
16153
16154 await contains(`div.o_control_panel .o_cp_action_menus .dropdown-toggle`).click();
16155 expect(`a:contains(Archive)`).toHaveCount(0, {
16156 message: "Archive action should not be available",
16157 });
16158 });
16159
16160 test(`open groups are kept when leaving and coming back`, async () => {
16161 Foo._views = {
16162 list: `<list><field name="foo"/></list>`,
16163 };
16164
16165 await mountWithCleanup(WebClient);
16166 await getService("action").doAction({
16167 name: "Partners",
16168 res_model: "foo",
16169 type: "ir.actions.act_window",
16170 views: [
16171 [false, "list"],
16172 [false, "form"],
16173 ],
16174 context: {
16175 group_by: ["bar"],
16176 },
16177 });
16178 expect(`.o_list_view`).toHaveCount(1);
16179 expect(`.o_group_header`).toHaveCount(2);
16180 expect(`.o_group_open`).toHaveCount(0);
16181 expect(`.o_data_row`).toHaveCount(0);
16182
16183 // unfold the second group
16184 await contains(`.o_group_header:eq(1)`).click();
16185 expect(`.o_group_open`).toHaveCount(1);
16186 expect(`.o_data_row`).toHaveCount(3);
16187
16188 // open a record and go back
16189 await contains(`.o_data_cell`).click();
16190 expect(`.o_form_view`).toHaveCount(1);
16191
16192 await contains(`.breadcrumb-item a, .o_back_button`).click();
16193 expect(`.o_group_open`).toHaveCount(1);
16194 expect(`.o_data_row`).toHaveCount(3);
16195 });
16196
16197 test("empty groups are removed when leaving and coming back", async () => {
16198 Foo._views = {
16199 list: `<list><field name="foo"/></list>`,
16200 search: "<search/>",
16201 form: `<form><field name="bar"/></form>`,
16202 };
16203 await mountWithCleanup(WebClient);
16204 await getService("action").doAction({
16205 name: "Partners",
16206 res_model: "foo",
16207 type: "ir.actions.act_window",
16208 views: [
16209 [false, "list"],
16210 [false, "form"],
16211 ],
16212 context: {
16213 group_by: ["bar"],
16214 },
16215 });
16216 expect(".o_group_header").toHaveCount(2);
16217 await contains(".o_group_header").click();
16218 await contains(".o_data_cell").click();
16219 await contains("[name='bar'] input").click();
16220 await contains(".breadcrumb-item a, .o_back_button").click();
16221 expect(".o_group_header").toHaveCount(1);
16222 });
16223
16224 test(`open groups are kept when leaving and coming back (grouped by date)`, async () => {
16225 Foo._fields.date = fields.Date({ default: "2022-10-10" });
16226 Foo._views = {
16227 list: `<list><field name="foo"/></list>`,
16228 };
16229
16230 await mountWithCleanup(WebClient);
16231 await getService("action").doAction({
16232 name: "Partners",
16233 res_model: "foo",
16234 type: "ir.actions.act_window",
16235 views: [
16236 [false, "list"],
16237 [false, "form"],
16238 ],
16239 context: {
16240 group_by: ["date"],
16241 },
16242 });
16243 expect(`.o_list_view`).toHaveCount(1);
16244 expect(`.o_group_header`).toHaveCount(2);
16245 expect(`.o_group_open`).toHaveCount(0);
16246 expect(`.o_data_row`).toHaveCount(0);
16247
16248 // unfold the second group
16249 await contains(`.o_group_header:eq(1)`).click();
16250 expect(`.o_group_open`).toHaveCount(1);
16251 expect(`.o_data_row`).toHaveCount(3);
16252
16253 // open a record and go back
16254 await contains(`.o_data_cell`).click();
16255 expect(`.o_form_view`).toHaveCount(1);
16256
16257 await contains(`.breadcrumb-item a, .o_back_button`).click();
16258 expect(`.o_group_open`).toHaveCount(1);
16259 expect(`.o_data_row`).toHaveCount(3);
16260 });
16261
16262 test(`go to the next page after leaving and coming back to a grouped list view`, async () => {
16263 Foo._views = {
16264 list: `<list groups_limit="1"><field name="foo"/></list>`,
16265 };
16266
16267 await mountWithCleanup(WebClient);
16268 await getService("action").doAction({
16269 name: "Partners",
16270 res_model: "foo",
16271 type: "ir.actions.act_window",
16272 views: [
16273 [false, "list"],
16274 [false, "form"],
16275 ],
16276 context: {
16277 group_by: ["bar"],
16278 },
16279 });
16280 expect(`.o_list_view`).toHaveCount(1);
16281 expect(`.o_group_header`).toHaveCount(1);
16282 expect(`.o_group_header`).toHaveText("No (1)");
16283
16284 // unfold the second group
16285 await contains(`.o_group_header`).click();
16286 expect(`.o_group_open`).toHaveCount(1);
16287 expect(`.o_data_row`).toHaveCount(1);
16288
16289 // open a record and go back
16290 await contains(`.o_data_cell`).click();
16291 expect(`.o_form_view`).toHaveCount(1);
16292
16293 await contains(`.breadcrumb-item a, .o_back_button`).click();
16294 expect(`.o_group_header`).toHaveCount(1);
16295 expect(`.o_group_header`).toHaveText("No (1)");
16296
16297 await pagerNext();
16298 expect(`.o_group_header`).toHaveCount(1);
16299 expect(`.o_group_header`).toHaveText("Yes (3)");
16300 });
16301
16302 test(`keep order after grouping`, async () => {
16303 await mountView({
16304 resModel: "foo",
16305 type: "list",
16306 arch: `<list><field name="foo"/></list>`,
16307 searchViewArch: `
16308 <search>
16309 <filter name="group_by_foo" string="Foo" context="{'group_by':'foo'}"/>
16310 </search>
16311 `,
16312 });
16313 expect(queryAllTexts`.o_data_row td[name=foo]`).toEqual(["yop", "blip", "gnap", "blip"]);
16314
16315 // Descending order on Bar
16316 await contains(`th.o_column_sortable[data-name=foo]`).click();
16317 await contains(`th.o_column_sortable[data-name=foo]`).click();
16318 expect(queryAllTexts`.o_data_row td[name=foo]`).toEqual(["yop", "gnap", "blip", "blip"]);
16319
16320 await toggleSearchBarMenu();
16321 await toggleMenuItem("Foo");
16322 expect(queryAllTexts`.o_group_name`).toEqual(["yop (1)", "gnap (1)", "blip (2)"]);
16323
16324 await toggleMenuItem("Foo");
16325 expect(queryAllTexts`.o_data_row td[name=foo]`).toEqual(["yop", "gnap", "blip", "blip"]);
16326 });
16327
16328 test.tags("desktop");
16329 test(`editable list header click should unselect record`, async () => {
16330 await mountView({
16331 resModel: "foo",
16332 type: "list",
16333 arch: `<list editable="top"><field name="foo"/></list>`,
16334 });
16335 await contains(`.o_data_cell`).click();
16336 expect(`.o_selected_row`).toHaveCount(1);
16337
16338 await contains(`.o_data_cell input`).edit("someInput", { confirm: false });
16339 await contains(`thead th:eq(1)`).click();
16340 await press("down");
16341 await animationFrame();
16342 expect(`.o_selected_row`).toHaveCount(0);
16343 });
16344
16345 test.tags("desktop");
16346 test(`editable list group header click should unselect record`, async () => {
16347 await mountView({
16348 resModel: "foo",
16349 type: "list",
16350 arch: `<list editable="top"><field name="foo"/></list>`,
16351 groupBy: ["bar"],
16352 });
16353 await contains(`.o_group_header`).click();
16354 await contains(`.o_group_header:not(.o_group_open)`).click();
16355 await contains(`.o_data_cell`).click();
16356 expect(`.o_selected_row`).toHaveCount(1);
16357
16358 await contains(`.o_data_cell input`).edit("someInput", { confirm: false });
16359 await contains(`.o_group_header:eq(1)`).click();
16360 expect(`.o_selected_row`).toHaveCount(0);
16361 });
16362
16363 test(`fieldDependencies support for fields`, async () => {
16364 Foo._records = [{ id: 1, int_field: 2 }];
16365
16366 registry.category("fields").add("custom_field", {
16367 component: class CustomField extends Component {
16368 static template = xml`<span t-esc="props.record.data.int_field"/>`;
16369 static props = ["*"];
16370 },
16371 fieldDependencies: [{ name: "int_field", type: "integer" }],
16372 });
16373
16374 await mountView({
16375 resModel: "foo",
16376 type: "list",
16377 arch: `<list><field name="foo" widget="custom_field"/></list>`,
16378 });
16379 expect(`[name=foo] span:eq(0)`).toHaveText("2");
16380 });
16381
16382 test(`fieldDependencies support for fields: dependence on a relational field`, async () => {
16383 registry.category("fields").add("custom_field", {
16384 component: class CustomField extends Component {
16385 static template = xml`<span t-esc="props.record.data.m2o.id"/>`;
16386 static props = ["*"];
16387 },
16388 fieldDependencies: [{ name: "m2o", type: "many2one", relation: "bar" }],
16389 });
16390
16391 stepAllNetworkCalls();
16392 await mountView({
16393 resModel: "foo",
16394 type: "list",
16395 arch: `<list><field name="foo" widget="custom_field"/></list>`,
16396 });
16397 expect(`[name=foo] span:eq(0)`).toHaveText("1");
16398 expect.verifySteps([
16399 "/web/webclient/translations",
16400 "/web/webclient/load_menus",
16401 "get_views",
16402 "web_search_read",
16403 "has_group",
16404 ]);
16405 });
16406
16407 test.tags("desktop");
16408 test(`editable list correctly saves dirty fields `, async () => {
16409 Foo._records = [Foo._records[0]];
16410
16411 onRpc("web_save", ({ args }) => {
16412 expect.step("web_save");
16413 expect(args).toEqual([[1], { foo: "test" }]);
16414 });
16415
16416 await mountView({
16417 resModel: "foo",
16418 type: "list",
16419 arch: `<list editable="bottom"><field name="foo"/></list>`,
16420 });
16421 await contains(`.o_data_cell`).click();
16422 await contains(`.o_data_cell input`).edit("test", { confirm: "tab" });
16423 expect.verifySteps(["web_save"]);
16424 });
16425
16426 test(`edit a field with a slow onchange in a new row`, async () => {
16427 Foo._onChanges = {
16428 int_field() {},
16429 };
16430 Foo._records = [];
16431
16432 let deferred;
16433 onRpc("onchange", () => deferred);
16434 stepAllNetworkCalls();
16435
16436 await mountView({
16437 resModel: "foo",
16438 type: "list",
16439 arch: `<list editable="bottom"><field name="int_field"/></list>`,
16440 });
16441 expect.verifySteps([
16442 "/web/webclient/translations",
16443 "/web/webclient/load_menus",
16444 "get_views",
16445 "web_search_read",
16446 "has_group",
16447 ]);
16448
16449 // add a new line
16450 await contains(`.o_list_button_add`).click();
16451 expect.verifySteps(["onchange"]);
16452
16453 // we want to add a delay to simulate an onchange
16454 deferred = new Deferred();
16455
16456 // write something in the field
16457 await contains(`[name=int_field] input`).edit("14", { confirm: false });
16458 expect(`[name=int_field] input`).toHaveValue("14");
16459
16460 await contains(`.o_list_view`).click();
16461 // check that nothing changed before the onchange finished
16462 expect(`[name=int_field] input`).toHaveValue("14");
16463 expect.verifySteps(["onchange"]);
16464
16465 // unlock onchange
16466 deferred.resolve();
16467 await animationFrame();
16468
16469 // check the current line is added with the correct content
16470 expect(`.o_data_row [name=int_field]:eq(0)`).toHaveText("14");
16471 expect.verifySteps(["web_save"]);
16472 });
16473
16474 test(`create a record with the correct context`, async () => {
16475 Foo._fields.text = fields.Text({ required: true });
16476 Foo._records = [];
16477
16478 onRpc("web_save", ({ kwargs }) => {
16479 expect.step("web_save");
16480 const { context } = kwargs;
16481 expect(context.default_text).toBe("yop");
16482 expect(context.test).toBe(true);
16483 });
16484
16485 await mountView({
16486 resModel: "foo",
16487 type: "list",
16488 arch: `
16489 <list editable="bottom">
16490 <field name="foo"/>
16491 <field name="text"/>
16492 </list>
16493 `,
16494 context: {
16495 default_text: "yop",
16496 test: true,
16497 },
16498 });
16499 await contains(`.o_list_button_add`).click();
16500 await contains(`[name='foo'] input`).edit("blop", { confirm: false });
16501 expect(`.o_selected_row`).toHaveCount(1);
16502
16503 await contains(`.o_list_view`).click();
16504 expect(`.o_selected_row`).toHaveCount(0);
16505 expect(queryAllTexts`.o_data_row:eq(-1) .o_data_cell`).toEqual(["blop", "yop"]);
16506 expect.verifySteps(["web_save"]);
16507 });
16508
16509 test(`create a record with the correct context in a group`, async () => {
16510 Foo._fields.text = fields.Text({ required: true });
16511
16512 onRpc("web_save", ({ kwargs }) => {
16513 expect.step("web_save");
16514 const { context } = kwargs;
16515 expect(context.default_bar).toBe(true);
16516 expect(context.default_text).toBe("yop");
16517 expect(context.test).toBe(true);
16518 });
16519
16520 await mountView({
16521 resModel: "foo",
16522 type: "list",
16523 arch: `
16524 <list editable="bottom">
16525 <field name="foo"/>
16526 <field name="text"/>
16527 </list>
16528 `,
16529 groupBy: ["bar"],
16530 context: {
16531 default_text: "yop",
16532 test: true,
16533 },
16534 });
16535 await contains(`.o_group_name:eq(1)`).click();
16536 await contains(`.o_group_field_row_add a`).click();
16537 await contains(`[name='foo'] input`).edit("blop", { confirm: false });
16538 expect(`.o_selected_row`).toHaveCount(1);
16539
16540 await contains(`.o_list_view`).click();
16541 expect(`.o_selected_row`).toHaveCount(0);
16542 expect(queryAllTexts`.o_data_row:eq(-1) .o_data_cell`).toEqual(["blop", "yop"]);
16543 expect.verifySteps(["web_save"]);
16544 });
16545
16546 test(`classNames given to a field are set on the right field directly`, async () => {
16547 await mountView({
16548 resModel: "foo",
16549 type: "list",
16550 arch: `
16551 <list editable="bottom">
16552 <field class="d-flex align-items-center" name="int_field" widget="progressbar" options="{'editable': true}"/>
16553 <field class="d-none" name="bar"/>
16554 </list>
16555 `,
16556 });
16557 expect(`.o_field_cell:eq(2)`).not.toHaveClass("d-flex align-items-center", {
16558 message: "classnames are not set on the first cell",
16559 });
16560 expect(`.o_field_progressbar`).toHaveClass("d-flex align-items-center", {
16561 message: "classnames are set on the corresponding field div directly",
16562 });
16563 expect(`.o_field_cell:eq(3)`).toHaveClass("d-none", {
16564 message: "classnames are set on the second cell",
16565 });
16566 });
16567
16568 test(`use a filter_domain in a list view`, async () => {
16569 await mountView({
16570 resModel: "foo",
16571 type: "list",
16572 arch: `<list><field name="foo"/><field name="m2o"/></list>`,
16573 searchViewArch: `
16574 <search>
16575 <field name="m2o" filter_domain="[('m2o', 'child_of', raw_value)]"/>
16576 </search>
16577 `,
16578 context: {
16579 search_default_m2o: 1,
16580 },
16581 });
16582 expect(`.o_data_row`).toHaveCount(3);
16583 });
16584
16585 test(`Formatted group operator`, async () => {
16586 Foo._records[0].qux = 0.4;
16587 Foo._records[1].qux = 0.2;
16588 Foo._records[2].qux = 0.01;
16589 Foo._records[3].qux = 0.48;
16590 await mountView({
16591 resModel: "foo",
16592 type: "list",
16593 arch: `<list><field name="qux" widget="percentage"/></list>`,
16594 groupBy: ["bar"],
16595 });
16596 expect(`td.o_list_number:eq(0)`).toHaveText("48%");
16597 expect(`td.o_list_number:eq(1)`).toHaveText("61%");
16598 });
16599
16600 test(`Formatted group operator with digit precision on the field definition`, async () => {
16601 Foo._fields.qux = fields.Float({ digits: [16, 3] });
16602 await mountView({
16603 resModel: "foo",
16604 type: "list",
16605 arch: `<list><field name="qux"/></list>`,
16606 groupBy: ["bar"],
16607 });
16608 expect(`td.o_list_number:eq(0)`).toHaveText("9.000");
16609 expect(`td.o_list_number:eq(1)`).toHaveText("10.400");
16610 });
16611
16612 test(`list view does not crash when clicked button cell`, async () => {
16613 await mountView({
16614 resModel: "foo",
16615 type: "list",
16616 arch: `<list><button name="a" type="object" icon="fa-car"/></list>`,
16617 });
16618 expect(`.o_data_row:eq(0) td.o_list_button`).toHaveCount(1);
16619 await contains(`.o_data_row:eq(0) td.o_list_button`).click();
16620 });
16621
16622 test.tags("desktop");
16623 test(`group by going to next page then back to first`, async () => {
16624 await mountView({
16625 resModel: "foo",
16626 type: "list",
16627 arch: `<list groups_limit="1"><field name="foo"/><field name="bar"/></list>`,
16628 groupBy: ["bar"],
16629 });
16630 expect([...getPagerValue(), getPagerLimit()]).toEqual([1, 2]);
16631
16632 await pagerNext();
16633 expect([...getPagerValue(), getPagerLimit()]).toEqual([2, 2]);
16634
16635 await pagerPrevious();
16636 expect([...getPagerValue(), getPagerLimit()]).toEqual([1, 2]);
16637 });
16638
16639 test(`sort on a non sortable field with allow_order option`, async () => {
16640 Foo._records = [{ bar: true }, { bar: false }, { bar: true }];
16641
16642 await mountView({
16643 resModel: "foo",
16644 type: "list",
16645 arch: `<list><field name="bar" options="{ 'allow_order': true }"/></list>`,
16646 });
16647 expect(queryAllProperties(`[name=bar] input`, "checked")).toEqual([true, false, true]);
16648 expect(`th[data-name=bar]`).toHaveClass("o_column_sortable");
16649 expect(`th[data-name=bar]`).not.toHaveClass("table-active");
16650
16651 await contains(`th[data-name=bar]`).click();
16652 expect(queryAllProperties(`[name=bar] input`, "checked")).toEqual([false, true, true]);
16653 expect(`th[data-name=bar]`).toHaveClass("o_column_sortable");
16654 expect(`th[data-name=bar]`).toHaveClass("table-active");
16655 expect(`th[data-name=bar] i`).toHaveClass("fa-sort-asc");
16656 });
16657
16658 test(`sort rows in a grouped list view`, async () => {
16659 await mountView({
16660 resModel: "foo",
16661 type: "list",
16662 arch: `<list><field name="int_field"/></list>`,
16663 groupBy: ["bar"],
16664 });
16665 await contains(`.o_group_header:eq(1)`).click();
16666 expect(queryAllTexts(`.o_data_cell`)).toEqual(["10", "9", "17"]);
16667 expect(`th[data-name=int_field]`).toHaveClass("o_column_sortable");
16668
16669 await contains(`th[data-name=int_field]`).click();
16670 expect(queryAllTexts(`.o_data_cell`)).toEqual(["9", "10", "17"]);
16671 expect(`th[data-name=int_field]`).toHaveClass("o_column_sortable");
16672 expect(`th[data-name=int_field] i`).toHaveClass("fa-sort-asc");
16673 });
16674
16675 test.tags("desktop");
16676 test(`have some records, then go to next page in pager then group by some field: at least one group should be visible`, async () => {
16677 await mountView({
16678 resModel: "foo",
16679 type: "list",
16680 arch: `
16681 <list limit="2">
16682 <field name="foo"/>
16683 <field name="bar"/>
16684 </list>
16685 `,
16686 searchViewArch: `
16687 <search>
16688 <filter name="group_by_bar" string="Bar" context="{ 'group_by': 'bar' }"/>
16689 </search>
16690 `,
16691 });
16692 expect(`tbody .o_data_row`).toHaveCount(2);
16693 expect(queryAllTexts(`tbody .o_data_row`)).toEqual(["yop", "blip"]);
16694
16695 await toggleSearchBarMenu();
16696 await toggleMenuItem("Bar");
16697 expect(`tbody .o_group_header`).toHaveCount(2);
16698 expect(queryAllTexts(`tbody .o_group_header`)).toEqual(["No (1)", "Yes (3)"]);
16699
16700 await removeFacet("Bar");
16701 expect(`tbody .o_data_row`).toHaveCount(2);
16702 expect(queryAllTexts(`tbody .o_data_row`)).toEqual(["yop", "blip"]);
16703
16704 await pagerNext();
16705 expect(`tbody .o_data_row`).toHaveCount(2);
16706 expect(queryAllTexts(`tbody .o_data_row`)).toEqual(["gnap", "blip"]);
16707
16708 await toggleSearchBarMenu();
16709 await toggleMenuItem("Bar");
16710 expect(`tbody .o_group_header`).toHaveCount(2);
16711 expect(queryAllTexts(`tbody .o_group_header`)).toEqual(["No (1)", "Yes (3)"]);
16712 });
16713
16714 test(`optional field selection do not unselect current row`, async () => {
16715 await mountView({
16716 resModel: "foo",
16717 type: "list",
16718 arch: `
16719 <list editable="top">
16720 <field name="text" optional="hide"/>
16721 <field name="foo" optional="show"/>
16722 <field name="bar" optional="hide"/>
16723 </list>
16724 `,
16725 });
16726 await contains(`.o_list_button_add`).click();
16727 expect(`.o_selected_row`).toHaveCount(1);
16728 expect(`div[name=foo] input`).toBeFocused();
16729
16730 await contains(`table .o_optional_columns_dropdown .dropdown-toggle`).click();
16731 expect(`.o_selected_row`).toHaveCount(1);
16732 // input loses focus when we open dropdown but gets it back when an item is toggled.
16733 expect(`div[name=foo] input`).not.toBeFocused();
16734
16735 await contains(`.o-dropdown--menu span.dropdown-item:eq(2) label`).click();
16736 expect(`.o_selected_row`).toHaveCount(1);
16737 expect(`div[name=foo] input`).toBeFocused();
16738 expect(`.o_selected_row div[name=bar]`).toHaveCount(1);
16739
16740 await contains(`.o-dropdown--menu span.dropdown-item:eq(0) label`).click();
16741 expect(`.o_selected_row`).toHaveCount(1);
16742 // This below would be better if it still focused foo, but it is an acceptable tradeoff.
16743 expect(`div[name=text] textarea`).toBeFocused();
16744 expect(`.o_selected_row div[name=text]`).toHaveCount(1);
16745 });
16746
16747 test(`view widgets are rendered in list view`, async () => {
16748 class TestWidget extends Component {
16749 static template = xml`<div class="test_widget" t-esc="props.record.data.bar"/>`;
16750 static props = ["*"];
16751 }
16752 registry.category("view_widgets").add("test_widget", { component: TestWidget });
16753
16754 await mountView({
16755 resModel: "foo",
16756 type: "list",
16757 arch: `
16758 <list>
16759 <field name="bar" column_invisible="1"/>
16760 <widget name="test_widget"/>
16761 </list>
16762 `,
16763 });
16764 expect(`td .test_widget`).toHaveCount(4, {
16765 message: "there should be one widget (inside td) per record",
16766 });
16767 expect(queryAllTexts`.test_widget`).toEqual(["true", "true", "true", "false"]);
16768 });
16769
16770 test(`view widget with options in list view`, async () => {
16771 class TestWidget extends Component {
16772 static template = xml`<div class="test_widget" t-esc="props.x"/>`;
16773 static props = ["*"];
16774 }
16775 registry.category("view_widgets").add("test_widget", {
16776 component: TestWidget,
16777 extractProps: ({ options }) => ({
16778 x: options.x,
16779 }),
16780 });
16781
16782 await mountView({
16783 resModel: "foo",
16784 type: "list",
16785 arch: `
16786 <list>
16787 <widget name="test_widget" options="{'x': 'y'}"/>
16788 </list>
16789 `,
16790 });
16791 expect(queryAllTexts`.test_widget`).toEqual(["y", "y", "y", "y"]);
16792 });
16793
16794 test(`edit a record then select another record with a throw error when saving`, async () => {
16795 onRpc("web_save", () => {
16796 throw makeServerError({ message: "Can't write" });
16797 });
16798
16799 await mountView({
16800 resModel: "foo",
16801 type: "list",
16802 arch: `<list editable="bottom"><field name="foo"/></list>`,
16803 });
16804 await contains(`.o_data_cell:eq(1)`).click();
16805 await contains(`[name=foo] input`).edit("plop", { confirm: false });
16806 expect(`[name=foo] input`).toHaveCount(1);
16807
16808 expect.errors(1);
16809 await contains(`.o_data_cell:eq(0)`).click();
16810 await animationFrame();
16811 expect.verifyErrors(["RPC_ERROR"]);
16812 expect(`.o_error_dialog`).toHaveCount(1);
16813
16814 await contains(`.o_error_dialog .btn-primary.o-default-button`).click();
16815 expect(`.o_selected_row`).toHaveCount(1);
16816 expect(`.o_data_row:eq(1)`).toHaveClass("o_selected_row");
16817 });
16818
16819 test(`no highlight of a (sortable) column without label`, async () => {
16820 await mountView({
16821 resModel: "foo",
16822 type: "list",
16823 arch: `
16824 <list default_order="foo">
16825 <field name="foo" nolabel="1"/>
16826 <field name="bar"/>
16827 </list>
16828 `,
16829 });
16830 expect(`thead th[data-name=foo]`).toHaveCount(1);
16831 expect(`thead th[data-name=foo]`).not.toHaveClass("table-active");
16832 });
16833
16834 test(`highlight of a (sortable) column with label`, async () => {
16835 await mountView({
16836 resModel: "foo",
16837 type: "list",
16838 arch: `
16839 <list default_order="foo">
16840 <field name="foo"/>
16841 </list>
16842 `,
16843 });
16844 expect(`thead th[data-name=foo]`).toHaveCount(1);
16845 expect(`thead th[data-name=foo]`).toHaveClass("table-active");
16846 });
16847
16848 test.tags("desktop");
16849 test(`Search more in a many2one`, async () => {
16850 Bar._views = {
16851 list: `<list><field name="display_name"/></list>`,
16852 };
16853
16854 patchWithCleanup(Many2XAutocomplete.defaultProps, {
16855 searchLimit: 1,
16856 });
16857
16858 onRpc("web_read", ({ args }) => expect.step(`web_read ${args[0]}`));
16859 onRpc("web_save", ({ args }) => expect.step(`web_save ${args[0]}`));
16860
16861 await mountView({
16862 resModel: "foo",
16863 type: "list",
16864 arch: `<list editable="bottom"><field name="m2o"/></list>`,
16865 });
16866 expect(queryAllTexts`.o_data_row td[name=m2o]`).toEqual([
16867 "Value 1",
16868 "Value 2",
16869 "Value 1",
16870 "Value 1",
16871 ]);
16872
16873 await contains(`.o_data_row:eq(0) td.o_list_many2one`).click();
16874 await selectFieldDropdownItem("m2o", "Search more...");
16875 expect.verifySteps([]);
16876
16877 await contains(`.modal .o_data_row:eq(2) td[name=display_name]`).click();
16878 expect.verifySteps(["web_read 3"]);
16879
16880 await contains(`.o_list_button_save`).click();
16881 expect(queryAllTexts`.o_data_row td[name=m2o]`).toEqual([
16882 "Value 3",
16883 "Value 2",
16884 "Value 1",
16885 "Value 1",
16886 ]);
16887 expect.verifySteps(["web_save 1"]);
16888 });
16889
16890 test.tags("desktop");
16891 test(`view's context is passed down as evalContext`, async () => {
16892 onRpc("web_name_search", ({ kwargs }) => {
16893 expect.step(`web_name_search`);
16894 expect(kwargs.domain).toEqual([["someField", "=", "some_value"]]);
16895 });
16896
16897 await mountView({
16898 resModel: "foo",
16899 type: "list",
16900 arch: `
16901 <list editable="bottom">
16902 <field name="m2o" domain="[['someField', '=', context.get('default_global_key', 'nope')]]"/>
16903 </list>
16904 `,
16905 context: {
16906 default_global_key: "some_value",
16907 },
16908 });
16909 await contains(`.o_data_row:eq(0) td.o_list_many2one`).click();
16910 await contains(`.o_field_many2one_selection .o-autocomplete--input`).click();
16911 expect.verifySteps(["web_name_search"]);
16912 });
16913
16914 test(`list view with default_group_by`, async () => {
16915 let readGroupCount = 0;
16916 onRpc("web_read_group", ({ kwargs }) => {
16917 readGroupCount++;
16918 expect.step(`web_read_group${readGroupCount}`);
16919 switch (readGroupCount) {
16920 case 1:
16921 case 3:
16922 case 4: {
16923 expect(kwargs.groupby).toEqual(["bar"]);
16924 break;
16925 }
16926 case 2: {
16927 expect(kwargs.groupby).toEqual(["m2m"]);
16928 break;
16929 }
16930 }
16931 });
16932
16933 await mountView({
16934 resModel: "foo",
16935 type: "list",
16936 arch: `
16937 <list default_group_by="bar">
16938 <field name="bar"/>
16939 </list>
16940 `,
16941 searchViewArch: `
16942 <search>
16943 <filter name="my_filter" string="My Filter" domain="[('id', '>', 1)]"/>
16944 </search>
16945 `,
16946 });
16947 expect(`.o_list_renderer table`).toHaveClass("o_list_table_grouped");
16948 expect(`.o_group_header`).toHaveCount(2);
16949 // open search bar in mobile
16950 if (getMockEnv().isSmall) {
16951 await contains(".o_control_panel_navigation > button").click();
16952 }
16953 expect(`.o_searchview_facet`).toHaveCount(1);
16954 expect(`.o_searchview_facet`).toHaveText("Bar");
16955 expect.verifySteps(["web_read_group1"]);
16956
16957 await selectGroup("m2m");
16958 expect(`.o_group_header`).toHaveCount(4);
16959 expect(`.o_searchview_facet`).toHaveCount(1);
16960 expect(`.o_searchview_facet`).toHaveText("M2m");
16961 expect.verifySteps(["web_read_group2"]);
16962
16963 await toggleMenuItem("M2m");
16964 expect(`.o_group_header`).toHaveCount(2);
16965 expect(`.o_searchview_facet`).toHaveCount(1);
16966 expect(`.o_searchview_facet`).toHaveText("Bar");
16967 expect.verifySteps(["web_read_group3"]);
16968
16969 await toggleMenuItem("My Filter");
16970 expect(`.o_searchview_facet`).toHaveCount(2);
16971 expect(queryAllTexts(`.o_searchview_facet`)).toEqual(["Bar", "My Filter"]);
16972 expect.verifySteps(["web_read_group4"]);
16973 });
16974
16975 test(`list view with multi-fields default_group_by`, async () => {
16976 let readGroupCount = 0;
16977 onRpc("web_read_group", ({ kwargs }) => {
16978 readGroupCount++;
16979 expect.step(`web_read_group${readGroupCount}`);
16980 switch (readGroupCount) {
16981 case 1: {
16982 expect(kwargs.groupby).toEqual(["foo", "bar"]);
16983 break;
16984 }
16985 case 2: {
16986 expect(kwargs.groupby).toEqual(["bar"]);
16987 break;
16988 }
16989 }
16990 });
16991
16992 await mountView({
16993 resModel: "foo",
16994 type: "list",
16995 arch: `
16996 <list default_group_by="foo,bar">
16997 <field name="bar"/>
16998 </list>
16999 `,
17000 });
17001 expect(`.o_list_renderer table`).toHaveClass("o_list_table_grouped");
17002 expect(`.o_group_header`).toHaveCount(3);
17003 // open search bar in mobile
17004 if (getMockEnv().isSmall) {
17005 await contains(".o_control_panel_navigation > button").click();
17006 }
17007 expect(`.o_searchview_facet`).toHaveCount(1);
17008 expect(`.o_searchview_facet`).toHaveText("Foo\n>\nBar");
17009 expect.verifySteps(["web_read_group1"]);
17010 await contains(`.o_group_header`).click();
17011 expect(`.o_group_header`).toHaveCount(5);
17012 expect.verifySteps(["web_read_group2"]);
17013 });
17014
17015 test.tags("desktop");
17016 test(`ungrouped list, apply filter, decrease limit`, async () => {
17017 await mountView({
17018 resModel: "foo",
17019 type: "list",
17020 arch: `<list limit="4"><field name="foo"/></list>`,
17021 searchViewArch: `
17022 <search>
17023 <filter name="my_filter" string="My Filter" domain="[('id', '>', 1)]"/>
17024 </search>
17025 `,
17026 });
17027 expect(`.o_data_row`).toHaveCount(4);
17028
17029 // apply the filter to trigger a reload of datapoints
17030 await toggleSearchBarMenu();
17031 await toggleMenuItem("My Filter");
17032 expect(`.o_data_row`).toHaveCount(3);
17033
17034 // edit the pager with a smaller limit
17035 await contains(`.o_pager_value`).click();
17036 await contains(`.o_pager_value`).edit("1-2");
17037 expect(`.o_data_row`).toHaveCount(2);
17038 });
17039
17040 test(`Properties: char`, async () => {
17041 const definition = {
17042 type: "char",
17043 name: "property_char",
17044 string: "Property char",
17045 };
17046 Bar._records[0].definitions = [definition];
17047 for (const record of Foo._records) {
17048 if (record.m2o === 1) {
17049 record.properties = { [definition.name]: "CHAR" };
17050 }
17051 }
17052
17053 onRpc("web_save", ({ args }) => {
17054 expect.step("web_save");
17055 expect(args).toEqual([[1], { properties: [{ ...definition, value: "TEST" }] }]);
17056 });
17057
17058 await mountView({
17059 resModel: "foo",
17060 type: "list",
17061 arch: `
17062 <list editable="bottom">
17063 <field name="m2o"/>
17064 <field name="properties"/>
17065 </list>
17066 `,
17067 });
17068 await contains(`.o_optional_columns_dropdown_toggle`).click();
17069 await contains(`.o-dropdown--menu input[type='checkbox']`).click();
17070 expect(`.o_list_renderer th[data-name='properties.property_char']`).toHaveCount(1);
17071 expect(`.o_list_renderer th[data-name='properties.property_char']`).toHaveText("Property char");
17072 expect(`.o_field_cell.o_char_cell`).toHaveCount(3);
17073 expect(`.o_field_cell.o_char_cell`).toHaveText("CHAR");
17074
17075 await contains(`.o_field_cell.o_char_cell`).click();
17076 await contains(`.o_field_cell.o_char_cell input`).edit("TEST", { confirm: false });
17077 expect(`.o_field_cell.o_char_cell input`).toHaveValue("TEST");
17078
17079 await contains(`[name='m2o']`).click();
17080 expect(`.o_field_cell.o_char_cell input`).toHaveValue("TEST");
17081
17082 await contains(`.o_list_button_save`).click();
17083 expect(`.o_field_cell.o_char_cell:eq(0)`).toHaveText("TEST");
17084 expect.verifySteps(["web_save"]);
17085
17086 expect(
17087 `.o_list_renderer th[data-name='properties.property_char'] .o_list_sortable_icon`
17088 ).not.toHaveClass("d-none"); // sortable
17089 });
17090
17091 test(`Properties: boolean`, async () => {
17092 const definition = {
17093 type: "boolean",
17094 name: "property_boolean",
17095 string: "Property boolean",
17096 };
17097 Bar._records[0].definitions = [definition];
17098 for (const record of Foo._records) {
17099 if (record.m2o === 1) {
17100 record.properties = { [definition.name]: true };
17101 }
17102 }
17103
17104 onRpc("web_save", ({ args }) => {
17105 expect.step("web_save");
17106 expect(args).toEqual([[1], { properties: [{ ...definition, value: false }] }]);
17107 });
17108
17109 await mountView({
17110 resModel: "foo",
17111 type: "list",
17112 arch: `
17113 <list editable="bottom">
17114 <field name="m2o"/>
17115 <field name="properties"/>
17116 </list>
17117 `,
17118 });
17119 await contains(`.o_optional_columns_dropdown_toggle`).click();
17120 await contains(`.o-dropdown--menu input[type='checkbox']`).click();
17121 expect(`.o_list_renderer th[data-name='properties.property_boolean']`).toHaveCount(1);
17122 expect(`.o_list_renderer th[data-name='properties.property_boolean']`).toHaveText(
17123 "Property boolean"
17124 );
17125 expect(`.o_field_cell.o_boolean_cell`).toHaveCount(3);
17126
17127 await contains(`.o_field_cell.o_boolean_cell`).click();
17128 await contains(`.o_list_button_save`).click();
17129 expect(`.o_field_cell.o_boolean_cell input:first`).not.toBeChecked();
17130 expect.verifySteps(["web_save"]);
17131 });
17132
17133 test(`Properties: integer`, async () => {
17134 const definition = {
17135 type: "integer",
17136 name: "property_integer",
17137 string: "Property integer",
17138 };
17139 Bar._records[0].definitions = [definition];
17140 for (const record of Foo._records) {
17141 if (record.m2o === 1) {
17142 record.properties = { [definition.name]: 123 };
17143 }
17144 }
17145
17146 onRpc("web_save", ({ args }) => {
17147 expect.step("web_save");
17148 expect(args).toEqual([[1], { properties: [{ ...definition, value: 321 }] }]);
17149 });
17150
17151 await mountView({
17152 resModel: "foo",
17153 type: "list",
17154 arch: `
17155 <list editable="bottom">
17156 <field name="m2o"/>
17157 <field name="properties"/>
17158 </list>
17159 `,
17160 });
17161 await contains(`.o_optional_columns_dropdown_toggle`).click();
17162 await contains(`.o-dropdown--menu input[type='checkbox']`).click();
17163 expect(`.o_list_renderer th[data-name='properties.property_integer']`).toHaveCount(1);
17164 expect(`.o_list_renderer th[data-name='properties.property_integer']`).toHaveText(
17165 "Property integer"
17166 );
17167 expect(`.o_field_cell.o_integer_cell`).toHaveCount(3);
17168
17169 await contains(`.o_field_cell.o_integer_cell`).click();
17170 await contains(`.o_field_cell.o_integer_cell input`).edit(321, { confirm: false });
17171 await contains(`.o_list_button_save`).click();
17172 expect(`.o_field_cell.o_integer_cell:eq(0)`).toHaveText("321");
17173 expect(`.o_list_footer .o_list_number`).toHaveText("567", {
17174 message:
17175 "First property is 321, second is zero because it has a different parent and the 2 others are 123 so the total should be 321 + 123 * 2 = 567",
17176 });
17177 expect.verifySteps(["web_save"]);
17178 });
17179
17180 test(`Properties: float`, async () => {
17181 const definition = {
17182 type: "float",
17183 name: "property_float",
17184 string: "Property float",
17185 };
17186 Bar._records[0].definitions = [definition];
17187 for (const record of Foo._records) {
17188 if (record.m2o === 1) {
17189 record.properties = { [definition.name]: record.id === 4 ? false : 123.45 };
17190 }
17191 }
17192
17193 onRpc("web_save", ({ args }) => {
17194 expect.step("web_save");
17195 expect(args).toEqual([[1], { properties: [{ ...definition, value: 3.21 }] }]);
17196 });
17197
17198 await mountView({
17199 resModel: "foo",
17200 type: "list",
17201 arch: `
17202 <list editable="bottom">
17203 <field name="m2o"/>
17204 <field name="properties"/>
17205 </list>
17206 `,
17207 });
17208 await contains(`.o_optional_columns_dropdown_toggle`).click();
17209 await contains(`.o-dropdown--menu input[type='checkbox']`).click();
17210 expect(`.o_list_renderer th[data-name='properties.property_float']`).toHaveCount(1);
17211 expect(`.o_list_renderer th[data-name='properties.property_float']`).toHaveText(
17212 "Property float"
17213 );
17214 expect(`.o_field_cell.o_float_cell`).toHaveCount(3);
17215
17216 await contains(`.o_field_cell.o_float_cell`).click();
17217 await contains(`.o_field_cell.o_float_cell input`).edit(3.21, { confirm: false });
17218 await contains(`.o_list_button_save`).click();
17219 expect(`.o_field_cell.o_float_cell:eq(0)`).toHaveText("3.21");
17220 expect(`.o_list_footer .o_list_number`).toHaveText("126.66", {
17221 message:
17222 "First property is 3.21, second is zero because it has a different parent the other is 123.45 and the last one zero because it is false so the total should be 3.21 + 123.45 = 126.66",
17223 });
17224 expect.verifySteps(["web_save"]);
17225 });
17226
17227 test(`Properties: date`, async () => {
17228 const definition = {
17229 type: "date",
17230 name: "property_date",
17231 string: "Property date",
17232 };
17233 Bar._records[0].definitions = [definition];
17234 for (const record of Foo._records) {
17235 if (record.m2o === 1) {
17236 record.properties = { [definition.name]: "2022-12-12" };
17237 }
17238 }
17239
17240 onRpc("web_save", ({ args }) => {
17241 expect.step("web_save");
17242 expect(args).toEqual([[1], { properties: [{ ...definition, value: "2022-12-19" }] }]);
17243 });
17244
17245 await mountView({
17246 resModel: "foo",
17247 type: "list",
17248 arch: `
17249 <list editable="bottom">
17250 <field name="m2o"/>
17251 <field name="properties"/>
17252 </list>
17253 `,
17254 });
17255 await contains(`.o_optional_columns_dropdown_toggle`).click();
17256 await contains(`.o-dropdown--menu input[type='checkbox']`).click();
17257 expect(`.o_list_renderer th[data-name='properties.property_date']`).toHaveCount(1);
17258 expect(`.o_list_renderer th[data-name='properties.property_date']`).toHaveText("Property date");
17259 expect(`.o_field_cell.o_date_cell`).toHaveCount(3);
17260
17261 await contains(`.o_field_cell.o_date_cell`).click();
17262 await contains(`.o_field_date input`).click();
17263 await contains(getPickerCell("19")).click();
17264 await contains(`.o_list_button_save`).click();
17265 expect(`.o_field_cell.o_date_cell:eq(0)`).toHaveText("Dec 19, 2022");
17266 expect.verifySteps(["web_save"]);
17267 });
17268
17269 test(`Properties: datetime`, async () => {
17270 mockTimeZone(0);
17271
17272 const definition = {
17273 type: "datetime",
17274 name: "property_datetime",
17275 string: "Property datetime",
17276 };
17277 Bar._records[0].definitions = [definition];
17278 for (const record of Foo._records) {
17279 if (record.m2o === 1) {
17280 record.properties = { [definition.name]: "2022-12-12 12:12:00" };
17281 }
17282 }
17283
17284 onRpc("web_save", ({ args }) => {
17285 expect.step("web_save");
17286 expect(args).toEqual([
17287 [1],
17288 { properties: [{ ...definition, value: "2022-12-19 12:12:00" }] },
17289 ]);
17290 });
17291
17292 await mountView({
17293 resModel: "foo",
17294 type: "list",
17295 arch: `
17296 <list editable="bottom">
17297 <field name="m2o"/>
17298 <field name="properties"/>
17299 </list>
17300 `,
17301 });
17302 await contains(`.o_optional_columns_dropdown_toggle`).click();
17303 await contains(`.o-dropdown--menu input[type='checkbox']`).click();
17304 expect(`.o_list_renderer th[data-name='properties.property_datetime']`).toHaveCount(1);
17305 expect(`.o_list_renderer th[data-name='properties.property_datetime']`).toHaveText(
17306 "Property datetime"
17307 );
17308 expect(`.o_field_cell.o_datetime_cell`).toHaveCount(3);
17309
17310 await contains(`.o_field_cell.o_datetime_cell`).click();
17311 await contains(`.o_field_datetime input`).click();
17312 await contains(getPickerCell("19")).click();
17313 await contains(`.o_list_button_save`).click();
17314 expect(`.o_field_cell.o_datetime_cell:eq(0)`).toHaveText("Dec 19, 2022, 12:12 PM");
17315 expect.verifySteps(["web_save"]);
17316 });
17317
17318 test(`Properties: selection`, async () => {
17319 const definition = {
17320 type: "selection",
17321 name: "property_selection",
17322 string: "Property selection",
17323 selection: [
17324 ["a", "A"],
17325 ["b", "B"],
17326 ["c", "C"],
17327 ],
17328 };
17329 Bar._records[0].definitions = [definition];
17330 for (const record of Foo._records) {
17331 if (record.m2o === 1) {
17332 record.properties = { [definition.name]: "b" };
17333 }
17334 }
17335
17336 onRpc("web_save", ({ args }) => {
17337 expect.step("web_save");
17338 expect(args).toEqual([[1], { properties: [{ ...definition, value: "a" }] }]);
17339 });
17340
17341 await mountView({
17342 resModel: "foo",
17343 type: "list",
17344 arch: `
17345 <list editable="bottom">
17346 <field name="m2o"/>
17347 <field name="properties"/>
17348 </list>
17349 `,
17350 });
17351 await contains(`.o_optional_columns_dropdown_toggle`).click();
17352 await contains(`.o-dropdown--menu input[type='checkbox']`).click();
17353 expect(`.o_list_renderer th[data-name='properties.property_selection']`).toHaveCount(1);
17354 expect(`.o_list_renderer th[data-name='properties.property_selection']`).toHaveText(
17355 "Property selection"
17356 );
17357 expect(`.o_field_cell.o_selection_cell`).toHaveCount(3);
17358
17359 await contains(`.o_field_cell.o_selection_cell`).click();
17360 await editSelectMenu(".o_field_cell.o_selection_cell input", { value: "A" });
17361 await contains(`.o_list_button_save`).click();
17362 expect(`.o_field_cell.o_selection_cell:eq(0)`).toHaveText("A");
17363 expect.verifySteps(["web_save"]);
17364 });
17365
17366 test(`Properties: tags`, async () => {
17367 const clickFieldDropdownItem = async (fieldName, itemContent, options) => {
17368 const dropdowns = queryAll(
17369 buildSelector(`[name='${fieldName}'] .dropdown .dropdown-menu`, options)
17370 );
17371 if (dropdowns.length === 0) {
17372 throw new Error(`No dropdown found for field ${fieldName}`);
17373 } else if (dropdowns.length > 1) {
17374 throw new Error(`Found ${dropdowns.length} dropdowns for field ${fieldName}`);
17375 }
17376 const dropdownItems = queryAll(buildSelector("li", options), { root: dropdowns[0] });
17377 const indexToClick = queryAllTexts(dropdownItems).indexOf(itemContent);
17378 if (indexToClick === -1) {
17379 throw new Error(`The element '${itemContent}' does not exist in the dropdown`);
17380 }
17381 await click(dropdownItems[indexToClick]);
17382 await animationFrame();
17383 };
17384 const definition = {
17385 type: "tags",
17386 name: "property_tags",
17387 string: "Property tags",
17388 tags: [
17389 ["a", "A", 1],
17390 ["b", "B", 2],
17391 ["c", "C", 3],
17392 ],
17393 };
17394 Bar._records[0].definitions = [definition];
17395 for (const record of Foo._records) {
17396 if (record.m2o === 1) {
17397 record.properties = { [definition.name]: ["a", "c"] };
17398 }
17399 }
17400
17401 let expectedValue = null;
17402 onRpc("web_save", ({ args }) => {
17403 expect.step("web_save");
17404 expect(args).toEqual([[1], { properties: [{ ...definition, value: expectedValue }] }]);
17405 });
17406
17407 await mountView({
17408 resModel: "foo",
17409 type: "list",
17410 arch: `
17411 <list editable="bottom">
17412 <field name="m2o"/>
17413 <field name="properties"/>
17414 </list>
17415 `,
17416 });
17417 await contains(`.o_optional_columns_dropdown_toggle`).click();
17418 await contains(`.o-dropdown--menu input[type='checkbox']`).click();
17419 expect(`.o_list_renderer th[data-name='properties.property_tags']`).toHaveCount(1);
17420 expect(`.o_list_renderer th[data-name='properties.property_tags']`).toHaveText("Property tags");
17421 expect(`.o_field_cell.o_property_tags_cell`).toHaveCount(3);
17422
17423 await contains(`.o_field_cell.o_property_tags_cell`).click();
17424 await contains(`.o_field_cell.o_property_tags_cell .o_delete`).click();
17425 expectedValue = ["c"];
17426 await contains(`.o_list_button_save`).click();
17427 expect(`.o_field_cell.o_property_tags_cell:eq(0)`).toHaveText("C");
17428 expect.verifySteps(["web_save"]);
17429
17430 await contains(`.o_field_cell.o_property_tags_cell`).click();
17431 await clickFieldDropdown(`properties.property_tags`);
17432 await clickFieldDropdownItem(`properties.property_tags`, "B");
17433 expectedValue = ["c", "b"];
17434 await contains(`.o_list_button_save`).click();
17435 expect(`.o_field_cell.o_property_tags_cell:eq(0)`).toHaveText("B\nC");
17436 expect.verifySteps(["web_save"]);
17437 });
17438
17439 test(`Properties: many2one`, async () => {
17440 Currency._views = {
17441 kanban: `<kanban><templates><t t-name="card"><field name="name"/></t></templates></kanban>`,
17442 };
17443 const definition = {
17444 type: "many2one",
17445 name: "property_many2one",
17446 string: "Property many2one",
17447 comodel: "res.currency",
17448 domain: "[]",
17449 };
17450 Bar._records[0].definitions = [definition];
17451
17452 onRpc("web_save", ({ args }) => {
17453 expect.step("web_save");
17454 expect(args[1].properties[0].value[0]).toBe(2);
17455 });
17456
17457 await mountView({
17458 resModel: "foo",
17459 type: "list",
17460 arch: `
17461 <list editable="bottom">
17462 <field name="m2o"/>
17463 <field name="properties"/>
17464 </list>
17465 `,
17466 });
17467 await contains(`.o_optional_columns_dropdown_toggle`).click();
17468 await contains(`.o-dropdown--menu input[type='checkbox']`).click();
17469 expect(`.o_list_renderer th[data-name='properties.property_many2one']`).toHaveCount(1);
17470 expect(`.o_list_renderer th[data-name='properties.property_many2one']`).toHaveText(
17471 "Property many2one"
17472 );
17473 expect(`.o_field_cell.o_many2one_cell`).toHaveCount(3);
17474
17475 await selectMany2xItem(`properties.property_many2one`, "EUR");
17476 await contains(`.o_list_button_save`).click();
17477 expect(`.o_field_cell.o_many2one_cell:eq(0)`).toHaveText("EUR");
17478 expect.verifySteps(["web_save"]);
17479 });
17480
17481 test(`Properties: many2many`, async () => {
17482 const definition = {
17483 type: "many2many",
17484 name: "property_many2many",
17485 string: "Property many2many",
17486 comodel: "res.currency",
17487 domain: "[]",
17488 };
17489 Bar._records[0].definitions = [definition];
17490 for (const record of Foo._records) {
17491 if (record.m2o === 1) {
17492 record.properties = { [definition.name]: [[1, "USD"]] };
17493 }
17494 }
17495
17496 await mountView({
17497 resModel: "foo",
17498 type: "list",
17499 arch: `
17500 <list editable="bottom">
17501 <field name="m2o"/>
17502 <field name="properties"/>
17503 </list>
17504 `,
17505 });
17506 await contains(`.o_optional_columns_dropdown_toggle`).click();
17507 await contains(`.o-dropdown--menu input[type='checkbox']`).click();
17508 expect(`.o_list_renderer th[data-name='properties.property_many2many']`).toHaveCount(1);
17509 expect(`.o_list_renderer th[data-name='properties.property_many2many']`).toHaveText(
17510 "Property many2many"
17511 );
17512 expect(`.o_field_cell.o_many2many_tags_cell`).toHaveCount(3);
17513 });
17514
17515 test(`multiple sources of properties definitions`, async () => {
17516 const definition0 = {
17517 type: "char",
17518 name: "property_char",
17519 string: "Property char",
17520 };
17521 const definition1 = {
17522 type: "boolean",
17523 name: "property_boolean",
17524 string: "Property boolean",
17525 };
17526 Bar._records[0].definitions = [definition0];
17527 Bar._records[1].definitions = [definition1];
17528 for (const record of Foo._records) {
17529 if (record.m2o === 1) {
17530 record.properties = { [definition0.name]: "0" };
17531 } else if (record.m2o === 2) {
17532 record.properties = { [definition1.name]: true };
17533 }
17534 }
17535
17536 await mountView({
17537 resModel: "foo",
17538 type: "list",
17539 arch: `
17540 <list editable="bottom">
17541 <field name="m2o"/>
17542 <field name="properties"/>
17543 </list>
17544 `,
17545 });
17546 await contains(`.o_optional_columns_dropdown_toggle`).click();
17547 await contains(`.o-dropdown--menu input[type=checkbox]:eq(0)`).click();
17548 await contains(`.o-dropdown--menu input[type=checkbox]:eq(1)`).click();
17549 expect(`.o_list_renderer th[data-name='properties.property_char']`).toHaveCount(1);
17550 expect(`.o_field_cell.o_char_cell`).toHaveCount(3);
17551 expect(`.o_list_renderer th[data-name='properties.property_boolean']`).toHaveCount(1);
17552 expect(`.o_field_cell.o_boolean_cell`).toHaveCount(1);
17553 });
17554
17555 test(`toggle properties`, async () => {
17556 const definition0 = {
17557 type: "char",
17558 name: "property_char",
17559 string: "Property char",
17560 };
17561 const definition1 = {
17562 type: "separator",
17563 name: "property_separator",
17564 string: "Group 1",
17565 };
17566 const definition2 = {
17567 type: "boolean",
17568 name: "property_boolean",
17569 string: "Property boolean",
17570 };
17571 Bar._records[0].definitions = [definition0];
17572 Bar._records[1].definitions = [definition1, definition2];
17573 for (const record of Foo._records) {
17574 if (record.m2o === 1) {
17575 record.properties = { [definition0.name]: "0" };
17576 } else if (record.m2o === 2) {
17577 record.properties = {
17578 [definition1.name]: false,
17579 [definition2.name]: true,
17580 };
17581 }
17582 }
17583
17584 await mountView({
17585 resModel: "foo",
17586 type: "list",
17587 arch: `
17588 <list editable="bottom">
17589 <field name="m2o"/>
17590 <field name="properties"/>
17591 </list>
17592 `,
17593 });
17594 await contains(`.o_optional_columns_dropdown_toggle`).click();
17595 expect(`.o-dropdown--menu input[type='checkbox']`).toHaveCount(2);
17596
17597 await contains(`.o-dropdown--menu input[type='checkbox']:eq(0)`).click();
17598 expect(`.o_list_renderer th[data-name='properties.property_char']`).toHaveCount(1);
17599 expect(`.o_list_renderer th[data-name='properties.property_boolean']`).toHaveCount(0);
17600
17601 await contains(`.o-dropdown--menu input[type='checkbox']:eq(1)`).click();
17602 expect(`.o_list_renderer th[data-name='properties.property_char']`).toHaveCount(1);
17603 expect(`.o_list_renderer th[data-name='properties.property_boolean']`).toHaveCount(1);
17604
17605 await contains(`.o-dropdown--menu input[type='checkbox']:eq(0)`).click();
17606 expect(`.o_list_renderer th[data-name='properties.property_char']`).toHaveCount(0);
17607 expect(`.o_list_renderer th[data-name='properties.property_boolean']`).toHaveCount(1);
17608
17609 await contains(`.o-dropdown--menu input[type='checkbox']:eq(1)`).click();
17610 expect(`.o_list_renderer th[data-name='properties.property_char']`).toHaveCount(0);
17611 expect(`.o_list_renderer th[data-name='properties.property_boolean']`).toHaveCount(0);
17612 });
17613
17614 test(`properties: optional show/hide (no config in local storage)`, async () => {
17615 const definition = {
17616 type: "char",
17617 name: "property_char",
17618 string: "Property char",
17619 };
17620 Bar._records[0].definitions = [definition];
17621 for (const record of Foo._records) {
17622 if (record.m2o === 1) {
17623 record.properties = { [definition.name]: "0" };
17624 }
17625 }
17626
17627 await mountView({
17628 resModel: "foo",
17629 type: "list",
17630 arch: `
17631 <list editable="bottom">
17632 <field name="m2o"/>
17633 <field name="properties"/>
17634 </list>
17635 `,
17636 });
17637 expect(`.o_list_table thead th:not(.o_list_record_selector)`).toHaveCount(2);
17638 expect(`.o_list_table thead th[data-name=m2o]`).toHaveCount(1);
17639 expect(`.o_list_table thead th.o_list_actions_header`).toHaveCount(1);
17640 });
17641
17642 test(`properties: optional show/hide (config from local storage)`, async () => {
17643 const definition = {
17644 type: "char",
17645 name: "property_char",
17646 string: "Property char",
17647 };
17648 Bar._records[0].definitions = [definition];
17649 for (const record of Foo._records) {
17650 if (record.m2o === 1) {
17651 record.properties = { [definition.name]: "0" };
17652 }
17653 }
17654
17655 localStorage.setItem("optional_fields,foo,list,1,m2o,properties", "properties.property_char");
17656
17657 await mountView({
17658 resModel: "foo",
17659 type: "list",
17660 arch: `
17661 <list editable="bottom">
17662 <field name="m2o"/>
17663 <field name="properties"/>
17664 </list>
17665 `,
17666 viewId: 1,
17667 });
17668 expect(`.o_list_table thead th:not(.o_list_record_selector)`).toHaveCount(3);
17669 expect(`.o_list_table thead th[data-name=m2o]`).toHaveCount(1);
17670 expect(`.o_list_table thead th[data-name='properties.property_char']`).toHaveCount(1);
17671 expect(`.o_list_table thead th.o_list_actions_header`).toHaveCount(1);
17672 });
17673
17674 test(`properties: optional show/hide (at reload, config from local storage)`, async () => {
17675 const definition = {
17676 type: "char",
17677 name: "property_char",
17678 string: "Property char",
17679 };
17680 Bar._records[0].definitions = [definition];
17681 for (const record of Foo._records) {
17682 if (record.m2o === 1) {
17683 record.properties = { [definition.name]: "0" };
17684 }
17685 }
17686
17687 localStorage.setItem("optional_fields,foo,list,1,m2o,properties", "properties.property_char");
17688
17689 await mountView({
17690 resModel: "foo",
17691 type: "list",
17692 arch: `
17693 <list editable="bottom">
17694 <field name="m2o"/>
17695 <field name="properties"/>
17696 </list>
17697 `,
17698 viewId: 1,
17699 groupBy: ["m2o"],
17700 });
17701
17702 // list is grouped, no record displayed
17703 expect(`.o_group_header`).toHaveCount(2);
17704 expect(`.o_data_row`).toHaveCount(0);
17705 expect(`.o_list_table thead th:not(.o_list_record_selector)`).toHaveCount(2);
17706 expect(`.o_list_table thead th[data-name=m2o]`).toHaveCount(1);
17707
17708 await contains(`.o_group_header`).click(); // open group Value 1
17709 expect(`.o_data_row`).toHaveCount(3);
17710 expect(`.o_list_table thead th:not(.o_list_record_selector)`).toHaveCount(3);
17711 expect(`.o_list_table thead th[data-name=m2o]`).toHaveCount(1);
17712 expect(`.o_list_table thead th[data-name='properties.property_char']`).toHaveCount(1);
17713 expect(`.o_list_table thead th.o_list_actions_header`).toHaveCount(1);
17714 });
17715
17716 test(`reload properties definitions when domain change`, async () => {
17717 const definition0 = {
17718 type: "char",
17719 name: "property_char",
17720 string: "Property char",
17721 };
17722 Bar._records[0].definitions = [definition0];
17723 for (const record of Foo._records) {
17724 if (record.m2o === 1) {
17725 record.properties = { [definition0.name]: "AA" };
17726 }
17727 }
17728
17729 stepAllNetworkCalls();
17730 await mountView({
17731 resModel: "foo",
17732 type: "list",
17733 arch: `
17734 <list editable="bottom">
17735 <field name="m2o"/>
17736 <field name="properties"/>
17737 </list>
17738 `,
17739 irFilters: [
17740 {
17741 context: "{}",
17742 domain: "[['id', '=', 1]]",
17743 id: 7,
17744 name: "only one",
17745 sort: "[]",
17746 user_ids: [2],
17747 },
17748 ],
17749 });
17750 expect.verifySteps([
17751 "/web/webclient/translations",
17752 "/web/webclient/load_menus",
17753 "get_views",
17754 "web_search_read",
17755 "has_group",
17756 ]);
17757
17758 await toggleSearchBarMenu();
17759 await toggleMenuItem("only one");
17760 expect.verifySteps(["web_search_read"]);
17761 });
17762
17763 test(`do not reload properties definitions when page change`, async () => {
17764 const definition0 = {
17765 type: "char",
17766 name: "property_char",
17767 string: "Property char",
17768 };
17769 Bar._records[0].definitions = [definition0];
17770 for (const record of Foo._records) {
17771 if (record.m2o === 1) {
17772 record.properties = { [definition0.name]: "0" };
17773 }
17774 }
17775
17776 stepAllNetworkCalls();
17777 await mountView({
17778 resModel: "foo",
17779 type: "list",
17780 arch: `
17781 <list editable="bottom" limit="2">
17782 <field name="m2o"/>
17783 <field name="properties"/>
17784 </list>
17785 `,
17786 });
17787 expect.verifySteps([
17788 "/web/webclient/translations",
17789 "/web/webclient/load_menus",
17790 "get_views",
17791 "web_search_read",
17792 "has_group",
17793 ]);
17794
17795 await pagerNext();
17796 expect.verifySteps(["web_search_read"]);
17797 });
17798
17799 test(`load properties definitions only once when grouped`, async () => {
17800 const definition0 = {
17801 type: "char",
17802 name: "property_char",
17803 string: "Property char",
17804 };
17805 Bar._records[0].definitions = [definition0];
17806 for (const record of Foo._records) {
17807 if (record.m2o === 1) {
17808 record.properties = { [definition0.name]: "0" };
17809 }
17810 }
17811
17812 stepAllNetworkCalls();
17813 await mountView({
17814 resModel: "foo",
17815 type: "list",
17816 arch: `
17817 <list editable="bottom">
17818 <field name="m2o"/>
17819 <field name="properties"/>
17820 </list>
17821 `,
17822 groupBy: ["m2o"],
17823 });
17824 expect.verifySteps([
17825 "/web/webclient/translations",
17826 "/web/webclient/load_menus",
17827 "get_views",
17828 "web_read_group",
17829 "has_group",
17830 ]);
17831
17832 await contains(`.o_group_header`).click();
17833 expect.verifySteps(["web_search_read"]);
17834 });
17835
17836 test(`Invisible Properties`, async () => {
17837 const definition = {
17838 type: "integer",
17839 name: "property_integer",
17840 string: "Property integer",
17841 };
17842 Bar._records[0].definitions = [definition];
17843 for (const record of Foo._records) {
17844 if (record.m2o === 1) {
17845 record.properties = { [definition.name]: 123 };
17846 }
17847 }
17848
17849 stepAllNetworkCalls();
17850 await mountView({
17851 resModel: "foo",
17852 type: "list",
17853 arch: `
17854 <list editable="bottom">
17855 <field name="m2o"/>
17856 <field name="properties" column_invisible="1"/>
17857 </list>
17858 `,
17859 });
17860 expect(`.o_optional_columns_dropdown_toggle`).toHaveCount(0);
17861 expect.verifySteps([
17862 "/web/webclient/translations",
17863 "/web/webclient/load_menus",
17864 "get_views",
17865 "web_search_read",
17866 "has_group",
17867 ]);
17868 });
17869
17870 test(`header buttons in list view`, async () => {
17871 onRpc("/web/dataset/call_button/*", async (request) => {
17872 const { params } = await request.json();
17873 expect.step(params.method);
17874 return true;
17875 });
17876 await mountView({
17877 resModel: "foo",
17878 type: "list",
17879 arch: `
17880 <list>
17881 <header>
17882 <button name="a" type="object" string="Confirm" confirm="Are you sure?"/>
17883 </header>
17884 <field name="foo"/>
17885 <field name="bar"/>
17886 </list>
17887 `,
17888 });
17889 await clickRecordSelector();
17890 await clickControlPanelAction("a");
17891 expect(`.modal`).toHaveCount(1);
17892 expect(`.modal-body`).toHaveText("Are you sure?");
17893
17894 await contains(`.modal footer button.btn-primary`).click();
17895 expect.verifySteps(["a"]);
17896 });
17897
17898 test(`restore order from state when using default order`, async () => {
17899 defineActions([
17900 {
17901 id: 1,
17902 name: "Foo",
17903 res_model: "foo",
17904 views: [
17905 [false, "list"],
17906 [false, "form"],
17907 ],
17908 },
17909 ]);
17910
17911 Foo._views = {
17912 list: `
17913 <list default_order="foo">
17914 <field name="foo"/>
17915 <field name="amount"/>
17916 </list>
17917 `,
17918 form: `
17919 <form>
17920 <field name="amount"/>
17921 <field name="foo"/>
17922 </form>
17923 `,
17924 };
17925
17926 onRpc("web_search_read", ({ kwargs }) => expect.step(`order:${kwargs.order}`));
17927 await mountWithCleanup(WebClient);
17928 await getService("action").doAction(1);
17929 await contains(`th[data-name=amount]`).click(); // order by amount
17930 await contains(`.o_data_row .o_data_cell`).click(); // switch to the form view
17931 await contains(`.breadcrumb-item, .o_back_button`).click(); // go back to the list view
17932 expect.verifySteps([
17933 "order:foo ASC", // initial list view
17934 "order:amount ASC, foo ASC", // order by amount
17935 "order:amount ASC, foo ASC", // go back to the list view, it should still be ordered by amount
17936 ]);
17937 });
17938
17939 test(`x2many onchange, check result`, async () => {
17940 const deferred = new Deferred();
17941 Foo._onChanges = {
17942 m2m() {},
17943 };
17944 Bar._views = {
17945 list: `<list><field name="name"/></list>`,
17946 kanban: `<kanban><templates><t t-name="card"><field name="name"/></t></templates></kanban>`,
17947 };
17948 onRpc("onchange", async () => {
17949 expect.step("onchange");
17950 await deferred;
17951 return { value: { m2o: [3, "Value 3"] } };
17952 });
17953 await mountView({
17954 resModel: "foo",
17955 type: "list",
17956 arch: `
17957 <list editable="bottom">
17958 <field name="m2m" widget="many2many_tags"/>
17959 <field name="m2o"/>
17960 </list>
17961 `,
17962 });
17963 expect(`.o_data_cell.o_many2many_tags_cell:eq(0)`).toHaveText("Value 1\nValue 2");
17964 expect(`.o_data_cell.o_list_many2one:eq(0)`).toHaveText("Value 1");
17965
17966 await selectMany2xItem("m2m", "Value 3");
17967 expect.verifySteps(["onchange"]);
17968
17969 await contains(`.o_list_button_save`).click();
17970 deferred.resolve();
17971 await animationFrame();
17972 expect(`.o_data_cell.o_many2many_tags_cell:eq(0)`).toHaveText("Value 1\nValue 2\nValue 3");
17973 expect(`.o_data_cell.o_list_many2one:eq(0)`).toHaveText("Value 3", {
17974 message: "onchange result should be applied",
17975 });
17976 });
17977
17978 test.tags("desktop");
17979 test(`list view: prevent record selection when editable list in edit mode`, async () => {
17980 await mountView({
17981 resModel: "foo",
17982 type: "list",
17983 arch: `<list editable="top"><field name="foo"/></list>`,
17984 });
17985
17986 // When we try to select new record in edit mode
17987 await contains(`.o_control_panel_main_buttons .o_list_button_add`).click();
17988 await contains(`.o_data_row .o_list_record_selector`).click();
17989 expect(`.o_data_row .o_list_record_selector input[type="checkbox"]`).not.toBeChecked();
17990
17991 // When we try to select all records in edit mode
17992 await contains(`th.o_list_record_selector.o_list_controller`).click();
17993 expect(`.o_list_controller input[type="checkbox"]`).not.toBeChecked();
17994 });
17995
17996 test.tags("desktop");
17997 test(`context keys not passed down the stack and not to fields`, async () => {
17998 defineActions([
17999 {
18000 id: 1,
18001 name: "Foo",
18002 res_model: "foo",
18003 views: [[false, "list"]],
18004 context: {
18005 list_view_ref: "foo_view_ref",
18006 search_default_bar: true,
18007 },
18008 },
18009 ]);
18010
18011 Foo._views = {
18012 "list,foo_view_ref": `
18013 <list default_order="foo" editable="top">
18014 <field name="m2m" widget="many2many_tags"/>
18015 </list>
18016 `,
18017 };
18018 Bar._views = {
18019 list: `<list><field name="name"/></list>`,
18020 };
18021
18022 Bar._records = [];
18023 for (let i = 1; i < 50; i++) {
18024 Bar._records.push({ id: i, name: `Value ${i}` });
18025 }
18026
18027 onRpc(["foo", "bar"], "*", ({ model, method, kwargs }) => {
18028 expect.step({ model, method, context: kwargs.context });
18029 });
18030
18031 await mountWithCleanup(WebClient);
18032 await getService("action").doAction(1);
18033 expect.verifySteps([
18034 {
18035 model: "foo",
18036 method: "get_views",
18037 context: {
18038 lang: "en",
18039 tz: "taht",
18040 uid: 7,
18041 allowed_company_ids: [1],
18042 list_view_ref: "foo_view_ref",
18043 },
18044 },
18045 {
18046 model: "foo",
18047 method: "web_search_read",
18048 context: {
18049 lang: "en",
18050 tz: "taht",
18051 uid: 7,
18052 allowed_company_ids: [1],
18053 bin_size: true,
18054 list_view_ref: "foo_view_ref",
18055 },
18056 },
18057 ]);
18058
18059 await contains(`.o_data_row .o_data_cell:eq(1)`).click();
18060 await contains(`.o_selected_row .o_field_many2many_tags input`).click();
18061 await runAllTimers();
18062 expect.verifySteps([
18063 {
18064 model: "bar",
18065 method: "web_name_search",
18066 context: { lang: "en", tz: "taht", uid: 7, allowed_company_ids: [1] },
18067 },
18068 ]);
18069
18070 await contains(
18071 `.o_selected_row .o_field_many2many_tags .dropdown-item:contains(Search more...)`
18072 ).click();
18073 expect.verifySteps([
18074 {
18075 model: "bar",
18076 method: "get_views",
18077 context: { lang: "en", tz: "taht", uid: 7, allowed_company_ids: [1] },
18078 },
18079 {
18080 model: "bar",
18081 method: "web_search_read",
18082 context: {
18083 lang: "en",
18084 tz: "taht",
18085 uid: 7,
18086 allowed_company_ids: [1],
18087 bin_size: true,
18088 },
18089 },
18090 ]);
18091 expect(`.modal`).toHaveCount(1);
18092 expect(`.modal .modal-header .modal-title`).toHaveText("Search: M2m");
18093 });
18094
18095 test.tags("desktop");
18096 test(`search nested many2one field with early option selection`, async () => {
18097 class Parent extends models.Model {
18098 foo = fields.One2many({ relation: "foo" });
18099 }
18100 defineModels([Parent]);
18101
18102 const deferred = new Deferred();
18103 onRpc("web_name_search", () => deferred);
18104
18105 await mountView({
18106 resModel: "parent",
18107 type: "form",
18108 arch: `
18109 <form>
18110 <field name="foo">
18111 <list editable="bottom">
18112 <field name="m2o"/>
18113 </list>
18114 </field>
18115 </form>
18116 `,
18117 });
18118 await contains(`.o_field_x2many_list_row_add a`).click();
18119
18120 await edit("alu", { confirm: false });
18121 await runAllTimers();
18122
18123 await edit("alue", { confirm: false });
18124 await press("enter");
18125 await runAllTimers();
18126
18127 deferred.resolve();
18128 await animationFrame();
18129 expect(`.o_field_widget input`).toBeFocused();
18130 expect(`.o_field_widget input`).toHaveValue("Value 1");
18131 });
18132
18133 test(`monetary field display for rtl languages`, async () => {
18134 defineParams({ lang_parameters: { direction: "rtl" } });
18135
18136 await mountView({
18137 resModel: "foo",
18138 type: "list",
18139 arch: `<list><field name="foo"/><field name="amount"/></list>`,
18140 });
18141 expect(`thead th:not(.o_list_record_selector):eq(1) .o_list_number_th`).toHaveCount(1, {
18142 message: "header cells of monetary fields should have o_list_number_th class",
18143 });
18144 expect(`thead th:not(.o_list_record_selector):eq(1)`).toHaveStyle(
18145 { "text-align": "right" },
18146 {
18147 message: "header cells of monetary fields should be right alined",
18148 }
18149 );
18150 expect(`tbody tr:eq(0) td:not(.o_list_record_selector):eq(1)`).toHaveStyle(
18151 { "text-align": "right" },
18152 {
18153 message: "Monetary cells should be right alined",
18154 }
18155 );
18156 expect(`tbody tr:eq(0) td:not(.o_list_record_selector):eq(1)`).toHaveStyle(
18157 { direction: "ltr" },
18158 {
18159 message: "Monetary cells should have ltr direction",
18160 }
18161 );
18162 });
18163
18164 test(`add record in editable list view with sample data`, async () => {
18165 Foo._records = [];
18166
18167 let deferred = null;
18168 onRpc("web_search_read", () => deferred);
18169
18170 await mountView({
18171 resModel: "foo",
18172 type: "list",
18173 arch: `<list sample="1" editable="top"><field name="int_field"/></list>`,
18174 noContentHelp: "click to add a record",
18175 });
18176 expect(`.o_view_sample_data`).toHaveCount(1);
18177 expect(`.o_view_nocontent`).toHaveCount(1);
18178 expect(`.o_data_row`).toHaveCount(10);
18179
18180 deferred = new Deferred();
18181 await contains(`.o_list_button_add`).click();
18182 expect(`.o_view_sample_data`).toHaveCount(1);
18183 expect(`.o_view_nocontent`).toHaveCount(1);
18184 expect(`.o_data_row`).toHaveCount(10);
18185
18186 deferred.resolve();
18187 await animationFrame();
18188 expect(`.o_view_sample_data`).toHaveCount(0);
18189 expect(`.o_view_nocontent`).toHaveCount(0);
18190 expect(`.o_data_row`).toHaveCount(1);
18191 expect(`.o_data_row.o_selected_row`).toHaveCount(1);
18192 });
18193
18194 test(`Adding new record in list view with open form view button`, async () => {
18195 await mountView({
18196 resModel: "foo",
18197 type: "list",
18198 arch: `<list editable="top" open_form_view="1"><field name="foo"/></list>`,
18199 selectRecord(resId, options) {
18200 expect.step(`switch to form - resId: ${resId} activeIds: ${options.activeIds}`);
18201 },
18202 });
18203
18204 await contains(`.o_list_button_add`).click();
18205 expect(`td.o_list_record_open_form_view`).toHaveCount(5, {
18206 message: "button to open form view should be present on each row",
18207 });
18208
18209 await contains(`.o_field_widget[name=foo] input`).edit("new", { confirm: false });
18210 await contains(`td.o_list_record_open_form_view`).click();
18211 expect.verifySteps(["switch to form - resId: 5 activeIds: 5,1,2,3,4"]);
18212 });
18213
18214 test(`onchange should only be called once after pressing enter on a field`, async () => {
18215 Foo._onChanges.foo = (record) => {
18216 if (record.foo) {
18217 record.int_field = 1;
18218 }
18219 };
18220
18221 onRpc("onchange", () => expect.step("onchange"));
18222 await mountView({
18223 resModel: "foo",
18224 type: "list",
18225 arch: `
18226 <list editable="top">
18227 <field name="foo"/>
18228 <field name="int_field"/>
18229 </list>
18230 `,
18231 });
18232 await contains(`.o_data_cell`).click();
18233 await contains(`.o_field_widget[name=foo] input`).edit("1", { confirm: "enter" });
18234 // There should only be one onchange call
18235 expect.verifySteps(["onchange"]);
18236 });
18237
18238 test.tags("desktop");
18239 test(`list: remove a record from sorted recordlist`, async () => {
18240 Foo._records = [{ id: 1, o2m: [1, 2, 3, 4, 5, 6] }];
18241 Bar._fields.name = fields.Char();
18242 Bar._fields.city = fields.Boolean({ default: false, sortable: false });
18243 Bar._records = [
18244 { id: 1, name: "a", city: true },
18245 { id: 2, name: "b" },
18246 { id: 3, name: "c" },
18247 { id: 4, name: "d" },
18248 { id: 5, name: "e" },
18249 { id: 6, name: "f", city: true },
18250 ];
18251
18252 await mountView({
18253 resModel: "foo",
18254 type: "form",
18255 arch: `
18256 <form>
18257 <sheet>
18258 <field name="o2m">
18259 <list limit="2">
18260 <field name="name" required="not city"/>
18261 <field name="city"/>
18262 </list>
18263 </field>
18264 </sheet>
18265 </form>
18266 `,
18267 resId: 1,
18268 });
18269 // 3 th (1 for delete button, 2 for columns)
18270 expect(`th`).toHaveCount(3, { message: "should have 2 columns and delete buttons" });
18271 expect(`tbody tr.o_data_row`).toHaveCount(2, { message: "should have 2 rows" });
18272 expect(`th.o_column_sortable`).toHaveCount(1, { message: "should have 1 sortable column" });
18273 expect(queryAllTexts`.o_data_cell[name="name"]`).toEqual(["a", "b"]);
18274
18275 // sort by name desc
18276 await contains(`th.o_column_sortable[data-name=name]`).click();
18277 await contains(`th.o_column_sortable[data-name=name]`).click();
18278 expect(queryAllTexts`.o_data_cell[name="name"]`).toEqual(["f", "e"]);
18279
18280 // remove second record
18281 await contains(`.o_list_record_remove:eq(1)`).click();
18282 expect(queryAllTexts`.o_data_cell[name="name"]`).toEqual(["f", "d"]);
18283 expect(`.o_list_view .o_pager_counter`).toHaveText("1-2 / 5");
18284 });
18285
18286 test("Pass context when duplicating data in list view", async () => {
18287 onRpc("copy", ({ kwargs }) => {
18288 expect(kwargs.context.ctx_key).toBe("ctx_val");
18289 expect.step("copy");
18290 });
18291 await mountView({
18292 type: "list",
18293 resModel: "res.partner",
18294 actionMenus: {},
18295 arch: `
18296 <list>
18297 <field name="name" />
18298 </list>`,
18299 context: { ctx_key: "ctx_val" },
18300 });
18301 await clickRecordSelector();
18302 await toggleActionMenu();
18303 await toggleMenuItem("Duplicate");
18304 expect.verifySteps(["copy"]);
18305 });
18306
18307 test(`properties do not disappear after domain change`, async () => {
18308 const definition0 = {
18309 type: "char",
18310 name: "property_char",
18311 string: "Property char",
18312 };
18313 Bar._records[0].definitions = [definition0];
18314 for (const record of Foo._records) {
18315 if (record.m2o === 1) {
18316 record.properties = { [definition0.name]: "AA" };
18317 }
18318 }
18319
18320 await mountView({
18321 resModel: "foo",
18322 type: "list",
18323 arch: `
18324 <list editable="bottom">
18325 <field name="m2o"/>
18326 <field name="properties"/>
18327 </list>
18328 `,
18329 searchViewArch: `
18330 <search>
18331 <filter name="properties_filter" string="My filter" domain="[['properties.property_char', '=', 'AA']]"/>
18332 <group>
18333 <!-- important -->
18334 <filter name="properties_groupby" string="My groupby" context="{'group_by':'properties'}"/>
18335 </group>
18336 </search>
18337 `,
18338 });
18339
18340 await contains(`.o_optional_columns_dropdown_toggle`).click();
18341 await contains(`.o-dropdown-item input[type="checkbox"]`).click();
18342 expect(`.o_list_renderer th[data-name="properties.property_char"]`).toHaveCount(1);
18343
18344 await toggleSearchBarMenu();
18345 await toggleMenuItem("My filter");
18346 expect(`.o_list_renderer th[data-name="properties.property_char"]`).toHaveCount(1);
18347
18348 await toggleMenuItem("My filter");
18349 expect(`.o_list_renderer th[data-name="properties.property_char"]`).toHaveCount(1);
18350 });
18351
18352 test.tags("desktop");
18353 test("two pages, go page 2, record deleted meanwhile", async () => {
18354 await mountView({
18355 resModel: "foo",
18356 type: "list",
18357 arch: `<list limit="3">
18358 <field name="foo"/>
18359 <field name="int_field"/>
18360 </list>
18361 `,
18362 });
18363
18364 expect(".o_data_row").toHaveCount(3);
18365 expect(getPagerValue()).toEqual([1, 3]);
18366 expect(getPagerLimit()).toBe(4);
18367
18368 MockServer.env["foo"].unlink(4);
18369 await pagerNext();
18370 expect(".o_data_row").toHaveCount(3);
18371 expect(getPagerValue()).toEqual([1, 3]);
18372 expect(getPagerLimit()).toBe(3);
18373 });
18374
18375 test.tags("desktop");
18376 test("two pages, go page 2, record deleted meanwhile (grouped case)", async () => {
18377 for (let i = 0; i < 4; i++) {
18378 Foo._records[i].bar = true;
18379 }
18380 await mountView({
18381 resModel: "foo",
18382 type: "list",
18383 groupBy: ["bar"],
18384 arch: `<list limit="3">
18385 <field name="foo"/>
18386 <field name="int_field"/>
18387 </list>
18388 `,
18389 });
18390
18391 expect(".o_group_header").toHaveCount(1);
18392 expect(".o_data_row").toHaveCount(0);
18393
18394 await contains(".o_group_header").click();
18395 expect(".o_data_row").toHaveCount(3);
18396 expect(getPagerValue(queryFirst(".o_group_header"))).toEqual([1, 3]);
18397 expect(getPagerLimit(queryFirst(".o_group_header"))).toBe(4);
18398
18399 MockServer.env["foo"].unlink(4);
18400 await pagerNext(queryFirst(".o_group_header"));
18401 expect(".o_data_row").toHaveCount(3);
18402 expect(".o_group_header .o_pager").toHaveCount(0);
18403 });
18404
18405 test.tags("desktop");
18406 test("select records range with shift click on several page", async () => {
18407 await mountView({
18408 resModel: "foo",
18409 type: "list",
18410 arch: `
18411 <list limit="3">
18412 <field name="foo"/>
18413 <field name="int_field"/>
18414 </list>`,
18415 });
18416
18417 await contains(`.o_data_row .o_list_record_selector input:eq(0)`).click();
18418 expect(`.o_data_row:eq(0) .o_list_record_selector input`).toBeChecked();
18419
18420 expect(`.o_selection_box .o_select_domain`).toHaveCount(0);
18421 expect(`.o_selection_box`).toHaveText("1\nselected");
18422 expect(`.o_data_row .o_list_record_selector input:checked`).toHaveCount(1);
18423 // click the pager next button
18424 await contains(".o_pager_next").click();
18425 // shift click the first record of the second page
18426 await contains(`.o_data_row .o_list_record_selector input`).click({ shiftKey: true });
18427 expect(`.o_selection_box`).toHaveText("1\nselected\n Select all 4");
18428 });
18429
18430 test("open record, with invalid record in list", async () => {
18431 // in this scenario, the record is already invalid in db, so we should be allowed to
18432 // leave it
18433 Foo._records[0].foo = false;
18434 Foo._views = {
18435 form: `<form><field name="foo"/><field name="int_field"/></form>`,
18436 list: `<list><field name="foo" required="1"/><field name="int_field"/></list>`,
18437 };
18438
18439 mockService("notification", {
18440 add() {
18441 throw new Error("should not display a notification");
18442 },
18443 });
18444
18445 await mountWithCleanup(WebClient);
18446 await getService("action").doAction({
18447 res_model: "foo",
18448 type: "ir.actions.act_window",
18449 views: [
18450 [false, "list"],
18451 [false, "form"],
18452 ],
18453 });
18454
18455 await contains(".o_data_cell").click();
18456
18457 expect(".o_form_view").toHaveCount(1);
18458 });
18459
18460 test("Open record in new tab on ctrl+click and middleclick", async () => {
18461 await mountView({
18462 type: "list",
18463 resModel: "res.partner",
18464 actionMenus: {},
18465 arch: `
18466 <list>
18467 <field name="name" />
18468 </list>`,
18469 selectRecord(resId, options) {
18470 expect.step(`open record - newWindow: ${options.newWindow}`);
18471 },
18472 });
18473 await contains(".o_data_cell").click({ ctrlKey: true });
18474 expect.verifySteps(["open record - newWindow: true"]);
18475 await middleClick(".o_data_cell");
18476 await animationFrame();
18477 expect.verifySteps(["open record - newWindow: true"]);
18478 });
18479
18480 test("Open record in new tab on ctrl+click and middleclick for an editable list", async () => {
18481 await mountView({
18482 type: "list",
18483 resModel: "res.partner",
18484 actionMenus: {},
18485 arch: `
18486 <list editable="bottom" open_form_view="true">
18487 <field name="name" />
18488 </list>`,
18489 selectRecord(resId, options) {
18490 expect.step(`open record - newWindow: ${options.newWindow}`);
18491 },
18492 });
18493 await contains(".o_list_record_open_form_view").click({ ctrlKey: true });
18494 expect.verifySteps(["open record - newWindow: true"]);
18495 await middleClick(".o_list_record_open_form_view");
18496 await animationFrame();
18497 expect.verifySteps(["open record - newWindow: true"]);
18498 });
18499
18500 test.tags("mobile");
18501 test("selection is properly displayed (single page) on mobile", async () => {
18502 await mountView({
18503 type: "list",
18504 resModel: "foo",
18505 arch: `
18506 <list>
18507 <field name="foo"/>
18508 <field name="bar"/>
18509 </list>
18510 `,
18511 loadActionMenus: true,
18512 });
18513
18514 expect(".o_data_row").toHaveCount(4);
18515 expect(".o_selection_box").toHaveCount(0);
18516 expect(".o_control_panel .fa-search").toHaveCount(1);
18517
18518 // select a record
18519 await contains(".o_data_row:nth-child(1)").drag();
18520 expect(".o_selection_box").toHaveCount(1);
18521 expect(".o_selection_box .o_select_domain").toHaveCount(1);
18522 expect(".o_control_panel .o_cp_searchview").toHaveCount(0);
18523 expect(queryFirst(".o_selection_box")).toHaveText("1\nselected\nAll");
18524
18525 // unselect a record
18526 await contains(".o_data_row:nth-child(1)").drag();
18527 expect(".o_selection_box .o_select_domain").toHaveCount(0);
18528
18529 // select 2 records
18530 await contains(".o_data_row:nth-child(1)").drag();
18531 await contains(".o_data_row:nth-child(2)").drag();
18532 expect(queryFirst(".o_selection_box")).toHaveText("2\nselected\nAll");
18533
18534 expect("div.o_control_panel .o_cp_action_menus").toHaveCount(1);
18535
18536 await toggleActionMenu();
18537 expect(getMenuItemTexts()).toEqual(["Export", "Duplicate", "Delete"]);
18538
18539 // unselect all
18540 await unselectAllRecords();
18541 expect(".o_selection_box").toHaveCount(0);
18542 expect(".o_control_panel .fa-search").toHaveCount(1);
18543 });
18544
18545 test.tags("mobile");
18546 test("export button is properly hidden", async () => {
18547 await mountView({
18548 type: "list",
18549 resModel: "foo",
18550 arch: `
18551 <list>
18552 <field name="foo"/>
18553 <field name="bar"/>
18554 </list>
18555 `,
18556 });
18557
18558 expect(".o_data_row").toHaveCount(4);
18559 expect(".o_list_export_xlsx").not.toHaveCount();
18560 });
18561
18562 test.tags("mobile");
18563 test("editable readonly list view is disabled", async () => {
18564 await mountView({
18565 type: "list",
18566 resModel: "foo",
18567 arch: `
18568 <list>
18569 <field name="foo" />
18570 </list>
18571 `,
18572 });
18573
18574 await contains(".o_data_row:nth-child(1)").click();
18575 await contains(".o_data_row:nth-child(1) .o_data_cell:nth-child(1)").click();
18576 expect(".o_selected_row .o_field_widget[name=foo]").toHaveCount(0, {
18577 message: "The listview should not contains an edit field",
18578 });
18579 });
18580
18581 test.tags("mobile");
18582 test("add custom field button not shown in mobile (with opt. col.)", async () => {
18583 await mountView({
18584 type: "list",
18585 resModel: "foo",
18586 arch: `
18587 <list>
18588 <field name="foo" />
18589 <field name="bar" optional="hide" />
18590 </list>
18591 `,
18592 });
18593 expect("table .o_optional_columns_dropdown_toggle").toHaveCount(1);
18594 await contains("table .o_optional_columns_dropdown_toggle").click();
18595 expect(".dropdown-item").toHaveCount(1);
18596 });
18597
18598 test.tags("mobile");
18599 test("add custom field button not shown to non-system users (wo opt. col.)", async () => {
18600 patchWithCleanup(user, { isSystem: false });
18601 await mountView({
18602 type: "list",
18603 resModel: "foo",
18604 arch: `
18605 <list>
18606 <field name="foo" />
18607 <field name="bar" />
18608 </list>
18609 `,
18610 });
18611
18612 expect("table .o_optional_columns_dropdown_toggle").toHaveCount(0);
18613 });
18614
18615 test(`display 'None' for false group, when grouped by char field`, async () => {
18616 Foo._records[0].foo = false;
18617
18618 await mountView({
18619 resModel: "foo",
18620 type: "list",
18621 arch: `<list><field name="foo"/></list>`,
18622 groupBy: ["foo"],
18623 });
18624
18625 expect(`tbody tr:nth-child(3)`).toHaveText("None (1)");
18626 });
18627
18628 test(`display '0' for false group, when grouped by int field`, async () => {
18629 Foo._records[0].int_field = 0;
18630
18631 await mountView({
18632 resModel: "foo",
18633 type: "list",
18634 arch: `<list><field name="foo"/></list>`,
18635 groupBy: ["int_field"],
18636 });
18637
18638 expect(`tbody tr:nth-child(2)`).toHaveText("0 (1)");
18639 });
18640
18641 test(`display the field's falsy_value_label for false group, if defined`, async () => {
18642 Foo._fields.foo.falsy_value_label = "I'm the false group";
18643 Foo._records[0].foo = false;
18644
18645 await mountView({
18646 resModel: "foo",
18647 type: "list",
18648 arch: `<list><field name="foo"/></list>`,
18649 groupBy: ["foo"],
18650 });
18651
18652 expect(`tbody tr:nth-child(3)`).toHaveText("I'm the false group (1)");
18653 });
18654
18655 test(`hide pager in the list view with sample data`, async () => {
18656 Foo._records = [];
18657
18658 await mountView({
18659 resModel: "foo",
18660 type: "list",
18661 arch: `
18662 <list sample="1">
18663 <field name="foo"/>
18664 <field name="bar"/>
18665 <field name="int_field"/>
18666 </list>
18667 `,
18668 noContentHelp: "click to add a partner",
18669 });
18670
18671 expect(".o_content").toHaveClass("o_view_sample_data");
18672 expect(".o_cp_pager").not.toHaveCount();
18673 });
18674
18675 test.tags("desktop");
18676 test("list views make their control panel available directly", async () => {
18677 const def = new Deferred();
18678 onRpc("web_search_read", () => def);
18679 await mountView({
18680 arch: `<list><field name="foo"/></list>`,
18681 resModel: "foo",
18682 type: "list",
18683 });
18684
18685 expect(".o_list_view").toHaveCount(1);
18686 expect(".o_list_view .o_control_panel .o_searchview").toHaveCount(1);
18687 expect(".o_list_view .o_list_renderer").toHaveCount(0);
18688
18689 def.resolve();
18690 await animationFrame();
18691 expect(".o_list_view .o_list_renderer").toHaveCount(1);
18692 expect(".o_list_view .o_data_row").toHaveCount(4);
18693 });
18694
18695 test.tags("desktop");
18696 test("interact with search view while list is loading", async () => {
18697 onRpc("web_search_read", () => new Deferred());
18698 await mountView({
18699 arch: `<list><field name="foo"/></list>`,
18700 searchViewArch: `
18701 <search>
18702 <filter name="group_by_foo" domain="[]" string="GroupBy Foo" context="{ 'group_by': 'foo' }"/>
18703 </search>`,
18704 resModel: "foo",
18705 type: "list",
18706 });
18707
18708 expect(".o_list_view").toHaveCount(1);
18709 expect(".o_list_view .o_control_panel .o_searchview").toHaveCount(1);
18710 expect(".o_list_view .o_list_renderer").toHaveCount(0);
18711
18712 await toggleSearchBarMenu();
18713 await toggleMenuItem("GroupBy Foo");
18714 expect(".o_list_view .o_list_renderer").toHaveCount(1);
18715 expect(".o_list_view .o_group_header").toHaveCount(3);
18716 });
18717
18718 test("click on New while list is loading", async () => {
18719 onRpc("web_search_read", () => new Deferred());
18720 await mountView({
18721 arch: `<list><field name="foo"/></list>`,
18722 resModel: "foo",
18723 type: "list",
18724 createRecord: () => expect.step("create record"),
18725 });
18726
18727 expect(".o_list_view").toHaveCount(1);
18728 expect(".o_list_view .o_control_panel").toHaveCount(1);
18729 expect(".o_list_view .o_list_renderer").toHaveCount(0);
18730
18731 await contains(".o_list_button_add").click();
18732 expect.verifySteps(["create record"]);
18733 });
18734
18735 test("click on New while list is loading (editable)", async () => {
18736 const def = new Deferred();
18737 onRpc("web_search_read", () => def);
18738 await mountView({
18739 arch: `<list editable="top"><field name="foo"/></list>`,
18740 resModel: "foo",
18741 type: "list",
18742 createRecord: () => expect.step("create record"),
18743 });
18744
18745 expect(".o_list_view").toHaveCount(1);
18746 expect(".o_list_view .o_control_panel").toHaveCount(1);
18747 expect(".o_list_view .o_list_renderer").toHaveCount(0);
18748
18749 await contains(".o_list_button_add").click();
18750 expect(".o_list_view").toHaveCount(1);
18751 expect(".o_list_view .o_list_renderer").toHaveCount(0);
18752 expect.verifySteps([]);
18753
18754 def.resolve();
18755 await animationFrame();
18756 expect(".o_list_view .o_list_renderer").toHaveCount(1);
18757 expect(".o_list_view .o_data_row").toHaveCount(5);
18758 expect(".o_list_view .o_data_row:eq(0)").toHaveClass("o_selected_row");
18759 });
18760
18761 test.tags("desktop");
18762 test(`cell-level keyboard navigation in grouped list`, async () => {
18763 await mountView({
18764 resModel: "foo",
18765 type: "list",
18766 arch: `
18767 <list>
18768 <field name="foo"/>
18769 <field name="int_field"/>
18770 <field name="bar"/>
18771 </list>
18772 `,
18773 groupBy: ["bar"],
18774 });
18775
18776 expect(`.o_data_row`).toHaveCount(0);
18777 expect(`.o_group_header`).toHaveCount(2);
18778
18779 // Expand the first and second group
18780 await contains(`.o_group_header:eq(0)`).click();
18781 await contains(`.o_group_header:eq(1)`).click();
18782 expect(`.o_data_row`).toHaveCount(4);
18783 await contains(`table thead tr th:nth-child(2)`).click();
18784
18785 //Navigate downward from the last cell of the first group
18786 await press("ArrowDown");
18787 await animationFrame();
18788
18789 await press("ArrowDown");
18790 await animationFrame();
18791
18792 // Move right to focus on the next cell in the same row
18793 await press("ArrowRight");
18794 await animationFrame();
18795
18796 await press("ArrowDown");
18797 await animationFrame();
18798
18799 await press("ArrowDown");
18800 await animationFrame();
18801
18802 //Ensure focus has moved to the same column in the second group
18803 await animationFrame();
18804 expect(`tbody tr:nth-child(4) td:nth-child(3)`).toBeFocused();
18805
18806 //Move back up within the second group
18807 await press("ArrowUp");
18808 await animationFrame();
18809
18810 //Verify that focus returns to the same column in the first group
18811 await press("ArrowUp");
18812 await animationFrame();
18813 expect(`tbody tr:nth-child(2) td:nth-child(3)`).toBeFocused();
18814 });
18815
18816 test.tags("desktop");
18817 test(`cell-level keyboard navigation in multiple grouped list`, async () => {
18818 await mountView({
18819 resModel: "foo",
18820 type: "list",
18821 arch: `
18822 <list>
18823 <field name="foo"/>
18824 <field name="int_field"/>
18825 <field name="bar"/>
18826 </list>
18827 `,
18828 groupBy: ["bar", "foo"],
18829 noContentHelp: "<p>should not be displayed</p>",
18830 });
18831
18832 expect(`.o_data_row`).toHaveCount(0);
18833 expect(`.o_group_header`).toHaveCount(2);
18834
18835 // Expand the first and second group
18836 await contains(`.o_group_header:eq(0)`).click();
18837 await contains(`.o_group_header:eq(1)`).click();
18838
18839 await contains(`table thead tr th:nth-child(2)`).click();
18840 //Navigate downward from the last cell of the sub group of first group
18841 await press("ArrowDown");
18842 await animationFrame();
18843
18844 await press("ArrowDown");
18845 await animationFrame();
18846
18847 await press("ArrowDown");
18848 await animationFrame();
18849
18850 // Move right to focus on the next cell in the same row
18851 await press("ArrowRight");
18852 await animationFrame();
18853
18854 await press("ArrowDown");
18855 await animationFrame();
18856
18857 await press("Enter");
18858 await animationFrame();
18859
18860 await press("ArrowDown");
18861 await animationFrame();
18862
18863 await press("Enter");
18864 await animationFrame();
18865
18866 await press("ArrowDown");
18867 await animationFrame();
18868
18869 await animationFrame();
18870 expect(`tbody tr:nth-child(6) td:nth-child(3)`).toBeFocused();
18871
18872 await press("ArrowUp");
18873 await animationFrame();
18874
18875 await press("ArrowUp");
18876 await animationFrame();
18877
18878 await press("ArrowUp");
18879 await animationFrame();
18880
18881 await animationFrame();
18882 expect(`tbody tr:nth-child(3) td:nth-child(3)`).toBeFocused();
18883 });
18884
18885 test(`list with custom cog action that has a confirmation target="new" action`, async () => {
18886 const contextualAction = {
18887 id: 80,
18888 name: "Sort of confirmation dialog",
18889 res_model: "foo",
18890 context: "{}",
18891 views: [[false, "form"]],
18892 type: "ir.actions.act_window",
18893 target: "new",
18894 };
18895 Foo._toolbar = {
18896 action: [contextualAction],
18897 print: [],
18898 };
18899 Foo._views = {
18900 list: `<list><field name="foo"/></list>`,
18901 search: `<search/>`,
18902 form: `
18903 <form>
18904 Are you sure blablabla
18905 <footer>
18906 <button name="my_action" type="action" string="Do it"/>
18907 </footer>
18908 </form>`,
18909 };
18910 defineActions([
18911 {
18912 id: 1,
18913 name: "Foo",
18914 res_model: "foo",
18915 views: [[false, "list"]],
18916 },
18917 {
18918 id: 2,
18919 name: "Foo",
18920 res_model: "foo",
18921 views: [[false, "form"]],
18922 res_id: 1,
18923 xml_id: "my_action",
18924 },
18925 contextualAction,
18926 ]);
18927
18928 stepAllNetworkCalls();
18929 await mountWithCleanup(WebClient);
18930 await getService("action").doAction(1);
18931 expect(".o_list_view").toHaveCount(1);
18932
18933 await selectAllRecords();
18934 await contains(`.o_cp_action_menus button:has(.fa-cog)`).click();
18935 await contains(`.o-dropdown-item:contains(Sort of confirmation dialog)`).click();
18936 expect(".o_dialog").toHaveCount(1);
18937
18938 await contains(".o_dialog footer button:contains(Do it)").click();
18939 expect(".o_dialog").toHaveCount(0);
18940 expect(".o_form_view").toHaveCount(1);
18941
18942 // should not reload the list view when confirming with Do it
18943 expect.verifySteps([
18944 "/web/webclient/translations",
18945 "/web/webclient/load_menus",
18946 "/web/action/load",
18947 "get_views",
18948 "web_search_read",
18949 "has_group",
18950 "/web/action/load",
18951 "get_views",
18952 "onchange",
18953 "web_save",
18954 "/web/action/load",
18955 "get_views",
18956 "web_read",
18957 ]);
18958 });
18959
18960 test(`cache web_search_read`, async () => {
18961 let searchReadDef;
18962 onRpc("web_search_read", () => searchReadDef);
18963
18964 Foo._views = {
18965 "list,false": `<list><field name="foo"/></list>`,
18966 "form,false": `<form><field name="foo"/></form>`,
18967 "search,false": `<search/>`,
18968 };
18969
18970 defineActions([
18971 {
18972 id: 1,
18973 name: "Partners Action",
18974 res_model: "foo",
18975 views: [
18976 [false, "list"],
18977 [false, "form"],
18978 ],
18979 search_view_id: [false, "search"],
18980 },
18981 ]);
18982
18983 await mountWithCleanup(WebClient);
18984 await getService("action").doAction(1);
18985
18986 expect(`tbody tr`).toHaveCount(4, { message: "should have 4 rows" });
18987 expect(queryAllTexts(`.o_list_char`)).toEqual(["yop", "blip", "gnap", "blip"]);
18988
18989 await contains(`.o_data_row .o_data_cell`).click(); // Open the first record
18990
18991 searchReadDef = new Deferred();
18992 await contains(`.breadcrumb-item a, .o_back_button`).click();
18993
18994 // Cached values !
18995 expect(`tbody tr`).toHaveCount(4, { message: "should have 4 rows" });
18996 expect(queryAllTexts(`.o_list_char`)).toEqual(["yop", "blip", "gnap", "blip"]);
18997
18998 // record 1 (yop) is removed
18999 // record 3 (gnap) is updated to gnap11
19000 // record 5 (plop) and record 6 (plop2) are added
19001 searchReadDef.resolve({
19002 length: 5,
19003 records: [
19004 {
19005 id: 2,
19006 foo: "blip",
19007 },
19008 {
19009 id: 3,
19010 foo: "gnap11",
19011 },
19012 {
19013 id: 4,
19014 foo: "blip",
19015 },
19016 {
19017 id: 5,
19018 foo: "plop",
19019 },
19020 {
19021 id: 6,
19022 foo: "plop2",
19023 },
19024 ],
19025 });
19026
19027 await animationFrame();
19028 // Updated values !
19029 expect(`tbody tr`).toHaveCount(5);
19030 expect(queryAllTexts(`.o_list_char`)).toEqual(["blip", "gnap11", "blip", "plop", "plop2"]);
19031 });
19032
19033 test(`cache web_search_read (onUpdate called after another load)`, async () => {
19034 const searchReadDefs = [null, new Deferred(), new Deferred()];
19035 let webSearchReadCount = 0;
19036 onRpc("web_search_read", () => searchReadDefs[webSearchReadCount++]);
19037
19038 Foo._views = {
19039 "list,false": `<list><field name="foo"/></list>`,
19040 "form,false": `<form><field name="foo"/></form>`,
19041 "search,false": `<search/>`,
19042 };
19043
19044 defineActions([
19045 {
19046 id: 1,
19047 name: "Partners Action",
19048 res_model: "foo",
19049 views: [
19050 [false, "list"],
19051 [false, "form"],
19052 ],
19053 search_view_id: [false, "search"],
19054 },
19055 ]);
19056
19057 await mountWithCleanup(WebClient);
19058 await getService("action").doAction(1);
19059 expect(`.o_data_row`).toHaveCount(4);
19060 expect(queryAllTexts(`.o_list_char`)).toEqual(["yop", "blip", "gnap", "blip"]);
19061
19062 // create a record and go back to the form => will display data from the cache
19063 await contains(`.o_list_button_add`).click();
19064 await contains(`.o_field_widget[name=foo] input`).edit("new record");
19065 await contains(`.breadcrumb-item a, .o_back_button`).click();
19066 // cached values
19067 expect(`.o_data_row`).toHaveCount(4);
19068 expect(queryAllTexts(`.o_list_char`)).toEqual(["yop", "blip", "gnap", "blip"]);
19069
19070 // sort data
19071 await contains(".o_column_sortable").click();
19072 // still cached values
19073 expect(`.o_data_row`).toHaveCount(4);
19074 expect(queryAllTexts(`.o_list_char`)).toEqual(["yop", "blip", "gnap", "blip"]);
19075
19076 // resolve third web_search_read (with the orderby)
19077 searchReadDefs[2].resolve();
19078 await animationFrame();
19079 expect(`.o_data_row`).toHaveCount(5);
19080 expect(queryAllTexts(`.o_list_char`)).toEqual(["blip", "blip", "gnap", "new record", "yop"]);
19081
19082 // resolve second web_search_read (without filter, when coming back to list) => must be ignored
19083 searchReadDefs[1].resolve();
19084 await animationFrame();
19085 expect(`.o_data_row`).toHaveCount(5);
19086 expect(queryAllTexts(`.o_list_char`)).toEqual(["blip", "blip", "gnap", "new record", "yop"]);
19087 });
19088
19089 test(`cache web_read_group (no change)`, async () => {
19090 let def;
19091 onRpc("web_read_group", () => def);
19092
19093 Foo._views = {
19094 "list,false": `<list default_group_by="bar"><field name="foo"/></list>`,
19095 "kanban,false": `
19096 <kanban>
19097 <templates>
19098 <t t-name="card">
19099 <field name="foo"/>
19100 </t>
19101 </templates>
19102 </kanban>`,
19103 "search,false": `<search/>`,
19104 };
19105
19106 defineActions([
19107 {
19108 id: 1,
19109 name: "Partners Action",
19110 res_model: "foo",
19111 views: [[false, "list"]],
19112 search_view_id: [false, "search"],
19113 },
19114 {
19115 id: 2,
19116 name: "Another action",
19117 res_model: "foo",
19118 views: [[false, "kanban"]],
19119 search_view_id: [false, "search"],
19120 },
19121 ]);
19122
19123 await mountWithCleanup(WebClient);
19124 await getService("action").doAction(1);
19125 expect(`.o_list_view`).toHaveCount(1);
19126 expect(`.o_group_header`).toHaveCount(2);
19127 expect(queryAllTexts(`.o_group_header`)).toEqual(["No (1)", "Yes (3)"]);
19128
19129 // execute another action to remove the list from the DOM
19130 await getService("action").doAction(2);
19131 expect(`.o_kanban_view`).toHaveCount(1);
19132
19133 // execute again action 1, but web_read_group is delayed
19134 def = new Deferred();
19135 await getService("action").doAction(1);
19136 expect(`.o_list_view`).toHaveCount(1);
19137 expect(`.o_group_header`).toHaveCount(2);
19138 expect(queryAllTexts(`.o_group_header`)).toEqual(["No (1)", "Yes (3)"]);
19139
19140 // simulate the return of web_read_group => nothing should have changed
19141 def.resolve();
19142 await animationFrame();
19143 expect(`.o_list_view`).toHaveCount(1);
19144 expect(`.o_group_header`).toHaveCount(2);
19145 expect(queryAllTexts(`.o_group_header`)).toEqual(["No (1)", "Yes (3)"]);
19146 });
19147
19148 test(`cache web_read_group (change)`, async () => {
19149 let def;
19150 onRpc("web_read_group", () => def);
19151
19152 Foo._views = {
19153 "list,false": `<list default_group_by="int_field"><field name="foo"/></list>`,
19154 "kanban,false": `
19155 <kanban>
19156 <templates>
19157 <t t-name="card">
19158 <field name="foo"/>
19159 </t>
19160 </templates>
19161 </kanban>`,
19162 "search,false": `<search/>`,
19163 };
19164
19165 defineActions([
19166 {
19167 id: 1,
19168 name: "Partners Action",
19169 res_model: "foo",
19170 views: [[false, "list"]],
19171 search_view_id: [false, "search"],
19172 },
19173 {
19174 id: 2,
19175 name: "Another action",
19176 res_model: "foo",
19177 views: [[false, "kanban"]],
19178 search_view_id: [false, "search"],
19179 },
19180 ]);
19181
19182 await mountWithCleanup(WebClient);
19183 await getService("action").doAction(1);
19184 expect(`.o_list_view`).toHaveCount(1);
19185 expect(`.o_group_header`).toHaveCount(4);
19186 expect(queryAllTexts(`.o_group_header`)).toEqual(["-4 (1)", "9 (1)", "10 (1)", "17 (1)"]);
19187
19188 // simulate the create of new records by someone else
19189 MockServer.env.foo.create([{ int_field: 44 }, { int_field: -4 }]);
19190
19191 // execute another action to remove the list from the DOM
19192 await getService("action").doAction(2);
19193 expect(`.o_kanban_view`).toHaveCount(1);
19194
19195 // execute again action 1, but web_read_group is delayed
19196 def = new Deferred();
19197 await getService("action").doAction(1);
19198 expect(`.o_list_view`).toHaveCount(1);
19199 expect(`.o_group_header`).toHaveCount(4);
19200 expect(queryAllTexts(`.o_group_header`)).toEqual(["-4 (1)", "9 (1)", "10 (1)", "17 (1)"]);
19201
19202 // simulate the return of web_read_group => the data should have been updated
19203 def.resolve();
19204 await animationFrame();
19205 expect(`.o_list_view`).toHaveCount(1);
19206 expect(`.o_group_header`).toHaveCount(5);
19207 expect(queryAllTexts(`.o_group_header`)).toEqual([
19208 "-4 (2)",
19209 "9 (1)",
19210 "10 (1)",
19211 "17 (1)",
19212 "44 (1)",
19213 ]);
19214 });
19215
19216 test(`cache web_read_group (with sample data, no change)`, async () => {
19217 let def;
19218 onRpc("web_read_group", () => def);
19219
19220 Foo._records = [];
19221 Foo._views = {
19222 "list,false": `<list sample="1" default_group_by="int_field"><field name="foo"/></list>`,
19223 "kanban,false": `
19224 <kanban>
19225 <templates>
19226 <t t-name="card">
19227 <field name="foo"/>
19228 </t>
19229 </templates>
19230 </kanban>`,
19231 "search,false": `<search/>`,
19232 };
19233
19234 defineActions([
19235 {
19236 id: 1,
19237 name: "Partners Action",
19238 res_model: "foo",
19239 views: [[false, "list"]],
19240 search_view_id: [false, "search"],
19241 },
19242 {
19243 id: 2,
19244 name: "Another action",
19245 res_model: "foo",
19246 views: [[false, "kanban"]],
19247 search_view_id: [false, "search"],
19248 },
19249 ]);
19250
19251 await mountWithCleanup(WebClient);
19252 await getService("action").doAction(1);
19253 expect(`.o_list_view .o_view_sample_data`).toHaveCount(1);
19254
19255 // execute another action to remove the list from the DOM
19256 await getService("action").doAction(2);
19257 expect(`.o_kanban_view`).toHaveCount(1);
19258
19259 // execute again action 1, but web_read_group is delayed
19260 def = new Deferred();
19261 await getService("action").doAction(1);
19262 expect(`.o_list_view .o_view_sample_data`).toHaveCount(1);
19263
19264 // simulate the return of web_read_group => the sample data should still be displayed
19265 def.resolve();
19266 await animationFrame();
19267 expect(`.o_list_view .o_view_sample_data`).toHaveCount(1);
19268 });
19269
19270 test(`cache web_read_group (with sample data, change)`, async () => {
19271 let def;
19272 onRpc("web_read_group", () => def);
19273
19274 Foo._records = [];
19275 Foo._views = {
19276 "list,false": `<list sample="1" default_group_by="int_field"><field name="foo"/></list>`,
19277 "kanban,false": `
19278 <kanban>
19279 <templates>
19280 <t t-name="card">
19281 <field name="foo"/>
19282 </t>
19283 </templates>
19284 </kanban>`,
19285 "search,false": `<search/>`,
19286 };
19287
19288 defineActions([
19289 {
19290 id: 1,
19291 name: "Partners Action",
19292 res_model: "foo",
19293 views: [[false, "list"]],
19294 search_view_id: [false, "search"],
19295 },
19296 {
19297 id: 2,
19298 name: "Another action",
19299 res_model: "foo",
19300 views: [[false, "kanban"]],
19301 search_view_id: [false, "search"],
19302 },
19303 ]);
19304
19305 await mountWithCleanup(WebClient);
19306 await getService("action").doAction(1);
19307 expect(`.o_list_view .o_view_sample_data`).toHaveCount(1);
19308
19309 // simulate the create of new records by someone else
19310 MockServer.env.foo.create([{ int_field: 44 }, { int_field: -4 }]);
19311
19312 // execute another action to remove the list from the DOM
19313 await getService("action").doAction(2);
19314 expect(`.o_kanban_view`).toHaveCount(1);
19315
19316 // execute again action 1, but web_read_group is delayed
19317 def = new Deferred();
19318 await getService("action").doAction(1);
19319 expect(`.o_list_view .o_view_sample_data`).toHaveCount(1);
19320
19321 // simulate the return of web_read_group => the data should have been updated
19322 def.resolve();
19323 await animationFrame();
19324 expect(`.o_list_view`).toHaveCount(1);
19325 expect(`.o_group_header`).toHaveCount(2);
19326 expect(queryAllTexts(`.o_group_header`)).toEqual(["-4 (1)", "44 (1)"]);
19327 });
19328
19329 test.tags("desktop");
19330 test(`multi_edit: edit field with operator with localization`, async () => {
19331 await mountView({
19332 resModel: "foo",
19333 type: "list",
19334 arch: `
19335 <list multi_edit="1">
19336 <field name="int_field"/>
19337 <field name="qux"/>
19338 <field name="amount"/>
19339 <field name="foo"/>
19340 </list>
19341 `,
19342 });
19343 await contains(`th .o-checkbox`).click();
19344 async function checkFieldValue(field, value, text) {
19345 await contains(`.o_data_cell[name=${field}]`).click();
19346 await edit(value, { confirm: "tab" });
19347 await waitFor(`.modal table [name=${field}]`);
19348 expect(`.modal table [name=${field}]`).toHaveText(text);
19349 expect(`.modal .alert`).toHaveCount(1);
19350 await contains(".modal footer button:contains(cancel)").click();
19351 }
19352 await checkFieldValue("int_field", "+=100", "Int field + 100");
19353 await checkFieldValue("int_field", "-=00100", "Int field - 100");
19354 await checkFieldValue("int_field", "/=100", "Int field / 100");
19355 await checkFieldValue("int_field", "*=100", "Int field * 100");
19356 patchWithCleanup(localization, { decimalPoint: ",", thousandsSep: "." });
19357 await checkFieldValue("qux", "*=1,5", "Qux * 1.5");
19358 await checkFieldValue("qux", "-=1,50000", "Qux - 1.5");
19359 await checkFieldValue("qux", "+=00001,50000", "Qux + 1.5");
19360 patchWithCleanup(localization, { decimalPoint: ".", thousandsSep: "@" });
19361 await checkFieldValue("amount", "/ = 1.4", "Amount / 1.4");
19362 await checkFieldValue("amount", "*=1.4", "Amount * 1.4");
19363 await checkFieldValue("amount", "- =1.4", "Amount - 1.4");
19364 await checkFieldValue("amount", "+= 1.4", "Amount + 1.4");
19365
19366 let field = "amount";
19367 await contains(`.o_data_cell[name=${field}]`).click();
19368 await edit("100", { confirm: "tab" });
19369 await waitFor(`.modal table [name=${field}]`);
19370 expect(`.modal table [name=${field}]`).toHaveText("100.00");
19371 expect(`.modal .alert`).toHaveCount(1);
19372 await contains(".modal footer button:contains(update)").click();
19373 expect(`table tr:eq(1) td[name=${field}]`).toHaveText("100.00");
19374 expect(`table tr:eq(2) td[name=${field}]`).toHaveText("100.00");
19375 expect(`table tr:eq(3) td[name=${field}]`).toHaveText("100.00");
19376 expect(`table tr:eq(4) td[name=${field}]`).toHaveText("100.00");
19377
19378 field = "int_field";
19379 await contains(`.o_data_cell[name=${field}]`).click();
19380 await edit("*=2", { confirm: "tab" });
19381 await waitFor(`.modal table [name=${field}]`);
19382 expect(`.modal table [name=${field}]`).toHaveText("Int field * 2");
19383 expect(`.modal .alert`).toHaveCount(1);
19384 await contains(".modal footer button:contains(update)").click();
19385 expect(`table tr:eq(1) td[name=${field}]`).toHaveText("20");
19386 expect(`table tr:eq(2) td[name=${field}]`).toHaveText("18");
19387 expect(`table tr:eq(3) td[name=${field}]`).toHaveText("34");
19388 expect(`table tr:eq(4) td[name=${field}]`).toHaveText("-8");
19389 });
19390
19391 test.tags("desktop");
19392 test(`basic open record with allowOpenAction`, async () => {
19393 mockService("action", {
19394 doActionButton(params) {
19395 const { name } = params;
19396 expect.step(`execute_action: ${name}`, params);
19397 },
19398 });
19399 await mountView({
19400 resModel: "foo",
19401 type: "list",
19402 arch: `<list action="test_action" type="object"><field name="foo"/></list>`,
19403 allowOpenAction: false,
19404 });
19405 await contains(".o_field_cell").click();
19406 expect.verifySteps([]);
19407 });
19408
19409 test.tags("desktop");
19410 test(`multi edition: many2many_tags add few tags in one time`, async () => {
19411 for (let i = 4; i <= 10; i++) {
19412 Bar._records.push({ id: i, name: "Value" + i });
19413 }
19414 Bar._views = {
19415 list: `<list><field name="name"/></list>`,
19416 };
19417
19418 await mountView({
19419 resModel: "foo",
19420 type: "list",
19421 arch: `<list multi_edit="1"><field name="m2m" widget="many2many_tags"/></list>`,
19422 });
19423
19424 expect(`.o_list_record_selector input:enabled`).toHaveCount(5);
19425
19426 // select two records and enter edit mode
19427 await contains(`.o_data_row:eq(0) .o_list_record_selector input`).click();
19428 await contains(`.o_data_row:eq(1) .o_list_record_selector input`).click();
19429 await contains(`.o_data_row:eq(0) .o_data_cell:eq(0)`).click();
19430 await contains(`.o_field_widget[name=m2m] input`).click();
19431 await contains(`.o-autocomplete--dropdown-item:contains(Search more...)`).click();
19432 expect(`.modal`).toHaveCount(1, { message: "should have open the modal" });
19433
19434 await contains(`.modal .o_list_record_selector .o-checkbox`).click();
19435 await contains(`.modal button:contains(select):enabled`).click();
19436 expect(`.modal .modal-header:contains(confirmation)`).toHaveCount(1, {
19437 message: "should have open the confirmation modal",
19438 });
19439 expect(`.modal .o_field_many2many_tags .badge`).toHaveCount(8);
19440 expect(`.modal .o_field_many2many_tags .badge:eq(0)`).toHaveText("Value 3", {
19441 message: "should have display_name in badge",
19442 });
19443 });
19444
19445 test.tags("desktop");
19446 test("multi_edit: must work for copy/paster or operation", async () => {
19447 Foo._records[1].datetime = "1989-05-03 12:51:35";
19448 Foo._records[2].datetime = "1987-11-13 12:12:34";
19449 Foo._records[3].datetime = "2019-04-09 03:21:35";
19450 await mountView({
19451 resModel: "foo",
19452 type: "list",
19453 arch: `
19454 <list multi_edit="1">
19455 <field name="foo"/>
19456 <field name="datetime"/>
19457 </list>
19458 `,
19459 });
19460
19461 await contains(`.o_list_record_selector`).click();
19462 await contains(`.o_data_cell[name=datetime]`).click();
19463 await animationFrame();
19464 await waitFor(`.o_datetime_picker`);
19465 await contains(`input[data-field=datetime]`).edit("+125d", { confirm: "tab" });
19466 expect(`tbody tr:eq(0) td[name=datetime]`).toHaveText("Jul 14, 11:30 AM");
19467 await contains(`.modal button:contains(update)`).click();
19468 expect(".modal").toHaveCount(0);
19469 expect(queryAllTexts(`.o_data_cell`)).toEqual([
19470 "yop",
19471 "Jul 14, 11:30 AM",
19472 "blip",
19473 "Jul 14, 11:30 AM",
19474 "gnap",
19475 "Jul 14, 11:30 AM",
19476 "blip",
19477 "Jul 14, 11:30 AM",
19478 ]);
19479 });
19480
19481 test.tags("mobile");
19482 test("scroll position is restored when coming back to list view", async () => {
19483 Foo._views = {
19484 kanban: `
19485 <kanban>
19486 <templates>
19487 <t t-name="card">
19488 <field name="foo"/>
19489 </t>
19490 </templates>
19491 </kanban>`,
19492 list: `<list><field name="foo"/></list>`,
19493 search: `<search />`,
19494 };
19495
19496 for (let i = 1; i < 30; i++) {
19497 Foo._records.push({ id: 100 + i, foo: `Record ${i}` });
19498 }
19499
19500 let def;
19501 onRpc("web_search_read", () => def);
19502 await mountWithCleanup(WebClient);
19503 await getService("action").doAction({
19504 res_model: "foo",
19505 type: "ir.actions.act_window",
19506 views: [
19507 [false, "kanban"],
19508 [false, "list"],
19509 ],
19510 });
19511
19512 expect(".o_kanban_view").toHaveCount(1);
19513 await getService("action").switchView("list");
19514 expect(".o_list_view").toHaveCount(1);
19515
19516 // simulate a scroll in the list view
19517 queryOne(".o_list_view").scrollTop = 200;
19518
19519 await getService("action").switchView("kanban");
19520 expect(".o_kanban_view").toHaveCount(1);
19521
19522 // the list is "lazy", so it displays the control panel directly, and the renderer later with
19523 // the data => simulate this and check that the scroll position is correctly restored
19524 def = new Deferred();
19525 await getService("action").switchView("list");
19526 expect(".o_list_view").toHaveCount(1);
19527 expect(".o_list_renderer").toHaveCount(0);
19528 def.resolve();
19529 await animationFrame();
19530 expect(".o_list_renderer").toHaveCount(1);
19531 expect(".o_list_view").toHaveProperty("scrollTop", 200);
19532 });