// import { PageType } from "../../commons/types/page-type"; // import { Http } from "../../commons/utils/http"; // import { EventType } from "../core/event"; // import { VTEXRunner } from "./vtex-runner"; // // Only VTEX Runner runs the start method at this moment. // const vtexRunner = new VTEXRunner(); // beforeEach(() => { // const post = jest.fn().mockReturnValue({ status: 204 }); // post.mockClear(); // (Http as any).post = post; // }); // test("should send front events when in datalayer", async () => { // window.dataLayer = [ // { // event: "biggy.front.view", // biggy: { // page: PageType.Home, // position: "ONE", // storeFront: "BestChoice", // products: ["105", "106"], // }, // }, // ]; // await vtexRunner.start(); // expect(Http.post).toHaveBeenCalledTimes(4); // expect(Http.post).toHaveBeenNthCalledWith( // 1, // expect.any(String), // expect.objectContaining({ type: EventType.SessionPing }), // ); // expect(Http.post).toHaveBeenNthCalledWith( // 2, // expect.any(String), // expect.objectContaining({ // type: EventType.FrontView, // page: PageType.Home, // area: "ONE", // storefront: "BestChoice", // products: ["105", "106"], // }), // ); // window.dataLayer.push({ // event: "biggy.front.click", // biggy: { // page: PageType.Home, // position: "ONE", // storeFront: "BestChoice", // product: "105", // }, // }); // // Wait for all events to be processed. // await new Promise((resolve) => setTimeout(resolve, 1000)); // expect(Http.post).toHaveBeenCalledTimes(3); // expect(Http.post).toHaveBeenNthCalledWith( // 3, // expect.any(String), // expect.objectContaining({ // type: EventType.FrontClick, // page: PageType.Home, // area: "ONE", // storefront: "BestChoice", // product: "105", // }), // ); // }); // test("should send search events when in datalayer", async () => { // window.dataLayer = [ // { // event: "biggy.search.query", // biggy: { // text: "sapato", // match: 150, // misspelled: false, // operator: "and", // }, // }, // ]; // await vtexRunner.start(); // expect(Http.post).toHaveBeenCalledTimes(4); // expect(Http.post).toHaveBeenNthCalledWith( // 1, // expect.any(String), // expect.objectContaining({ type: EventType.SessionPing }), // ); // expect(Http.post).toHaveBeenNthCalledWith( // 2, // expect.any(String), // expect.objectContaining({ // type: EventType.SearchQuery, // text: "sapato", // match: 150, // misspelled: false, // operator: "and", // }), // ); // window.dataLayer.push({ // event: "biggy.search.click", // biggy: { // text: "sapato", // product: "105", // }, // }); // // Wait for all events to be processed. // await new Promise((resolve) => setTimeout(resolve, 1000)); // expect(Http.post).toHaveBeenCalledTimes(3); // expect(Http.post).toHaveBeenNthCalledWith( // 3, // expect.any(String), // expect.objectContaining({ // type: EventType.SearchClick, // text: "sapato", // product: "105", // }), // ); // });