Debian Codegraph @

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

raw
1 import { expect, test } from "@odoo/hoot";
2 import { queryAllTexts } from "@odoo/hoot-dom";
3 import { onMounted } from "@odoo/owl";
4 import {
5 defineModels,
6 fields,
7 models,
8 mountView,
9 patchWithCleanup,
10 } from "@web/../tests/web_test_helpers";
11 import { GaugeField } from "@web/views/fields/gauge/gauge_field";
12 import { setupChartJsForTests } from "../graph/graph_test_helpers";
13
14 class Partner extends models.Model {
15 int_field = fields.Integer({ string: "int_field" });
16 another_int_field = fields.Integer({ string: "another_int_field" });
17 _records = [
18 { id: 1, int_field: 10, another_int_field: 45 },
19 { id: 2, int_field: 4, another_int_field: 10 },
20 ];
21 }
22
23 class User extends models.Model {
24 _name = "res.users";
25 has_group() {
26 return true;
27 }
28 }
29
30 defineModels([Partner, User]);
31
32 setupChartJsForTests();
33
34 test("GaugeField in kanban view", async () => {
35 await mountView({
36 type: "kanban",
37 resModel: "partner",
38 arch: /* xml */ `
39 <kanban>
40 <field name="another_int_field"/>
41 <templates>
42 <t t-name="card">
43 <field name="int_field" widget="gauge" options="{'max_field': 'another_int_field'}"/>
44 </t>
45 </templates>
46 </kanban>`,
47 });
48
49 expect(".o_kanban_record:not(.o_kanban_ghost)").toHaveCount(2);
50 expect(".o_field_widget[name=int_field] .oe_gauge canvas").toHaveCount(2);
51 expect(queryAllTexts(".o_gauge_value")).toEqual(["10", "4"]);
52 });
53
54 test("GaugeValue supports max_value option", async () => {
55 patchWithCleanup(GaugeField.prototype, {
56 setup() {
57 super.setup();
58 onMounted(() => {
59 expect.step("gauge mounted");
60 expect(this.chart.config.options.plugins.tooltip.callbacks.label({})).toBe(
61 "Max: 120"
62 );
63 });
64 },
65 });
66
67 Partner._records = Partner._records.slice(0, 1);
68
69 await mountView({
70 type: "kanban",
71 resModel: "partner",
72 arch: `
73 <kanban>
74 <templates>
75 <t t-name="card">
76 <div>
77 <field name="int_field" widget="gauge" options="{'max_value': 120}"/>
78 </div>
79 </t>
80 </templates>
81 </kanban>`,
82 });
83
84 expect.verifySteps(["gauge mounted"]);
85 expect(".o_field_widget[name=int_field] .oe_gauge canvas").toHaveCount(1);
86 expect(".o_gauge_value").toHaveText("10");
87 });