Debian Codegraph @

addons/web/static/tests/views/widgets/document_link.test.js

raw
1 import {
2 defineModels,
3 fields,
4 models,
5 mountView,
6 mountWithCleanup,
7 } from "@web/../tests/web_test_helpers";
8 import { Component, xml } from "@odoo/owl";
9 import { expect, test } from "@odoo/hoot";
10 import { DocumentationLink } from "@web/views/widgets/documentation_link/documentation_link";
11
12 class Partner extends models.Model {
13 bar = fields.Boolean();
14 }
15
16 defineModels([Partner]);
17
18 test("documentation_link: default label and icon", async () => {
19 await mountView({
20 type: "form",
21 resModel: "partner",
22 arch: /* xml */ `
23 <form>
24 <field name="bar"/>
25 <widget name="documentation_link" path="/this_is_a_test.html"/>
26 </form>`,
27 });
28 expect(".o_doc_link").toHaveText("View Documentation");
29 expect("a.alert-link").toHaveCount(0);
30 expect(".o_doc_link .fa-external-link").toHaveCount(1);
31 });
32
33 test("documentationLink: alert-link", async () => {
34 await mountView({
35 type: "form",
36 resModel: "partner",
37 arch: /* xml */ `
38 <form>
39 <field name="bar"/>
40 <widget name="documentation_link" path="/this_is_a_test.html" alert_link="true"/>
41 </form>`,
42 });
43 expect("a.alert-link").toHaveCount(1);
44 });
45
46 test("DocumentationLink Component: alert-link", async () => {
47 class Parent extends Component {
48 static components = { DocumentationLink };
49 static template = xml`
50 <DocumentationLink path="'/this_is_a_test.html'" alertLink="true"/>`;
51 static props = ["*"];
52 }
53 await mountWithCleanup(Parent);
54 expect("a.alert-link").toHaveCount(1);
55 });
56
57 test("documentation_link: given label", async () => {
58 await mountView({
59 type: "form",
60 resModel: "partner",
61 arch: /* xml */ `
62 <form>
63 <field name="bar"/>
64 <widget name="documentation_link" path="/this_is_a_test.html" label="docdoc"/>
65 </form>`,
66 });
67 expect(".o_doc_link").toHaveText("docdoc");
68 expect(".o_doc_link .fa").toHaveCount(0);
69 });
70
71 test("documentation_link: given icon", async () => {
72 await mountView({
73 type: "form",
74 resModel: "partner",
75 arch: /* xml */ `
76 <form>
77 <field name="bar"/>
78 <widget name="documentation_link" path="/this_is_a_test.html" icon="fa-question-circle"/>
79 </form>`,
80 });
81 expect(".o_doc_link").toHaveText("");
82 expect(".o_doc_link .fa-question-circle").toHaveCount(1);
83 });
84
85 test("documentation_link: given label and icon", async () => {
86 await mountView({
87 type: "form",
88 resModel: "partner",
89 arch: /* xml */ `
90 <form>
91 <field name="bar"/>
92 <widget name="documentation_link" path="/this_is_a_test.html" label="docdoc" icon="fa-question-circle"/>
93 </form>`,
94 });
95 expect(".o_doc_link").toHaveText("docdoc");
96 expect(".o_doc_link .fa-question-circle").toHaveCount(1);
97 });
98
99 test("documentation_link: relative path", async () => {
100 await mountView({
101 type: "form",
102 resModel: "partner",
103 arch: /* xml */ `
104 <form>
105 <field name="bar"/>
106 <widget name="documentation_link" path="/applications/technical/web/settings/this_is_a_test.html"/>
107 </form>`,
108 });
109 expect(".o_doc_link").toHaveAttribute(
110 "href",
111 "https://www.odoo.com/documentation/1.0/applications/technical/web/settings/this_is_a_test.html"
112 );
113 });
114
115 test("documentation_link: absolute path (http)", async () => {
116 await mountView({
117 type: "form",
118 resModel: "partner",
119 arch: /* xml */ `
120 <form>
121 <field name="bar"/>
122 <widget name="documentation_link" path="http://www.odoo.com/"/>
123 </form>`,
124 });
125 expect(".o_doc_link").toHaveAttribute("href", "http://www.odoo.com/");
126 });
127
128 test("documentation_link: absolute path (https)", async () => {
129 await mountView({
130 type: "form",
131 resModel: "partner",
132 arch: /* xml */ `
133 <form>
134 <field name="bar"/>
135 <widget name="documentation_link" path="https://www.odoo.com/"/>
136 </form>`,
137 });
138
139 expect(".o_doc_link").toHaveAttribute("href", "https://www.odoo.com/");
140 });