import { PageType } from "../../../commons/types/page-type"; import { Http } from "../../../commons/utils/http"; import { DataLayerAutocompleteClick, AutocompleteClickType } from "./datalayer-autocomplete-click"; import { DataLayerFrontClickEvent } from "./datalayer-front-click"; import { DataLayerFrontViewEvent } from "./datalayer-front-view"; import { DataLayerSearchAutocompleteQueryEvent } from "./datalayer-search-autocomplete-query"; import { DataLayerSearchClickEvent } from "./datalayer-search-click"; import { DataLayerSearchQueryEvent } from "./datalayer-search-query"; import { DataLayerShelfView } from "./datalayer-shelf-view"; import { DataLayerShelfProductClick } from "./datalayer-shelf-product-click"; import { DataLayerPageCategoryClickEvent } from "./datalayer-page-category-click"; import { product } from "./product-mock"; import { DataLayerPageCategoryEvent } from "./datalayer-page-category"; beforeEach(() => { const post = jest.fn(); post.mockClear(); (Http as any).post = post; }); test("creating a front click event with the necessary parameters", async () => { const event = new DataLayerFrontClickEvent({ page: PageType.Home, position: "ONE", storeFront: "BestChoice", product: "105", }); await event.push(); expect(Http.post).toHaveBeenCalled(); expect(Http.post).toHaveBeenCalledWith( expect.any(String), expect.objectContaining({ page: PageType.Home, area: "ONE", storefront: "BestChoice", product: "105", }), ); }); test("creating a front view event with the necessary parameters", async () => { const event = new DataLayerFrontViewEvent({ page: PageType.Home, position: "ONE", storeFront: "BestChoice", products: ["105", "106"], }); await event.push(); expect(Http.post).toHaveBeenCalled(); expect(Http.post).toHaveBeenCalledWith( expect.any(String), expect.objectContaining({ page: PageType.Home, area: "ONE", storefront: "BestChoice", products: ["105", "106"], }), ); }); test("creating a search query event with the necessary parameters", async () => { const event = new DataLayerSearchQueryEvent({ text: "sapato", match: 150, misspelled: false, operator: "and", }); await event.push(); expect(Http.post).toHaveBeenCalled(); expect(Http.post).toHaveBeenCalledWith( expect.any(String), expect.objectContaining({ text: "sapato", match: 150, misspelled: false, operator: "and", }), ); }); test("creating a page category event with the necessary parameters", async () => { const event = new DataLayerPageCategoryEvent({ text: "sapato", match: 150, }); await event.push(); expect(Http.post).toHaveBeenCalled(); expect(Http.post).toHaveBeenCalledWith( expect.any(String), expect.objectContaining({ text: "sapato", match: 150, }), ); }); test("creating a search click event with the necessary parameters", async () => { const event = new DataLayerSearchClickEvent({ product: "105", text: "sapato", position: 1, }); await event.push(); expect(Http.post).toHaveBeenCalled(); expect(Http.post).toHaveBeenCalledWith( expect.any(String), expect.objectContaining({ type: "search.click", product: "105", text: "sapato", position: 1, }), ); }); test("creating a page category click event with the necessary parameters", async () => { const event = new DataLayerPageCategoryClickEvent({ product: "105", position: 1, }); await event.push(); expect(Http.post).toHaveBeenCalled(); expect(Http.post).toHaveBeenCalledWith( expect.any(String), expect.objectContaining({ type: "page.category.click", product: "105", position: 1, }), ); }); test("creating an autocomplete click event with the necessary parameters", async () => { const event = new DataLayerAutocompleteClick({ // eslint-disable-next-line @typescript-eslint/camelcase click_type: AutocompleteClickType.ProductClick, page: PageType.Home, position: 7, product: "105", text: "text", }); await event.push(); expect(Http.post).toHaveBeenCalled(); expect(Http.post).toHaveBeenCalledWith( expect.any(String), expect.objectContaining({ // eslint-disable-next-line @typescript-eslint/camelcase click_type: AutocompleteClickType.ProductClick, page: PageType.Home, position: 7, product: "105", text: "text", }), ); }); test("creating a search autocomplete query event with the necessary parameters", async () => { const event = new DataLayerSearchAutocompleteQueryEvent({ text: "sapato", match: 150, misspelled: false, operator: "and", }); await event.push(); expect(Http.post).toHaveBeenCalled(); expect(Http.post).toHaveBeenCalledWith( expect.any(String), expect.objectContaining({ text: "sapato", match: 150, misspelled: false, operator: "and", }), ); }); test("creating an shelf product click event with the necessary parameters", async () => { const event = new DataLayerShelfProductClick({ page: PageType.Home, product: product, }); await event.push(); expect(Http.post).toHaveBeenCalled(); expect(Http.post).toHaveBeenCalledWith( expect.any(String), expect.objectContaining({ page: PageType.Home, product: product, }), ); }); test("creating an shelf view event with the necessary parameters", async () => { const event = new DataLayerShelfView({ page: PageType.Home, shelf: "buy-together", }); await event.push(); expect(Http.post).toHaveBeenCalled(); expect(Http.post).toHaveBeenCalledWith( expect.any(String), expect.objectContaining({ page: PageType.Home, shelf: "buy-together", }), ); });