Debian Codegraph @

addons/point_of_sale/static/tests/customer_display/customer_display_tour.js

raw
1 import * as Order from "@point_of_sale/../tests/generic_helpers/order_widget_util";
2 import * as CustomerDisplay from "@point_of_sale/../tests/customer_display/customer_display_utils";
3 import { registry } from "@web/core/registry";
4 import { isVisible } from "@web/core/utils/ui";
5
6 registry.category("web_tour.tours").add("CustomerDisplayTour", {
7 steps: () =>
8 [
9 CustomerDisplay.addProduct(CustomerDisplay.ADD_PRODUCT, "add product"),
10 Order.hasLine({ productName: "Letter Tray", price: "2,972.75" }),
11 {
12 content: "An order line with `isSelected: false` should not have 'selected' class",
13 trigger: ".order-container .orderline:last-child:not(.selected)",
14 },
15 CustomerDisplay.amountIs("Total", "2,972.75"),
16 CustomerDisplay.postMessage(CustomerDisplay.PAY_WITH_CASH, "pay with cash"),
17 CustomerDisplay.amountIs("Cash", "2,972.75"),
18 CustomerDisplay.postMessage(CustomerDisplay.ORDER_IS_FINALIZED, "order is finalized"),
19 {
20 content: "Check that we are now on the 'Thank you' screen",
21 trigger: "div:contains('Thank you.')",
22 },
23 CustomerDisplay.postMessage(CustomerDisplay.NEW_ORDER, "new order"),
24 {
25 trigger: " div:contains('Welcome.')",
26 },
27 Order.doesNotHaveLine({}),
28 CustomerDisplay.amountIs("Total", "0.00"),
29 {
30 trigger: "body",
31 run: () =>
32 CustomerDisplay.postMessage(
33 CustomerDisplay.ADD_PRODUCT_SELECTED,
34 "add products"
35 ).run(),
36 },
37 {
38 content: "An order line with `isSelected: true` should have 'selected' class",
39 trigger: ".order-container .orderline:last-child.selected",
40 },
41 ].flat(),
42 });
43
44 registry.category("web_tour.tours").add("CustomerDisplayTourScroll", {
45 steps: () =>
46 [
47 CustomerDisplay.addProduct(CustomerDisplay.ADD_MULTI_PRODUCTS, "add 20 products"),
48 {
49 content: "An order line with `isSelected: true` should have 'selected' class",
50 trigger: ".order-container .orderline:last-child.selected",
51 run: async () =>
52 await new Promise((resolve) => {
53 const orderLine = document.querySelector(
54 ".order-container .orderline:last-child.selected"
55 );
56 const animationDuration = parseFloat(
57 getComputedStyle(orderLine).animationDuration
58 );
59 if (animationDuration === 0) {
60 return resolve();
61 }
62 orderLine.onanimationend = function (event) {
63 if (event.target === orderLine && event.animationName === "item_in") {
64 resolve(event);
65 }
66 };
67 }),
68 },
69 {
70 content: "The order container should have scrolled to show the selected order line",
71 trigger: ".order-container",
72 run: async () => {
73 const orderContainer = document.querySelector(".order-container");
74 const orderLine = document.querySelector(
75 ".order-container .orderline:last-child.selected"
76 );
77 await new Promise((resolve) => {
78 const checkScroll = () => {
79 requestAnimationFrame(() => {
80 if (orderContainer.scrollTop > 0 && isVisible(orderLine)) {
81 resolve();
82 } else {
83 setTimeout(checkScroll, 1000);
84 }
85 });
86 };
87 checkScroll();
88 });
89 },
90 },
91 ].flat(),
92 });
93
94 registry.category("web_tour.tours").add("CustomerDisplayTourWithQr", {
95 steps: () =>
96 [
97 CustomerDisplay.addProduct(CustomerDisplay.ADD_PRODUCT, "add product"),
98 Order.hasLine({ productName: "Letter Tray", price: "2,972.75" }),
99 CustomerDisplay.amountIs("Total", "2,972.75"),
100 CustomerDisplay.postMessage(CustomerDisplay.PAY_WITH_CARD, "pay with card"),
101 CustomerDisplay.postMessage(CustomerDisplay.SEND_QR, "send qr code"),
102 { trigger: "img[alt='QR Code']" },
103 CustomerDisplay.postMessage(CustomerDisplay.PAY_WITH_CARD, "confirm payment"),
104 CustomerDisplay.postMessage(CustomerDisplay.ORDER_IS_FINALIZED, "order is finalized"),
105 {
106 content: "Check that we are now on the 'Thank you' screen",
107 trigger: "div:contains('Thank you.')",
108 },
109 ].flat(),
110 });