Debian Codegraph @

addons/hr_timesheet/static/tests/timesheet_uom.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"/>
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 used when current company uom uses float_toggle widget", 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').toBeVisible({
48 message: "unit_amount should be displayed as float toggle",
49 });
50 });
51
52 test("hr.timesheet (form): FloatToggleField is dependent on timesheet_uom_factor of the current company when current company uom uses float_toggle widget", async () => {
53 serverState.companies[0].timesheet_uom_id = 2;
54 serverState.companies[0].timesheet_uom_factor = 2;
55 await mountView({
56 type: "form",
57 resModel: "account.analytic.line",
58 resId: 1,
59 });
60 expect('div[name="unit_amount"] .o_field_float_toggle').toBeVisible({
61 message: "timesheet_uom_factor should be taken into account",
62 });
63 });
64
65 test("hr.timesheet (form): FloatFactorField is used when the current_company uom is not part of the session uom", async () => {
66 serverState.companies[0].timesheet_uom_id = "dummy";
67 await mountView({
68 type: "form",
69 resModel: "account.analytic.line",
70 resId: 1,
71 });
72 expect('div[name="unit_amount"] input[inputmode="decimal"]').toBeVisible({
73 message: "unit_amount is displayed as float",
74 });
75 expect('div[name="unit_amount"] input').toHaveValue("1.00", {
76 message: "unit_amount is not displayed as float and not as time",
77 });
78 expect('div[name="unit_amount"].o_field_float_toggle').not.toHaveCount(null, {
79 message: "unit_amount is not displayed as float toggle",
80 });
81 });
82
83 test("hr.timesheet (form): FloatFactorField is dependent on timesheet_uom_factor of the current company when current company uom uses float_toggle widget", async () => {
84 serverState.companies[0].timesheet_uom_id = "dummy";
85 serverState.companies[0].timesheet_uom_factor = 2;
86 await mountView({
87 type: "form",
88 resModel: "account.analytic.line",
89 resId: 1,
90 });
91 expect('div[name="unit_amount"] input').toHaveValue("2.00", {
92 message: "timesheet_uom_factor is taken into account",
93 });
94 });