From 140f94913ee62c2342e011c92b3e21c754d1fcba Mon Sep 17 00:00:00 2001 From: Kroell Date: Tue, 7 Feb 2023 15:48:22 -0500 Subject: [PATCH 1/7] build molding-questions page --- .../molding-questions/molding-questions.vue | 199 +++++++++++++----- src/store/index.js | 28 +++ 2 files changed, 175 insertions(+), 52 deletions(-) diff --git a/src/layouts/molding-questions/molding-questions.vue b/src/layouts/molding-questions/molding-questions.vue index bdf3e956..23f1c519 100644 --- a/src/layouts/molding-questions/molding-questions.vue +++ b/src/layouts/molding-questions/molding-questions.vue @@ -2,66 +2,53 @@
-
- - - -
-

Placeholder for molding-questions page

- - -
-
+ + + \ No newline at end of file diff --git a/src/store/index.js b/src/store/index.js index abb22d83..d664f46b 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -701,6 +701,34 @@ export const useMainStore = defineStore({ //Save new values this.updatePartQuestionAnswers(partQuestionAnswersArray); }, + saveMoldingQuestionAnswers(moldingQuestionAnswers) { + const sortedPreviousResultsArray = sortArrayOfObjectsByPropertyValue( + this.getters.damage.moldingQuestionAnswers, + "partNum" + ); + const sortedMoldingQuestionAnswersArray = sortArrayOfObjectsByPropertyValue( + moldingQuestionAnswers, + "partNum" + ); + const haveMoldingQuestionAnswersChanged = + sortedPreviousResultsArray?.length !== sortedMoldingQuestionAnswersArray.length || + !sortedPreviousResultsArray?.every( + (x, i) => x.partNum === sortedMoldingQuestionAnswersArray[i].partNum + ); + + if (haveMoldingQuestionAnswersChanged) { + this.updateGlassParts(null); + this.updateSupportingItems(null); + this.updateCapabilityQuestionAnswers(null); + this.updatePageData({ + page: issPageValues.CAPABILITY_QUESTIONS, + data: null, + }); + } + + // Save new values + this.updateMoldingQuestionAnswers(moldingQuestionAnswers); + }, addEventToBus (event) { this.applicationUser.eventBus.push(event); From ec8731f9a348b52c5a84216902915870f0986bb6 Mon Sep 17 00:00:00 2001 From: Kroell Date: Wed, 8 Feb 2023 15:40:46 -0500 Subject: [PATCH 2/7] navigation for molding-questions --- .../molding-questions/molding-questions.vue | 10 +++++----- src/router/router-constants/routing-table.js | 2 +- src/store/index.js | 14 +++++++------- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/layouts/molding-questions/molding-questions.vue b/src/layouts/molding-questions/molding-questions.vue index 23f1c519..44b4cd38 100644 --- a/src/layouts/molding-questions/molding-questions.vue +++ b/src/layouts/molding-questions/molding-questions.vue @@ -86,7 +86,7 @@ export default { }, methods: { arePagePrerequisiteValid() { - const moldingQuestionsFromPageData = useMainStore().getters.pageData( + const moldingQuestionsFromPageData = useMainStore().pageData( issPageValues.MOLDING_QUESTIONS ); return ( @@ -102,7 +102,7 @@ export default { getInitialQuestionData() { // get any questions that were already answered const alreadyAnsweredQuestions = - useMainStore().order.damage.moldingQuestionAnswers; + useMainStore().damage.moldingQuestionAnswers; this.questionsData = this.partsOrQuestionsData .filter((x) => x.parts[0].childPartQuestions.length) .map((glass, index) => { @@ -121,7 +121,7 @@ export default { "selectedAnswers." + glass.answerKey, (newValue) => { if (newValue && Object.keys(newValue).length > 0) { - this.handleCompletedQuestionChainAnswers( + this.handleAnswerUpdates( newValue, glass.answerKey ); @@ -147,7 +147,7 @@ export default { glass.answerData = {}; }); // save to store as order.damage.moldingQuestionArrays (array) - await useMainStore().saveMoldingQuestionAnswers(questionAnswersArray); + await this.mainStore.saveMoldingQuestionAnswers(questionAnswersArray); // get parts from the questionAnswers let partsOrQuestions = this.partsOrQuestionsData; @@ -163,7 +163,7 @@ export default { }, ]; } - this.navigateForward(partsOrQuestions); + this.navigateForward(partsOrQuestions, null); }, }, components: { diff --git a/src/router/router-constants/routing-table.js b/src/router/router-constants/routing-table.js index 95179d81..78dbb55a 100644 --- a/src/router/router-constants/routing-table.js +++ b/src/router/router-constants/routing-table.js @@ -235,7 +235,7 @@ const routingTable = function(store) { }, { scenario: navigationScenarios.CLICKED_BACK_WITH_NO_VIN_NOR_QUESTIONS, - destinationIssPageValue: issPageValues.ESTIMATE, + destinationIssPageValue: issPageValues.VEHICLE_LOOKUP, }, { scenario: navigationScenarios.CLICKED_BACK_WITH_PART_QUESTIONS, diff --git a/src/store/index.js b/src/store/index.js index d664f46b..db172dde 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -701,19 +701,19 @@ export const useMainStore = defineStore({ //Save new values this.updatePartQuestionAnswers(partQuestionAnswersArray); }, - saveMoldingQuestionAnswers(moldingQuestionAnswers) { + saveMoldingQuestionAnswers(moldingQuestionAnswersArray) { const sortedPreviousResultsArray = sortArrayOfObjectsByPropertyValue( - this.getters.damage.moldingQuestionAnswers, - "partNum" + this.order.damage.moldingQuestionAnswers, + "result" ); const sortedMoldingQuestionAnswersArray = sortArrayOfObjectsByPropertyValue( - moldingQuestionAnswers, - "partNum" + moldingQuestionAnswersArray, + "result" ); const haveMoldingQuestionAnswersChanged = sortedPreviousResultsArray?.length !== sortedMoldingQuestionAnswersArray.length || !sortedPreviousResultsArray?.every( - (x, i) => x.partNum === sortedMoldingQuestionAnswersArray[i].partNum + (x, i) => x.result === sortedMoldingQuestionAnswersArray[i].result ); if (haveMoldingQuestionAnswersChanged) { @@ -727,7 +727,7 @@ export const useMainStore = defineStore({ } // Save new values - this.updateMoldingQuestionAnswers(moldingQuestionAnswers); + this.updateMoldingQuestionAnswers(moldingQuestionAnswersArray); }, addEventToBus (event) { From 4f31b1c8f06cae3b1a90c19524d4564023ed4318 Mon Sep 17 00:00:00 2001 From: Kroell Date: Thu, 9 Feb 2023 15:02:16 -0500 Subject: [PATCH 3/7] Reverting change for SSR-257 - zipCode will either pull registration.zip or customer.address.zip --- src/store/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/store/index.js b/src/store/index.js index b08671f5..db172dde 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -341,7 +341,7 @@ export const useMainStore = defineStore({ payload: { carId: carId, glassPieces: glassArrayForPayload, - zip: zipCode ? zipCode : "", + zip: zipCode, vin: vin, }, }); From 3686e4907dbba94661ea119ab98f11aac44fa72c Mon Sep 17 00:00:00 2001 From: Kroell Date: Thu, 9 Feb 2023 15:02:47 -0500 Subject: [PATCH 4/7] fix to navigation from molding-questions --- src/layouts/molding-questions/molding-questions.vue | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/layouts/molding-questions/molding-questions.vue b/src/layouts/molding-questions/molding-questions.vue index 44b4cd38..e3c6c13e 100644 --- a/src/layouts/molding-questions/molding-questions.vue +++ b/src/layouts/molding-questions/molding-questions.vue @@ -31,6 +31,7 @@ import { errorMessages } from "@/constants/error-messages"; import vehicleQuestionsMixin from "@/mixins/vehicle-questions-mixin"; import { useMainStore } from "@/store"; import { issPageValues } from "@/router/router-constants/issPage-values"; +import BaseFormMixin from '@/mixins/base-form-mixin.js'; // Import Component import { Form } from "vee-validate"; @@ -41,7 +42,7 @@ defineRule("questions-required", required(errorMessages.OPTION_REQUIRED)); export default { name: "molding-questions", - mixins: [vehicleQuestionsMixin], + mixins: [BaseFormMixin, vehicleQuestionsMixin], async beforeRouteEnter(to, from, next) { const cmsContentPromise = fetchCmsContentForPage(to.query.issPage); @@ -163,6 +164,7 @@ export default { }, ]; } + this.navigateForward(partsOrQuestions, null); }, }, From a7e3c8b66905ddcaf3ae1d40008e2ece4d396bf7 Mon Sep 17 00:00:00 2001 From: Kroell Date: Thu, 9 Feb 2023 15:03:11 -0500 Subject: [PATCH 5/7] start of unit tests for molding-questions --- .../molding-questions.spec.js | 331 ++++++++++++++++++ 1 file changed, 331 insertions(+) create mode 100644 src/layouts/molding-questions/molding-questions.spec.js diff --git a/src/layouts/molding-questions/molding-questions.spec.js b/src/layouts/molding-questions/molding-questions.spec.js new file mode 100644 index 00000000..ba3d5438 --- /dev/null +++ b/src/layouts/molding-questions/molding-questions.spec.js @@ -0,0 +1,331 @@ +// Components +import moldingQuestions from "@/layouts/molding-questions/molding-questions"; + +// Supporting Files +import { shallowMount } from "@vue/test-utils"; +import { getMountOptions } from "@/helpers/unit-test-helper.js"; +import { useMainStore } from "@/store"; +import baseMixin from "../../mixins/base-mixin"; +import vehicleQuestionsMixin from "@/mixins/vehicle-questions-mixin"; +import { nextTick } from "vue"; + +// Mock our module for promises. +jest.mock("@/helpers/layout-helper.js", () => ({ + settleAllPromises: jest.fn(), +})); + +// Mock fetchCmsContentForPage +jest.mock("@/helpers/cms-content-helper", () => ({ + fetchCmsContentForPage: jest.fn(), +})); + +const baseStoreGettersPageData = () => { + return { + partsOrQuestions: [ + { + parts: [ + { + childPartQuestions: [ + { + questionSequence: 1, + questionText: + "Does the rubber seal around your windshield have a chrome strip running through it?", + answers: [ + { + answerResult: "WKT D1106 C", + answerText: "Yes", + nextQuestionSequence: null, + }, + { + answerResult: "WKT D1106 B", + answerText: "No", + nextQuestionSequence: null, + }, + ], + }, + ], + basePartNumber: "DW01105", + color: "Green Tint, Blue Shade", + requiresRecalibration: false, + recalibrationType: "", + canSafeliteRecalibrate: false, + requiresCapabilityQuestions: false, + childParts: null, + partNumber: "DW01105GBNN", + description: "solar", + partType: "WINDSHIELD", + }, + ], + partQuestions: [], + glassLocation: "Windshield", + glassName: "Single", + answerKey: "Windshield-Single", + answerData: null, + }, + ], + }; +}; +const baseStoreGettersDamage = () => { + return { + partsQuestionAnswers: [ + { + glassLocation: "Windshield", + glassName: "Single", + result: "FW04848", + answeredQuestions: [ + { + questionText: + "Is your vehicle equipped with the Panoramic Sunroof which can be identified by having a glass panel over the rear seats?", + selectedAnswer: "1|nextQuestion|3|Yes", + selectedAnswerText: "Yes", + questionNum: 1, + }, + { + questionText: + "Is your vehicle equipped with a heated windshield that melts snow and ice from underneath the windshield wiper blades?", + selectedAnswer: "2|nextQuestion|3|Yes", + selectedAnswerText: "Yes", + questionNum: 2, + }, + ], + }, + ], + }; +}; + +useMainStore().pageData = baseStoreGettersDamage; +useMainStore().damage = baseStoreGettersDamage; + +describe("moldingQuestions.vue", () => { + describe("method arePagePrerequisitesValid...", () => { + test("Should return true for valid page requisites if pageData exists", () => { + // Arrange + const { wrapper } = setupMocks({}); + + // Act + const result = wrapper.vm.arePagePrerequisitesValid(); + + //Assert + expect(result).toBe(true); + + wrapper.unmount(); + }); + + test("Should return false for valid page requisites if partsOrQuestions in pageData is missing", () => { + // Arrange + const { wrapper } = setupMocks({}); + store.getters.pageData = jest.fn(() => { + return undefined; + }); + + // Act + const result = wrapper.vm.arePagePrerequisitesValid(); + + //Assert + expect(result).toBeFalsy(); + + wrapper.unmount(); + }); + + test("Should be at least one item in partsOrQuestions", () => { + // Arrange + store.getters = { + pageData: jest.fn(() => { + return { + partsOrQuestions: [], + }; + }), + damage: baseStoreGettersDamage, + }; + const { wrapper } = setupMocks({}); + + // Act + const result = wrapper.vm.arePagePrerequisitesValid(); + + //Assert + expect(result).toBeFalsy(); + + wrapper.unmount(); + }); + }); + + describe("watch on selectedAnswers should be set up...", () => { + test("Should trigger handleCompletedQuestionChainAnswers if watched data changes", async () => { + // Arrange + const { wrapper } = setupMocks({}); + const spy = jest.spyOn(wrapper.vm, "handleCompletedQuestionChainAnswers"); + + // Act + wrapper.setData({ + selectedAnswers: { + "Windshield-Single": { + answerResult: "FW04848", + answeredQuestions: [ + { + questionText: + "Is your vehicle equipped with the Panoramic Sunroof which can be identified by having a glass panel over the rear seats?", + selectedAnswer: "1|nextQuestion|3|Yes", + selectedAnswerText: "Yes", + questionNum: 1, + }, + { + questionText: + "Is your vehicle equipped with a heated windshield that melts snow and ice from underneath the windshield wiper blades?", + selectedAnswer: "2|nextQuestion|3|Yes", + selectedAnswerText: "Yes", + questionNum: 2, + }, + ], + index: 0, + }, + }, + }); + + await nextTick(); + + //Assert + expect(spy).toHaveBeenCalled(); + + wrapper.unmount(); + }); + }); + +// describe("forwardButtonAction", () => { +// test("Should clear out answerData", () => { +// // Arrange +// const { wrapper } = setupMocks({}); + +// wrapper.vm.questionsData = [ +// { +// glassLocation: "Windshield", +// glassName: "Single", +// answerData: { +// answerResult: "FW04848", +// answeredQuestions: [], +// }, +// }, +// ]; +// wrapper.vm.dispatchStoreAction = jest.fn(() => { +// return { +// data: { +// glassPieceParts: [], +// }, +// }; +// }); + +// // Act +// wrapper.vm.forwardButtonAction(); + +// //Assert +// expect(wrapper.vm.questionsData[0].answerData).toEqual({}); + +// wrapper.unmount(); +// }); + +// test("Should save to Vuex store", async () => { +// // Arrange +// const { wrapper } = setupMocks({}); + +// wrapper.vm.questionsData = [ +// { +// glassLocation: "Windshield", +// glassName: "Single", +// answerData: { +// answerResult: "FW04848", +// answeredQuestions: [], +// }, +// }, +// ]; +// wrapper.vm.dispatchStoreAction = jest.fn(() => { +// return { +// data: { +// glassPieceParts: [], +// }, +// }; +// }); +// const spy = jest.spyOn(wrapper.vm, "dispatchStoreAction"); + +// // Act +// wrapper.vm.forwardButtonAction(); + +// await nextTick(); + +// //Assert +// expect(spy).toHaveBeenNthCalledWith( +// 1, +// "saveMoldingQuestionAnswers", +// [ +// { +// answeredQuestions: [], +// glassLocation: "Windshield", +// glassName: "Single", +// isSuppressedPart: undefined, +// partNum: "FW04848", +// }, +// ], +// false +// ); + +// wrapper.unmount(); +// }); + +// test("Should trigger navigateForward", async () => { +// // Arrange +// const { wrapper } = setupMocks({}); + +// wrapper.vm.questionsData = [ +// { +// glassLocation: "Windshield", +// glassName: "Single", +// answerData: { +// answerResult: "FW04848", +// answeredQuestions: [], +// }, +// }, +// ]; +// wrapper.vm.dispatchStoreAction = jest.fn(() => { +// return { +// data: { +// glassPieceParts: [], +// }, +// }; +// }); +// wrapper.vm.navigateForward = jest.fn(); + +// // Act +// await wrapper.vm.forwardButtonAction(); + +// //Assert +// expect(wrapper.vm.navigateForward).toHaveBeenCalled(); + +// wrapper.unmount(); +// }); +// }); + }); + +function setupMocks({ + mountOptionsMockData = { + router: { + navigate: jest.fn(), + }, + store: { + getters: store.getters, + commit: store.commit, + }, + route: { + query: { + issPage: "molding-questions", + }, + }, + }, +}) { + const mountOptions = getMountOptions({ + ...mountOptionsMockData, + mixins: [baseMixin, vehicleQuestionsMixin], + }); + mountOptions["attachTo"] = document.body; + + const wrapper = shallowMount(moldingQuestions, mountOptions); + + return { wrapper }; +} \ No newline at end of file From e9bcab540239e5978a505ec6919ac9dba2a32f6c Mon Sep 17 00:00:00 2001 From: Kroell Date: Thu, 9 Feb 2023 16:49:08 -0500 Subject: [PATCH 6/7] typo fix --- src/layouts/molding-questions/molding-questions.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/layouts/molding-questions/molding-questions.vue b/src/layouts/molding-questions/molding-questions.vue index e3c6c13e..e06dfe58 100644 --- a/src/layouts/molding-questions/molding-questions.vue +++ b/src/layouts/molding-questions/molding-questions.vue @@ -86,7 +86,7 @@ export default { this.getInitialQuestionData(); }, methods: { - arePagePrerequisiteValid() { + arePagePrerequisitesValid() { const moldingQuestionsFromPageData = useMainStore().pageData( issPageValues.MOLDING_QUESTIONS ); From 9a536d2886c8b3a506ffc1e46d10788675e65cb0 Mon Sep 17 00:00:00 2001 From: Kroell Date: Thu, 9 Feb 2023 16:49:29 -0500 Subject: [PATCH 7/7] completed unit tests for molding-questions --- .../molding-questions.spec.js | 281 +++++++++++------- 1 file changed, 169 insertions(+), 112 deletions(-) diff --git a/src/layouts/molding-questions/molding-questions.spec.js b/src/layouts/molding-questions/molding-questions.spec.js index ba3d5438..ee5a11b1 100644 --- a/src/layouts/molding-questions/molding-questions.spec.js +++ b/src/layouts/molding-questions/molding-questions.spec.js @@ -93,7 +93,7 @@ const baseStoreGettersDamage = () => { }; }; -useMainStore().pageData = baseStoreGettersDamage; +useMainStore().pageData = baseStoreGettersPageData; useMainStore().damage = baseStoreGettersDamage; describe("moldingQuestions.vue", () => { @@ -114,7 +114,7 @@ describe("moldingQuestions.vue", () => { test("Should return false for valid page requisites if partsOrQuestions in pageData is missing", () => { // Arrange const { wrapper } = setupMocks({}); - store.getters.pageData = jest.fn(() => { + useMainStore().pageData = jest.fn(() => { return undefined; }); @@ -129,14 +129,13 @@ describe("moldingQuestions.vue", () => { test("Should be at least one item in partsOrQuestions", () => { // Arrange - store.getters = { - pageData: jest.fn(() => { - return { - partsOrQuestions: [], - }; - }), - damage: baseStoreGettersDamage, - }; + useMainStore().pageData = jest.fn(() => { + return { + partsOrQuestions: [], + }; + }); + useMainStore().damage = baseStoreGettersDamage; + const { wrapper } = setupMocks({}); // Act @@ -150,10 +149,13 @@ describe("moldingQuestions.vue", () => { }); describe("watch on selectedAnswers should be set up...", () => { - test("Should trigger handleCompletedQuestionChainAnswers if watched data changes", async () => { + test("Should trigger handleAnswerUpdates if watched data changes", async () => { // Arrange + useMainStore().pageData = baseStoreGettersPageData; + useMainStore().damage = baseStoreGettersDamage; + const { wrapper } = setupMocks({}); - const spy = jest.spyOn(wrapper.vm, "handleCompletedQuestionChainAnswers"); + const spy = jest.spyOn(wrapper.vm, "handleAnswerUpdates"); // Act wrapper.setData({ @@ -190,135 +192,190 @@ describe("moldingQuestions.vue", () => { }); }); -// describe("forwardButtonAction", () => { -// test("Should clear out answerData", () => { -// // Arrange -// const { wrapper } = setupMocks({}); + describe("forwardButtonAction", () => { + test("Should clear out answerData", () => { + // Arrange + const { wrapper } = setupMocks({}); -// wrapper.vm.questionsData = [ -// { -// glassLocation: "Windshield", -// glassName: "Single", -// answerData: { -// answerResult: "FW04848", -// answeredQuestions: [], -// }, -// }, -// ]; -// wrapper.vm.dispatchStoreAction = jest.fn(() => { -// return { -// data: { -// glassPieceParts: [], -// }, -// }; -// }); + wrapper.vm.questionsData = [ + { + glassLocation: "Windshield", + glassName: "Single", + answerData: { + answerResult: "FW04848", + answeredQuestions: [], + }, + }, + ]; + wrapper.vm.dispatchStoreAction = jest.fn(() => { + return { + data: { + partsOrQuestions: [], + }, + }; + }); -// // Act -// wrapper.vm.forwardButtonAction(); + // Act + wrapper.vm.forwardButtonAction(); -// //Assert -// expect(wrapper.vm.questionsData[0].answerData).toEqual({}); + //Assert + expect(wrapper.vm.questionsData[0].answerData).toEqual({}); -// wrapper.unmount(); -// }); + wrapper.unmount(); + }); -// test("Should save to Vuex store", async () => { -// // Arrange -// const { wrapper } = setupMocks({}); + test("Should save to pinia store", async () => { + // Arrange + const { wrapper } = setupMocks({}); -// wrapper.vm.questionsData = [ -// { -// glassLocation: "Windshield", -// glassName: "Single", -// answerData: { -// answerResult: "FW04848", -// answeredQuestions: [], -// }, -// }, -// ]; -// wrapper.vm.dispatchStoreAction = jest.fn(() => { -// return { -// data: { -// glassPieceParts: [], -// }, -// }; -// }); -// const spy = jest.spyOn(wrapper.vm, "dispatchStoreAction"); + wrapper.vm.questionsData = [ + { + glassLocation: "Windshield", + glassName: "Single", + answerData: { + answerResult: "FW04848", + answeredQuestions: [], + }, + }, + ]; + useMainStore().getPartsOrQuestions = jest.fn(() => { + return { + data: { + partsOrQuestions: [], + }, + }; + }); -// // Act -// wrapper.vm.forwardButtonAction(); + // Act + wrapper.vm.forwardButtonAction(); -// await nextTick(); + await nextTick(); -// //Assert -// expect(spy).toHaveBeenNthCalledWith( -// 1, -// "saveMoldingQuestionAnswers", -// [ -// { -// answeredQuestions: [], -// glassLocation: "Windshield", -// glassName: "Single", -// isSuppressedPart: undefined, -// partNum: "FW04848", -// }, -// ], -// false -// ); + //Assert + expect(wrapper.vm.saveMoldingQuestionAnswers).toHaveBeenCalled; + wrapper.unmount(); + }); -// wrapper.unmount(); -// }); + test("Should call GET_PARTS_OR_QUESTIONS API", async () => { + // Arrange + const { wrapper } = setupMocks({}); -// test("Should trigger navigateForward", async () => { -// // Arrange -// const { wrapper } = setupMocks({}); + wrapper.vm.questionsData = [ + { + glassLocation: "Windshield", + glassName: "Single", + answerData: { + answerResult: "FW04848", + answeredQuestions: [], + }, + }, + ]; + useMainStore().getPartsOrQuestions = jest.fn(() => { + return { + data: { + partsOrQuestions: [], + }, + }; + }); -// wrapper.vm.questionsData = [ -// { -// glassLocation: "Windshield", -// glassName: "Single", -// answerData: { -// answerResult: "FW04848", -// answeredQuestions: [], -// }, -// }, -// ]; -// wrapper.vm.dispatchStoreAction = jest.fn(() => { -// return { -// data: { -// glassPieceParts: [], -// }, -// }; -// }); -// wrapper.vm.navigateForward = jest.fn(); + // Act + wrapper.vm.forwardButtonAction(); -// // Act -// await wrapper.vm.forwardButtonAction(); + await nextTick(); -// //Assert -// expect(wrapper.vm.navigateForward).toHaveBeenCalled(); + //Assert + expect(wrapper.vm.getPartsOrQuestions).toHaveBeenCalled; -// wrapper.unmount(); -// }); -// }); + wrapper.unmount(); + }); + + test("Should trigger navigateForward", async () => { + // Arrange + const { wrapper } = setupMocks({}); + + wrapper.vm.questionsData = [ + { + glassLocation: "Windshield", + glassName: "Single", + answerData: { + answerResult: "FW04848", + answeredQuestions: [], + }, + }, + ]; + useMainStore().getPartsOrQuestions = jest.fn(() => { + return { + data: { + partsOrQuestions: [], + }, + }; + }); + wrapper.vm.navigateForward = jest.fn(); + + // Act + await wrapper.vm.forwardButtonAction(); + + //Assert + expect(wrapper.vm.navigateForward).toHaveBeenCalled(); + + wrapper.unmount(); + }); }); +}); function setupMocks({ mountOptionsMockData = { router: { navigate: jest.fn(), }, - store: { - getters: store.getters, - commit: store.commit, - }, + actionList: [ + { + actionName: "saveMoldingQuestionAnswers", + data: {}, + }, + { + actionName: "getPartsOrQuestions", + data: {}, + }, + ], route: { query: { issPage: "molding-questions", }, }, + data() { + return { + computedSwitcher: [ + { + glassLocation: "Windshield", + glassName: "Single", + answerData: { + answerResult: "FW04848", + answeredQuestions: [], + }, + }, + ], + }; + }, + questionsData: { + get() { + return this.computedSwitcher; + }, + set(val) { + this.computedSwitcher = val; + }, + }, }, }) { + + useMainStore().getPartsOrQuestions = jest.fn(() => { + return { + data: { + partsOrQuestions: [], + } + }; + }); + const mountOptions = getMountOptions({ ...mountOptionsMockData, mixins: [baseMixin, vehicleQuestionsMixin],