Debian Codegraph @

addons/web/static/tests/views/fields/handle_field.test.js

raw
1 import { expect, test } from "@odoo/hoot";
2 import { click, queryFirst } from "@odoo/hoot-dom";
3 import { animationFrame } from "@odoo/hoot-mock";
4 import {
5 defineModels,
6 fields,
7 MockServer,
8 models,
9 mountView,
10 onRpc,
11 } from "@web/../tests/web_test_helpers";
12
13 class Partner extends models.Model {
14 display_name = fields.Char({ string: "Displayed name", searchable: true });
15 p = fields.One2many({ string: "one2many field", relation: "partner", searchable: true });
16 sequence = fields.Integer({ string: "Sequence", searchable: true });
17 _records = [
18 {
19 id: 1,
20 display_name: "first record",
21 p: [],
22 },
23 {
24 id: 2,
25 display_name: "second record",
26 p: [],
27 sequence: 4,
28 },
29 {
30 id: 4,
31 display_name: "aaa",
32 sequence: 9,
33 },
34 ];
35 }
36 defineModels([Partner]);
37
38 test("HandleField in x2m", async () => {
39 Partner._records[0].p = [2, 4];
40 await mountView({
41 type: "form",
42 resModel: "partner",
43 resId: 1,
44 arch: /* xml */ `
45 <form>
46 <field name="p">
47 <list editable="bottom">
48 <field name="sequence" widget="handle" />
49 <field name="display_name" />
50 </list>
51 </field>
52 </form>`,
53 });
54
55 expect("td span.o_row_handle").toHaveText("", {
56 message: "handle should not have any content",
57 });
58 expect(queryFirst("td span.o_row_handle")).toBeVisible({
59 message: "handle should be invisible",
60 });
61
62 expect("span.o_row_handle").toHaveCount(2, { message: "should have 2 handles" });
63
64 expect(queryFirst("td")).toHaveClass("o_handle_cell", {
65 message: "column widget should be displayed in css class",
66 });
67 await click("td:eq(1)");
68 await animationFrame();
69
70 expect("td:eq(0) span.o_row_handle").toHaveCount(1, {
71 message: "content of the cell should have been replaced",
72 });
73 });
74
75 test("HandleField with falsy values", async () => {
76 onRpc("has_group", () => true);
77 await mountView({
78 type: "list",
79 resModel: "partner",
80 arch: /* xml */ `
81 <list>
82 <field name="sequence" widget="handle" />
83 <field name="display_name" />
84 </list>`,
85 });
86
87 expect(".o_row_handle:visible").toHaveCount(MockServer.env["partner"].length, {
88 message: "there should be a visible handle for each record",
89 });
90 });
91
92 test("HandleField in a readonly one2many", async () => {
93 Partner._records[0].p = [1, 2, 4];
94
95 await mountView({
96 type: "form",
97 resModel: "partner",
98 arch: /* xml */ `
99 <form>
100 <field name="p" readonly="1">
101 <list editable="top">
102 <field name="sequence" widget="handle" />
103 <field name="display_name" />
104 </list>
105 </field>
106 </form>`,
107 resId: 1,
108 });
109
110 expect(".o_row_handle.o_disabled").toHaveCount(3, {
111 message: "there should be 3 handles but they should be disabled from readonly",
112 });
113 });