Debian Codegraph @

addons/lunch/static/tests/lunch_is_favorite_field.test.js

raw symbols SCIP
1 import { defineMailModels } from "@mail/../tests/mail_test_helpers";
2 import { expect, test } from "@odoo/hoot";
3 import { click } from "@odoo/hoot-dom";
4 import { animationFrame } from "@odoo/hoot-mock";
5 import { defineModels, fields, models, mountView, onRpc } from "@web/../tests/web_test_helpers";
6
7 class LunchProduct extends models.Model {
8 _name = "lunch.product";
9
10 name = fields.Char();
11 is_favorite = fields.Boolean();
12
13 _records = [
14 {
15 id: 1,
16 name: "Product A",
17 },
18 ];
19
20 _views = {
21 kanban: `
22 <kanban class="o_kanban_test" edit="0">
23 <template>
24 <t t-name="card">
25 <field name="is_favorite" widget="lunch_is_favorite" nolabel="1"/>
26 <field name="name"/>
27 </t>
28 </template>
29 </kanban>
30 `,
31 };
32 }
33
34 defineMailModels();
35 defineModels([LunchProduct]);
36
37 test("Check is_favorite field is still editable even if the record/view is in readonly.", async () => {
38 onRpc("lunch.product", "web_save", ({ args }) => {
39 const [ids, vals] = args;
40 expect(ids).toEqual([1]);
41 expect(vals).toEqual({ is_favorite: true });
42 expect.step("web_save");
43 });
44
45 await mountView({
46 resModel: "lunch.product",
47 type: "kanban",
48 });
49
50 expect("div[name=is_favorite] .o_favorite").toHaveCount(1);
51 expect.verifySteps([]);
52 await click("div[name=is_favorite] .o_favorite");
53 await animationFrame();
54 expect.verifySteps(["web_save"]);
55 });
56
57 test("Check is_favorite field is readonly if the field is readonly", async () => {
58 onRpc("lunch.product", "web_save", () => {
59 expect.step("web_save");
60 });
61
62 LunchProduct._views["kanban"] = LunchProduct._views["kanban"].replace(
63 'widget="lunch_is_favorite"',
64 'widget="lunch_is_favorite" readonly="1"'
65 );
66
67 await mountView({
68 resModel: "lunch.product",
69 type: "kanban",
70 });
71
72 expect("div[name=is_favorite] .o_favorite").toHaveCount(1);
73 expect.verifySteps([]);
74 await click("div[name=is_favorite] .o_favorite");
75 await animationFrame();
76 expect.verifySteps([]);
77 });