From 6526dbbbad91bac5d4aa83ed62ab95c7e7b0171c Mon Sep 17 00:00:00 2001 From: Adam Caouette Date: Thu, 17 Feb 2022 11:21:48 -0500 Subject: [PATCH 01/12] CSR-296: add back glass replace options question --- .../button-question/button-question.vue | 1 + .../replace-options-question.vue | 9 +++--- src/layouts/vehicle-damage/vehicle-damage.vue | 29 ++++++++++++++++--- src/ux-components/list-card/list-card.vue | 16 ++++------ 4 files changed, 37 insertions(+), 18 deletions(-) diff --git a/src/common-components/button-question/button-question.vue b/src/common-components/button-question/button-question.vue index 417230464..0e17e9de7 100644 --- a/src/common-components/button-question/button-question.vue +++ b/src/common-components/button-question/button-question.vue @@ -121,6 +121,7 @@ export default { }, }, mounted(){ + // UPDATE SELECTEDVALUES IF ONLY ONE ANSWER if(Array.isArray(this.answers) && this.answers.length === 1) { const newSelectedValues = this.selectedValues; newSelectedValues.push(typeof(this.answers[0]) === 'object' ? this.answers[0].Name : this.answers[0]); diff --git a/src/layouts/vehicle-damage/replace-options-question/replace-options-question.vue b/src/layouts/vehicle-damage/replace-options-question/replace-options-question.vue index 31c739b49..9a06e3502 100644 --- a/src/layouts/vehicle-damage/replace-options-question/replace-options-question.vue +++ b/src/layouts/vehicle-damage/replace-options-question/replace-options-question.vue @@ -2,9 +2,9 @@
{ const name = ans.Name.split('-'); - return this.filterByVehicleCategory ? name[0].toUpperCase() === store.getters.vehicle.category : name[0].toUpperCase() === store.getters.vehicle.category && this.replaceOptions.includes(name[1]) + return this.filterByVehicleCategory ? name[0].toUpperCase() === store.getters.vehicle.category && this.replaceOptions.includes(name[1]) : this.replaceOptions.includes(ans.Name); }) : []; }, diff --git a/src/layouts/vehicle-damage/vehicle-damage.vue b/src/layouts/vehicle-damage/vehicle-damage.vue index 9f6a38650..0d454a754 100644 --- a/src/layouts/vehicle-damage/vehicle-damage.vue +++ b/src/layouts/vehicle-damage/vehicle-damage.vue @@ -3,8 +3,25 @@ - - + + +
@@ -62,11 +79,14 @@ export default { vm.$refs.funnelSubHeader.initializeComponent( resultMap.cmsContent.FunnelSubHeaderWidget ); + vm.$refs.damageLocation.initializeComponent( + resultMap.cmsContent.DamageLocationQuestion, resultMap.damageOptions + ); vm.$refs.driverSideOptions.initializeComponent( resultMap.cmsContent.DriverSideReplaceOptionsQuestion, resultMap.damageOptions.driverSideOptions.availableReplacementOptions ); - vm.$refs.damageLocation.initializeComponent( - resultMap.cmsContent.DamageLocationQuestion, resultMap.damageOptions + vm.$refs.backGlassOptions.initializeComponent( + resultMap.cmsContent.RearReplaceOptionsQuestion, resultMap.damageOptions.backGlassOptions.availableReplacementOptions ); vm.$refs.funnelFooter.initializeComponent( resultMap.cmsContent.FunnelFooterWidget @@ -77,6 +97,7 @@ export default { return { selectedDamageLocations: [], driverSideOptionsData: [], + selectedRearReplaceOptions: [], } }, methods: { diff --git a/src/ux-components/list-card/list-card.vue b/src/ux-components/list-card/list-card.vue index 7550c9ec4..ae1102f12 100644 --- a/src/ux-components/list-card/list-card.vue +++ b/src/ux-components/list-card/list-card.vue @@ -74,16 +74,6 @@ export default { validationRules: String, selectedButtonIDs: [Array, String], }, - data(){ - return { - checkValue: Boolean, - } - }, - created(){ - if(this.selectedButtonIDs){ - this.checkValue = this.isMultiSelect ? this.selectedButtonIDs.includes(this.buttonID) : this.selectedButtonIDs[0]; - } - }, computed: { getLabelClasses() { if (this.isWide) { @@ -96,6 +86,12 @@ export default { return "flex-column pt-4 pb-2"; } }, + checkValue() { + if(this.selectedButtonIDs){ + return this.isMultiSelect ? this.selectedButtonIDs.includes(this.buttonID) : this.selectedButtonIDs[0]; + } + return false; + }, }, methods: { handleCheckChange(newValue, oldValue){ From b14f2c7359fdec33fd740eb219abcfc71fb14663 Mon Sep 17 00:00:00 2001 From: Adam Caouette Date: Tue, 22 Feb 2022 13:11:46 -0500 Subject: [PATCH 02/12] CSR-296: create/clean up unit tests --- .../replace-options-question.spec.js | 180 +++++++++++------- .../replace-options-question.vue | 22 ++- .../vehicle-damage/vehicle-damage.spec.js | 72 +++++-- src/layouts/vehicle-damage/vehicle-damage.vue | 16 +- src/ux-components/list-card/list-card.vue | 16 +- 5 files changed, 216 insertions(+), 90 deletions(-) diff --git a/src/layouts/vehicle-damage/replace-options-question/replace-options-question.spec.js b/src/layouts/vehicle-damage/replace-options-question/replace-options-question.spec.js index df8a16f90..4d18fbd1c 100644 --- a/src/layouts/vehicle-damage/replace-options-question/replace-options-question.spec.js +++ b/src/layouts/vehicle-damage/replace-options-question/replace-options-question.spec.js @@ -1,76 +1,128 @@ import { shallowMount } from "@vue/test-utils"; import replaceOptionsQuestion from "@/layouts/vehicle-damage/replace-options-question/replace-options-question"; import { getMountOptions } from "@/helpers/unit-test-helper.js"; +import { nextTick } from "vue"; import store from "@/store"; jest.mock("@/store", () => { return {}; }, {virtual: true}); describe("replace-options-question.vue", () => { - test("Selected damage option is emitted upon selection.", async () => { - - //Arrange - const { wrapper } = setupMocks({ modelValueProp: ["Windshield"] }); - const damageToSelect = ["Backseat"]; - - //Act - wrapper.setValue({ modelValue: damageToSelect }); - await wrapper.vm.$nextTick(); - - //Assert - expect(wrapper.emitted()["update:modelValue"][0]).toEqual([{modelValue: ["Backseat"]}]); - }); - }); + test("Selected damage option is emitted upon selection.", async () => { - describe("replace-options-question.vue", () => { - test("Answers to display filtered by data from api.", async () => { - - //Arrange - const { wrapper, cmsContent, replaceOptions } = setupMocks({ dataFromStoreApi: ["Windshield", "FrontDoor"], filterByVehicleCategory: true}); - - //Act - replaceOptionsQuestion.methods.initializeComponent.call(wrapper.vm, cmsContent, replaceOptions, "car-group"); - - //Assert - expect(wrapper.vm.answersToDisplay).toStrictEqual([ { Name: 'car-Windshield' }, { Name: 'car-FrontDoor' } ]) - }); - }); + //Arrange + const { wrapper } = setupMocks({ modelValueProp: ["Windshield"] }); + const damageToSelect = ["Backseat"]; - function setupMocks({ - modelValueProp = ["Windshield"], - isAvailale = true, - isMultiSelect = false, - filterByVehicleCategory = false, - groupName = "damageQuestion", - cmsQuestionText = "CMS text goes here", - cmsAnswers = [{Name: "car-Windshield"}, {Name: "car-BackDoor"}, {Name: "car-FrontDoor"}], - dataFromStoreApi = [], - }) { - - //Mock store - store.dispatch = jest.fn(() => dataFromStoreApi); - store.getters = { vehicle: {year: 2019, make: 'honda', model: 'civc', style: '2 Door', category: 'CAR'} }; - const mountOptions = getMountOptions({ - store: { - dispatch: store.dispatch, - getters: store.getters, + //Act + wrapper.setValue({ modelValue: damageToSelect }); + await wrapper.vm.$nextTick(); + + //Assert + expect(wrapper.emitted()["update:modelValue"][0]).toEqual([{modelValue: ["Backseat"]}]); + }); +}); + +describe("replace-options-question.vue", () => { + test("Answers to display filtered by data from api.", async () => { + + //Arrange + const { wrapper, cmsContent, replaceOptions } = setupMocks({ dataFromStoreApi: ["Windshield", "FrontDoor"], filterByVehicleCategory: true}); + + //Act + replaceOptionsQuestion.methods.initializeComponent.call(wrapper.vm, cmsContent, replaceOptions, "car-group"); + + //Assert + expect(wrapper.vm.answersToDisplay).toStrictEqual([ { Name: 'car-Windshield' }, { Name: 'car-FrontDoor' } ]) + }); +}); + +describe("replace-options-question.vue", () => { + test("when updateSelectedValues method is called with a single answerToDisplay it will update this.selectedValues", async () => { + + //Arrange + const { wrapper, cmsContent, replaceOptions + } = setupMocks({ + modelValueProp: [], + }); + wrapper.setData({answersFromCms: [ + { + "Name": "Stationary", }, - }); + { + "Name": "Slider", + } + ]}); + wrapper.setData({replaceOptions: ["Stationary"]}); + + //Act + wrapper.vm.$options.methods.updateSelectedValues.call(wrapper.vm); + + //Assert + expect(wrapper.vm.selectedValues).toStrictEqual(['Stationary']); + + }); +}); + +describe("replace-options-question.vue", () => { + test("when isAvailable is true, will run updateSelectedValues method", async () => { + + //Arrange + const { wrapper, cmsContent, replaceOptions } = setupMocks({ isAvailable: false, methodsToMock: ["updateSelectedValues"] }); + + //Act + wrapper.vm.$options.methods.initializeComponent.call(wrapper.vm, cmsContent, replaceOptions, "car-group"); + wrapper.vm.$options.watch.isAvailable.call(wrapper.vm, true); + + //Assert + expect(replaceOptionsQuestion.methods.updateSelectedValues).toHaveBeenCalled(); + wrapper.unmount(); + }); +}); + + + +function setupMocks({ + modelValueProp = ["Windshield"], + isAvailable = true, + isMultiSelect = false, + filterByVehicleCategory = false, + groupName = "damageQuestion", + cmsQuestionText = "CMS text goes here", + cmsAnswers = [{Name: "car-Windshield"}, {Name: "car-BackDoor"}, {Name: "car-FrontDoor"}], + dataFromStoreApi = [], + methodsToMock = [], +}) { - //Mock props - mountOptions.propsData = { - modelValue: modelValueProp, - isAvailable: isAvailale, - isMultiSelect: isMultiSelect, - filterByVehicleCategory: filterByVehicleCategory - }; - - const wrapper = shallowMount(replaceOptionsQuestion, mountOptions); + //Mock store + store.dispatch = jest.fn(() => dataFromStoreApi); + store.getters = { vehicle: {year: 2019, make: 'honda', model: 'civc', style: '2 Door', category: 'CAR'} }; + const mountOptions = getMountOptions({ + store: { + dispatch: store.dispatch, + getters: store.getters, + }, + }); + + //Mock props + mountOptions.propsData = { + modelValue: modelValueProp, + isAvailable: isAvailable, + isMultiSelect: isMultiSelect, + filterByVehicleCategory: filterByVehicleCategory + }; + + //Mock methods + methodsToMock.forEach((methodName) => { + replaceOptionsQuestion.methods[methodName] = jest.fn(); + }); - //Mock CMS content - const cmsContent = { - groupName: groupName, - QuestionText: cmsQuestionText, - Answers: cmsAnswers, - }; - const replaceOptions = dataFromStoreApi; - return { wrapper, cmsContent, replaceOptions }; - } \ No newline at end of file + const wrapper = shallowMount(replaceOptionsQuestion, mountOptions); + + //Mock CMS content + const cmsContent = { + groupName: groupName, + QuestionText: cmsQuestionText, + Answers: cmsAnswers, + }; + const replaceOptions = dataFromStoreApi; + return { wrapper, cmsContent, replaceOptions }; +} \ No newline at end of file diff --git a/src/layouts/vehicle-damage/replace-options-question/replace-options-question.vue b/src/layouts/vehicle-damage/replace-options-question/replace-options-question.vue index 20cd1ba57..419b15f7f 100644 --- a/src/layouts/vehicle-damage/replace-options-question/replace-options-question.vue +++ b/src/layouts/vehicle-damage/replace-options-question/replace-options-question.vue @@ -1,6 +1,6 @@