Debian Codegraph @

addons/pos_sale/static/tests/unit/services/pos_store.test.js

raw symbols SCIP
1 import { test, expect, describe } from "@odoo/hoot";
2 import { setupPosEnv, getFilledOrder } from "@point_of_sale/../tests/unit/utils";
3 import { click, waitFor } from "@odoo/hoot-dom";
4 import { mountWithCleanup } from "@web/../tests/web_test_helpers";
5 import { ProductScreen } from "@point_of_sale/app/screens/product_screen/product_screen";
6 import { Orderline } from "@point_of_sale/app/components/orderline/orderline";
7 import { definePosModels } from "@point_of_sale/../tests/unit/data/generate_model_definitions";
8
9 definePosModels();
10
11 describe("onClickSaleOrder", () => {
12 test("no selection → abort", async () => {
13 const store = await setupPosEnv();
14 const order = await getFilledOrder(store);
15 await mountWithCleanup(ProductScreen, { props: { orderUuid: order.uuid } });
16
17 const promiseResult = store.onClickSaleOrder(1);
18 const button =
19 ".modal-header:has(.modal-title:contains('What do you want to do?')) button[aria-label='Close']";
20 await waitFor(button);
21 await click(button);
22
23 await promiseResult;
24
25 const currentOrder = store.getOrder();
26 expect(currentOrder.id).toBe(order.id);
27 expect(currentOrder.lines.length).toBe(2);
28
29 expect(currentOrder.lines[0].product_id.id).toBe(5);
30 expect(currentOrder.lines[0].qty).toBe(3);
31
32 expect(currentOrder.lines[1].product_id.id).toBe(6);
33 expect(currentOrder.lines[1].qty).toBe(2);
34 });
35
36 test("settle → calls settleSO", async () => {
37 const store = await setupPosEnv();
38 const order = await getFilledOrder(store);
39 await mountWithCleanup(ProductScreen, { props: { orderUuid: order.uuid } });
40
41 const promiseResult = store.onClickSaleOrder(1);
42 const button = ".modal-body button:contains('Settle the order')";
43 await waitFor(button);
44 await click(button);
45 await promiseResult;
46
47 const currentOrder = store.getOrder();
48
49 expect(currentOrder.id).toBe(order.id);
50 expect(currentOrder.lines.length).toBe(4);
51
52 expect(currentOrder.lines[0].product_id.id).toBe(5);
53 expect(currentOrder.lines[0].qty).toBe(3);
54 expect(currentOrder.lines[0].price_unit).toBe(3);
55 expect(currentOrder.lines[0].prices.total_excluded).toBe(9);
56
57 expect(currentOrder.lines[1].product_id.id).toBe(6);
58 expect(currentOrder.lines[1].qty).toBe(2);
59 expect(currentOrder.lines[1].price_unit).toBe(3);
60 expect(currentOrder.lines[1].prices.total_excluded).toBe(6);
61
62 expect(currentOrder.lines[2].product_id.id).toBe(5);
63 expect(currentOrder.lines[2].qty).toBe(5);
64 expect(currentOrder.lines[2].price_unit).toBe(100);
65 expect(currentOrder.lines[2].prices.total_excluded).toBe(500);
66
67 expect(currentOrder.lines[3].product_id.id).toBe(6);
68 expect(currentOrder.lines[3].qty).toBe(3);
69 expect(currentOrder.lines[3].price_unit).toBe(50);
70 expect(currentOrder.lines[3].prices.total_excluded).toBe(150);
71 });
72
73 test("dpPercentage → calls downPaymentSO", async () => {
74 const store = await setupPosEnv();
75 const order = await getFilledOrder(store);
76 await mountWithCleanup(ProductScreen, { props: { orderUuid: order.uuid } });
77
78 const promiseResult = store.onClickSaleOrder(1);
79 const buttonDownPaymentPercentage =
80 ".modal-body button:contains('Apply a down payment (percentage)')";
81 await waitFor(buttonDownPaymentPercentage);
82 await click(buttonDownPaymentPercentage);
83 await waitFor(".modal-title:contains('Down Payment')");
84 await click(".modal-body .numpad .numpad-button[value='+50']");
85 await new Promise((resolve) => setTimeout(resolve, 50));
86 await click(".modal-footer .btn:contains('Apply')");
87 await promiseResult;
88
89 const currentOrder = store.getOrder();
90 expect(currentOrder.id).toBe(order.id);
91 expect(currentOrder.lines.length).toBe(3);
92
93 expect(currentOrder.lines[0].product_id.id).toBe(5);
94 expect(currentOrder.lines[0].qty).toBe(3);
95 expect(currentOrder.lines[0].price_unit).toBe(3);
96 expect(currentOrder.lines[0].prices.total_excluded).toBe(9);
97
98 expect(currentOrder.lines[1].product_id.id).toBe(6);
99 expect(currentOrder.lines[1].qty).toBe(2);
100 expect(currentOrder.lines[1].price_unit).toBe(3);
101 expect(currentOrder.lines[1].prices.total_excluded).toBe(6);
102
103 expect(currentOrder.lines[2].product_id.id).toBe(105);
104 expect(currentOrder.lines[2].qty).toBe(1);
105 expect(currentOrder.lines[2].price_unit).toBe(325);
106 expect(currentOrder.lines[2].prices.total_excluded).toBe(325);
107
108 const comp = await mountWithCleanup(Orderline, {
109 props: { line: currentOrder.lines[2] },
110 });
111
112 const saleOrderInfo = ".orderline .info-list .sale-order-info";
113 const cell = (tr, td) => `${saleOrderInfo} tr:nth-child(${tr}) td:nth-child(${td})`;
114
115 expect(comp.line).toEqual(currentOrder.lines[2]);
116 expect(`${saleOrderInfo} tr`).toHaveCount(4);
117
118 expect(cell(1, 1)).toHaveText("5x");
119 expect(cell(1, 2)).toHaveText("TEST");
120 expect(cell(1, 4)).toHaveText(`$ 500.00 (tax incl.)`);
121
122 expect(cell(2, 1)).toHaveText("3x");
123 expect(cell(2, 2)).toHaveText("TEST 2");
124 expect(cell(2, 4)).toHaveText(`$ 150.00 (tax incl.)`);
125 });
126
127 test("dpAmount → calls downPaymentSO", async () => {
128 const store = await setupPosEnv();
129 const order = await getFilledOrder(store);
130 await mountWithCleanup(ProductScreen, { props: { orderUuid: order.uuid } });
131
132 const promiseResult = store.onClickSaleOrder(1);
133 const buttonDownPaymentPercentage =
134 ".modal-body button:contains('Apply a down payment (fixed amount)')";
135 await waitFor(buttonDownPaymentPercentage);
136 await click(buttonDownPaymentPercentage);
137 await waitFor(".modal-title:contains('Down Payment')");
138 await click(".modal-body .numpad .numpad-button[value='+50']");
139 await new Promise((resolve) => setTimeout(resolve, 50));
140 await click(".modal-footer .btn:contains('Apply')");
141 await promiseResult;
142
143 const currentOrder = store.getOrder();
144 expect(currentOrder.id).toBe(order.id);
145 expect(currentOrder.lines.length).toBe(3);
146
147 expect(currentOrder.lines[0].product_id.id).toBe(5);
148 expect(currentOrder.lines[0].qty).toBe(3);
149 expect(currentOrder.lines[0].price_unit).toBe(3);
150 expect(currentOrder.lines[0].prices.total_excluded).toBe(9);
151
152 expect(currentOrder.lines[1].product_id.id).toBe(6);
153 expect(currentOrder.lines[1].qty).toBe(2);
154 expect(currentOrder.lines[1].price_unit).toBe(3);
155 expect(currentOrder.lines[1].prices.total_excluded).toBe(6);
156
157 expect(currentOrder.lines[2].product_id.id).toBe(105);
158 expect(currentOrder.lines[2].qty).toBe(1);
159 expect(currentOrder.lines[2].price_unit).toBe(50);
160 expect(currentOrder.lines[2].prices.total_excluded).toBe(50);
161
162 const comp = await mountWithCleanup(Orderline, {
163 props: { line: currentOrder.lines[2] },
164 });
165
166 const saleOrderInfo = ".orderline .info-list .sale-order-info";
167 const cell = (tr, td) => `${saleOrderInfo} tr:nth-child(${tr}) td:nth-child(${td})`;
168
169 expect(comp.line).toEqual(currentOrder.lines[2]);
170 expect(`${saleOrderInfo} tr`).toHaveCount(4);
171
172 expect(cell(1, 1)).toHaveText("5x");
173 expect(cell(1, 2)).toHaveText("TEST");
174 expect(cell(1, 4)).toHaveText(`$ 500.00 (tax incl.)`);
175
176 expect(cell(2, 1)).toHaveText("3x");
177 expect(cell(2, 2)).toHaveText("TEST 2");
178 expect(cell(2, 4)).toHaveText(`$ 150.00 (tax incl.)`);
179 });
180 });