| 1 |
import * as Numpad from "@point_of_sale/../tests/generic_helpers/numpad_util"; |
| 2 |
import { negate } from "@point_of_sale/../tests/generic_helpers/utils"; |
| 3 |
|
| 4 |
export function table({ name, withClass = "", withoutClass, run = () => {}, numOfSeats }) { |
| 5 |
let trigger = `.floor-map .table${withClass}`; |
| 6 |
if (withoutClass) { |
| 7 |
trigger += `:not(${withoutClass})`; |
| 8 |
} |
| 9 |
if (name) { |
| 10 |
trigger += `:has(.label:contains("${name}"))`; |
| 11 |
} |
| 12 |
return { |
| 13 |
content: `Check table with attributes: ${JSON.stringify(arguments[0])}`, |
| 14 |
trigger, |
| 15 |
run: typeof run === "string" ? run : (helpers) => run(helpers, trigger), |
| 16 |
}; |
| 17 |
} |
| 18 |
export const clickTable = (name) => table({ name, run: "click" }); |
| 19 |
export const hasTable = (name) => table({ name }); |
| 20 |
export const selectedTableIs = (name) => table({ name, withClass: ".selected" }); |
| 21 |
export const ctrlClickTable = (name) => |
| 22 |
table({ |
| 23 |
name, |
| 24 |
run: (helpers, trigger) => { |
| 25 |
helpers |
| 26 |
.queryOne(trigger) |
| 27 |
.dispatchEvent(new MouseEvent("click", { bubbles: true, ctrlKey: true })); |
| 28 |
}, |
| 29 |
}); |
| 30 |
export function clickFloor(name) { |
| 31 |
return [ |
| 32 |
{ |
| 33 |
content: `click '${name}' floor`, |
| 34 |
trigger: `.floor-selector .button-floor:contains("${name}")`, |
| 35 |
run: "click", |
| 36 |
}, |
| 37 |
]; |
| 38 |
} |
| 39 |
export function hasFloor(name) { |
| 40 |
return [ |
| 41 |
{ |
| 42 |
content: `has '${name}' floor`, |
| 43 |
trigger: `.floor-selector .button-floor:contains("${name}")`, |
| 44 |
}, |
| 45 |
]; |
| 46 |
} |
| 47 |
export function hasNotFloor(name) { |
| 48 |
return [ |
| 49 |
{ |
| 50 |
content: `has not '${name}' floor`, |
| 51 |
trigger: negate(`.floor-selector .button-floor:contains("${name}")`), |
| 52 |
}, |
| 53 |
]; |
| 54 |
} |
| 55 |
export function clickEditButton(button) { |
| 56 |
return [ |
| 57 |
{ |
| 58 |
content: "add table", |
| 59 |
trigger: `.edit-buttons i[aria-label="${button}"]`, |
| 60 |
run: "click", |
| 61 |
}, |
| 62 |
]; |
| 63 |
} |
| 64 |
export function clickSaveEditButton() { |
| 65 |
return [ |
| 66 |
{ |
| 67 |
content: "add table", |
| 68 |
trigger: '.edit-buttons button:contains("Save")', |
| 69 |
run: "click", |
| 70 |
}, |
| 71 |
{ |
| 72 |
trigger: negate(".edit-buttons button:contains('Save')"), |
| 73 |
}, |
| 74 |
]; |
| 75 |
} |
| 76 |
export function clickTableSelectorButton() { |
| 77 |
return [ |
| 78 |
{ |
| 79 |
content: "click on table selector button", |
| 80 |
trigger: ".floor-screen .right-buttons button i.fa-hashtag", |
| 81 |
run: "click", |
| 82 |
}, |
| 83 |
]; |
| 84 |
} |
| 85 |
export function goTo(name) { |
| 86 |
return [ |
| 87 |
...clickTableSelectorButton(), |
| 88 |
...Numpad.enterValue(name), |
| 89 |
{ |
| 90 |
trigger: ".floor-screen .right-buttons .jump-button", |
| 91 |
run: "click", |
| 92 |
}, |
| 93 |
]; |
| 94 |
} |
| 95 |
export function selectedFloorIs(name) { |
| 96 |
return [ |
| 97 |
{ |
| 98 |
content: `selected floor is '${name}'`, |
| 99 |
trigger: `.button-floor.active:contains("${name}")`, |
| 100 |
}, |
| 101 |
]; |
| 102 |
} |
| 103 |
export function orderCountSyncedInTableIs(table, count) { |
| 104 |
if (count === 0 || count === "0") { |
| 105 |
return [ |
| 106 |
{ |
| 107 |
trigger: `.floor-map .table:has(.label:contains("${table}")):not(:has(.order-count))`, |
| 108 |
}, |
| 109 |
]; |
| 110 |
} |
| 111 |
return [ |
| 112 |
{ |
| 113 |
trigger: `.floor-map .table:has(.label:contains("${table}")):has(.order-count:contains("${count}"))`, |
| 114 |
}, |
| 115 |
]; |
| 116 |
} |
| 117 |
export function isShown() { |
| 118 |
return [ |
| 119 |
{ |
| 120 |
trigger: ".floor-map", |
| 121 |
}, |
| 122 |
]; |
| 123 |
} |
| 124 |
export function linkTables(child, parent) { |
| 125 |
async function drag_multiple_and_then_drop(helpers, ...drags) { |
| 126 |
const dragEffectDelay = async () => { |
| 127 |
console.log(helpers.delay); |
| 128 |
await new Promise((resolve) => requestAnimationFrame(resolve)); |
| 129 |
await new Promise((resolve) => setTimeout(resolve, helpers.delay)); |
| 130 |
}; |
| 131 |
const element = helpers.anchor; |
| 132 |
const { drag } = odoo.loader.modules.get("@odoo/hoot-dom"); |
| 133 |
const { drop, moveTo } = await drag(element); |
| 134 |
await dragEffectDelay(); |
| 135 |
await helpers.hover(element, { |
| 136 |
position: { |
| 137 |
top: 20, |
| 138 |
left: 20, |
| 139 |
}, |
| 140 |
relative: true, |
| 141 |
}); |
| 142 |
await dragEffectDelay(); |
| 143 |
for (const [selector, options] of drags) { |
| 144 |
console.log("Selector", selector, options); |
| 145 |
const target = await helpers.waitFor(selector, { |
| 146 |
visible: true, |
| 147 |
timeout: 500, |
| 148 |
}); |
| 149 |
await moveTo(target, options); |
| 150 |
await dragEffectDelay(); |
| 151 |
} |
| 152 |
await drop(); |
| 153 |
await dragEffectDelay(); |
| 154 |
} |
| 155 |
return { |
| 156 |
content: `Drag table ${child} onto table ${parent} in order to link them`, |
| 157 |
trigger: table({ name: child }).trigger, |
| 158 |
async run(helpers) { |
| 159 |
helpers.delay = 500; |
| 160 |
await drag_multiple_and_then_drop( |
| 161 |
helpers, |
| 162 |
[ |
| 163 |
table({ name: parent }).trigger, |
| 164 |
{ |
| 165 |
position: "top", |
| 166 |
relative: true, |
| 167 |
}, |
| 168 |
], |
| 169 |
[ |
| 170 |
table({ name: parent }).trigger, |
| 171 |
{ |
| 172 |
position: "center", |
| 173 |
relative: true, |
| 174 |
}, |
| 175 |
] |
| 176 |
); |
| 177 |
}, |
| 178 |
}; |
| 179 |
} |
| 180 |
export function unlinkTables(child, parent) { |
| 181 |
return { |
| 182 |
content: `Drag table ${child} away from table ${parent} to unlink them`, |
| 183 |
trigger: table({ name: child }).trigger, |
| 184 |
async run(helpers) { |
| 185 |
await helpers.drag_and_drop(`div.floor-map`, { |
| 186 |
position: { |
| 187 |
bottom: 0, |
| 188 |
}, |
| 189 |
relative: true, |
| 190 |
}); |
| 191 |
}, |
| 192 |
}; |
| 193 |
} |
| 194 |
export function isChildTable(child) { |
| 195 |
return { |
| 196 |
content: `Verify that table ${child} is a child table`, |
| 197 |
trigger: table({ name: child }).trigger + ` .info.opacity-25`, |
| 198 |
}; |
| 199 |
} |
| 200 |
export function clickNewOrder() { |
| 201 |
return { trigger: ".new-order", run: "click" }; |
| 202 |
} |
| 203 |
|
| 204 |
export function addFloor(floorName) { |
| 205 |
return [ |
| 206 |
{ |
| 207 |
trigger: ".floor-selector button i[aria-label='Add Floor']", |
| 208 |
run: "click", |
| 209 |
}, |
| 210 |
{ |
| 211 |
trigger: ".modal-body textarea", |
| 212 |
run: `edit ${floorName}`, |
| 213 |
}, |
| 214 |
{ |
| 215 |
trigger: ".modal-footer button.btn-primary", |
| 216 |
run: "click", |
| 217 |
}, |
| 218 |
...selectedFloorIs(floorName), |
| 219 |
]; |
| 220 |
} |