From 39a5385b5706e85f881f77a21a4582f13d8308cb Mon Sep 17 00:00:00 2001 From: Sneha Date: Wed, 22 Feb 2023 20:42:32 +0530 Subject: [PATCH 1/6] SSR-141 Capability Questions --- .../questions-page-layout.vue | 8 + .../capability-questions.spec.js | 360 ++++++++++++++++++ .../capability-questions.vue | 168 +++++--- src/store/index.js | 24 +- 4 files changed, 515 insertions(+), 45 deletions(-) create mode 100644 src/layouts/capability-questions/capability-questions.spec.js diff --git a/src/iss-components/questions-page-layout/questions-page-layout.vue b/src/iss-components/questions-page-layout/questions-page-layout.vue index c8fc745a..75e64358 100644 --- a/src/iss-components/questions-page-layout/questions-page-layout.vue +++ b/src/iss-components/questions-page-layout/questions-page-layout.vue @@ -64,6 +64,9 @@ export default { }, }, }, + mounted(){ + this.getbuttonText(); + }, methods: { showThisQuestionChain(glass, i) { // return false if no questions or if suppressed @@ -81,6 +84,11 @@ export default { showLoadingModal() { this.$refs.loadingModal.showModal(); }, + getbuttonText(){ + this.$refs.siteFooter.updateButtonText( + `Continue` + ); + } }, components: { siteHeader, diff --git a/src/layouts/capability-questions/capability-questions.spec.js b/src/layouts/capability-questions/capability-questions.spec.js new file mode 100644 index 00000000..61e8b9ae --- /dev/null +++ b/src/layouts/capability-questions/capability-questions.spec.js @@ -0,0 +1,360 @@ +// Components +import capabilityQuestions from "@/layouts/capability-questions/capability-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: [], + }, + ], + capabilityQuestions: [ + { + questionSequence: 1, + questionText: + "Is your vehicle equipped with the optional Lane-Keeping System which tugs on the steering wheel and/or beeps to alert you if you drift too close to the edge of the lane?", + answers: [ + { + answerResult1: "DYNAMIC", + answerResult2: "1", + answerText: "Yes", + nextQuestionSequence: null, + answerResult: "DYNAMIC", + }, + { + answerResult1: "Unknown", + answerResult2: "0", + answerText: "No", + nextQuestionSequence: null, + answerResult: "Unknown", + }, + ], + }, + ], + partQuestions: [], + questions: [], + 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 = baseStoreGettersPageData; +useMainStore().damage = baseStoreGettersDamage; + +describe("capabilityQuestions.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({}); + useMainStore().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 + useMainStore().pageData = jest.fn(() => { + return { + partsOrQuestions: [], + }; + }); + useMainStore().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: [], + }, + questions: [], + parts: [ + { + childPartQuestions: [{}], + }, + ], + }, + ]; + wrapper.vm.dispatchStoreAction = jest.fn(() => { + return { + data: [], + }; + }); + + // Act + wrapper.vm.forwardButtonAction(); + + //Assert + expect(wrapper.vm.questionsData[0].answerData).toEqual({}); + + wrapper.unmount(); + }); + + test("Should save to pinia store", async () => { + // Arrange + const { wrapper } = setupMocks({}); + + wrapper.vm.questionsData = [ + { + glassLocation: "Windshield", + glassName: "Single", + answerData: { + answerResult: "FW04848", + answeredQuestions: [], + }, + questions: [], + parts: [ + { + childPartQuestions: [], + }, + ], + }, + ]; + useMainStore().getPartsOrQuestions = jest.fn(() => { + return { + data: { + partsOrQuestions: [], + }, + }; + }); + + // Act + wrapper.vm.forwardButtonAction(); + + await nextTick(); + + //Assert + expect(wrapper.vm.saveCapabilityQuestionAnswers).toHaveBeenCalled; + wrapper.unmount(); + }); + + test("Should trigger navigateForward", async () => { + // Arrange + const { wrapper } = setupMocks({}); + + wrapper.vm.questionsData = [ + { + glassLocation: "Windshield", + glassName: "Single", + answerData: { + answerResult: "FW04848", + answeredQuestions: [], + }, + questions: [], + parts: [ + { + childPartQuestions: [], + }, + ], + }, + ]; + wrapper.vm.dispatchStoreAction = jest.fn(() => { + return { + data: [], + }; + }); + 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(), + }, + actionList: [ + { + actionName: "saveCapabilityQuestionAnswers", + data: {}, + }, + { + actionName: "getPartsOrQuestions", + data: {}, + }, + ], + route: { + query: { + issPage: "capability-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], + }); + mountOptions["attachTo"] = document.body; + + const wrapper = shallowMount(capabilityQuestions, mountOptions); + + return { wrapper }; +} \ No newline at end of file diff --git a/src/layouts/capability-questions/capability-questions.vue b/src/layouts/capability-questions/capability-questions.vue index 23ba630f..b5dd3e99 100644 --- a/src/layouts/capability-questions/capability-questions.vue +++ b/src/layouts/capability-questions/capability-questions.vue @@ -1,33 +1,21 @@ diff --git a/src/store/index.js b/src/store/index.js index b30dd12c..40774e7c 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -395,7 +395,6 @@ export const useMainStore = defineStore({ endpoint: `${endpoints.GetCapabilityQuestions.url}/${carId}/${partNumber}`, }); }, - lookupVehicleByVin(vin) { return globalMethods.callHttpClient({ method: endpoints.LookupVehicleByVin.method, @@ -729,6 +728,29 @@ export const useMainStore = defineStore({ // Save new values this.updateMoldingQuestionAnswers(moldingQuestionAnswersArray); }, + saveCapabilityQuestionAnswers(capabilityQuestionAnswersArray) { + const sortedPreviousResultsArray = sortArrayOfObjectsByPropertyValue( + this.order.damage.capabilityQuestionAnswers, + "result" + ); + const sortedCapabilityQuestionAnswersArray = sortArrayOfObjectsByPropertyValue( + capabilityQuestionAnswersArray, + "result" + ); + const haveCapabilityQuestionAnswersChanged = + sortedPreviousResultsArray?.length !== sortedCapabilityQuestionAnswersArray.length || + !sortedPreviousResultsArray?.every( + (x, i) => x.result === sortedCapabilityQuestionAnswersArray[i].result + ); + + if (haveCapabilityQuestionAnswersChanged) { + this.updateGlassParts(null); + this.updateSupportingItems(null); + } + + // Save new values + this.updateCapabilityQuestionAnswers(capabilityQuestionAnswersArray); + }, addEventToBus (event) { this.applicationUser.eventBus.push(event); From af50992a0ca8ba06e559852160b2e471833c6910 Mon Sep 17 00:00:00 2001 From: Sneha Date: Thu, 23 Feb 2023 09:32:25 +0530 Subject: [PATCH 2/6] Update capability-questions.spec.js --- .../capability-questions/capability-questions.spec.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/layouts/capability-questions/capability-questions.spec.js b/src/layouts/capability-questions/capability-questions.spec.js index 61e8b9ae..42dcff14 100644 --- a/src/layouts/capability-questions/capability-questions.spec.js +++ b/src/layouts/capability-questions/capability-questions.spec.js @@ -278,9 +278,11 @@ describe("capabilityQuestions.vue", () => { ], }, ]; - wrapper.vm.dispatchStoreAction = jest.fn(() => { + useMainStore().getPartsOrQuestions = jest.fn(() => { return { - data: [], + data: { + partsOrQuestions: [], + }, }; }); wrapper.vm.navigateForward = jest.fn(); From 9112046093d43713da6544a8bc08f0f0175a5c99 Mon Sep 17 00:00:00 2001 From: Sneha Date: Thu, 23 Feb 2023 12:27:43 +0530 Subject: [PATCH 3/6] Update capability-questions.spec.js --- .../capability-questions.spec.js | 44 ++++++++++++++++++- 1 file changed, 42 insertions(+), 2 deletions(-) diff --git a/src/layouts/capability-questions/capability-questions.spec.js b/src/layouts/capability-questions/capability-questions.spec.js index 42dcff14..0e488e9e 100644 --- a/src/layouts/capability-questions/capability-questions.spec.js +++ b/src/layouts/capability-questions/capability-questions.spec.js @@ -144,10 +144,12 @@ describe("capabilityQuestions.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({ @@ -257,6 +259,44 @@ describe("capabilityQuestions.vue", () => { expect(wrapper.vm.saveCapabilityQuestionAnswers).toHaveBeenCalled; wrapper.unmount(); }); + test("Should call GET_PARTS_OR_QUESTIONS API", async () => { + // Arrange + const { wrapper } = setupMocks({}); + + wrapper.vm.questionsData = [ + { + glassLocation: "Windshield", + glassName: "Single", + answerData: { + answerResult: "FW04848", + answeredQuestions: [], + }, + questions: [], + parts: [ + { + childPartQuestions: [], + }, + ], + }, + ]; + useMainStore().getPartsOrQuestions = jest.fn(() => { + return { + data: { + partsOrQuestions: [], + }, + }; + }); + + // Act + wrapper.vm.forwardButtonAction(); + + await nextTick(); + + //Assert + expect(wrapper.vm.getPartsOrQuestions).toHaveBeenCalled; + + wrapper.unmount(); + }); test("Should trigger navigateForward", async () => { // Arrange From 8179a019c26d897c84b1614555a5f7a3029e8d9a Mon Sep 17 00:00:00 2001 From: Sneha Date: Thu, 23 Feb 2023 12:53:53 +0530 Subject: [PATCH 4/6] Update capability-questions.vue --- src/layouts/capability-questions/capability-questions.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/layouts/capability-questions/capability-questions.vue b/src/layouts/capability-questions/capability-questions.vue index b5dd3e99..6d4eccea 100644 --- a/src/layouts/capability-questions/capability-questions.vue +++ b/src/layouts/capability-questions/capability-questions.vue @@ -83,7 +83,7 @@ export default { }, methods: { - arePagePrerequisiteValid() { + arePagePrerequisitesValid() { const capabilityQuestionsFromPageData = useMainStore().pageData(issPageValues.CAPABILITY_QUESTIONS); return ( capabilityQuestionsFromPageData?.partsOrQuestions?.some((part) => part?.glassName) && From dbf449089bfb0edc40ff360237725aae7014e39d Mon Sep 17 00:00:00 2001 From: Sneha Date: Thu, 23 Feb 2023 13:02:26 +0530 Subject: [PATCH 5/6] fixing build errors --- .../questions-page-layout.vue | 16 ++++++++-------- .../capability-questions.vue | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/iss-components/questions-page-layout/questions-page-layout.vue b/src/iss-components/questions-page-layout/questions-page-layout.vue index 75e64358..941464ca 100644 --- a/src/iss-components/questions-page-layout/questions-page-layout.vue +++ b/src/iss-components/questions-page-layout/questions-page-layout.vue @@ -64,9 +64,9 @@ export default { }, }, }, - mounted(){ - this.getbuttonText(); - }, + // mounted(){ + // this.getbuttonText(); + // }, methods: { showThisQuestionChain(glass, i) { // return false if no questions or if suppressed @@ -84,11 +84,11 @@ export default { showLoadingModal() { this.$refs.loadingModal.showModal(); }, - getbuttonText(){ - this.$refs.siteFooter.updateButtonText( - `Continue` - ); - } + // getbuttonText(){ + // this.$refs.siteFooter.updateButtonText( + // `Continue` + // ); + // } }, components: { siteHeader, diff --git a/src/layouts/capability-questions/capability-questions.vue b/src/layouts/capability-questions/capability-questions.vue index 6d4eccea..0b5cca78 100644 --- a/src/layouts/capability-questions/capability-questions.vue +++ b/src/layouts/capability-questions/capability-questions.vue @@ -87,7 +87,7 @@ export default { const capabilityQuestionsFromPageData = useMainStore().pageData(issPageValues.CAPABILITY_QUESTIONS); return ( capabilityQuestionsFromPageData?.partsOrQuestions?.some((part) => part?.glassName) && - capabilityQuestionsDFromPageData?.partsOrQuestions?.some( + capabilityQuestionsFromPageData?.partsOrQuestions?.some( (part) => part?.capabilityQuestions?.length > 0) ); }, From 01c6ee9c270cdfc0fd8af41d46ef9304d29bc9ef Mon Sep 17 00:00:00 2001 From: Sneha Date: Thu, 23 Feb 2023 18:21:06 +0530 Subject: [PATCH 6/6] Update questions-page-layout.vue removed the commented code --- .../questions-page-layout/questions-page-layout.vue | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/iss-components/questions-page-layout/questions-page-layout.vue b/src/iss-components/questions-page-layout/questions-page-layout.vue index 941464ca..c8fc745a 100644 --- a/src/iss-components/questions-page-layout/questions-page-layout.vue +++ b/src/iss-components/questions-page-layout/questions-page-layout.vue @@ -64,9 +64,6 @@ export default { }, }, }, - // mounted(){ - // this.getbuttonText(); - // }, methods: { showThisQuestionChain(glass, i) { // return false if no questions or if suppressed @@ -84,11 +81,6 @@ export default { showLoadingModal() { this.$refs.loadingModal.showModal(); }, - // getbuttonText(){ - // this.$refs.siteFooter.updateButtonText( - // `Continue` - // ); - // } }, components: { siteHeader,