Debian Codegraph @

addons/pos_loyalty/static/tests/tours/utils/pos_loyalty_util.js

raw
1 import * as Order from "@point_of_sale/../tests/generic_helpers/order_widget_util";
2 import * as ProductScreen from "@point_of_sale/../tests/pos/tours/utils/product_screen_util";
3 import * as TextInputPopup from "@point_of_sale/../tests/generic_helpers/text_input_popup_util";
4 import * as PaymentScreen from "@point_of_sale/../tests/pos/tours/utils/payment_screen_util";
5 import * as ReceiptScreen from "@point_of_sale/../tests/pos/tours/utils/receipt_screen_util";
6 import * as Dialog from "@point_of_sale/../tests/generic_helpers/dialog_util";
7 import { negate } from "@point_of_sale/../tests/generic_helpers/utils";
8 import * as Chrome from "@point_of_sale/../tests/pos/tours/utils/chrome_util";
9
10 export function selectRewardLine(rewardName) {
11 return [
12 ...Order.hasLine({
13 withClass: ".fst-italic",
14 withoutClass: ".selected",
15 run: "click",
16 productName: rewardName,
17 }),
18 ...Order.hasLine({
19 withClass: ".selected.fst-italic",
20 productName: rewardName,
21 }),
22 ];
23 }
24 export function enterCode(code) {
25 return [
26 ...ProductScreen.clickControlButton("Enter Code"),
27 TextInputPopup.inputText(code),
28 Dialog.confirm(),
29 ];
30 }
31 export function clickEWalletButton(text = "eWallet") {
32 return [{ trigger: ProductScreen.controlButtonTrigger(text), run: "click" }];
33 }
34 export function claimReward(rewardName) {
35 return [
36 ...ProductScreen.clickControlButton("Reward"),
37 {
38 // There should be description because a program always has a name.
39 trigger: ".selection-item span:nth-child(2)",
40 },
41 {
42 content: "select reward",
43 trigger: `.selection-item:contains("${rewardName}")`,
44 run: "click",
45 },
46 ];
47 }
48 export function unselectPartner() {
49 return [{ trigger: ".unselect-tag", run: "click" }];
50 }
51 export function clickDiscountButton() {
52 return [
53 ...ProductScreen.clickControlButtonMore(),
54 {
55 content: "click discount button",
56 trigger: ".js_discount",
57 run: "click",
58 },
59 ];
60 }
61 export function hasRewardLine(rewardName, amount, qty) {
62 return Order.hasLine({
63 withClass: ".fst-italic",
64 productName: rewardName,
65 price: amount,
66 quantity: qty,
67 });
68 }
69 export function orderTotalIs(total_str) {
70 return [...Order.hasTotal(total_str)];
71 }
72 export function isRewardButtonHighlighted(isHighlighted, closeModal = true) {
73 const steps = [
74 ...ProductScreen.clickControlButtonMore(),
75 {
76 trigger: isHighlighted
77 ? '.control-buttons button.highlight:contains("Reward")'
78 : '.control-buttons button.disabled:contains("Reward")',
79 },
80 ];
81 if (closeModal) {
82 steps.push({
83 content: "Close modal after checked if reward button is highlighted",
84 trigger: ".modal header .btn-close",
85 run: "click",
86 });
87 }
88 return steps;
89 }
90 export function eWalletButtonState({ highlighted, text = "eWallet", click = false }) {
91 const step = {
92 trigger: highlighted
93 ? `.control-buttons button.highlight:contains("${text}")`
94 : `.control-buttons button.disabled:contains("${text}")`,
95 };
96 if (click) {
97 step.run = "click";
98 }
99 const steps = [...ProductScreen.clickControlButtonMore(), step];
100 if (!click) {
101 steps.push({
102 //Previous step is just a check. No need to keep modal openened
103 trigger: ".modal header .btn-close",
104 run: "click",
105 });
106 }
107 return steps;
108 }
109 export function customerIs(name) {
110 return [
111 {
112 trigger: `.product-screen .set-partner:contains("${name}")`,
113 },
114 ];
115 }
116 export function isPointsDisplayed(isDisplayed) {
117 return [
118 {
119 trigger: isDisplayed
120 ? ".loyalty-points-title"
121 : "body:not(:has(.loyalty-points-title))",
122 },
123 ];
124 }
125 export function pointsAwardedAre(points_str) {
126 return [
127 {
128 content: "loyalty points awarded " + points_str,
129 trigger: '.loyalty-points-won:contains("' + points_str + '")',
130 },
131 ];
132 }
133 export function pointsTotalIs(points_str) {
134 return [
135 {
136 content: "loyalty points awarded " + points_str,
137 trigger: '.loyalty-points-totaltext-end:contains("' + points_str + '")',
138 },
139 ];
140 }
141 export function finalizeOrder(paymentMethod, amount) {
142 return [
143 ...ProductScreen.clickPayButton(),
144 ...PaymentScreen.clickPaymentMethod(paymentMethod),
145 ...PaymentScreen.clickNumpad([...amount].join(" ")),
146 ...PaymentScreen.clickValidate(),
147 ...ReceiptScreen.clickNextOrder(),
148 ];
149 }
150 export function removeRewardLine(name) {
151 return [selectRewardLine(name), ProductScreen.clickNumpad("⌫"), Dialog.confirm()].flat();
152 }
153
154 export function checkAddedLoyaltyPoints(points) {
155 return [
156 {
157 trigger: `.loyalty-points-won:contains("${points}")`,
158 },
159 ];
160 }
161
162 export function useExistingLoyaltyCard(code, valid = true) {
163 const steps = [
164 {
165 trigger: `a:contains("Sell physical gift card?")`,
166 run: "click",
167 },
168 {
169 content: `Input code '${code}'`,
170 trigger: `input[id="code"]`,
171 run: `edit ${code}`,
172 },
173 {
174 content: "Not loading",
175 trigger: negate(".gift-card-loading"),
176 },
177 ];
178
179 if (!valid) {
180 steps.push(Dialog.confirm("Ok"));
181 steps.push(Dialog.cancel());
182 steps.push({
183 trigger: `a:contains("Sell physical gift card?")`,
184 run: () => {},
185 });
186 } else {
187 steps.push(...Chrome.waitRequest());
188 steps.push(Dialog.confirm());
189 }
190
191 return steps;
192 }
193
194 export function createManualGiftCard(code, amount, date = false) {
195 const steps = [
196 {
197 trigger: `a:contains("Sell physical gift card?")`,
198 run: "click",
199 },
200 {
201 content: `Input code '${code}'`,
202 trigger: `input[id="code"]`,
203 run: `edit ${code}`,
204 },
205 {
206 content: `Input amount '${amount}'`,
207 trigger: `input[id="amount"]`,
208 run: `edit ${amount}`,
209 },
210 ];
211 if (date !== false) {
212 steps.push({
213 content: `Input date '${date}'`,
214 trigger: `.modal input.o_datetime_input.cursor-pointer.form-control.form-control-lg`,
215 run: `edit ${date}`,
216 });
217 }
218 steps.push({
219 trigger: `.btn-primary:contains("Add Balance")`,
220 run: "click",
221 });
222 return steps;
223 }
224
225 export function clickGiftCardProgram(name) {
226 return [
227 {
228 content: `Click gift card program '${name}'`,
229 trigger: `button.selection-item:has(span:contains("${name}"))`,
230 run: "click",
231 },
232 ];
233 }
234
235 export function clickPhysicalGiftCard(code = "Sell physical gift card?") {
236 return [
237 {
238 trigger: `ul.info-list .text-wrap:contains("${code}")`,
239 run: "click",
240 },
241 ];
242 }
243
244 export function checkPartnerPoints(name, points) {
245 return [
246 ...ProductScreen.clickPartnerButton(),
247 {
248 content: `Check '${name}' has ${points} Loyalty Points`,
249 trigger: `.partner-list .partner-line:contains(${name}) .partner-line-balance:contains(${points} Loyalty Point(s))`,
250 },
251 ];
252 }
253
254 export function isMoreControlButtonActive(active) {
255 return {
256 content: "More control button is " + (active ? "active" : "not active"),
257 trigger: active
258 ? ".control-buttons .more-btn.active"
259 : ".control-buttons:not(:has(.more-btn.active))",
260 };
261 }
262 export function isLoyaltyPointsAvailable() {
263 return {
264 content: "Loyalty Points are visible on the receipt",
265 trigger: ".pos-receipt .loyalty",
266 };
267 }