Debian Codegraph @

addons/point_of_sale/static/tests/pos/tours/utils/receipt_screen_util.js

raw
1 export function clickNextOrder() {
2 return [
3 {
4 isActive: ["desktop"],
5 content: "go to next screen",
6 trigger: ".receipt-screen .button.next.highlight[name='done']",
7 run: "click",
8 },
9 {
10 isActive: ["mobile"],
11 content: "go to next screen",
12 trigger: ".receipt-screen .btn-switchpane.validation-button.highlight[name='done']",
13 run: "click",
14 },
15 ];
16 }
17 export function clickContinueOrder() {
18 return [
19 {
20 content: "go to next screen",
21 trigger: ".receipt-screen .button.next.highlight[name='resume']",
22 run: "click",
23 },
24 ];
25 }
26 export function setEmail(email) {
27 return [
28 {
29 trigger: ".receipt-screen .send-receipt-email-input",
30 run: `edit ${email}`,
31 },
32 ];
33 }
34 export function clickSend() {
35 return [
36 {
37 run: "click",
38 trigger: `.receipt-screen button i.fa-paper-plane`,
39 },
40 ];
41 }
42 export function clickBack() {
43 return [
44 {
45 trigger: ".receipt-screen .button.back",
46 run: "click",
47 },
48 ];
49 }
50
51 export function isShown() {
52 return [
53 {
54 content: "receipt screen is shown",
55 trigger: ".pos .receipt-screen",
56 },
57 ];
58 }
59 export function receiptIsThere() {
60 return [
61 {
62 content: "there should be the receipt",
63 trigger: ".receipt-screen .pos-receipt",
64 },
65 ];
66 }
67 export function totalAmountContains(value) {
68 return [
69 {
70 isActive: ["desktop"], // not rendered on mobile
71 trigger: `.receipt-screen .o_payment_successful:contains("${value}")`,
72 },
73 {
74 isActive: ["mobile"], // On mobile, at least wait for the receipt screen to show
75 trigger: `.receipt-screen`,
76 },
77 ];
78 }
79 export function receiptAmountTotalIs(value) {
80 return [
81 {
82 isActive: ["desktop"], // not rendered on mobile
83 trigger: `.receipt-screen .receipt-total:contains("${value}")`,
84 },
85 {
86 isActive: ["mobile"], // On mobile, at least wait for the receipt screen to show
87 trigger: `.receipt-screen`,
88 },
89 ];
90 }
91 export function receiptRoundingAmountIs(value) {
92 return [
93 {
94 isActive: ["desktop"], // not rendered on mobile
95 trigger: `.receipt-screen .receipt-rounding:contains("${value}")`,
96 },
97 ];
98 }
99 export function paymentLineContains(paymentMethodName, amount) {
100 return [
101 {
102 content: `Check if payment line contains ${paymentMethodName} with amount ${amount}`,
103 trigger: `.receipt-screen .paymentlines:contains("${paymentMethodName}"):has(.pos-receipt-right-align:contains("${amount}"))`,
104 },
105 ];
106 }
107 export function receiptToPayAmountIs(value) {
108 return [
109 {
110 isActive: ["desktop"], // not rendered on mobile
111 trigger: `.receipt-screen .receipt-to-pay:contains("${value}")`,
112 },
113 ];
114 }
115 export function receiptToPayAmountIsNotThere() {
116 return [
117 {
118 isActive: ["desktop"], // not rendered on mobile
119 trigger: ".receipt-screen",
120 run: function () {
121 if (document.querySelector(".receipt-to-pay")) {
122 throw new Error("An amount to pay has been found in receipt.");
123 }
124 },
125 },
126 ];
127 }
128 export function receiptChangeAmountIs(value) {
129 return [
130 {
131 isActive: ["desktop"], // not rendered on mobile
132 trigger: `.receipt-screen .receipt-change:contains("${value}")`,
133 },
134 ];
135 }
136 export function receiptChangeAmountIsNotThere() {
137 return [
138 {
139 isActive: ["desktop"], // not rendered on mobile
140 trigger: ".receipt-screen",
141 run: function () {
142 if (document.querySelector(".receipt-change")) {
143 throw new Error("An change amount has been found in receipt.");
144 }
145 },
146 },
147 ];
148 }
149 export function emailIsSuccessful() {
150 return [
151 {
152 trigger: `.receipt-screen .notice .text-success`,
153 },
154 ];
155 }
156 export function trackingMethodIsLot(lot) {
157 return [
158 {
159 content: `tracking method is Lot`,
160 trigger: `li.lot-number:contains("Lot Number ${lot}")`,
161 run: function () {
162 if (document.querySelectorAll("li.lot-number").length !== 1) {
163 throw new Error(`Expected exactly one 'Lot Number ${lot}' element.`);
164 }
165 },
166 },
167 ];
168 }
169
170 export function noDiscountAmount() {
171 return [
172 {
173 trigger: `.pos-receipt:not(:contains("Discounts"))`,
174 run: () => {},
175 },
176 ];
177 }
178
179 export function shippingDateExists() {
180 return [
181 {
182 content: "Shipping date must be printed",
183 trigger: ".pos-receipt-order-data:contains('Expected delivery:')",
184 run: "click",
185 },
186 ];
187 }
188
189 export function shippingDateIsToday() {
190 // format the date in US, the language used by the tests
191 const expectedDelivery = new Date().toLocaleString("en-US", luxon.DateTime.DATE_SHORT);
192
193 return [
194 {
195 content: "Shipping date must be today",
196 trigger: `.pos-receipt-order-data:contains('Expected delivery:') > div:contains('${expectedDelivery}')`,
197 },
198 ];
199 }
200
201 export function cashierNameExists(name) {
202 return [
203 {
204 content: `Cashier ${name} exists on the receipt`,
205 trigger: `.pos-receipt-contact .cashier:contains(Served by):contains(${name})`,
206 },
207 ];
208 }
209
210 export function containsOrderLine(name, quantity, price_unit, line_price) {
211 return [
212 {
213 content: `Order line with name: ${name}, quantity: ${quantity}, price per unit: ${price_unit}, and line price: ${line_price} exists`,
214 trigger: `.pos-receipt .orderline:has(.product-name:contains('${name}')):has(.qty:contains('${quantity}')):has(.product-price:contains('${line_price}')):has(.price-per-unit:contains('${price_unit}'))`,
215 },
216 ];
217 }