| 1 |
import { _t } from "@web/core/l10n/translation"; |
| 2 |
import { clickOnElement } from '@website/js/tours/tour_utils'; |
| 3 |
|
| 4 |
export function addToCart({ |
| 5 |
productName, |
| 6 |
search = true, |
| 7 |
productHasVariants = false, |
| 8 |
expectUnloadPage = false, |
| 9 |
} = {}) { |
| 10 |
const steps = []; |
| 11 |
if (search) { |
| 12 |
steps.push(...searchProduct(productName)); |
| 13 |
} |
| 14 |
steps.push({ |
| 15 |
content: productName, |
| 16 |
trigger: `a:contains(${productName})`, |
| 17 |
run: "click", |
| 18 |
expectUnloadPage, |
| 19 |
}); |
| 20 |
steps.push({ |
| 21 |
content: "Add to cart", |
| 22 |
trigger: "#add_to_cart", |
| 23 |
run: "click", |
| 24 |
}); |
| 25 |
if (productHasVariants) { |
| 26 |
steps.push(clickOnElement('Continue Shopping', 'button:contains("Continue Shopping")')); |
| 27 |
} |
| 28 |
return steps; |
| 29 |
} |
| 30 |
|
| 31 |
export function assertCartAmounts({taxes = false, untaxed = false, total = false, delivery = false}) { |
| 32 |
let steps = []; |
| 33 |
if (taxes) { |
| 34 |
steps.push({ |
| 35 |
content: 'Check if the tax is correct', |
| 36 |
trigger: `tr[name="o_order_total_taxes"] .oe_currency_value:text(${taxes})`, |
| 37 |
}); |
| 38 |
} |
| 39 |
if (untaxed) { |
| 40 |
steps.push({ |
| 41 |
content: 'Check if the subtotal is correct', |
| 42 |
trigger: `tr[name="o_order_total_untaxed"] .oe_currency_value:text(${untaxed})`, |
| 43 |
}); |
| 44 |
} |
| 45 |
if (total) { |
| 46 |
steps.push({ |
| 47 |
content: 'Check if the total is correct', |
| 48 |
trigger: `tr[name="o_order_total"] .oe_currency_value:text(${total})`, |
| 49 |
}); |
| 50 |
} |
| 51 |
if (delivery) { |
| 52 |
steps.push({ |
| 53 |
content: 'Check if the delivery is correct', |
| 54 |
trigger: `tr[name='o_order_delivery'] .oe_currency_value:text(${delivery})`, |
| 55 |
}); |
| 56 |
} |
| 57 |
return steps |
| 58 |
} |
| 59 |
|
| 60 |
export function assertCartContains({productName, backend, notContains = false, combinationName = false} = {}) { |
| 61 |
let trigger = `h6:contains(${productName})`; |
| 62 |
|
| 63 |
if (notContains) { |
| 64 |
trigger = `:not(${trigger})`; |
| 65 |
} |
| 66 |
let steps = [{ |
| 67 |
content: `Checking if ${productName} is in the cart`, |
| 68 |
trigger: `${backend ? ":iframe" : ""} ${trigger}`, |
| 69 |
}]; |
| 70 |
|
| 71 |
if (combinationName) { |
| 72 |
const combination_trigger = `span[class*=h6]:contains(${combinationName})`; |
| 73 |
steps.push({ |
| 74 |
content: `Checking if ${combinationName} is the chosen combination in the cart`, |
| 75 |
trigger: `${backend ? ":iframe" : ""} ${combination_trigger}`, |
| 76 |
}) |
| 77 |
} |
| 78 |
|
| 79 |
return steps; |
| 80 |
} |
| 81 |
|
| 82 |
/** |
| 83 |
* Used to assert if the price attribute of a given product is correct on the /shop view |
| 84 |
*/ |
| 85 |
export function assertProductPrice(attribute, value, productName) { |
| 86 |
return { |
| 87 |
content: `The ${attribute} of the ${productName} is ${value}`, |
| 88 |
trigger: `div:contains("${productName}") [data-oe-expression="template_price_vals['${attribute}']"] .oe_currency_value:contains("${value}")`, |
| 89 |
}; |
| 90 |
} |
| 91 |
|
| 92 |
export function fillAdressForm( |
| 93 |
adressParams = { |
| 94 |
name: "John Doe", |
| 95 |
phone: "123456789", |
| 96 |
email: "[email protected]", |
| 97 |
street: "1 rue de la paix", |
| 98 |
city: "Paris", |
| 99 |
zip: "75000", |
| 100 |
}, |
| 101 |
expectUnloadPage = false |
| 102 |
) { |
| 103 |
const steps = []; |
| 104 |
steps.push({ |
| 105 |
trigger: "#o_country_id", |
| 106 |
run: "selectByLabel Belgium", |
| 107 |
}); |
| 108 |
for (const arg of ["name", "phone", "email", "street", "city", "zip"]) { |
| 109 |
steps.push({ |
| 110 |
content: `Address filling ${arg}`, |
| 111 |
trigger: `form.address_autoformat input[name=${arg}]`, |
| 112 |
run: `edit ${adressParams[arg]}`, |
| 113 |
}); |
| 114 |
} |
| 115 |
steps.push({ |
| 116 |
content: "Continue checkout", |
| 117 |
trigger: "a[name='website_sale_main_button']", |
| 118 |
run: "click", |
| 119 |
expectUnloadPage, |
| 120 |
}); |
| 121 |
return steps; |
| 122 |
} |
| 123 |
|
| 124 |
export function goToCart({ |
| 125 |
quantity = 1, |
| 126 |
position = "bottom", |
| 127 |
backend = false, |
| 128 |
expectUnloadPage = true, |
| 129 |
} = {}) { |
| 130 |
return { |
| 131 |
content: _t("Go to cart"), |
| 132 |
trigger: `${backend ? ":iframe" : ""} a sup.my_cart_quantity:text(${quantity})`, |
| 133 |
tooltipPosition: position, |
| 134 |
run: "click", |
| 135 |
expectUnloadPage, |
| 136 |
}; |
| 137 |
} |
| 138 |
|
| 139 |
export function goToCheckout() { |
| 140 |
return { |
| 141 |
content: 'Checkout your order', |
| 142 |
trigger: 'a[href^="/shop/checkout"]', |
| 143 |
run: 'click', |
| 144 |
expectUnloadPage: true, |
| 145 |
}; |
| 146 |
} |
| 147 |
|
| 148 |
export function confirmOrder() { |
| 149 |
return { |
| 150 |
content: 'Confirm', |
| 151 |
trigger: 'a[href^="/shop/payment"]', |
| 152 |
run: 'click', |
| 153 |
expectUnloadPage: true, |
| 154 |
}; |
| 155 |
} |
| 156 |
|
| 157 |
export function pay({ expectUnloadPage = false, waitFinalizeYourPayment = false } = {}) { |
| 158 |
const steps = [ |
| 159 |
{ |
| 160 |
content: 'Pay', |
| 161 |
//Either there are multiple payment methods, and one is checked, either there is only one, and therefore there are no radio inputs |
| 162 |
trigger: 'button[name="o_payment_submit_button"]', |
| 163 |
run: "click", |
| 164 |
expectUnloadPage, |
| 165 |
}, |
| 166 |
]; |
| 167 |
if (waitFinalizeYourPayment) { |
| 168 |
steps.push({ |
| 169 |
trigger: "h1:contains(finalize your payment)", |
| 170 |
expectUnloadPage: true, |
| 171 |
}); |
| 172 |
} |
| 173 |
return steps; |
| 174 |
} |
| 175 |
|
| 176 |
export function payWithDemo() { |
| 177 |
return [{ |
| 178 |
content: 'eCommerce: add card number', |
| 179 |
trigger: 'input[name="customer_input"]', |
| 180 |
run: "edit 4242424242424242", |
| 181 |
}, |
| 182 |
...pay({expectUnloadPage: true}), |
| 183 |
{ |
| 184 |
content: 'eCommerce: check that the payment is successful', |
| 185 |
trigger: '[name="order_confirmation"]:contains("Your payment has been processed.")', |
| 186 |
}] |
| 187 |
} |
| 188 |
|
| 189 |
export function payWithTransfer({ |
| 190 |
redirect = false, |
| 191 |
expectUnloadPage = false, |
| 192 |
waitFinalizeYourPayment = false, |
| 193 |
} = {}) { |
| 194 |
const first_step = { |
| 195 |
content: "Select `Wire Transfer` payment method", |
| 196 |
trigger: 'input[name="o_payment_radio"][data-payment-method-code="wire_transfer"]', |
| 197 |
run: "click", |
| 198 |
} |
| 199 |
if (!redirect) { |
| 200 |
return [ |
| 201 |
first_step, |
| 202 |
...pay({ expectUnloadPage, waitFinalizeYourPayment }), |
| 203 |
{ |
| 204 |
content: "Last step", |
| 205 |
trigger: |
| 206 |
'[name="order_confirmation"]:contains("Please use the following transfer details")', |
| 207 |
timeout: 30000, |
| 208 |
}, |
| 209 |
]; |
| 210 |
} else { |
| 211 |
return [ |
| 212 |
first_step, |
| 213 |
...pay({ expectUnloadPage, waitFinalizeYourPayment }), |
| 214 |
{ |
| 215 |
content: "Last step", |
| 216 |
trigger: |
| 217 |
'[name="order_confirmation"]:contains("Please use the following transfer details")', |
| 218 |
timeout: 30000, |
| 219 |
run() { |
| 220 |
window.location.href = '/contactus'; // Redirect in JS to avoid the RPC loop (20x1sec) |
| 221 |
}, |
| 222 |
expectUnloadPage: true, |
| 223 |
}, |
| 224 |
{ |
| 225 |
content: "wait page loaded", |
| 226 |
trigger: 'h1:contains("Contact us")', |
| 227 |
}, |
| 228 |
]; |
| 229 |
} |
| 230 |
} |
| 231 |
|
| 232 |
export function searchProduct(productName, { select = false } = {}) { |
| 233 |
const steps = [ |
| 234 |
{ |
| 235 |
content: "Search for the product", |
| 236 |
trigger: 'form input[name="search"]', |
| 237 |
run: `edit ${productName}`, |
| 238 |
}, |
| 239 |
{ |
| 240 |
content: `Search ${productName}`, |
| 241 |
trigger: `form:has(input[name="search"]) .oe_search_button`, |
| 242 |
run: "click", |
| 243 |
expectUnloadPage: true, |
| 244 |
}, |
| 245 |
]; |
| 246 |
if (select) { |
| 247 |
steps.push({ |
| 248 |
content: `Select ${productName}`, |
| 249 |
trigger: `.oe_product_cart:first a:text(${productName})`, |
| 250 |
run: "click", |
| 251 |
expectUnloadPage: true, |
| 252 |
}); |
| 253 |
} |
| 254 |
return steps; |
| 255 |
} |
| 256 |
|
| 257 |
/** |
| 258 |
* Used to select a pricelist on the /shop view |
| 259 |
*/ |
| 260 |
export function selectPriceList(pricelist) { |
| 261 |
return [ |
| 262 |
{ |
| 263 |
content: "Click on pricelist dropdown", |
| 264 |
trigger: "div.o_pricelist_dropdown a[data-bs-toggle=dropdown]", |
| 265 |
run: "click", |
| 266 |
}, |
| 267 |
{ |
| 268 |
content: "Click on pricelist", |
| 269 |
trigger: `span:contains(${pricelist})`, |
| 270 |
run: "click", |
| 271 |
expectUnloadPage: true, |
| 272 |
}, |
| 273 |
]; |
| 274 |
} |
| 275 |
|
| 276 |
/** |
| 277 |
* Used for resolving indeterministic behavior of tours |
| 278 |
*/ |
| 279 |
export function waitForInteractionToLoad() { |
| 280 |
return { |
| 281 |
content: "Wait for interaction to be ready", |
| 282 |
trigger: `body[is-ready=true]`, |
| 283 |
}; |
| 284 |
} |