From 883b7b09161d3124aa4ffa482bd0d72a37c235fe Mon Sep 17 00:00:00 2001 From: hiteshkumar87 Date: Mon, 22 Jul 2024 17:00:58 +0530 Subject: [PATCH] csr-2087 estimate and quote page unit test --- src/layouts/estimate/estimate.spec.js | 20 +++++++++----------- src/layouts/quote/quote.spec.js | 5 +++++ 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/layouts/estimate/estimate.spec.js b/src/layouts/estimate/estimate.spec.js index 9278c24bf..3ea0babd1 100644 --- a/src/layouts/estimate/estimate.spec.js +++ b/src/layouts/estimate/estimate.spec.js @@ -215,23 +215,17 @@ describe("estimate.vue", () => { describe("estimate.vue", () => { test("should call forwardButtonAction if isLeadGen is true and form is valid", async () => { - // update store with isLeadGen as true - store.getters = { - isLeadGen: true, - leadGenEstimate: { - vinSelection: "decline", - }, - }; + store.commit(storeMutations.UPDATE_IS_LEAD_GEN, true); + store.commit(storeMutations.UPDATE_LEAD_GEN_VIN_SELECTION, "decline"); // Set up the component const { wrapper } = setupMocks({}); - baseMixin.methods.isFormValid = jest.fn().mockReturnValue(true); wrapper.vm.forwardButtonAction = jest.fn(); + const nextFunction = jest.fn((c) => { c(wrapper.vm); }); - // Call the method that contains the if-else logic await estimate.beforeRouteEnter.call( wrapper.vm, @@ -239,9 +233,13 @@ describe("estimate.vue", () => { undefined, nextFunction ); - await nextTick(); + await wrapper.vm.$nextTick(); expect(nextFunction).toHaveBeenCalled(); + expect(baseMixin.methods.isFormValid).toHaveBeenCalled(); + expect(baseMixin.methods.isFormValid()).toBe(true); + await wrapper.vm.$nextTick(); + expect(wrapper.vm.forwardButtonAction).toHaveBeenCalled(); }); }); @@ -287,7 +285,7 @@ function setupMocks({ const apiPromise = Promise.resolve({ cmsContent }); settleAllPromises.mockImplementation(() => apiPromise); fetchCmsContentForPage.mockImplementation(() => Promise.resolve()); - + baseMixin.methods.isFormValid = jest.fn().mockReturnValue(true); const mountOptions = getMountOptions({ ...mountOptionsMockData, mixins: [baseMixin, mockMixin], diff --git a/src/layouts/quote/quote.spec.js b/src/layouts/quote/quote.spec.js index f7a158fc4..f6cb82858 100644 --- a/src/layouts/quote/quote.spec.js +++ b/src/layouts/quote/quote.spec.js @@ -705,6 +705,10 @@ describe("quote.vue", () => { ); await nextTick(); expect(nextFunction).toHaveBeenCalled(); + expect(baseMixin.methods.isFormValid).toHaveBeenCalled(); + expect(baseMixin.methods.isFormValid()).toBe(true); + await wrapper.vm.$nextTick(); + expect(wrapper.vm.forwardButtonAction).toHaveBeenCalled(); }); }); @@ -714,6 +718,7 @@ function setupMocks({ customMountOptions }) { }); baseMixin.methods.hideFmgLoadingModal = jest.fn(); + baseMixin.methods.isFormValid = jest.fn().mockReturnValue(true); mountOptions.global.mocks["$store"] = store; mountOptions["attachTo"] = document.body; const wrapper = shallowMount(quote, mountOptions);