diff --git a/src/layouts/license-plate-lookup/license-plate-lookup.spec.js b/src/layouts/license-plate-lookup/license-plate-lookup.spec.js index d367826d..37f6ae14 100644 --- a/src/layouts/license-plate-lookup/license-plate-lookup.spec.js +++ b/src/layouts/license-plate-lookup/license-plate-lookup.spec.js @@ -32,7 +32,7 @@ jest.mock("@/helpers/damage-helper", () => ({ })); describe("license-plate-lookup.vue", () => { - test("Make set, arePagePrerequisitesValid should be true ", () => { + test("Vehicle make set, arePagePrerequisitesValid should be true", () => { //Arrange const { wrapper } = setupMocks({}); useMainStore().order.vehicle.carId = "CR00000395"; @@ -52,6 +52,43 @@ describe("license-plate-lookup.vue", () => { }); }); +describe("navigation", () => { + test("BackButtonAction triggers a router.navigate change", async () => { + //Arrange + const { wrapper, apiPromise } = setupMocks({ + mountOptionsMockData: { + router: { + navigate: jest.fn(), + }, + }, + }); + //Act + licensePlateLookup.beforeRouteEnter.call( + wrapper.vm, + { query: { issPage: "license-plate-lookup" } }, + undefined, + (c) => c(wrapper.vm) + ); + wrapper.vm.backButtonAction(); + await nextTick(); + + //Assert + return apiPromise.finally(() => { + try { + expect(wrapper.vm.$router.navigate).toHaveBeenCalled(); + } + catch (e) { + throw e + } + }); + }); + + // TODO: Create test for navigating forward when user clicks Continue + // and information entered is correct (no alerts) + // Will be implemented once navigation from page is complete + + }); + function setupMocks({ licensePlateQuestionCmsContent = {}, licensePlateQuestionInitialData = {}, @@ -60,9 +97,8 @@ function setupMocks({ mountOptionsMockData = {}, //Values to set in the state store carId = null, - registrationZipCode = null, + registrationZipCode = null, //"55555", licensePlate = null, //"TESTPLATE", - }) { //Mock api responses const apiResponses = { @@ -103,7 +139,7 @@ function setupMocks({ }, }; - + const apiPromise = Promise.resolve(apiResponses); settleAllPromises.mockImplementation(() => apiPromise); @@ -116,13 +152,19 @@ function setupMocks({ }; const mountOptions = getMountOptions(mountOptionsMockData); + const wrapper = shallowMount(licensePlateLookup, mountOptions); const licensePlateQuestionWrapper = wrapper.findComponent({ name: "licensePlateQuestion" }); licensePlateQuestionWrapper.vm.initializeComponent = licensePlateQuestion.methods.initializeComponent; - wrapper.vm.setCmsContent = baseMixin.methods.setCmsContent; - + wrapper.vm.setCmsContent = jest.fn(); + wrapper.vm.getCmsContent = jest.fn().mockImplementation(() => ""); + wrapper.vm.$refs.siteFooter.updateButtonText = jest.fn(); + return { wrapper, apiPromise }; - } \ No newline at end of file + } + + + // npm run test:unit src/layouts/license-plate-lookup/license-plate-lookup.spec.js \ No newline at end of file diff --git a/src/layouts/license-plate-lookup/license-plate-lookup.vue b/src/layouts/license-plate-lookup/license-plate-lookup.vue index 6be4545f..be2a0e70 100644 --- a/src/layouts/license-plate-lookup/license-plate-lookup.vue +++ b/src/layouts/license-plate-lookup/license-plate-lookup.vue @@ -1,5 +1,8 @@