Debian Codegraph @

addons/website_sale/static/tests/tours/website_sale_google_analytics.js

raw symbols SCIP
1 import { registry } from "@web/core/registry";
2 import { patch } from "@web/core/utils/patch";
3 import * as tourUtils from "@website_sale/js/tours/tour_utils";
4
5 /**
6 * Patch tracking to avoid third party calls during tests.
7 */
8 function patchTracking() {
9 const { Tracking } = odoo.loader.modules.get('@website_sale/interactions/tracking');
10 patch(Tracking.prototype, {
11 // Don't call super to avoid third party calls (GA).
12 onViewItem(event) {
13 const productTrackingInfo = event.detail;
14 document.body.setAttribute("view-event-id", productTrackingInfo.item_id);
15 },
16 onAddToCart(event) {
17 const productsTrackingInfo = event.detail;
18 document.body.setAttribute("cart-event-id", productsTrackingInfo[0].item_id);
19 },
20 });
21 }
22
23 if (odoo.loader.modules.has('@website_sale/interactions/tracking')) {
24 patchTracking();
25 } else {
26 odoo.loader.bus.addEventListener('module-started', (e) => {
27 if (e.detail.moduleName === '@website_sale/interactions/tracking') patchTracking();
28 });
29 }
30
31 let itemId;
32
33
34 registry.category("web_tour.tours").add('google_analytics_view_item', {
35 url: '/shop?search=Colored T-Shirt',
36 steps: () => [
37 {
38 content: "select Colored T-Shirt",
39 trigger: '.oe_product_cart a:contains("Colored T-Shirt")',
40 run: "click",
41 expectUnloadPage: true,
42 },
43 {
44 content: "wait until `_getCombinationInfo()` rpc is done",
45 trigger: 'body[view-event-id]',
46 timeout: 25000,
47 run: () => {
48 itemId = document.body.getAttribute("view-event-id");
49 }
50 },
51 {
52 content: 'select another variant',
53 trigger:
54 "ul.js_add_cart_variants ul.d-flex li:has(label.active) + li:has(label) input:not(:visible)",
55 run: "click",
56 },
57 {
58 content: 'wait until `_getCombinationInfo()` rpc is done (2)',
59 // a new view event should have been generated, for another variant
60 trigger: `body[view-event-id]:not([view-event-id="${itemId}"])`,
61 timeout: 25000,
62 },
63 ]});
64
65 registry.category("web_tour.tours").add('google_analytics_add_to_cart', {
66 url: '/shop?search=Basic Shirt',
67 steps: () => [
68 ...tourUtils.addToCart({productName: 'Basic Shirt', search: false, expectUnloadPage: true}),
69 {
70 trigger: "body[cart-event-id]",
71 },
72 {
73 content: 'check add to cart event',
74 trigger: "a:has(.my_cart_quantity:text(1))",
75 timeout: 25000,
76 },
77 ]});