Debian Codegraph @

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

raw
1 import { expect, test } from "@odoo/hoot";
2 import {
3 clickSave,
4 contains,
5 defineModels,
6 fields,
7 models,
8 mountView,
9 onRpc,
10 } from "@web/../tests/web_test_helpers";
11
12 class Partner extends models.Model {
13 qux = fields.Float();
14
15 _records = [{ id: 5, qux: 9.1 }];
16 }
17
18 defineModels([Partner]);
19
20 test("FloatTimeField in form view", async () => {
21 expect.assertions(4);
22 onRpc("partner", "web_save", ({ args }) => {
23 // 48 / 60 = 0.8
24 expect(args[1].qux).toBe(-11.8, {
25 message: "the correct float value should be saved",
26 });
27 });
28
29 await mountView({
30 type: "form",
31 resModel: "partner",
32 arch: `
33 <form>
34 <sheet>
35 <field name="qux" widget="float_time"/>
36 </sheet>
37 </form>`,
38 resId: 5,
39 });
40
41 // 9 + 0.1 * 60 = 9.06
42 expect(".o_field_float_time[name=qux] input").toHaveValue("09:06", {
43 message: "The value should be rendered correctly in the input.",
44 });
45
46 await contains(".o_field_float_time[name=qux] input").edit("-11:48");
47 expect(".o_field_float_time[name=qux] input").toHaveValue("-11:48", {
48 message: "The new value should be displayed properly in the input.",
49 });
50
51 await clickSave();
52 expect(".o_field_widget input").toHaveValue("-11:48", {
53 message: "The new value should be saved and displayed properly.",
54 });
55 });
56
57 test("FloatTimeField value formatted on blur", async () => {
58 expect.assertions(4);
59 onRpc("partner", "web_save", ({ args }) => {
60 expect(args[1].qux).toBe(9.5, {
61 message: "the correct float value should be saved",
62 });
63 });
64 await mountView({
65 type: "form",
66 resModel: "partner",
67 arch: `
68 <form>
69 <field name="qux" widget="float_time"/>
70 </form>`,
71 resId: 5,
72 });
73
74 expect(".o_field_widget input").toHaveValue("09:06", {
75 message: "The formatted time value should be displayed properly.",
76 });
77
78 await contains(".o_field_float_time[name=qux] input").edit("9.5");
79 expect(".o_field_float_time[name=qux] input").toHaveValue("09:30", {
80 message: "The new value should be displayed properly in the input.",
81 });
82
83 await clickSave();
84 expect(".o_field_widget input").toHaveValue("09:30", {
85 message: "The new value should be saved and displayed properly.",
86 });
87 });
88
89 test("FloatTimeField with invalid value", async () => {
90 await mountView({
91 type: "form",
92 resModel: "partner",
93 arch: `
94 <form>
95 <field name="qux" widget="float_time"/>
96 </form>`,
97 });
98
99 await contains(".o_field_float_time[name=qux] input").edit("blabla");
100 await clickSave();
101 expect(".o_notification_content").toHaveText("Missing required fields");
102 expect(".o_notification_bar").toHaveClass("bg-danger");
103 expect(".o_field_float_time[name=qux]").toHaveClass("o_field_invalid");
104
105 await contains(".o_field_float_time[name=qux] input").edit("6.5");
106 expect(".o_field_float_time[name=qux] input").not.toHaveClass("o_field_invalid", {
107 message: "date field should not be displayed as invalid now",
108 });
109 });
110
111 test("float_time field does not have an inputmode attribute", async () => {
112 await mountView({
113 type: "form",
114 resModel: "partner",
115 arch: `
116 <form>
117 <field name="qux" widget="float_time"/>
118 </form>`,
119 });
120
121 expect(".o_field_widget[name='qux'] input").not.toHaveAttribute("inputmode");
122 });