| 1 | import { negate } from "@point_of_sale/../tests/generic_helpers/utils"; |
| 2 | |
| 3 | const productTrigger = (productName) => |
| 4 | `article.product:has(.product-name:contains("${productName}"))`; |
| 5 | const isComboSelectedTrigger = (productName) => |
| 6 | `label.combo-item.selected ${productTrigger(productName)}`; |
| 7 | const confirmationButtonTrigger = `footer button.confirm`; |
| 8 | |
| 9 | export function select(productName) { |
| 10 | return { |
| 11 | content: `Select combo item ${productName}`, |
| 12 | trigger: `.modal label.combo-item ${productTrigger(productName)}`, |
| 13 | run: "click", |
| 14 | }; |
| 15 | } |
| 16 | export function isSelected(productName) { |
| 17 | return { |
| 18 | content: `Check that ${productName} is selected`, |
| 19 | trigger: `.modal ${isComboSelectedTrigger(productName)}`, |
| 20 | }; |
| 21 | } |
| 22 | export function isNotSelected(productName) { |
| 23 | return { |
| 24 | content: `Check that ${productName} is not selected`, |
| 25 | trigger: `.modal ${negate(isComboSelectedTrigger(productName), ".modal-body")}`, |
| 26 | }; |
| 27 | } |
| 28 | export function isConfirmationButtonDisabled() { |
| 29 | return { |
| 30 | content: "try to click `confirm` without having made all the selections", |
| 31 | trigger: `.modal ${confirmationButtonTrigger}[disabled]`, |
| 32 | }; |
| 33 | } |
| 34 | export function checkTotal(expectedAmount) { |
| 35 | return { |
| 36 | content: `Check that combo total amount is $${expectedAmount}`, |
| 37 | trigger: `.modal div.h3:contains("Total: $ ${expectedAmount}")`, |
| 38 | }; |
| 39 | } |
| 40 | export function clickQtyBtnAdd(productName) { |
| 41 | return { |
| 42 | content: `Click the add quantity button for ${productName}`, |
| 43 | trigger: `.modal article:has(.product-name:contains("${productName}")) button[name="pos_quantity_button_plus"]`, |
| 44 | run: "click", |
| 45 | }; |
| 46 | } |
| 47 | export function clickQtyBtnMinus(productName) { |
| 48 | return { |
| 49 | content: `Click the minus quantity button for ${productName}`, |
| 50 | trigger: `.modal article:has(.product-name:contains("${productName}")) button[name="pos_quantity_button_minus"]`, |
| 51 | run: "click", |
| 52 | }; |
| 53 | } |
| 54 | export function checkProductQty(productName, expectedQty) { |
| 55 | return { |
| 56 | content: `Check that product ${productName} has quantity ${expectedQty}`, |
| 57 | trigger: `.modal article:has(.product-name:contains("${productName}")):has(input[name="pos_quantity"])`, |
| 58 | run: () => { |
| 59 | const article = [...document.querySelectorAll(".modal article")].find((el) => |
| 60 | el.textContent.includes(productName) |
| 61 | ); |
| 62 | const input = article.querySelector('input[name="pos_quantity"]'); |
| 63 | if (input.value != expectedQty) { |
| 64 | throw new Error( |
| 65 | `Expected ${expectedQty}, but got ${input.value} for "${productName}".` |
| 66 | ); |
| 67 | } |
| 68 | }, |
| 69 | }; |
| 70 | } |
| 71 | export function checkImgAndSelect(productName, checkImg = false) { |
| 72 | const productArticleSelector = productTrigger(productName); |
| 73 | const withImg = `${productArticleSelector}:has(.product-img)`; |
| 74 | const withoutImg = `${productArticleSelector}:not(:has(.product-img))`; |
| 75 | const trigger = `.modal ${checkImg ? withImg : withoutImg}`; |
| 76 | return { |
| 77 | content: `Check image & select combo item ${productName}`, |
| 78 | trigger: trigger, |
| 79 | run: "click", |
| 80 | }; |
| 81 | } |