| 1 |
function comboSelector(comboName) { |
| 2 |
return ` |
| 3 |
.sale-combo-configurator-dialog |
| 4 |
[name="sale_combo_configurator_title"]:contains("${comboName}") |
| 5 |
`; |
| 6 |
} |
| 7 |
|
| 8 |
function comboItemSelector(comboItemName, extraClasses=[]) { |
| 9 |
const extraClassesSelector = extraClasses.map(extraClass => `.${extraClass}`).join(''); |
| 10 |
return ` |
| 11 |
.sale-combo-configurator-dialog |
| 12 |
.product-card${extraClassesSelector}:has(h6:contains("${comboItemName}")) |
| 13 |
`; |
| 14 |
} |
| 15 |
|
| 16 |
function assertComboCount(count) { |
| 17 |
return { |
| 18 |
content: `Assert that there are ${count} combos`, |
| 19 |
trigger: '.sale-combo-configurator-dialog', |
| 20 |
run() { |
| 21 |
const selector = `.sale-combo-configurator-dialog [name="sale_combo_configurator_title"]`; |
| 22 |
if (document.querySelectorAll(selector).length !== count) { |
| 23 |
console.error(`Assertion failed`); |
| 24 |
} |
| 25 |
}, |
| 26 |
}; |
| 27 |
} |
| 28 |
|
| 29 |
function assertComboItemCount(comboName, count) { |
| 30 |
return { |
| 31 |
content: `Assert that there are ${count} combo items in combo ${comboName}`, |
| 32 |
trigger: comboSelector(comboName), |
| 33 |
run({ queryAll }) { |
| 34 |
const selector = `${comboSelector(comboName)} + .row .product-card`; |
| 35 |
if (queryAll(selector).length !== count) { |
| 36 |
console.error(`Assertion failed`); |
| 37 |
} |
| 38 |
}, |
| 39 |
}; |
| 40 |
} |
| 41 |
|
| 42 |
function assertSelectedComboItemCount(count) { |
| 43 |
return { |
| 44 |
content: `Assert that there are ${count} selected combo items`, |
| 45 |
trigger: '.sale-combo-configurator-dialog', |
| 46 |
run() { |
| 47 |
const selector = `.sale-combo-configurator-dialog .row .product-card.selected`; |
| 48 |
if (document.querySelectorAll(selector).length !== count) { |
| 49 |
console.error(`Assertion failed`); |
| 50 |
} |
| 51 |
}, |
| 52 |
}; |
| 53 |
} |
| 54 |
|
| 55 |
function assertPreselectedComboItemCount(count) { |
| 56 |
return { |
| 57 |
content: `Assert that there are ${count} preselected combo items`, |
| 58 |
trigger: '.sale-combo-configurator-dialog', |
| 59 |
run() { |
| 60 |
const selector = '.sale-combo-configurator-dialog div[name="preselected_product_name"]'; |
| 61 |
if (document.querySelectorAll(selector).length !== count) { |
| 62 |
console.error(`Assertion failed`); |
| 63 |
} |
| 64 |
}, |
| 65 |
}; |
| 66 |
} |
| 67 |
|
| 68 |
function selectComboItem(comboItemName) { |
| 69 |
return { |
| 70 |
content: `Select combo item ${comboItemName}`, |
| 71 |
trigger: comboItemSelector(comboItemName), |
| 72 |
run: 'click', |
| 73 |
}; |
| 74 |
} |
| 75 |
|
| 76 |
function assertComboItemSelected(comboItemName) { |
| 77 |
return { |
| 78 |
content: `Assert that combo item ${comboItemName} is selected`, |
| 79 |
trigger: comboItemSelector(comboItemName, ['selected']), |
| 80 |
}; |
| 81 |
} |
| 82 |
|
| 83 |
function assertComboItemPreselected(comboItemName) { |
| 84 |
return { |
| 85 |
content: `Assert that combo item ${comboItemName} is preselected`, |
| 86 |
trigger: `[name="preselected_product_name"]:contains(${comboItemName})`, |
| 87 |
}; |
| 88 |
} |
| 89 |
|
| 90 |
function increaseQuantity() { |
| 91 |
return { |
| 92 |
content: "Increase the combo quantity", |
| 93 |
trigger: '.sale-combo-configurator-dialog button[name="sale_quantity_button_plus"]', |
| 94 |
run: 'click', |
| 95 |
}; |
| 96 |
} |
| 97 |
|
| 98 |
function decreaseQuantity() { |
| 99 |
return { |
| 100 |
content: "Decrease the combo quantity", |
| 101 |
trigger: '.sale-combo-configurator-dialog button[name="sale_quantity_button_minus"]', |
| 102 |
run: 'click', |
| 103 |
}; |
| 104 |
} |
| 105 |
|
| 106 |
function setQuantity(quantity) { |
| 107 |
return { |
| 108 |
content: `Set the combo quantity to ${quantity}`, |
| 109 |
trigger: '.sale-combo-configurator-dialog input[name="sale_quantity"]', |
| 110 |
run: `edit ${quantity} && click .modal-body`, |
| 111 |
}; |
| 112 |
} |
| 113 |
|
| 114 |
function assertQuantity(quantity) { |
| 115 |
return { |
| 116 |
content: `Assert that the combo quantity is ${quantity}`, |
| 117 |
trigger: `.sale-combo-configurator-dialog input[name="sale_quantity"]:value(${quantity})`, |
| 118 |
}; |
| 119 |
} |
| 120 |
|
| 121 |
function assertPrice(price) { |
| 122 |
return { |
| 123 |
content: `Assert that the price is ${price}`, |
| 124 |
trigger: ` |
| 125 |
.sale-combo-configurator-dialog |
| 126 |
[name="sale_combo_configurator_total"]:contains("${price}") |
| 127 |
`, |
| 128 |
}; |
| 129 |
} |
| 130 |
|
| 131 |
function assertPriceInfo(priceInfo) { |
| 132 |
return { |
| 133 |
content: `Assert that the price info is ${priceInfo}`, |
| 134 |
trigger: `.sale-combo-configurator-dialog footer.modal-footer:contains("${priceInfo}")`, |
| 135 |
}; |
| 136 |
} |
| 137 |
|
| 138 |
function assertFooterButtonsDisabled() { |
| 139 |
return { |
| 140 |
content: "Assert that the footer buttons are disabled", |
| 141 |
trigger: '.sale-combo-configurator-dialog footer.modal-footer button:disabled', |
| 142 |
}; |
| 143 |
} |
| 144 |
|
| 145 |
function assertFooterButtonsEnabled() { |
| 146 |
return { |
| 147 |
content: "Assert that the footer buttons are enabled", |
| 148 |
trigger: '.sale-combo-configurator-dialog footer.modal-footer button:enabled', |
| 149 |
}; |
| 150 |
} |
| 151 |
|
| 152 |
function assertConfirmButtonDisabled() { |
| 153 |
return { |
| 154 |
content: "Assert that the confirm button is disabled", |
| 155 |
trigger: ` |
| 156 |
.sale-combo-configurator-dialog |
| 157 |
button[name="sale_combo_configurator_confirm_button"]:disabled |
| 158 |
`, |
| 159 |
}; |
| 160 |
} |
| 161 |
|
| 162 |
function assertConfirmButtonEnabled() { |
| 163 |
return { |
| 164 |
content: "Assert that the confirm button is enabled", |
| 165 |
trigger: ` |
| 166 |
.sale-combo-configurator-dialog |
| 167 |
button[name="sale_combo_configurator_confirm_button"]:enabled |
| 168 |
`, |
| 169 |
}; |
| 170 |
} |
| 171 |
|
| 172 |
function saveConfigurator() { |
| 173 |
return [ |
| 174 |
{ |
| 175 |
content: "Confirm the combo configurator", |
| 176 |
trigger: ` |
| 177 |
.sale-combo-configurator-dialog |
| 178 |
button[name="sale_combo_configurator_confirm_button"] |
| 179 |
`, |
| 180 |
run: 'click', |
| 181 |
}, { |
| 182 |
content: "Wait until the modal is closed", |
| 183 |
trigger: 'body:not(:has(.sale-combo-configurator-dialog))', |
| 184 |
}, |
| 185 |
]; |
| 186 |
} |
| 187 |
|
| 188 |
export default { |
| 189 |
comboSelector, |
| 190 |
comboItemSelector, |
| 191 |
assertComboCount, |
| 192 |
assertComboItemCount, |
| 193 |
assertSelectedComboItemCount, |
| 194 |
assertPreselectedComboItemCount, |
| 195 |
selectComboItem, |
| 196 |
assertComboItemSelected, |
| 197 |
assertComboItemPreselected, |
| 198 |
increaseQuantity, |
| 199 |
decreaseQuantity, |
| 200 |
setQuantity, |
| 201 |
assertQuantity, |
| 202 |
assertPrice, |
| 203 |
assertPriceInfo, |
| 204 |
assertFooterButtonsDisabled, |
| 205 |
assertFooterButtonsEnabled, |
| 206 |
assertConfirmButtonDisabled, |
| 207 |
assertConfirmButtonEnabled, |
| 208 |
saveConfigurator, |
| 209 |
}; |