diff --git a/src/common-components/button-question/button-question.spec.js b/src/common-components/button-question/button-question.spec.js index 464fcf245..d36b73012 100644 --- a/src/common-components/button-question/button-question.spec.js +++ b/src/common-components/button-question/button-question.spec.js @@ -53,7 +53,7 @@ describe("buttonQuestion.vue", () => { answers: ["2022", "2021", "2020"], isMultiSelect: false }); - const val = {isChecked: true, buttonId: "2021", } + const val = {checkValue: true, value: "2021", } wrapper.vm.handleCheckedChanged(val); // Assert expect(wrapper.emitted()["update:modelValue"][0]).toEqual([["2021"]]); @@ -69,7 +69,7 @@ describe("buttonQuestion.vue", () => { isMultiSelect: true, } }); - const val = {isChecked: true, buttonId: "2019", } + const val = {checkValue: true, value: "2019", } wrapper.vm.handleCheckedChanged(val); // Assert expect(wrapper.emitted()["update:modelValue"][0]).toEqual([["2022", "2021", "2020", "2019"]]); diff --git a/src/common-components/button-question/button-question.vue b/src/common-components/button-question/button-question.vue index 4ca468502..e96f15df5 100644 --- a/src/common-components/button-question/button-question.vue +++ b/src/common-components/button-question/button-question.vue @@ -12,7 +12,7 @@ v-for="answer in answers" :key="answer.Name ? answer.Name : answer" @isCheckedChanged="handleCheckedChanged" - :buttonID="answer.Name ? answer.Name : answer" + :buttonID="answer.Name ? groupName + '-' + answer.Name : groupName + '-' + answer" :value="answer.Name ? answer.Name : answer" :buttonLabel="answer.Text ? answer.Text : answer" :buttonLabelSubCopy="answer.SubText" @@ -29,7 +29,7 @@ :altText="answer.Name ? answer.Name : answer" screenReaderOnlyText="(opens new window)" :colLength="getColLength" - :selectedButtonIDs="selectedValues" + :selectedValues="selectedValues" data-test="button" :validationRules="validationRules" /> @@ -124,11 +124,13 @@ export default { handleCheckedChanged(val) { if(this.isMultiSelect && this.selectedValues) { // Add or remove item to array of data to emit - const newSelectedValues = this.selectedValues; - val.isChecked ? newSelectedValues.push(val.buttonId) : newSelectedValues.splice(newSelectedValues.indexOf(val.buttonId), 1); - this.selectedValues = newSelectedValues; + if(Array.isArray(this.selectedValues)) { + const newSelectedValues = this.selectedValues; + val.checkValue ? newSelectedValues.push(val.value) : newSelectedValues.splice(newSelectedValues.indexOf(val.value), 1); + this.selectedValues = newSelectedValues; + } } else { - this.selectedValues = [val.buttonId]; + this.selectedValues = [val.value]; } }, }, diff --git a/src/layouts/vehicle-damage/damage-location-question/damage-location-question.spec.js b/src/layouts/vehicle-damage/damage-location-question/damage-location-question.spec.js index 01f063eef..92feec9b8 100644 --- a/src/layouts/vehicle-damage/damage-location-question/damage-location-question.spec.js +++ b/src/layouts/vehicle-damage/damage-location-question/damage-location-question.spec.js @@ -41,7 +41,7 @@ describe("damage-location-question.vue", () => { damageLocationQuestion.methods.initializeComponent.call(wrapper.vm, cmsContent, damageOptions, "car-group"); //Assert - expect(wrapper.vm.answersToDisplay).toStrictEqual([ { Name: 'car-Windshield' }, { Name: 'car-SideDoor' } ]) + expect(wrapper.vm.answersToDisplay).toStrictEqual([ { Name: 'Windshield' }, { Name: 'SideDoor' } ]) }); }); diff --git a/src/layouts/vehicle-damage/damage-location-question/damage-location-question.vue b/src/layouts/vehicle-damage/damage-location-question/damage-location-question.vue index 58a74a31c..89b3244e3 100644 --- a/src/layouts/vehicle-damage/damage-location-question/damage-location-question.vue +++ b/src/layouts/vehicle-damage/damage-location-question/damage-location-question.vue @@ -67,13 +67,18 @@ export default ({ } }, answersToDisplay(){ - return Array.isArray(this.answersFromCms) + const filteredAnswers = Array.isArray(this.answersFromCms) ? this.answersFromCms.filter(ans => { const name = ans.Name.split('-'); return name[0].toUpperCase() === store.getters.vehicle.category && this.damageOptionsMap[name[1]]; }) : []; + return filteredAnswers.map(ans => { + const newName = ans.Name.includes('-') ? ans.Name.split('-')[1] : ans.Name; + ans.Name = newName; + return ans; + }); }, }, components: { 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 4d18fbd1c..a6ee43924 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 @@ -31,12 +31,12 @@ describe("replace-options-question.vue", () => { replaceOptionsQuestion.methods.initializeComponent.call(wrapper.vm, cmsContent, replaceOptions, "car-group"); //Assert - expect(wrapper.vm.answersToDisplay).toStrictEqual([ { Name: 'car-Windshield' }, { Name: 'car-FrontDoor' } ]) + expect(wrapper.vm.answersToDisplay).toStrictEqual([ { Name: 'Windshield' }, { Name: 'FrontDoor' } ]) }); }); describe("replace-options-question.vue", () => { - test("when updateSelectedValues method is called with a single answerToDisplay it will update this.selectedValues", async () => { + test("when updateSelectedValues method is called with a single answerToDisplay it will call to update this.selectedValues", async () => { //Arrange const { wrapper, cmsContent, replaceOptions @@ -56,9 +56,7 @@ describe("replace-options-question.vue", () => { //Act wrapper.vm.$options.methods.updateSelectedValues.call(wrapper.vm); - //Assert - expect(wrapper.vm.selectedValues).toStrictEqual(['Stationary']); - + expect(wrapper.emitted()["update:modelValue"][0]).toEqual([['Stationary']]); }); }); @@ -78,8 +76,6 @@ describe("replace-options-question.vue", () => { }); }); - - function setupMocks({ modelValueProp = ["Windshield"], isAvailable = true, 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 cfbc7bd77..d8fdd45c3 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,8 +1,7 @@