Debian Codegraph @

addons/point_of_sale/static/tests/generic_helpers/order_widget_util.js

raw
1 import { negate } from "@point_of_sale/../tests/generic_helpers/utils";
2 /**
3 * @typedef {{
4 * withClass?: string, // ex: withClass: ".selected.blue"
5 * withoutClass?: string,
6 * run?: function | string,
7 * productName?: string,
8 * quantity?: string,
9 * price?: string,
10 * customerNote?: string,
11 * comboParent?: string,
12 * }} LineOptions
13 */
14
15 /**
16 * @param {LineOptions} options
17 * @returns {import("@web_tour/js/tour_service").TourStep[]}
18 */
19 export function hasLine({
20 withClass = "",
21 withoutClass = "",
22 run = () => {},
23 productName,
24 quantity,
25 price,
26 priceUnit,
27 customerNote,
28 internalNote,
29 comboParent,
30 discount,
31 oldPrice,
32 priceNoDiscount,
33 attributeLine,
34 } = {}) {
35 let trigger = `.order-container .orderline${withClass}`;
36 if (withoutClass) {
37 trigger += `:not(${withoutClass})`;
38 }
39 if (productName) {
40 trigger += `:has(.product-name:contains("${productName}"))`;
41 }
42 if (quantity) {
43 quantity = parseFloat(quantity) % 1 === 0 ? parseInt(quantity).toString() : quantity;
44 trigger += `:has(.qty:contains("${quantity}"))`;
45 }
46 if (price) {
47 trigger += `:has(.price:contains("${price}"))`;
48 }
49 if (priceUnit) {
50 trigger += `:has(.price-per-unit:contains("${priceUnit}"))`;
51 }
52 if (customerNote) {
53 trigger += `:has(.info-list .customer-note:contains("${customerNote}"))`;
54 }
55 if (internalNote) {
56 trigger += `:has(.info-list .o_tag_badge_text:contains("${internalNote}"))`;
57 }
58 if (comboParent) {
59 trigger += `:has(.info-list .combo-parent-name:contains("${comboParent}"))`;
60 }
61 if (discount || discount === "") {
62 trigger += `:has(.info-list .discount.em:contains("${discount}"))`;
63 }
64 if (priceNoDiscount) {
65 trigger += `:has(.info-list:contains("${priceNoDiscount}"))`;
66 }
67 if (attributeLine) {
68 trigger += `:has(.attribute-line:contains("${attributeLine}"))`;
69 }
70 const args = JSON.stringify(arguments[0]);
71 return [
72 {
73 content: `Check orderline with attributes: ${args}`,
74 trigger,
75 run: typeof run === "string" ? run : () => run(trigger),
76 },
77 ];
78 }
79 /**
80 * @param {LineOptions} options
81 * @returns {import("@web_tour/tour_service").TourStep}
82 */
83 export function doesNotHaveLine(options = {}) {
84 const step = hasLine(options)[0];
85 return [{ ...step, trigger: negate(step.trigger) }];
86 }
87
88 // TODO: there are instances where we have no selected orderline. Fix those instances
89
90 export function hasTotal(amount) {
91 return [
92 {
93 isActive: ["desktop"],
94 content: `order total amount is '${amount}'`,
95 trigger: `.product-screen .order-summary .total:contains("${amount}")`,
96 },
97 {
98 isActive: ["mobile"],
99 content: `order total amount is '${amount}'`,
100 trigger: `.product-screen .order-summary .total:contains("${amount}"):not(:visible)`,
101 },
102 ];
103 }
104 export function hasSubtotal(amount) {
105 return [
106 {
107 isActive: ["desktop"],
108 content: `order total amount is '${amount}'`,
109 trigger: `.product-screen .order-summary .subtotal:contains("${amount}")`,
110 },
111 {
112 isActive: ["mobile"],
113 content: `order total amount is '${amount}'`,
114 trigger: `.product-screen .order-summary .subtotal:contains("${amount}"):not(:visible)`,
115 },
116 ];
117 }
118 export function hasTax(amount) {
119 return {
120 content: `order total tax is '${amount}'`,
121 trigger: `.order-summary .tax:contains("${amount}")`,
122 };
123 }
124 export function hasInternalNote(note) {
125 return [
126 {
127 content: `Order internal note is '${note}'`,
128 trigger: `.order-container .internal-note-container span div:contains("${note}")`,
129 },
130 ];
131 }
132 export function hasCustomerNote(note) {
133 return [
134 {
135 content: `Order customer note is '${note}'`,
136 trigger: `.order-container .customer-note div:contains("${note}")`,
137 },
138 ];
139 }
140
141 export function hasNoTax() {
142 return {
143 content: "order has not tax",
144 trigger: negate(".tax-info"),
145 };
146 }