Debian Codegraph @

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

raw
1 import { expect, test, describe } from "@odoo/hoot";
2
3 import {
4 defineModels,
5 fields,
6 models,
7 mountView,
8 preloadBundle,
9 preventResizeObserverError,
10 } from "@web/../tests/web_test_helpers";
11
12 const INVALID_LOCATOR = ".invalid_locator";
13
14 class IrUiView extends models.Model {
15 _name = "ir.ui.view";
16 _rec_name = "name";
17
18 name = fields.Char({ required: true });
19 arch = fields.Text({});
20 invalid_locators = fields.Json();
21
22 _records = [
23 {
24 id: 1,
25 name: "Child View",
26 arch: `
27 <data>
28 <xpath expr="//field[@name='name']" position="after"/>
29 <xpath expr="//group" position="inside"/>
30 <xpath expr="//field[@name='inherit_id']" position="replace"/>
31 <xpath expr="//field[@name='non_existent_field']" position="after"/>
32 <xpath expr="//nonexistent_tag" position="inside"/>
33 <xpath expr="//field[@name='arch_invalid']" position="after"/>
34 <field name="invalid" position="replace"/>
35 </data>
36 `,
37 invalid_locators: false,
38 },
39 ];
40 }
41 defineModels([IrUiView]);
42
43 // Preload necessary bundles and prevent ResizeObserver errors
44 preloadBundle("web.ace_lib");
45 preventResizeObserverError();
46
47 const mountChildView = async () =>
48 await mountView({
49 resModel: "ir.ui.view",
50 resId: 1,
51 type: "form",
52 arch: `
53 <form>
54 <field name="invalid_locators"/>
55 <field name="arch" widget="code_ir_ui_view" options='{"mode": "xml"}'/>
56 </form>
57 `,
58 });
59
60 describe("Highlight invalid locators in inherited ir.ui.view", () => {
61 test("with no invalid locators", async () => {
62 await mountChildView();
63 expect(INVALID_LOCATOR).toHaveCount(0);
64 });
65
66 test("with invalid locators", async () => {
67 const invalid_locators = [
68 {
69 tag: "xpath",
70 attrib: {
71 expr: "//field[@name='non_existent_field']",
72 position: "after",
73 },
74 sourceline: 6,
75 },
76 {
77 tag: "xpath",
78 attrib: {
79 expr: "//nonexistent_tag",
80 position: "inside",
81 },
82 sourceline: 7,
83 },
84 {
85 tag: "xpath",
86 attrib: {
87 expr: "//field[@name='arch_invalid']",
88 position: "after",
89 },
90 sourceline: 8,
91 },
92 {
93 tag: "field",
94 attrib: {
95 name: "invalid",
96 position: "replace",
97 },
98 sourceline: 9,
99 },
100 ];
101 IrUiView._records[0].invalid_locators = invalid_locators;
102 await mountChildView();
103 expect(INVALID_LOCATOR).toHaveCount(invalid_locators.length);
104 });
105 });