Debian Codegraph @

addons/hr_timesheet/static/tests/timesheet_uom_no_toggle.test.js

raw
1 import { beforeEach, expect, test } from "@odoo/hoot";
2 import { mountView, serverState } from "@web/../tests/web_test_helpers";
3
4 import { HRTimesheet, defineTimesheetModels, patchSession } from "./hr_timesheet_models";
5
6 HRTimesheet._views.form = `
7 <form>
8 <field name="project_id"/>
9 <field name="task_id"/>
10 <field name="unit_amount" widget="timesheet_uom_no_toggle"/>
11 </form>
12 `;
13 defineTimesheetModels();
14
15 beforeEach(patchSession);
16
17 test("hr.timesheet (form): FloatTimeField is used when current company uom uses float_time widget", async () => {
18 await mountView({
19 type: "form",
20 resModel: "account.analytic.line",
21 resId: 1,
22 });
23 expect('div[name="unit_amount"] input').toHaveValue("01:00", {
24 message: "unit_amount should be displayed as time",
25 });
26 });
27
28 test("hr.timesheet (form): FloatTimeField is not dependent of timesheet_uom_factor of the current company when current company uom uses float_time widget", async () => {
29 serverState.companies[0].timesheet_uom_factor = 2;
30 await mountView({
31 type: "form",
32 resModel: "account.analytic.line",
33 resId: 1,
34 });
35 expect('div[name="unit_amount"] input').toHaveValue("01:00", {
36 message: "timesheet_uom_factor shouldn't be taken into account",
37 });
38 });
39
40 test("hr.timesheet (form): FloatToggleField is not used when current company uom uses float_toggle widget, FloatFactorField is used instead", async () => {
41 serverState.companies[0].timesheet_uom_id = 2;
42 await mountView({
43 type: "form",
44 resModel: "account.analytic.line",
45 resId: 1,
46 });
47 expect('div[name="unit_amount"] .o_field_float_toggle').not.toHaveCount(null, {
48 message: "unit_amount shouldn't be displayed as float toggle",
49 });
50 expect('div[name="unit_amount"] input[inputmode="decimal"]').toBeVisible({
51 message: "unit_amount should be displayed as float",
52 });
53 expect('div[name="unit_amount"] input').toHaveValue("1.00", {
54 message: "unit_amount shouldn't be displayed as float and not as time",
55 });
56 });
57
58 test("FloatFactorField is used when the current_company uom is not part of the session uom", async () => {
59 serverState.companies[0].timesheet_uom_id = "dummy";
60 await mountView({
61 type: "form",
62 resModel: "account.analytic.line",
63 resId: 1,
64 });
65 expect('div[name="unit_amount"] input[inputmode="decimal"]').toBeVisible({
66 message: "unit_amount should be displayed as float",
67 });
68 expect('div[name="unit_amount"] input').toHaveValue("1.00", {
69 message: "unit_amount shouldn't be displayed as float and not as time",
70 });
71 expect('div[name="unit_amount"].o_field_float_toggle').not.toHaveCount(null, {
72 message: "unit_amount shouldn't be displayed as float toggle",
73 });
74 });
75
76 test("FloatFactorField is dependent of timesheet_uom_factor of the current company when current company uom uses float_toggle widget", async () => {
77 serverState.companies[0].timesheet_uom_id = "dummy";
78 serverState.companies[0].timesheet_uom_factor = 2;
79 await mountView({
80 type: "form",
81 resModel: "account.analytic.line",
82 resId: 1,
83 });
84 expect('div[name="unit_amount"] input').toHaveValue("2.00", {
85 message: "timesheet_uom_factor should be taken into account",
86 });
87 });