1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | var tslib_1 = require("tslib");
|
4 | var page_type_1 = require("../../commons/types/page-type");
|
5 | var http_1 = require("../../commons/utils/http");
|
6 | var event_1 = require("../core/event");
|
7 | var vtex_runner_1 = require("./vtex-runner");
|
8 |
|
9 | var vtexRunner = new vtex_runner_1.VTEXRunner();
|
10 | beforeEach(function () {
|
11 | var post = jest.fn().mockReturnValue({ status: 204 });
|
12 | post.mockClear();
|
13 | http_1.Http.post = post;
|
14 | });
|
15 | test("should send front events when in datalayer", function () { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
|
16 | return tslib_1.__generator(this, function (_a) {
|
17 | switch (_a.label) {
|
18 | case 0:
|
19 | window.dataLayer = [
|
20 | {
|
21 | event: "biggy.front.view",
|
22 | biggy: {
|
23 | page: page_type_1.PageType.Home,
|
24 | position: "ONE",
|
25 | storeFront: "BestChoice",
|
26 | products: ["105", "106"],
|
27 | },
|
28 | },
|
29 | ];
|
30 | return [4 , vtexRunner.start()];
|
31 | case 1:
|
32 | _a.sent();
|
33 | expect(http_1.Http.post).toHaveBeenCalledTimes(2);
|
34 | expect(http_1.Http.post).toHaveBeenNthCalledWith(1, expect.any(String), expect.objectContaining({ type: event_1.EventType.SessionPing }));
|
35 | expect(http_1.Http.post).toHaveBeenNthCalledWith(2, expect.any(String), expect.objectContaining({
|
36 | type: event_1.EventType.FrontView,
|
37 | page: page_type_1.PageType.Home,
|
38 | area: "ONE",
|
39 | storefront: "BestChoice",
|
40 | products: ["105", "106"],
|
41 | }));
|
42 | window.dataLayer.push({
|
43 | event: "biggy.front.click",
|
44 | biggy: {
|
45 | page: page_type_1.PageType.Home,
|
46 | position: "ONE",
|
47 | storeFront: "BestChoice",
|
48 | product: "105",
|
49 | },
|
50 | });
|
51 |
|
52 | return [4 , new Promise(function (resolve) { return setTimeout(resolve, 1000); })];
|
53 | case 2:
|
54 |
|
55 | _a.sent();
|
56 | expect(http_1.Http.post).toHaveBeenCalledTimes(3);
|
57 | expect(http_1.Http.post).toHaveBeenNthCalledWith(3, expect.any(String), expect.objectContaining({
|
58 | type: event_1.EventType.FrontClick,
|
59 | page: page_type_1.PageType.Home,
|
60 | area: "ONE",
|
61 | storefront: "BestChoice",
|
62 | product: "105",
|
63 | }));
|
64 | return [2 ];
|
65 | }
|
66 | });
|
67 | }); });
|
68 | test("should send search events when in datalayer", function () { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
|
69 | return tslib_1.__generator(this, function (_a) {
|
70 | switch (_a.label) {
|
71 | case 0:
|
72 | window.dataLayer = [
|
73 | {
|
74 | event: "biggy.search.query",
|
75 | biggy: {
|
76 | text: "sapato",
|
77 | match: 150,
|
78 | misspelled: false,
|
79 | operator: "and",
|
80 | },
|
81 | },
|
82 | ];
|
83 | return [4 , vtexRunner.start()];
|
84 | case 1:
|
85 | _a.sent();
|
86 | expect(http_1.Http.post).toHaveBeenCalledTimes(2);
|
87 | expect(http_1.Http.post).toHaveBeenNthCalledWith(1, expect.any(String), expect.objectContaining({ type: event_1.EventType.SessionPing }));
|
88 | expect(http_1.Http.post).toHaveBeenNthCalledWith(2, expect.any(String), expect.objectContaining({
|
89 | type: event_1.EventType.SearchQuery,
|
90 | text: "sapato",
|
91 | match: 150,
|
92 | misspelled: false,
|
93 | operator: "and",
|
94 | }));
|
95 | window.dataLayer.push({
|
96 | event: "biggy.search.click",
|
97 | biggy: {
|
98 | text: "sapato",
|
99 | product: "105",
|
100 | },
|
101 | });
|
102 |
|
103 | return [4 , new Promise(function (resolve) { return setTimeout(resolve, 1000); })];
|
104 | case 2:
|
105 |
|
106 | _a.sent();
|
107 | expect(http_1.Http.post).toHaveBeenCalledTimes(3);
|
108 | expect(http_1.Http.post).toHaveBeenNthCalledWith(3, expect.any(String), expect.objectContaining({
|
109 | type: event_1.EventType.SearchClick,
|
110 | text: "sapato",
|
111 | product: "105",
|
112 | }));
|
113 | return [2 ];
|
114 | }
|
115 | });
|
116 | }); });
|
117 |
|
\ | No newline at end of file |