From fb8e4db6a94e5ea94d2f5ae618d4b0e9a3cc7888 Mon Sep 17 00:00:00 2001 From: Kroell Date: Fri, 3 Feb 2023 16:43:22 -0500 Subject: [PATCH] unit tests, work in progress --- .../address-vehicles/address-vehicles.spec.js | 110 ++++++++---------- 1 file changed, 49 insertions(+), 61 deletions(-) diff --git a/src/layouts/address-vehicles/address-vehicles.spec.js b/src/layouts/address-vehicles/address-vehicles.spec.js index 5e6cd3b4..551419e5 100644 --- a/src/layouts/address-vehicles/address-vehicles.spec.js +++ b/src/layouts/address-vehicles/address-vehicles.spec.js @@ -3,29 +3,33 @@ import { settleAllPromises } from "@/helpers/layout-helper.js"; import { shallowMount } from "@vue/test-utils"; import { getMountOptions } from "@/helpers/unit-test-helper.js"; import { useMainStore } from "@/store"; +import { fetchCmsContentForPage } from "@/helpers/cms-content-helper"; jest.mock("@/helpers/damage-helper", () => ({ isGlassAvailableForCarId: jest.fn().mockImplementation(() => true), getDamageString: jest.fn(), })); - + +// Mock fetchCmsContentForPage +jest.mock("@/helpers/cms-content-helper", () => ({ + fetchCmsContentForPage: jest.fn(), + doesCopyContainRouterLink: jest.fn(), + splitCopyOnCMSPlaceHolder: jest.fn().mockImplementation(() => "test"), + getRouterLinkRouteFromCopy: jest.fn(), + getRouterLinkDisplayTextFromCopy: jest.fn(), + splitCMSCopyOnParagraphTag: jest.fn(), +})); + // Mock our module for promises. jest.mock("@/helpers/layout-helper.js", () => ({ settleAllPromises: jest.fn(), })); - + describe("address-vehicles.vue", () => { test("Should navigate to CLICKED_BACK if backButtonAction is run", async () => { // Arrange - const mockSelectedVehicleVin = "TESTVIN"; const { wrapper } = setupMocks({}); - await wrapper.setData({ - selectedVehicle: { - vin: mockSelectedVehicleVin - }, - }); - // Act await wrapper.vm.backButtonAction(); @@ -51,29 +55,37 @@ describe("address-vehicles.vue", () => { // Assert expect(arePagePrerequisitesValid).toBe(true); }); - - // test("Should return false for valid page requisites if carId is missing", async () => { - // // Arrange - // const { wrapper } = setupMocks({}); - - // // Act - // store.commit(storeMutations.UPDATE_CAR_ID, null); - // const result = wrapper.vm.arePagePrerequisitesValid(); - - // //Assert - // expect(result).toBe(false); - - // wrapper.unmount(); - // }); }); function setupMocks({ - lookupVinResponse, - partsOrQuestions = [], + //partsOrQuestions = [], carId = "C0000", route = null, }) { + useMainStore().applicationUser = { + pageData: { + "address-vehicles": + [ + { vehicle: { + carId: "CARID", + category: "SUV", + imageUrl: + "https://dbhdyzvm8lm25.cloudfront.net/color_0320_032/MY2020/13769/13769_cc0320_032_WW8.jpg", + imageVifColor: "white", + imageVifNumber: "13769", + make: "Hyundai", + model: "Santa Fe", + style: "4 door utility", + year: 2020, + + }, + vin: "TESTVIN123412341234" + }, + ], + } + }; + const mountOptions = getMountOptions({ route: route ? route : undefined, router: { @@ -84,54 +96,30 @@ function setupMocks({ vehicle: { carId: carId, category: "SUV", - year: 2020, + imageUrl: + "https://dbhdyzvm8lm25.cloudfront.net/color_0320_032/MY2020/13769/13769_cc0320_032_WW8.jpg", + imageVifColor: "white", + imageVifNumber: "13769", make: "Hyundai", model: "Santa Fe", style: "4 door utility", - imageUrl: - "https://dbhdyzvm8lm25.cloudfront.net/color_0320_032/MY2020/13769/13769_cc0320_032_WW8.jpg", - imageVifNumber: "13769", - imageVifColor: "white", - }, + year: 2020, + }, vin: "5NMS3CADXLH233004", }, }, - - }); - - useMainStore().lookupVehicleByVin = jest.fn().mockImplementation(() => { - return Promise.resolve({ - data: lookupVinResponse - ? lookupVinResponse - : { - carId: "CARID", - category: "TESTCAR", - year: "0000", - make: "TestMake", - model: "TestModel", - style: "TestStyle", - imageUrl: "url", - imageVifNumber: "00000", - imageVifColor: "color" - }, - }) - }); - - useMainStore().getPartsOrQuestions = jest.fn().mockImplementation(() => { - return Promise.resolve({ - data: { - partsOrQuestions: partsOrQuestions, - }, - }) - }); + }, + ); const apiResponses = { - vinLookup: { - carId: carId, + cmsContent: { + }, }; settleAllPromises.mockImplementation(() => apiResponses); + fetchCmsContentForPage.mockImplementation(() => Promise.resolve()); + //Mock props const mockMixin = {