Debian Codegraph @

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

raw
1 import { after, beforeEach, describe, expect, getFixture, test } from "@odoo/hoot";
2 import { queryAllProperties, queryAllTexts, queryOne, queryRect, resize } from "@odoo/hoot-dom";
3 import { animationFrame, runAllTimers } from "@odoo/hoot-mock";
4 import { Component, xml } from "@odoo/owl";
5 import {
6 contains,
7 defineModels,
8 defineParams,
9 fields,
10 models,
11 mountView,
12 pagerNext,
13 removeFacet,
14 serverState,
15 toggleMenuItem,
16 toggleSearchBarMenu,
17 webModels,
18 } from "@web/../tests/web_test_helpers";
19
20 import { registry } from "@web/core/registry";
21 import { resetDateFieldWidths } from "@web/views/list/column_width_hook";
22
23 describe.current.tags("desktop");
24
25 const { ResCompany, ResPartner, ResUsers } = webModels;
26
27 class Foo extends models.Model {
28 foo = fields.Char();
29 bar = fields.Boolean();
30 date = fields.Date();
31 datetime = fields.Datetime();
32 int_field = fields.Integer();
33 qux = fields.Float();
34 m2o = fields.Many2one({ relation: "bar" });
35 o2m = fields.One2many({ relation: "bar" });
36 foo_o2m = fields.One2many({ relation: "foo" });
37 m2m = fields.Many2many({ relation: "bar" });
38 text = fields.Text();
39 amount = fields.Monetary({ currency_field: "currency_id" });
40 currency_id = fields.Many2one({ relation: "res.currency", default: 1 });
41 reference = fields.Reference({
42 selection: [
43 ["bar", "Bar"],
44 ["res.currency", "Currency"],
45 ],
46 });
47
48 _records = [
49 {
50 id: 1,
51 foo: "yop",
52 bar: true,
53 date: "2017-01-25",
54 datetime: "2016-12-12 10:55:05",
55 int_field: 10,
56 qux: 0.4,
57 m2o: 1,
58 m2m: [1, 2],
59 amount: 1200,
60 currency_id: 2,
61 reference: "bar,1",
62 },
63 {
64 id: 2,
65 foo: "blip",
66 bar: true,
67 int_field: 9,
68 qux: 13,
69 m2o: 2,
70 m2m: [1, 2, 3],
71 amount: 500,
72 reference: "res.currency,1",
73 },
74 {
75 id: 3,
76 foo: "gnap",
77 bar: true,
78 int_field: 17,
79 qux: -3,
80 m2o: 1,
81 m2m: [],
82 amount: 300,
83 reference: "res.currency,2",
84 },
85 {
86 id: 4,
87 foo: "blip",
88 bar: false,
89 int_field: -4,
90 qux: 9,
91 m2o: 1,
92 m2m: [1],
93 amount: 0,
94 },
95 ];
96 }
97
98 class Bar extends models.Model {
99 name = fields.Char();
100
101 _records = [
102 { id: 1, name: "Value 1" },
103 { id: 2, name: "Value 2" },
104 { id: 3, name: "Value 3" },
105 ];
106 }
107
108 class Currency extends models.Model {
109 _name = "res.currency";
110
111 name = fields.Char();
112 symbol = fields.Char();
113 position = fields.Selection({
114 selection: [
115 ["after", "A"],
116 ["before", "B"],
117 ],
118 });
119 inverse_rate = fields.Float();
120
121 _records = [
122 { id: 1, name: "USD", symbol: "$", position: "before", inverse_rate: 1 },
123 { id: 2, name: "EUR", symbol: "€", position: "after", inverse_rate: 0.5 },
124 ];
125 }
126
127 defineModels([Foo, Bar, Currency, ResCompany, ResPartner, ResUsers]);
128
129 beforeEach(() => {
130 resize({ width: 800 });
131 document.body.style.fontFamily = "sans-serif";
132 });
133
134 function getColumnWidths() {
135 return queryAllProperties(".o_list_table thead th", "offsetWidth");
136 }
137
138 function expectedColumnWidthsToBeCloseTo(expectedColumnWidths) {
139 getColumnWidths().forEach((width, index) =>
140 expect(width).toBeCloseTo(expectedColumnWidths[index], { margin: 3 })
141 );
142 }
143
144 // width computation
145 test(`width computation: no record, lot of fields`, async () => {
146 Foo._records = [];
147 await mountView({
148 type: "list",
149 resModel: "foo",
150 arch: `
151 <list>
152 <field name="bar"/>
153 <field name="foo"/>
154 <field name="int_field"/>
155 <field name="m2o"/>
156 <field name="qux"/>
157 <field name="date"/>
158 <field name="datetime"/>
159 <field name="amount"/>
160 <field name="currency_id"/>
161 </list>`,
162 });
163 expectedColumnWidthsToBeCloseTo([40, 29, 89, 80, 89, 102, 99, 188, 114, 100]);
164 });
165
166 test(`width computation: no record, few fields`, async () => {
167 Foo._records = [];
168 await mountView({
169 type: "list",
170 resModel: "foo",
171 arch: `
172 <list>
173 <field name="bar"/>
174 <field name="foo"/>
175 <field name="int_field"/>
176 </list>`,
177 });
178 expect(getColumnWidths()).toEqual([40, 109, 559, 91]);
179 });
180
181 test(`width computation: no record, all fields with a max width`, async () => {
182 Foo._records = [];
183 await mountView({
184 type: "list",
185 resModel: "foo",
186 arch: `
187 <list>
188 <field name="bar"/>
189 <field name="int_field"/>
190 <field name="qux"/>
191 </list>`,
192 });
193 expect(getColumnWidths()).toEqual([40, 262, 233, 266]);
194 });
195
196 test(`width computation: no record, sample data`, async () => {
197 Foo._records = [];
198 await mountView({
199 type: "list",
200 resModel: "foo",
201 arch: `
202 <list sample="1">
203 <field name="bar"/>
204 <field name="foo"/>
205 <field name="text"/>
206 <field name="m2o"/>
207 <field name="int_field"/>
208 </list>`,
209 });
210 expect(getColumnWidths()).toEqual([40, 109, 186, 186, 186, 91]);
211 });
212
213 test(`width computation: with records, lot of fields`, async () => {
214 await mountView({
215 type: "list",
216 resModel: "foo",
217 arch: `
218 <list>
219 <field name="bar"/>
220 <field name="foo"/>
221 <field name="int_field"/>
222 <field name="m2o"/>
223 <field name="qux"/>
224 <field name="date"/>
225 <field name="datetime"/>
226 <field name="amount"/>
227 <field name="currency_id"/>
228 </list>`,
229 });
230 expectedColumnWidthsToBeCloseTo([40, 29, 89, 80, 89, 102, 99, 188, 114, 100]);
231 });
232
233 test(`width computation: with records, lot of fields, grouped`, async () => {
234 await mountView({
235 resModel: "foo",
236 type: "list",
237 arch: `
238 <list>
239 <field name="bar"/>
240 <field name="foo"/>
241 <field name="int_field"/>
242 <field name="m2o"/>
243 <field name="qux"/>
244 <field name="date"/>
245 <field name="datetime"/>
246 <field name="amount"/>
247 <field name="currency_id" width="25px"/>
248 </list>
249 `,
250 groupBy: ["int_field"],
251 });
252 expect(`.o_resize`).toHaveCount(9);
253 expectedColumnWidthsToBeCloseTo([40, 29, 89, 80, 89, 102, 99, 188, 114, 34, 32]);
254 });
255
256 test(`width computation: with records, few fields`, async () => {
257 await mountView({
258 type: "list",
259 resModel: "foo",
260 arch: `
261 <list>
262 <field name="bar"/>
263 <field name="foo"/>
264 <field name="int_field"/>
265 </list>`,
266 });
267 expect(getColumnWidths()).toEqual([40, 109, 559, 91]);
268 });
269
270 test(`width computation: with records, no relative fields`, async () => {
271 await mountView({
272 type: "list",
273 resModel: "foo",
274 arch: `
275 <list>
276 <field name="bar"/>
277 <field name="int_field"/>
278 <field name="qux"/>
279 <field name="date"/>
280 </list>`,
281 });
282 expect(getColumnWidths()).toEqual([40, 199, 170, 192, 200]);
283 });
284
285 test(`width computation: with records, very long text field`, async () => {
286 Foo._records[0].text =
287 "Lorem ipsum dolor sit amet, consectetur adipiscing elit, " +
288 "sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim " +
289 "veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo " +
290 "consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum " +
291 "dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, " +
292 "sunt in culpa qui officia deserunt mollit anim id est laborum";
293
294 await mountView({
295 type: "list",
296 resModel: "foo",
297 arch: `
298 <list>
299 <field name="bar"/>
300 <field name="text"/>
301 <field name="qux"/>
302 </list>`,
303 });
304 expect(getColumnWidths()).toEqual([40, 29, 618, 113]);
305 });
306
307 test(`width computation: with records, lot of fields, long texts`, async () => {
308 Foo._records[0].text =
309 "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt";
310 Foo._records[1].foo = "Duis aute irure dolor in reprehenderit in voluptate velit esse cillumt";
311
312 await mountView({
313 type: "list",
314 resModel: "foo",
315 arch: `
316 <list>
317 <field name="bar"/>
318 <field name="foo"/>
319 <field name="int_field"/>
320 <field name="qux"/>
321 <field name="date"/>
322 <field name="text"/>
323 <field name="datetime"/>
324 <field name="amount"/>
325 <field name="currency_id"/>
326 </list>`,
327 });
328 expectedColumnWidthsToBeCloseTo([40, 29, 89, 80, 102, 99, 89, 188, 114, 100]);
329 });
330
331 test(`width computation: editable list, overflowing table`, async () => {
332 class Abc extends models.Model {
333 titi = fields.Char();
334 grosminet = fields.Char();
335
336 _records = [
337 {
338 id: 1,
339 titi: "Tiny text",
340 grosminet:
341 // Just want to make sure that the table is overflowed
342 `Lorem ipsum dolor sit amet, consectetur adipiscing elit.
343 Donec est massa, gravida eget dapibus ac, eleifend eget libero.
344 Suspendisse feugiat sed massa eleifend vestibulum. Sed tincidunt
345 velit sed lacinia lacinia. Nunc in fermentum nunc. Vestibulum ante
346 ipsum primis in faucibus orci luctus et ultrices posuere cubilia
347 Curae; Nullam ut nisi a est ornare molestie non vulputate orci.
348 Nunc pharetra porta semper. Mauris dictum eu nulla a pulvinar. Duis
349 eleifend odio id ligula congue sollicitudin. Curabitur quis aliquet
350 nunc, ut aliquet enim. Suspendisse malesuada felis non metus
351 efficitur aliquet.`,
352 },
353 ];
354 }
355 defineModels([Abc]);
356
357 await mountView({
358 resModel: "abc",
359 type: "list",
360 arch: `
361 <list editable="top">
362 <field name="titi"/>
363 <field name="grosminet" widget="char"/>
364 </list>
365 `,
366 });
367 expect(`table`).toHaveRect(queryRect`.o_list_renderer`, {
368 message: "Table should not be stretched by its content",
369 });
370 expect(getColumnWidths()).toEqual([40, 89, 671]);
371 });
372
373 test(`width computation: with records, few fields, long texts`, async () => {
374 Foo._records[0].text =
375 "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt. Duis aute irure dolor in reprehenderit in voluptate velit esse cillumt";
376 Foo._records[1].foo =
377 "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt. Duis aute irure dolor in reprehenderit in voluptate velit esse cillumt";
378
379 await mountView({
380 type: "list",
381 resModel: "foo",
382 arch: `
383 <list>
384 <field name="bar"/>
385 <field name="foo"/>
386 <field name="text"/>
387 </list>`,
388 });
389 expect(getColumnWidths()).toEqual([40, 29, 354, 377]);
390 });
391
392 test(`width computation: list with handle field`, async () => {
393 await mountView({
394 type: "list",
395 resModel: "foo",
396 arch: `
397 <list>
398 <field name="int_field" widget="handle"/>
399 <field name="foo"/>
400 </list>`,
401 });
402 expect(getColumnWidths()).toEqual([40, 29, 731]);
403 });
404
405 test(`width computation: editable list, no record, with handle field`, async () => {
406 Foo._records = [];
407
408 await mountView({
409 resModel: "foo",
410 type: "list",
411 arch: `
412 <list editable="bottom">
413 <field name="int_field" widget="handle"/>
414 <field name="currency_id"/>
415 <field name="m2o"/>
416 </list>
417 `,
418 });
419 expect(`thead th`).toHaveCount(4, { message: "there should be 4 th" });
420 expect(`thead th:eq(0)`).toHaveClass("o_list_record_selector");
421 expect(`thead th:eq(1)`).toHaveClass("o_handle_cell");
422 expect(`thead th:eq(0)`).toHaveText("", {
423 message: "the handle field shouldn't have a header description",
424 });
425 expect(getColumnWidths()).toEqual([40, 29, 360, 371]);
426 });
427
428 test(`width computation: widget with listViewWidth in its definition`, async () => {
429 class MyWidget extends Component {
430 static template = xml`<span>My custom widget</span>`;
431 static props = ["*"];
432 }
433 const myWidget = {
434 listViewWidth: 171,
435 component: MyWidget,
436 };
437 registry.category("view_widgets").add("my_widget", myWidget);
438 await mountView({
439 type: "list",
440 resModel: "foo",
441 arch: `
442 <list>
443 <widget name="my_widget"/>
444 <field name="foo"/>
445 </list>`,
446 });
447 expect(getColumnWidths()).toEqual([40, 180, 580]);
448 });
449
450 test(`width computation: list with width attribute in arch`, async () => {
451 await mountView({
452 type: "list",
453 resModel: "foo",
454 arch: `
455 <list>
456 <field name="int_field" width="52px"/>
457 <field name="foo" width="63px"/>
458 <field name="qux"/>
459 <field name="currency_id"/>
460 </list>`,
461 });
462 expect(getColumnWidths()).toEqual([40, 61, 72, 102, 524]);
463 });
464
465 test(`width computation: datetime in numeric, am/pm format`, async () => {
466 defineParams({
467 lang_parameters: {
468 date_format: "%m/%d/%Y",
469 time_format: "%I:%M:%S %p",
470 },
471 });
472 resetDateFieldWidths();
473 after(resetDateFieldWidths);
474
475 await mountView({
476 type: "list",
477 resModel: "foo",
478 arch: `
479 <list>
480 <field name="foo"/>
481 <field name="date" options="{'numeric': true}"/>
482 <field name="datetime" options="{'numeric': true}"/>
483 </list>`,
484 });
485
486 expect(queryAllTexts(".o_data_row:eq(0) .o_data_cell")).toEqual([
487 "yop",
488 "01/25/2017",
489 "12/12/2016 11:55:05 AM",
490 ]);
491 expect(getColumnWidths()).toEqual([40, 494, 83, 182]);
492 });
493
494 test(`width computation: width attribute in arch and overflowing table`, async () => {
495 Foo._records[0].text =
496 "Lorem ipsum dolor sit amet, consectetur adipiscing elit, " +
497 "sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim " +
498 "veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo " +
499 "consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum " +
500 "dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, " +
501 "sunt in culpa qui officia deserunt mollit anim id est laborum";
502
503 await mountView({
504 resModel: "foo",
505 type: "list",
506 arch: `
507 <list editable="bottom">
508 <field name="datetime"/>
509 <field name="int_field" width="200px"/>
510 <field name="text"/>
511 </list>
512 `,
513 });
514 expectedColumnWidthsToBeCloseTo([40, 188, 210, 362]);
515 });
516
517 test(`width computation: no record, nameless and stringless buttons`, async () => {
518 Foo._records = [];
519
520 await mountView({
521 resModel: "foo",
522 type: "list",
523 arch: `
524 <list>
525 <field name="foo"/>
526 <button string="choucroute"/>
527 <button icon="fa-heart"/>
528 </list>
529 `,
530 });
531 const columnWidths = getColumnWidths();
532 expect(columnWidths[0]).toBe(40);
533 expect(columnWidths[1]).toBeGreaterThan(300);
534 expect(columnWidths[2]).toBeGreaterThan(300);
535 });
536
537 test(`width computation: x2many`, async () => {
538 await mountView({
539 type: "form",
540 resModel: "foo",
541 arch: `
542 <form>
543 <sheet>
544 <field name="foo_o2m">
545 <list>
546 <field name="bar"/>
547 <field name="foo"/>
548 <field name="qux"/>
549 </list>
550 </field>
551 </sheet>
552 </form>`,
553 });
554
555 const columnWidths = getColumnWidths();
556 expect(columnWidths[1]).toBeGreaterThan(380);
557 });
558
559 test(`width computation: x2many, column_invisible`, async () => {
560 await mountView({
561 type: "form",
562 resModel: "foo",
563 arch: `
564 <form>
565 <sheet>
566 <field name="bar"/>
567 <field name="foo_o2m">
568 <list>
569 <field name="bar"/>
570 <field name="int_field" column_invisible="not parent.bar"/>
571 <field name="foo"/>
572 <field name="qux"/>
573 </list>
574 </field>
575 </sheet>
576 </form>`,
577 });
578
579 let columnWidths = getColumnWidths();
580 const fooWidth = columnWidths[1];
581 expect(fooWidth).toBeGreaterThan(380);
582
583 await contains(".o_field_widget[name=bar] input").click();
584 columnWidths = getColumnWidths();
585 expect(columnWidths[2]).toBeLessThan(fooWidth);
586 expect(columnWidths[2]).toBeGreaterThan(220);
587 });
588
589 test(`width computation: x2many, editable list, initially invisible, overflowing`, async () => {
590 Foo._fields.o2m = fields.One2many({ relation: "abc" });
591 Foo._records = [{ id: 1, o2m: [1] }];
592
593 class Abc extends models.Model {
594 titi = fields.Char();
595 grosminet = fields.Char();
596
597 _records = [
598 {
599 id: 1,
600 titi: "Tiny text",
601 grosminet:
602 "Lorem ipsum dolor sit amet, consectetur adipiscing elit. " +
603 "Ut at nisi congue, facilisis neque nec, pulvinar nunc. " +
604 "Vivamus ac lectus velit.",
605 },
606 ];
607 }
608 defineModels([Abc]);
609
610 await mountView({
611 resModel: "foo",
612 type: "form",
613 arch: `
614 <form>
615 <sheet>
616 <notebook>
617 <page string="Page1"></page>
618 <page string="Page2">
619 <field name="o2m">
620 <list editable="bottom">
621 <field name="titi"/>
622 <field name="grosminet"/>
623 </list>
624 </field>
625 </page>
626 </notebook>
627 </sheet>
628 </form>
629 `,
630 resId: 1,
631 });
632 expect(`.o_field_one2many`).toHaveCount(0);
633
634 await contains(`.nav-item:eq(-1) .nav-link`).click();
635 expect(`.o_field_one2many`).toHaveCount(1);
636 const columnWidths = getColumnWidths();
637 expect(columnWidths[1]).toBeGreaterThan(500);
638 });
639
640 test(`width computation: x2many, editable list, with invisible modifier on x2many`, async () => {
641 Foo._fields.o2m = fields.One2many({ relation: "abc" });
642 Foo._records = [{ id: 1, bar: true, o2m: [1] }];
643 class Abc extends models.Model {
644 titi = fields.Char();
645 grosminet = fields.Char();
646
647 _records = [
648 {
649 id: 1,
650 titi: "Tiny text",
651 grosminet:
652 "Lorem ipsum dolor sit amet, consectetur adipiscing elit. " +
653 "Ut at nisi congue, facilisis neque nec, pulvinar nunc. " +
654 "Vivamus ac lectus velit.",
655 },
656 ];
657 }
658 defineModels([Abc]);
659
660 await mountView({
661 resModel: "foo",
662 type: "form",
663 arch: `
664 <form>
665 <sheet>
666 <field name="bar"/>
667 <field name="o2m" invisible="bar">
668 <list editable="bottom">
669 <field name="titi"/>
670 <field name="grosminet"/>
671 </list>
672 </field>
673 </sheet>
674 </form>
675 `,
676 resId: 1,
677 });
678 expect(`.o_field_one2many`).toHaveCount(0);
679
680 await contains(`.o_field_boolean input`).click();
681 expect(`.o_field_one2many`).toHaveCount(1);
682 const columnWidths = getColumnWidths();
683 expect(columnWidths[1]).toBeGreaterThan(500);
684 });
685
686 test(`width computation: widths are re-computed on window resize`, async () => {
687 Foo._records[0].text =
688 "Lorem ipsum dolor sit amet, consectetur adipiscing elit. " +
689 "Sed blandit, justo nec tincidunt feugiat, mi justo suscipit libero, sit amet tempus " +
690 "ipsum purus bibendum est.";
691
692 await mountView({
693 resModel: "foo",
694 type: "list",
695 arch: `
696 <list>
697 <field name="int_field"/>
698 <field name="text"/>
699 </list>
700 `,
701 });
702
703 expect(getColumnWidths()).toEqual([40, 80, 680]);
704
705 resize({ width: queryRect(getFixture()).width * 1.2 });
706 await runAllTimers();
707 expect(getColumnWidths()).toEqual([40, 80, 840]);
708 });
709
710 test(`width computation: widths are re-computed on parent resize`, async () => {
711 Foo._records[0].text =
712 "Lorem ipsum dolor sit amet, consectetur adipiscing elit. " +
713 "Sed blandit, justo nec tincidunt feugiat, mi justo suscipit libero, sit amet tempus " +
714 "ipsum purus bibendum est.";
715
716 await mountView({
717 resModel: "foo",
718 type: "list",
719 arch: `
720 <list>
721 <field name="int_field"/>
722 <field name="text"/>
723 </list>
724 `,
725 });
726
727 expect(getColumnWidths()).toEqual([40, 80, 680]);
728
729 queryOne(".o_list_renderer").style.width = "600px";
730 await runAllTimers();
731 expect(getColumnWidths()).toEqual([40, 80, 480]);
732 });
733
734 test(`width computation: button columns don't have a max width`, async () => {
735 // set a long foo value s.t. the column can be squeezed
736 Foo._records[0].foo = "Lorem ipsum dolor sit amet";
737
738 await mountView({
739 resModel: "foo",
740 type: "list",
741 arch: `
742 <list>
743 <field name="foo"/>
744 <button name="b1" string="Do This"/>
745 <button name="b2" string="Do That"/>
746 <button name="b3" string="Or Rather Do Something Else"/>
747 </list>
748 `,
749 });
750
751 expect(queryAllProperties(".o_list_table", "offsetWidth")[0]).toBe(800);
752 let columnWidths = getColumnWidths();
753 expect(columnWidths[1]).toBeGreaterThan(130);
754 expect(columnWidths[2]).toBeGreaterThan(330);
755
756 // simulate a window resize (buttons column width should not be squeezed)
757 await resize({ width: 300 });
758 await runAllTimers();
759 await animationFrame();
760 const tableWidth = queryAllProperties(".o_list_table", "offsetWidth")[0];
761 expect(tableWidth).toBeGreaterThan(300);
762 expect(tableWidth).toBeLessThan(800);
763 columnWidths = getColumnWidths();
764 // indices 0 and 1 because selectors aren't displayed on small screens
765 expect(columnWidths[0]).toBe(100);
766 expect(columnWidths[1]).toBeGreaterThan(330);
767 });
768
769 test(`width computation: button with width in arch`, async () => {
770 Foo._records = [];
771
772 await mountView({
773 resModel: "foo",
774 type: "list",
775 arch: `
776 <list>
777 <field name="foo"/>
778 <button string="choucroute"/>
779 <button icon="fa-heart" width="25px"/>
780 <button icon="fa-cog" width="59px"/>
781 <button icon="fa-list"/>
782 <button icon="fa-play"/>
783 </list>
784 `,
785 });
786
787 expect(getColumnWidths()).toEqual([40, 216, 216, 34, 68, 227]);
788 });
789
790 // freeze column widths
791 test(`freeze widths: add first record`, async () => {
792 Foo._records = []; // in this scenario, we start with no records
793
794 await mountView({
795 resModel: "foo",
796 type: "list",
797 arch: `
798 <list editable="top">
799 <field name="datetime"/>
800 <field name="text"/>
801 </list>
802 `,
803 });
804
805 const initialWidths = getColumnWidths();
806 await contains(`.o_list_button_add`).click();
807 expect(`.o_data_row`).toHaveCount(1);
808 expect(getColumnWidths()).toEqual(initialWidths);
809 });
810
811 test(`freeze widths: edit a record`, async () => {
812 await mountView({
813 resModel: "foo",
814 type: "list",
815 arch: `
816 <list editable="bottom">
817 <field name="datetime"/>
818 <field name="text"/>
819 <field name="foo"/>
820 </list>
821 `,
822 });
823
824 const initialWidths = getColumnWidths();
825 await contains(`.o_data_row:eq(0) > .o_data_cell:eq(1)`).click();
826 expect(`.o_selected_row`).toHaveCount(1);
827 const longVal =
828 "Lorem ipsum dolor sit amet, consectetur adipiscing elit. " +
829 "Sed blandit, justo nec tincidunt feugiat, mi justo suscipit libero, sit amet tempus " +
830 "ipsum purus bibendum est.";
831 await contains(`.o_field_widget[name=text] .o_input`).edit(longVal, { confirm: false });
832 await contains(`.o_list_button_save`).click();
833 expect(`.o_selected_row`).toHaveCount(0);
834 expect(getColumnWidths()).toEqual(initialWidths);
835 });
836
837 test(`freeze widths: switch records in edition`, async () => {
838 await mountView({
839 resModel: "foo",
840 type: "list",
841 arch: `
842 <list editable="bottom">
843 <field name="m2o"/>
844 <field name="text"/>
845 </list>
846 `,
847 });
848
849 const initialWidths = getColumnWidths();
850 await contains(`.o_data_row:eq(0) > .o_data_cell:eq(1)`).click();
851 expect(`.o_data_row:eq(0)`).toHaveClass("o_selected_row");
852 expect(getColumnWidths()).toEqual(initialWidths);
853
854 await contains(`.o_data_row:eq(1) > .o_data_cell:eq(1)`).click();
855 expect(`.o_data_row:eq(1)`).toHaveClass("o_selected_row");
856 expect(getColumnWidths()).toEqual(initialWidths);
857 });
858
859 test(`freeze widths: switch mode`, async () => {
860 // Warning: this test is css dependant
861 await mountView({
862 resModel: "foo",
863 type: "list",
864 arch: `
865 <list editable="top">
866 <field name="foo"/>
867 <field name="int_field" readonly="1"/>
868 <field name="m2o"/>
869 <field name="m2m" widget="many2many_tags"/>
870 </list>
871 `,
872 });
873 const startWidths = getColumnWidths();
874 const startWidth = queryRect(`table`).width;
875
876 // start edition of first row
877 await contains(`td:not(.o_list_record_selector)`).click();
878 const editionWidths = getColumnWidths();
879 const editionWidth = queryRect(`table`).width;
880
881 // leave edition
882 await contains(`.o_list_button_save`).click();
883 const readonlyWidths = getColumnWidths();
884 const readonlyWidth = queryRect(`table`).width;
885 expect(editionWidth).toBe(startWidth, {
886 message: "table should have kept the same width when switching from readonly to edit mode",
887 });
888 expect(editionWidths).toEqual(startWidths, {
889 message:
890 "width of columns should remain unchanged when switching from readonly to edit mode",
891 });
892 expect(readonlyWidth).toBe(editionWidth, {
893 message: "table should have kept the same width when switching from edit to readonly mode",
894 });
895 expect(readonlyWidths).toEqual(editionWidths, {
896 message:
897 "width of columns should remain unchanged when switching from edit to readonly mode",
898 });
899 });
900
901 test(`freeze widths: switch mode (lot of fields)`, async () => {
902 // Warning: this test is css dependant
903 serverState.multiLang = true;
904
905 Foo._fields.foo = fields.Char({ translate: true });
906 Foo._fields.boolean = fields.Boolean();
907
908 // the width is hardcoded to make sure we have the same condition
909 // between debug mode and non debug mode
910 await resize({ width: 1200 });
911 await mountView({
912 resModel: "foo",
913 type: "list",
914 arch: `
915 <list editable="top">
916 <field name="foo" required="1"/>
917 <field name="int_field" readonly="1"/>
918 <field name="boolean"/>
919 <field name="date"/>
920 <field name="text"/>
921 <field name="amount"/>
922 <field name="currency_id" column_invisible="1"/>
923 <field name="m2o"/>
924 <field name="m2m" widget="many2many_tags"/>
925 </list>
926 `,
927 });
928 const startHeight = queryRect(`.o_data_row:eq(0)`).height;
929 const startWidth = queryRect(`.o_data_row:eq(0)`).width;
930
931 // start edition of first row
932 await contains(`.o_data_row > td:not(.o_list_record_selector)`).click();
933 expect(`.o_data_row:eq(0)`).toHaveClass("o_selected_row");
934 const editionHeight = queryRect(`.o_data_row:eq(0)`).height;
935 const editionWidth = queryRect(`.o_data_row:eq(0)`).width;
936
937 // leave edition
938 await contains(`.o_list_button_save`).click();
939 const readonlyHeight = queryRect(`.o_data_row:eq(0)`).height;
940 const readonlyWidth = queryRect(`.o_data_row:eq(0)`).width;
941 expect(startHeight).toBe(editionHeight);
942 expect(startHeight).toBe(readonlyHeight);
943 expect(startWidth).toBe(editionWidth);
944 expect(startWidth).toBe(readonlyWidth);
945 });
946
947 test(`freeze widths: navigate with the pager`, async () => {
948 Foo._records[0].foo = "Some very very long value for a char field";
949
950 await mountView({
951 resModel: "foo",
952 type: "list",
953 arch: `
954 <list editable="top">
955 <field name="bar"/>
956 <field name="foo"/>
957 <field name="int_field"/>
958 <field name="qux"/>
959 <field name="date"/>
960 <field name="datetime"/>
961 </list>
962 `,
963 limit: 2,
964 });
965
966 const initialWidths = getColumnWidths();
967 await pagerNext();
968 expect(getColumnWidths()).toEqual(initialWidths);
969 });
970
971 test(`freeze widths: toggle a filter`, async () => {
972 Foo._records[0].foo = "Some very very long value for a char field";
973 Foo._records[3].text = "Some very very long value for a char field";
974
975 await mountView({
976 resModel: "foo",
977 type: "list",
978 arch: `
979 <list>
980 <field name="bar"/>
981 <field name="foo"/>
982 <field name="text"/>
983 </list>
984 `,
985 searchViewArch: `
986 <search>
987 <filter string="My Filter" name="my_filter" domain="[['id', '>', 2]]"/>
988 </search>
989 `,
990 limit: 2,
991 });
992
993 const initialWidths = getColumnWidths();
994 await toggleSearchBarMenu();
995 await toggleMenuItem("My Filter");
996 expect(getColumnWidths()).toEqual(initialWidths);
997 });
998
999 test(`freeze widths: empty list, remove a filter s.t. records appear`, async () => {
1000 Foo._records[0].foo = "Some very very long value for a char field";
1001
1002 await mountView({
1003 resModel: "foo",
1004 type: "list",
1005 arch: `
1006 <list>
1007 <field name="bar"/>
1008 <field name="foo"/>
1009 <field name="text"/>
1010 </list>
1011 `,
1012 searchViewArch: `
1013 <search>
1014 <filter string="My Filter" name="my_filter" domain="[['id', '=', 0]]"/>
1015 </search>
1016 `,
1017 context: {
1018 search_default_my_filter: true,
1019 },
1020 });
1021
1022 expect(".o_data_row").toHaveCount(0);
1023
1024 const initialWidths = getColumnWidths();
1025 await toggleSearchBarMenu();
1026 await toggleMenuItem("My Filter");
1027 expect(".o_data_row").toHaveCount(4);
1028 expect(getColumnWidths()).not.toEqual(initialWidths);
1029 });
1030
1031 test(`freeze widths: grouped list, open a group`, async () => {
1032 Foo._records[3].foo = "Some very very long value for a char field";
1033
1034 await mountView({
1035 resModel: "foo",
1036 type: "list",
1037 arch: `
1038 <list>
1039 <field name="bar"/>
1040 <field name="foo"/>
1041 <field name="text"/>
1042 </list>
1043 `,
1044 groupBy: ["bar"],
1045 });
1046
1047 expect(".o_data_row").toHaveCount(0);
1048
1049 const initialWidths = getColumnWidths();
1050 await contains(".o_group_header").click();
1051 expect(".o_data_row").toHaveCount(1);
1052 expect(getColumnWidths()).not.toEqual(initialWidths);
1053 });
1054
1055 test(`freeze widths: toggle a filter, vertical scrollbar appears`, async () => {
1056 await resize({ height: 500 });
1057
1058 for (let i = 10; i < 20; i++) {
1059 Foo._records.push({ id: i, bar: true, foo: `Foo ${i}` });
1060 }
1061 await mountView({
1062 resModel: "foo",
1063 type: "list",
1064 arch: `
1065 <list>
1066 <field name="bar"/>
1067 <field name="foo"/>
1068 </list>
1069 `,
1070 searchViewArch: `
1071 <search>
1072 <filter string="My Filter" name="my_filter" domain="[['id', '>', 16]]"/>
1073 </search>
1074 `,
1075 context: {
1076 search_default_my_filter: true,
1077 },
1078 });
1079
1080 expect(".o_data_row").toHaveCount(3);
1081 const renderer = queryOne(".o_list_renderer");
1082 expect(renderer.scrollHeight).toBe(renderer.clientHeight);
1083
1084 await removeFacet("My Filter");
1085 expect(".o_data_row").toHaveCount(14);
1086 expect(renderer.scrollHeight).toBeGreaterThan(renderer.clientHeight); // there must be a vertical scrollbar
1087 expect(renderer.scrollWidth).toBe(renderer.clientWidth); // there must be no horizontal scrollbar
1088 });
1089
1090 test(`freeze widths: add a record in empty list`, async () => {
1091 Foo._records = [];
1092
1093 await mountView({
1094 resModel: "foo",
1095 type: "list",
1096 arch: `
1097 <list editable="bottom">
1098 <field name="bar"/>
1099 <field name="foo"/>
1100 <field name="text"/>
1101 </list>
1102 `,
1103 noContentHelp: '<p class="hello">click to add a foo</p>',
1104 });
1105 expect(`.o_view_nocontent`).toHaveCount(1, { message: "should have no content help" });
1106 const initialWidths = getColumnWidths();
1107
1108 // click on create button
1109 await contains(`.o_list_button_add`).click();
1110 expect(getColumnWidths()).toEqual(initialWidths);
1111
1112 // creating one record
1113 await contains(`.o_selected_row [name='foo'] input`).edit(
1114 "Some very very long value for a char field",
1115 { confirm: false }
1116 );
1117 await contains(`.o_list_button_save`).click();
1118 expect(getColumnWidths()).toEqual(initialWidths);
1119 });
1120
1121 test(`freeze widths: add a record in empty list with handle widget`, async () => {
1122 Foo._records = [];
1123
1124 await mountView({
1125 resModel: "foo",
1126 type: "list",
1127 arch: `
1128 <list editable="bottom">
1129 <field name="int_field" widget="handle"/>
1130 <field name="foo"/>
1131 </list>
1132 `,
1133 noContentHelp: '<p class="hello">click to add a foo</p>',
1134 });
1135 expect(`.o_view_nocontent`).toHaveCount(1, { message: "should have no content help" });
1136 const initialWidths = getColumnWidths();
1137
1138 // click on create button
1139 await contains(`.o_list_button_add`).click();
1140 expect(getColumnWidths()).toEqual(initialWidths);
1141
1142 // creating one record
1143 await contains(`.o_selected_row [name='foo'] input`).edit("test_foo", { confirm: false });
1144 await contains(`.o_list_button_save`).click();
1145 expect(getColumnWidths()).toEqual(initialWidths);
1146 });
1147
1148 test(`freeze widths: edit multiple records`, async () => {
1149 await mountView({
1150 resModel: "foo",
1151 type: "list",
1152 arch: `
1153 <list multi_edit="1">
1154 <field name="datetime"/>
1155 <field name="text"/>
1156 </list>
1157 `,
1158 });
1159
1160 const initialWidths = getColumnWidths();
1161
1162 // select two records and edit
1163 await contains(`.o_data_row:eq(0) .o_list_record_selector input`).click();
1164 await contains(`.o_data_row:eq(1) .o_list_record_selector input`).click();
1165 await contains(`.o_data_row:eq(0) .o_data_cell:eq(1)`).click();
1166 expect(`.o_selected_row`).toHaveCount(1);
1167
1168 const longVal =
1169 "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed blandit, " +
1170 "justo nec tincidunt feugiat, mi justo suscipit libero, sit amet tempus ipsum purus " +
1171 "bibendum est.";
1172 await contains(`.o_field_widget[name=text] textarea`).edit(longVal);
1173 expect(`.modal`).toHaveCount(1);
1174
1175 await contains(`.modal .btn-primary`).click();
1176 expect(`.o_selected_row`).toHaveCount(0);
1177 expect(getColumnWidths()).toEqual(initialWidths);
1178 });
1179
1180 test(`freeze widths: toggle optional fields`, async () => {
1181 Foo._records[0].foo = "Lorem ipsum dolor sit amet, consectetur adipiscing elit.";
1182 await mountView({
1183 resModel: "foo",
1184 type: "list",
1185 arch: `
1186 <list>
1187 <field name="date"/>
1188 <field name="text"/>
1189 <field name="qux" optional="hide"/>
1190 <field name="datetime" optional="show"/>
1191 <field name="foo" optional="hide"/>
1192 </list>
1193 `,
1194 });
1195
1196 expectedColumnWidthsToBeCloseTo([40, 99, 440, 188, 32]);
1197
1198 await contains(".o_optional_columns_dropdown_toggle").click();
1199 await contains(".dropdown-item input:eq(0)").click();
1200 expectedColumnWidthsToBeCloseTo([40, 99, 337, 102, 189, 32]);
1201
1202 await contains(".dropdown-item input:eq(1)").click();
1203 expect(getColumnWidths()).toEqual([40, 99, 526, 102, 32]);
1204
1205 await contains(".dropdown-item input:eq(2)").click();
1206 expect(getColumnWidths()).toEqual([40, 99, 89, 102, 437, 32]);
1207
1208 await contains(".dropdown-item input:eq(1)").click();
1209 expectedColumnWidthsToBeCloseTo([40, 99, 89, 103, 189, 247, 32]);
1210 });
1211
1212 test(`freeze widths: x2many, add first record`, async () => {
1213 await mountView({
1214 type: "form",
1215 resModel: "foo",
1216 arch: `
1217 <form>
1218 <field name="foo_o2m">
1219 <list editable="top">
1220 <field name="date"/>
1221 <field name="foo"/>
1222 </list>
1223 </field>
1224 </form>`,
1225 });
1226
1227 const initialWidths = getColumnWidths();
1228 await contains(".o_field_x2many_list_row_add a").click();
1229 expect(".o_data_row").toHaveCount(1);
1230 expect(getColumnWidths()).toEqual(initialWidths);
1231 });
1232
1233 test(`freeze widths: x2many, edit a record`, async () => {
1234 Foo._records[0].foo_o2m = [2];
1235
1236 await mountView({
1237 type: "form",
1238 resModel: "foo",
1239 arch: `
1240 <form>
1241 <field name="foo_o2m">
1242 <list editable="top">
1243 <field name="date"/>
1244 <field name="foo"/>
1245 </list>
1246 </field>
1247 </form>`,
1248 resId: 1,
1249 });
1250
1251 const initialWidths = getColumnWidths();
1252 await contains(".o_data_row .o_data_cell").click();
1253 expect(getColumnWidths()).toEqual(initialWidths);
1254
1255 const longVal =
1256 "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed blandit, " +
1257 "justo nec tincidunt feugiat, mi justo suscipit libero, sit amet tempus ipsum " +
1258 "purus bibendum est.";
1259 await contains(".o_field_widget[name=foo] input").edit(longVal);
1260 expect(getColumnWidths()).toEqual(initialWidths);
1261 });
1262
1263 test(`freeze widths: x2many, remove last record`, async () => {
1264 Foo._records[0].foo_o2m = [2];
1265
1266 await mountView({
1267 type: "form",
1268 resModel: "foo",
1269 arch: `
1270 <form>
1271 <field name="foo_o2m">
1272 <list editable="top">
1273 <field name="date"/>
1274 <field name="foo"/>
1275 </list>
1276 </field>
1277 </form>`,
1278 resId: 1,
1279 });
1280
1281 const initialWidths = getColumnWidths();
1282 await contains(".o_data_row .o_list_record_remove").click();
1283 expect(getColumnWidths()).toEqual(initialWidths);
1284 });
1285
1286 test(`freeze widths: x2many, toggle optional field`, async () => {
1287 Foo._records[0].foo_o2m = [2];
1288
1289 await mountView({
1290 type: "form",
1291 resModel: "foo",
1292 arch: `
1293 <form>
1294 <field name="foo_o2m">
1295 <list editable="top">
1296 <field name="date" required="1"/>
1297 <field name="foo"/>
1298 <field name="int_field" optional="1"/>
1299 </list>
1300 </field>
1301 </form>`,
1302 });
1303
1304 expect(getColumnWidths()).toEqual([110, 626, 32]);
1305
1306 // create a record to store the current widths, but discard it directly to keep
1307 // the list empty (otherwise, the browser automatically computes the optimal widths)
1308 await contains(".o_field_x2many_list_row_add a").click();
1309 expect(getColumnWidths()).toEqual([110, 626, 32]);
1310
1311 await contains(".o_optional_columns_dropdown_toggle").click();
1312 await contains(".dropdown-item input").click();
1313 expect(getColumnWidths()).toEqual([110, 545, 80, 32]);
1314 });
1315
1316 // manually resize columns
1317 test(`resize, reorder, resize again`, async () => {
1318 await mountView({
1319 resModel: "foo",
1320 type: "list",
1321 arch: `
1322 <list>
1323 <field name="foo"/>
1324 <field name="int_field"/>
1325 </list>
1326 `,
1327 });
1328
1329 // 1. Resize column foo to middle of column int_field.
1330 const originalWidths = getColumnWidths();
1331 await contains(`th:eq(1) .o_resize`, { visible: false }).dragAndDrop(`th:eq(2)`);
1332 let widthsAfterResize = getColumnWidths();
1333 expect(widthsAfterResize[0]).toBe(originalWidths[0]);
1334 expect(widthsAfterResize[1]).toBeGreaterThan(originalWidths[1]);
1335
1336 // 2. Reorder column foo.
1337 await contains(`th:eq(1)`).click();
1338 const widthsAfterReorder = getColumnWidths();
1339 expect(widthsAfterResize[0]).toBe(widthsAfterReorder[0]);
1340 expect(widthsAfterResize[1]).toBe(widthsAfterReorder[1]);
1341
1342 // 3. Resize again, this time check sizes while dragging and after drop.
1343 const { moveTo, drop } = await contains(`th:eq(1) .o_resize`, { visible: false }).drag();
1344 await moveTo(`th:eq(2)`);
1345 widthsAfterResize = getColumnWidths();
1346 expect(widthsAfterResize[1]).toBeGreaterThan(widthsAfterReorder[1]);
1347
1348 await drop();
1349 expect(widthsAfterResize[1]).toBeGreaterThan(widthsAfterReorder[1]);
1350 });
1351
1352 test(`resize column and toggle one checkbox`, async () => {
1353 await mountView({
1354 resModel: "foo",
1355 type: "list",
1356 arch: `
1357 <list>
1358 <field name="foo"/>
1359 <field name="int_field"/>
1360 </list>
1361 `,
1362 });
1363
1364 // 1. Resize column foo to middle of column int_field.
1365 await contains(`th:eq(1) .o_resize`, { visible: false }).dragAndDrop(`th:eq(2)`);
1366 const widthsAfterResize = getColumnWidths();
1367
1368 // 2. Column size should be the same after selecting a row
1369 await contains(`tbody .o_list_record_selector`).click();
1370 expect(getColumnWidths()).toEqual(widthsAfterResize, {
1371 message: "Width must not have been changed after selecting a row",
1372 });
1373 });
1374
1375 test(`resize column, then resize window`, async () => {
1376 await mountView({
1377 resModel: "foo",
1378 type: "list",
1379 arch: `
1380 <list>
1381 <field name="int_field"/>
1382 <field name="foo"/>
1383 </list>
1384 `,
1385 });
1386
1387 expect(getColumnWidths()).toEqual([40, 80, 680]);
1388
1389 // Resize column foo to middle of column int_field.
1390 await contains(`th:eq(1) .o_resize`, { visible: false }).dragAndDrop(`th:eq(2)`);
1391 expect(getColumnWidths()).toEqual([40, 520, 679]);
1392
1393 // Resize the window
1394 resize({ width: 1200 });
1395 await runAllTimers();
1396 await animationFrame();
1397 expect(getColumnWidths()).toEqual([40, 80, 1080]); // all available space should be used again
1398
1399 // Reduce size of column foo
1400 await contains(`th:eq(2) .o_resize`, { visible: false }).dragAndDrop(`th:eq(2)`);
1401 expect(getColumnWidths()).toEqual([40, 80, 591]);
1402
1403 // Resize the window
1404 resize({ width: 1000 });
1405 await runAllTimers();
1406 await animationFrame();
1407 expect(getColumnWidths()).toEqual([40, 80, 880]); // all available space should be used again
1408 });
1409
1410 test(`resize column and toggle check all`, async () => {
1411 await mountView({
1412 resModel: "foo",
1413 type: "list",
1414 arch: `
1415 <list>
1416 <field name="foo"/>
1417 <field name="int_field"/>
1418 </list>
1419 `,
1420 });
1421
1422 // 1. Resize column foo to middle of column int_field.
1423 await contains(`th:eq(1) .o_resize`, { visible: false }).dragAndDrop(`th:eq(2)`);
1424 const widthsAfterResize = getColumnWidths();
1425
1426 // 2. Column size should be the same after selecting all
1427 await contains(`thead .o_list_record_selector`).click();
1428 expect(getColumnWidths()).toEqual(widthsAfterResize, {
1429 message: "Width must not have been changed after selecting all",
1430 });
1431 });
1432
1433 test("resize column headers in editable list", async () => {
1434 await mountView({
1435 resModel: "foo",
1436 type: "list",
1437 arch: `
1438 <list editable="top">
1439 <field name="foo"/>
1440 <field name="reference" optional="hide"/>
1441 </list>
1442 `,
1443 });
1444
1445 const originalWidths = getColumnWidths();
1446
1447 await contains(`th:eq(1) .o_resize`, { visible: false }).dragAndDrop(`th:eq(2)`);
1448
1449 const finalWidths = getColumnWidths();
1450 expect(finalWidths[0]).toBe(originalWidths[0]);
1451 expect(finalWidths[1]).toBeGreaterThan(originalWidths[1]);
1452 expect(finalWidths[2]).toBe(originalWidths[2]);
1453 });
1454
1455 test("resize column headers in editable list (2)", async () => {
1456 // This test will ensure that, on resize list header,
1457 // the resized element have the correct size and other elements are not resized
1458 Foo._records[0].foo = "a".repeat(200);
1459
1460 await mountView({
1461 resModel: "foo",
1462 type: "list",
1463 arch: `
1464 <list editable="top">
1465 <field name="foo"/>
1466 <field name="bar"/>
1467 <field name="reference" optional="hide"/>
1468 </list>
1469 `,
1470 });
1471
1472 const originalWidths = getColumnWidths();
1473
1474 await contains(".o_resize:first", { visible: false }).dragAndDrop("th[data-name=foo]", {
1475 position: { x: 100 },
1476 relative: true,
1477 });
1478
1479 const finalWidths = getColumnWidths();
1480 expect(finalWidths[0]).toBe(originalWidths[0]);
1481 expect(finalWidths[1]).toBeCloseTo(100, { margin: 10 });
1482 expect(finalWidths[2]).toBe(originalWidths[2]);
1483 });
1484
1485 test(`resize column with several x2many lists in form group`, async () => {
1486 Bar._fields.text = fields.Char();
1487 Foo._records[0].o2m = [1, 2];
1488
1489 await mountView({
1490 resModel: "foo",
1491 type: "form",
1492 arch: `
1493 <form>
1494 <group>
1495 <field name="o2m">
1496 <list editable="bottom">
1497 <field name="display_name"/>
1498 <field name="text"/>
1499 </list>
1500 </field>
1501 <field name="m2m">
1502 <list editable="bottom">
1503 <field name="display_name"/>
1504 <field name="text"/>
1505 </list>
1506 </field>
1507 </group>
1508 </form>
1509 `,
1510 resId: 1,
1511 });
1512 const initialWidth0 = queryRect(`.o_field_x2many_list table:eq(0)`).width;
1513 const initialWidth1 = queryRect(`.o_field_x2many_list table:eq(1)`).width;
1514 expect(initialWidth0).toBe(initialWidth1, {
1515 message: "both table columns have same width",
1516 });
1517
1518 await contains(`th:eq(0) .o_resize`, { visible: false }).dragAndDrop(`th:eq(1)`, {
1519 position: "right",
1520 });
1521 expect(`.o_field_x2many_list table:eq(0)`).not.toHaveRect(
1522 { width: initialWidth0 },
1523 {
1524 message: "first o2m table is resized and width of table has changed",
1525 }
1526 );
1527 expect(`.o_field_x2many_list table:eq(1)`).toHaveRect(
1528 { width: initialWidth1 },
1529 {
1530 message: "second o2m table should not be impacted on first o2m in group resized",
1531 }
1532 );
1533 });
1534
1535 test(`resize column with x2many list with several fields in form notebook`, async () => {
1536 Foo._records[0].o2m = [1, 2];
1537
1538 await mountView({
1539 resModel: "foo",
1540 type: "form",
1541 arch: `
1542 <form>
1543 <sheet>
1544 <notebook>
1545 <page string="Page 1">
1546 <field name="o2m">
1547 <list editable="bottom">
1548 <field name="display_name"/>
1549 <field name="display_name"/>
1550 <field name="display_name"/>
1551 <field name="display_name"/>
1552 </list>
1553 </field>
1554 </page>
1555 </notebook>
1556 </sheet>
1557 </form>
1558 `,
1559 resId: 1,
1560 });
1561
1562 const listInitialWidth = queryRect(`.o_list_renderer`).width;
1563 await contains(`th:eq(0) .o_resize`, { visible: false }).dragAndDrop(`th:eq(1)`, {
1564 position: "right",
1565 });
1566 expect(`.o_list_renderer`).toHaveRect(
1567 { width: listInitialWidth },
1568 {
1569 message: "resizing the column should not impact the width of list",
1570 }
1571 );
1572 });
1573
1574 test(`resize: unnamed columns cannot be resized`, async () => {
1575 Foo._records = [{ id: 1, o2m: [1] }];
1576 Bar._records = [{ id: 1, display_name: "Oui" }];
1577
1578 await mountView({
1579 resModel: "foo",
1580 type: "form",
1581 arch: `
1582 <form>
1583 <sheet>
1584 <field name="o2m">
1585 <list editable="top">
1586 <field name="display_name"/>
1587 <button name="the_button" icon="fa-heart"/>
1588 </list>
1589 </field>
1590 </sheet>
1591 </form>
1592 `,
1593 resId: 1,
1594 });
1595 expect(Math.floor(queryRect(`.o_field_one2many th:eq(0)`).right)).toBe(
1596 Math.floor(queryRect(`.o_field_one2many th:eq(0) .o_resize`).right),
1597 {
1598 message: "First resize handle should be attached at the end of the first header",
1599 }
1600 );
1601 expect(`.o_field_one2many th:eq(1) .o_resize`).toHaveCount(0, {
1602 message: "Columns without name should not have a resize handle",
1603 });
1604 });
1605
1606 test(`dblclick on resize handle to force a recomputation of all widths`, async () => {
1607 await mountView({
1608 type: "list",
1609 resModel: "foo",
1610 arch: `
1611 <list>
1612 <field name="foo"/>
1613 <field name="int_field"/>
1614 </list>`,
1615 });
1616
1617 const originalWidths = getColumnWidths();
1618 await contains(`th:eq(1) .o_resize`, { visible: false }).dragAndDrop(`th:eq(2)`);
1619 const widthsAfterResize = getColumnWidths();
1620 expect(widthsAfterResize[0]).toBe(originalWidths[0]);
1621 expect(widthsAfterResize[1]).toBeGreaterThan(originalWidths[1]);
1622
1623 await contains(".o_list_table th .o_resize", { visible: false }).dblclick();
1624 expect(getColumnWidths()).toEqual(originalWidths);
1625 });