// import { Http } from "../../commons/utils/http"; // import { EventType } from "../../event/core/event"; // import { VTEXRunner } from "./vtex-runner"; // const vtexRunner = new VTEXRunner(); // beforeEach(() => { // const post = jest.fn().mockReturnValue({ status: 204 }); // post.mockClear(); // (Http as any).post = post; // }); // test("running the vtex runner on a confirmation page should trigger order confirmation event", async () => { // window.dataLayer = [ // { // event: "orderPlaced", // transactionId: "orderId", // transactionProducts: [ // { // id: "productId", // quantity: 1, // price: 99.99, // }, // ], // }, // ]; // vtexRunner.start(); // // Wait for all events to be processed. // await new Promise((resolve) => setTimeout(resolve, 1000)); // 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.PageConfirmation, products: expect.any(Array) }), // ); // }); // test("running the vtex runner on a cart page should trigger cart events", async () => { // window.dataLayer = [ // { // event: "cart", // ecommerce: { // checkout: { // products: [ // { // id: "111", // quantity: 1, // }, // { // id: "222", // quantity: 2, // }, // ], // }, // }, // }, // ]; // await vtexRunner.start(); // window.dataLayer.push({ // event: "removeFromCart", // ecommerce: { // remove: { // products: [ // { // id: "222", // quantity: 1, // }, // ], // }, // }, // }); // // Wait for all events to be processed. // await new Promise((resolve) => setTimeout(resolve, 1000)); // expect(Http.post).toHaveBeenCalledTimes(3); // 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.PageCart, products: expect.any(Array) }), // ); // expect(Http.post).toHaveBeenNthCalledWith( // 3, // expect.any(String), // expect.objectContaining({ type: EventType.SessionCartRemove, products: expect.any(Array) }), // ); // }); // test("should not send an event if no important dataLayer events were found", async () => { // window.dataLayer = []; // await vtexRunner.start(); // expect(Http.post).toHaveBeenCalledTimes(1); // expect(Http.post).toHaveBeenNthCalledWith( // 1, // expect.any(String), // expect.objectContaining({ type: EventType.SessionPing }), // ); // });