diff --git a/src/helpers/damage-helper.js b/src/helpers/damage-helper.js index 55d10738d..ed353e51b 100644 --- a/src/helpers/damage-helper.js +++ b/src/helpers/damage-helper.js @@ -19,7 +19,7 @@ export function getDamageString() { if (damageLocations.length > 1) { returnString = "match" } else { - switch(damageLocations[0]?.location) { + switch(damageLocations[0]?.glassLocation) { case "Windshield": returnString = "windshield" break; @@ -36,7 +36,7 @@ export function getDamageString() { export function getIsWindshieldOnly () { const damageLocations = store.getters.damage.glassToReplace; - const returnString = damageLocations.length === 1 && damageLocations[0]?.location === "Windshield" ? "windshield" : "glass"; + const returnString = damageLocations.length === 1 && damageLocations[0]?.glassLocation === "Windshield" ? "windshield" : "glass"; return returnString; } @@ -56,7 +56,7 @@ export async function isGlassAvailableForCarId(carId){ } for(const option of currentGlassOptions){ - if(!newGlassOptions.data[optionsMap[option.location]].availableReplacementOptions.includes(option.name)){ + if(!newGlassOptions.data[optionsMap[option.glassLocation]].availableReplacementOptions.includes(option.glassName)){ return false; } } diff --git a/src/helpers/damage-helper.spec.js b/src/helpers/damage-helper.spec.js index 2a46978dc..210bf96cc 100644 --- a/src/helpers/damage-helper.spec.js +++ b/src/helpers/damage-helper.spec.js @@ -16,7 +16,7 @@ jest.mock("@/mixins/base-mixin.js", () => ({ it("Should return match when multiple selected damage options are in the store", () => { // Arrange / Act - store.getters.damage.glassToReplace = [{location: "Windshield", name: "windshield"}, {location: "Passenger", name: "sideWindow"}]; + store.getters.damage.glassToReplace = [{glassLocation: "Windshield", glassName: "windshield"}, {glassLocation: "Passenger", glassName: "sideWindow"}]; const damage = getDamageString(); @@ -29,7 +29,7 @@ jest.mock("@/mixins/base-mixin.js", () => ({ it("Should return windshield when Windshield is the only selected damage option in the store", () => { // Arrange / Act - store.getters.damage.glassToReplace = [{location: "Windshield", name: "windshield"}]; + store.getters.damage.glassToReplace = [{glassLocation: "Windshield", glassName: "windshield"}]; const damage = getDamageString(); @@ -42,7 +42,7 @@ jest.mock("@/mixins/base-mixin.js", () => ({ it("Should return side window when Driver or Passenger is the only selected damage option in the store", () => { // Arrange / Act - store.getters.damage.glassToReplace = [{location: "Passenger", name: "sideWindow"}]; + store.getters.damage.glassToReplace = [{glassLocation: "Passenger", glassName: "sideWindow"}]; const damage = getDamageString(); @@ -55,7 +55,7 @@ jest.mock("@/mixins/base-mixin.js", () => ({ it("Should return rear window when Rear is the only selected damage option in the store", () => { // Arrange / Act - store.getters.damage.glassToReplace = [{location: "Rear", name: "rear"}]; + store.getters.damage.glassToReplace = [{glassLocation: "Rear", glassName: "rear"}]; const damage = getDamageString(); @@ -67,7 +67,7 @@ jest.mock("@/mixins/base-mixin.js", () => ({ describe("damage-helper.js", () => { it("Should return true if no mismatches between each array exist", async () => { // Arrange - store.getters.damage.glassToReplace = [{location: "Windshield", name: "windshield"}]; + store.getters.damage.glassToReplace = [{glassLocation: "Windshield", glassName: "windshield"}]; // Act const isGlassAvailable = await isGlassAvailableForCarId(); @@ -80,7 +80,7 @@ jest.mock("@/mixins/base-mixin.js", () => ({ describe("damage-helper.js", () => { it("Should return false if any mismatches between each array exist", async () => { // Arrange - store.getters.damage.glassToReplace = [{location: "Windshield", name: "sideWindow"}]; + store.getters.damage.glassToReplace = [{glassLocation: "Windshield", glassName: "sideWindow"}]; const isGlassAvailable = await isGlassAvailableForCarId(); diff --git a/src/layouts/capability-questions/capability-questions.vue b/src/layouts/capability-questions/capability-questions.vue index 6491a76df..187f02fe1 100644 --- a/src/layouts/capability-questions/capability-questions.vue +++ b/src/layouts/capability-questions/capability-questions.vue @@ -11,7 +11,7 @@ v-bind:isDismissible="false" />
@@ -86,7 +86,7 @@ export default { return this.getCmsContent("AdditionalPartsQuestionsAlert", "BodyText"); }, windshieldPart() { - return this.pageData.partsOrQuestions.find(x => x.location === damageLocationsSelected.WINDSHIELD); + return this.pageData.partsOrQuestions.find(x => x.glassLocation === damageLocationsSelected.WINDSHIELD); }, windshieldPartInfo() { return this.windshieldPart.parts[0]; @@ -122,8 +122,8 @@ export default { const selectedAnswerResult2 = this.getCorrespondingAnswerResult2(glass.answerData.answerResult); return { - location: glass.location, - name: glass.name, + glassLocation: glass.glassLocation, + glassName: glass.glassName, result: glass.answerData.answerResult, result1: glass.answerData.answerResult, result2: selectedAnswerResult2, @@ -143,8 +143,8 @@ export default { // get parts from the capabilityQuestionAnswers let partsOrQuestions = this.pageData.partsOrQuestions; for (let answer of capabilityQuestionsAnswersArray) { - const correspondingPart = partsOrQuestions.find(partOrQuestion => partOrQuestion.location === answer.location); - const partFromCapabilityQuestionAnswer = (await this.dispatchStoreAction(storeActions.GET_PART_FROM_CAPABILITY_QUESTION_ANSWER, answer.location, false)).data; + const correspondingPart = partsOrQuestions.find(partOrQuestion => partOrQuestion.glassLocation === answer.glassLocation); + const partFromCapabilityQuestionAnswer = (await this.dispatchStoreAction(storeActions.GET_PART_FROM_CAPABILITY_QUESTION_ANSWER, answer.glassLocation, false)).data; partsOrQuestions.find(partOrQuestion => partOrQuestion.location === answer.location).parts = partFromCapabilityQuestionAnswer; } @@ -239,7 +239,7 @@ export default { }); // Update the key to re-render this part's question-chain component - this.capabilityQuestionsData[gpIndex].key = this.capabilityQuestionsData[gpIndex].location + this.capabilityQuestionsData[gpIndex].name + Date.now().toString(); + this.capabilityQuestionsData[gpIndex].key = this.capabilityQuestionsData[gpIndex].glassLocation + this.capabilityQuestionsData[gpIndex].glassName + Date.now().toString(); // handle suppressing downstream in this question chain @@ -325,7 +325,7 @@ export default { }); // Update the key to re-render this part's question-chain component - this.capabilityQuestionsData[gpIndex].key = this.capabilityQuestionsData[gpIndex].location + this.capabilityQuestionsData[gpIndex].name + Date.now().toString(); + this.capabilityQuestionsData[gpIndex].key = this.capabilityQuestionsData[gpIndex].glassLocation + this.capabilityQuestionsData[gpIndex].glassName + Date.now().toString(); } }); diff --git a/src/layouts/molding-questions/molding-questions.vue b/src/layouts/molding-questions/molding-questions.vue index c73c6e5e1..50cfe42c2 100644 --- a/src/layouts/molding-questions/molding-questions.vue +++ b/src/layouts/molding-questions/molding-questions.vue @@ -23,7 +23,7 @@
{ return { - location: glass.location, - name: glass.name, + glassLocation: glass.glassLocation, + glassName: glass.glassName, partNum: glass.answerData.answerResult, answeredQuestions: glass.answerData.answeredQuestions, isSuppressedPart: glass.isSuppressedPart, @@ -152,7 +152,7 @@ export default { let partsOrQuestions = this.pageData.partsOrQuestions; for (let answer of questionAnswersArray) { partsOrQuestions.find(partOrQuestion => { - return partOrQuestion.location === answer.location && partOrQuestion.name === answer.name; + return partOrQuestion.glassLocation === answer.glassLocation && partOrQuestion.glassName === answer.glassName; }).parts[0].childParts = [ { partNumber: answer.partNum @@ -250,7 +250,7 @@ export default { }); // Update the key to re-render this part's question-chain component - this.moldingQuestionsData[gpIndex].key = this.moldingQuestionsData[gpIndex].location + this.moldingQuestionsData[gpIndex].name + Date.now().toString(); + this.moldingQuestionsData[gpIndex].key = this.moldingQuestionsData[gpIndex].glassLocation + this.moldingQuestionsData[gpIndex].glassName + Date.now().toString(); // handle suppressing downstream in this question chain @@ -336,7 +336,7 @@ export default { }); // Update the key to re-render this part's question-chain component - this.moldingQuestionsData[gpIndex].key = this.moldingQuestionsData[gpIndex].location + this.moldingQuestionsData[gpIndex].name + Date.now().toString(); + this.moldingQuestionsData[gpIndex].key = this.moldingQuestionsData[gpIndex].glassLocation + this.moldingQuestionsData[gpIndex].glassName + Date.now().toString(); } diff --git a/src/layouts/part-questions/part-questions.vue b/src/layouts/part-questions/part-questions.vue index 0b0cc0165..7423cb6bb 100644 --- a/src/layouts/part-questions/part-questions.vue +++ b/src/layouts/part-questions/part-questions.vue @@ -23,7 +23,7 @@
{ return { - location: glass.location, - name: glass.name, + glassLocation: glass.glassLocation, + glassName: glass.glassName, result: glass.answerData.answerResult, answeredQuestions: glass.answerData.answeredQuestions, isSuppressedPart: glass.isSuppressedPart, @@ -246,7 +246,7 @@ export default { }); // Update the key to re-render this part's question-chain component - this.partsQuestionsData[gpIndex].key = this.partsQuestionsData[gpIndex].location + this.partsQuestionsData[gpIndex].name + Date.now().toString(); + this.partsQuestionsData[gpIndex].key = this.partsQuestionsData[gpIndex].glassLocation + this.partsQuestionsData[gpIndex].glassName + Date.now().toString(); // handle suppressing downstream in this question chain @@ -332,7 +332,7 @@ export default { }); // Update the key to re-render this part's question-chain component - this.partsQuestionsData[gpIndex].key = this.partsQuestionsData[gpIndex].location + this.partsQuestionsData[gpIndex].name + Date.now().toString(); + this.partsQuestionsData[gpIndex].key = this.partsQuestionsData[gpIndex].glassLocation + this.partsQuestionsData[gpIndex].glassName + Date.now().toString(); } diff --git a/src/layouts/vehicle-damage/vehicle-damage.spec.js b/src/layouts/vehicle-damage/vehicle-damage.spec.js index 27778feed..7791dff37 100644 --- a/src/layouts/vehicle-damage/vehicle-damage.spec.js +++ b/src/layouts/vehicle-damage/vehicle-damage.spec.js @@ -81,8 +81,8 @@ describe("vehicle-damage.vue", () => { //Arrange const partsData = { partsOrQuestions: [{ - name: "Single", - location: "Windshield", + glassName: "Single", + glassLocation: "Windshield", parts: null, partQuestions: [{ questionSequence: 1, @@ -144,8 +144,8 @@ describe("vehicle-damage.vue", () => { wrapper.vm.selectedRearReplaceOptions = ["Stationary"]; - const expectedGlassToReplace = [{ location: "Windshield", name: "Single" }, { location: "Driver", name: "Back" }, - { location: "Passenger", name: "Quarter" }, { location: "Rear", name: "Stationary" }]; + const expectedGlassToReplace = [{ glassLocation: "Windshield", glassName: "Single" }, { glassLocation: "Driver", glassName: "Back" }, + { glassLocation: "Passenger", glassName: "Quarter" }, { glassLocation: "Rear", glassName: "Stationary" }]; //Act vehicleDamage.beforeRouteEnter.call( @@ -168,8 +168,8 @@ describe("vehicle-damage.vue", () => { const partsData = { partsOrQuestions: [ { - location: "Windshield", - name: "Single", + glassLocation: "Windshield", + glassName: "Single", partQuestions: null, parts: [ { @@ -189,8 +189,8 @@ describe("vehicle-damage.vue", () => { ] }, { - name: "Stationary", - location: "Rear", + glassName: "Stationary", + glassLocation: "Rear", parts: [ { partNumber: "DB09626GTYN", @@ -235,7 +235,7 @@ describe("vehicle-damage.vue", () => { selectedWindshieldDamageType: "Replace" }; - const expectedGlassToReplace = [{ location: "Windshield", name: "Single" },]; + const expectedGlassToReplace = [{ glassLocation: "Windshield", glassName: "Single" },]; //Act vehicleDamage.beforeRouteEnter.call( @@ -509,7 +509,7 @@ describe("vehicle-damage.vue", () => { (c) => c(wrapper.vm) ); - store.getters = { vehicle: { carId: "C0000000" }, eventBusItem: jest.fn(), damage: { glassToReplace: [{ location: damageLocation }] }, isRepair: true }; + store.getters = { vehicle: { carId: "C0000000" }, eventBusItem: jest.fn(), damage: { glassToReplace: [{ glassLocation: damageLocation }] }, isRepair: true }; var glassSelections = wrapper.vm.getDamageLocationsFromStore(); @@ -553,7 +553,7 @@ describe("vehicle-damage.vue", () => { eventBusItem: jest.fn(), damage: { - glassToReplace: [{ location: damageLocation, name: damageName }], + glassToReplace: [{ glassLocation: damageLocation, glassName: damageName }], isRepair: isRepair, numberOfChips: 2 }, @@ -583,7 +583,7 @@ describe("vehicle-damage.vue", () => { (c) => c(wrapper.vm) ); - store.getters = { vehicle: { carId: "C0000000" }, eventBusItem: jest.fn(), damage: { glassToReplace: [{ location: damageLocation, name: damageName }] }, isRepair: true }; + store.getters = { vehicle: { carId: "C0000000" }, eventBusItem: jest.fn(), damage: { glassToReplace: [{ glassLocation: damageLocation, glassName: damageName }] }, isRepair: true }; var glassSelections = wrapper.vm.getDriverSideReplaceOptionsFromStore(); @@ -610,7 +610,7 @@ describe("vehicle-damage.vue", () => { (c) => c(wrapper.vm) ); - store.getters = { vehicle: { carId: "C0000000" }, eventBusItem: jest.fn(), damage: { glassToReplace: [{ location: damageLocation, name: damageName }] }, isRepair: true }; + store.getters = { vehicle: { carId: "C0000000" }, eventBusItem: jest.fn(), damage: { glassToReplace: [{ glassLocation: damageLocation, glassName: damageName }] }, isRepair: true }; var glassSelections = wrapper.vm.getPassengerSideReplaceOptionsFromStore(); @@ -634,7 +634,7 @@ describe("vehicle-damage.vue", () => { (c) => c(wrapper.vm) ); - store.getters = { vehicle: { carId: "C0000000" }, eventBusItem: jest.fn(), damage: { glassToReplace: [{ location: damageLocation, name: damageName }] }, isRepair: true }; + store.getters = { vehicle: { carId: "C0000000" }, eventBusItem: jest.fn(), damage: { glassToReplace: [{ glassLocation: damageLocation, glassName: damageName }] }, isRepair: true }; var glassSelections = wrapper.vm.getRearReplaceOptionsFromStore(); diff --git a/src/layouts/vehicle-damage/vehicle-damage.vue b/src/layouts/vehicle-damage/vehicle-damage.vue index f729b8b1a..2b9f08db3 100644 --- a/src/layouts/vehicle-damage/vehicle-damage.vue +++ b/src/layouts/vehicle-damage/vehicle-damage.vue @@ -179,16 +179,16 @@ export default { getDamageLocationsFromStore() { var glassSelections = []; - if (store.getters.damage.glassToReplace?.some(glass => { return glass.location === damageLocationsSelected.WINDSHIELD }) || + if (store.getters.damage.glassToReplace?.some(glass => { return glass.glassLocation === damageLocationsSelected.WINDSHIELD }) || store.getters.damage.isRepair) { glassSelections.push(damageLocationsSelected.WINDSHIELD); } - if (store.getters.damage.glassToReplace?.some(glass => { return glass.location === damageLocationsSelected.DRIVER || - glass.location === damageLocationsSelected.PASSENGER })) { + if (store.getters.damage.glassToReplace?.some(glass => { return glass.glassLocation === damageLocationsSelected.DRIVER || + glass.glassLocation === damageLocationsSelected.PASSENGER })) { glassSelections.push(damageLocationsSelected.SIDEDOOR); } - if (store.getters.damage.glassToReplace?.some(glass => { return glass.location === damageLocationsSelected.REAR })) { + if (store.getters.damage.glassToReplace?.some(glass => { return glass.glassLocation === damageLocationsSelected.REAR })) { glassSelections.push(damageLocationsSelected.REARWINDOW); } @@ -201,20 +201,20 @@ export default { if (store.getters.damage.isRepair === undefined) return windshieldOptions; if (!store.getters.damage.isRepair) { - if (store.getters.damage.glassToReplace?.some(glass => { return glass.location === damageLocationsSelected.WINDSHIELD && - glass.name === damageLocationsSelected.SINGLE })) { + if (store.getters.damage.glassToReplace?.some(glass => { return glass.glassLocation === damageLocationsSelected.WINDSHIELD && + glass.glassName === damageLocationsSelected.SINGLE })) { windShieldOptions.selectedWindshieldDamageType = damageLocationsSelected.REPLACE; windShieldOptions.selectedWindshieldReplaceOptions.push(damageLocationsSelected.SINGLE); } - if (store.getters.damage.glassToReplace?.some(glass => { return glass.location === damageLocationsSelected.WINDSHIELD && - glass.name === damageLocationsSelected.DRIVER })) { + if (store.getters.damage.glassToReplace?.some(glass => { return glass.glassLocation === damageLocationsSelected.WINDSHIELD && + glass.glassName === damageLocationsSelected.DRIVER })) { windShieldOptions.selectedWindshieldDamageType = damageLocationsSelected.REPLACE; windShieldOptions.selectedWindshieldReplaceOptions.push(damageLocationsSelected.DRIVER); } - if (store.getters.damage.glassToReplace?.some(glass => { return glass.location === damageLocationsSelected.WINDSHIELD && - glass.name === damageLocationsSelected.PASSENGER })) { + if (store.getters.damage.glassToReplace?.some(glass => { return glass.glassLocation === damageLocationsSelected.WINDSHIELD && + glass.glassName === damageLocationsSelected.PASSENGER })) { windShieldOptions.selectedWindshieldDamageType = damageLocationsSelected.REPLACE; windShieldOptions.selectedWindshieldReplaceOptions.push(damageLocationsSelected.PASSENGER); } @@ -231,11 +231,11 @@ export default { getDoorSidesFromStore() { var doorSides = []; - if (store.getters.damage.glassToReplace?.some(glass => { return glass.location === damageLocationsSelected.DRIVER })){ + if (store.getters.damage.glassToReplace?.some(glass => { return glass.glassLocation === damageLocationsSelected.DRIVER })){ doorSides.push(damageLocationsSelected.DRIVERSIDE); } - if (store.getters.damage.glassToReplace?.some(glass => { return glass.location === damageLocationsSelected.PASSENGER })){ + if (store.getters.damage.glassToReplace?.some(glass => { return glass.glassLocation === damageLocationsSelected.PASSENGER })){ doorSides.push(damageLocationsSelected.PASSENGERSIDE); } @@ -246,8 +246,8 @@ export default { var driverSideReplaceOptions = []; store.getters.damage.glassToReplace?.forEach(glass => { - if (glass.location === damageLocationsSelected.DRIVER){ - driverSideReplaceOptions.push(glass.name); + if (glass.glassLocation === damageLocationsSelected.DRIVER){ + driverSideReplaceOptions.push(glass.glassName); } }); @@ -258,8 +258,8 @@ export default { var passengerSideReplaceOptions = []; store.getters.damage.glassToReplace?.forEach(glass => { - if (glass.location === damageLocationsSelected.PASSENGER){ - passengerSideReplaceOptions.push(glass.name); + if (glass.glassLocation === damageLocationsSelected.PASSENGER){ + passengerSideReplaceOptions.push(glass.glassName); } }); @@ -270,8 +270,8 @@ export default { var rearReplaceOptions = []; store.getters.damage.glassToReplace?.forEach(glass => { - if (glass.location === damageLocationsSelected.REAR){ - rearReplaceOptions.push(glass.name); + if (glass.glassLocation === damageLocationsSelected.REAR){ + rearReplaceOptions.push(glass.glassName); } }); @@ -304,25 +304,25 @@ export default { const selectedGlassToReplace = []; if (this.isWindshieldDamageLocation && !this.isWindshieldRepair){ this.selectedWindshieldOptions.selectedWindshieldReplaceOptions.forEach(wsItem => { - selectedGlassToReplace.push({ location: damageLocationsSelected.WINDSHIELD, name: wsItem}); + selectedGlassToReplace.push({ glassLocation: damageLocationsSelected.WINDSHIELD, glassName: wsItem}); }) } if (this.isDriverSideReplace){ this.sideDoorOptionsData.selectedDriverSideReplaceOptions.forEach(driverItem => { - selectedGlassToReplace.push({ location: damageLocationsSelected.DRIVER, name: driverItem}); + selectedGlassToReplace.push({ glassLocation: damageLocationsSelected.DRIVER, glassName: driverItem}); }) } if (this.isPassengerSideReplace){ this.sideDoorOptionsData.selectedPassengerSideReplaceOptions.forEach(passengerItem => { - selectedGlassToReplace.push({ location: damageLocationsSelected.PASSENGER, name: passengerItem}); + selectedGlassToReplace.push({ glassLocation: damageLocationsSelected.PASSENGER, glassName: passengerItem}); }) } if (this.isRearWindowDamageLocation) { this.selectedRearReplaceOptions.forEach(rearItem => { - selectedGlassToReplace.push({ location: damageLocationsSelected.REAR, name: rearItem}); + selectedGlassToReplace.push({ glassLocation: damageLocationsSelected.REAR, glassName: rearItem}); }) } diff --git a/src/layouts/vehicle-parts/glass-part-question/glass-part-question.spec.js b/src/layouts/vehicle-parts/glass-part-question/glass-part-question.spec.js index 2acf1d87d..52471bf34 100644 --- a/src/layouts/vehicle-parts/glass-part-question/glass-part-question.spec.js +++ b/src/layouts/vehicle-parts/glass-part-question/glass-part-question.spec.js @@ -13,8 +13,8 @@ const featureListData = { { ColorAnswerText: 'Green Tint', FeatureAnswers: [{ FeatureAnswerText: "heated glass, solar, 1 hole", PartNumber: "DB12209GTYN" }] }, { ColorAnswerText: 'Gray Tint Privacy', FeatureAnswers: [{ FeatureAnswerText: "heated glass, solar, 1 hole", PartNumber: "DB12209YPYN" }] } ], - locationProp: "Rear", - nameProp: "Stationary", + glassLocationProp: "Rear", + glassNameProp: "Stationary", modelValueProp: {} } @@ -37,7 +37,7 @@ describe("glass-part-question.vue", () => { }); - test("Tint mapper, should get tint image by location and tintColor", async () => { + test("Tint mapper, should get tint image by glassLocation and tintColor", async () => { //Arrange @@ -72,7 +72,7 @@ describe("glass-part-question.vue", () => { //Arrange const { wrapper } = setupMocks(featureListData); store.getters.pageData.mockReset(); - store.getters.pageData.mockReturnValueOnce({ partsOrQuestions: [{name: "Stationary", location: "Rear", parts: [{ partNumber: "DB12209GTYN", color: "Green Tint"}]}] }); + store.getters.pageData.mockReturnValueOnce({ partsOrQuestions: [{glassName: "Stationary", glassLocation: "Rear", parts: [{ partNumber: "DB12209GTYN", color: "Green Tint"}]}] }); //Act await wrapper.vm.$nextTick(); @@ -111,7 +111,7 @@ describe("glass-part-question.vue", () => { test("default is selected if only one option", async () => { // Arrange store.getters.pageData.mockReset(); - store.getters.pageData.mockReturnValueOnce({ partsOrQuestions: [{name: "Stationary", location: "Rear", parts: [{ partNumber: "DB12209GTYN", color: "Green Tint"}]}] }); + store.getters.pageData.mockReturnValueOnce({ partsOrQuestions: [{glassName: "Stationary", glassLocation: "Rear", parts: [{ partNumber: "DB12209GTYN", color: "Green Tint"}]}] }); const { wrapper } = setupMocks(featureListData); // Act @@ -129,7 +129,7 @@ describe("glass-part-question.vue", () => { test("default is not selected if more than one option", async () => { // Arrange store.getters.pageData.mockReset(); - store.getters.pageData.mockReturnValueOnce({ partsOrQuestions: [{name: "Stationary", location: "Rear", parts: [{ partNumber: "DB12209GTYN", color: "Green Tint"}, { partNumber: "DB12209GTYNXXX", color: "Green Tint"}]}] }); + store.getters.pageData.mockReturnValueOnce({ partsOrQuestions: [{glassName: "Stationary", glassLocation: "Rear", parts: [{ partNumber: "DB12209GTYN", color: "Green Tint"}, { partNumber: "DB12209GTYNXXX", color: "Green Tint"}]}] }); const { wrapper } = setupMocks(featureListData); // Act @@ -150,13 +150,13 @@ describe("glass-part-question.vue", () => { ["Windshield", "Single", "Blue Tint", []], ["Driver", "Quarter", "Green Tint", []] ]; - test.each(partsForSelectedTintTestCases)("partsForSelectedTint returns correct parts", async (location, name, selectedTint, expectedResults) => { + test.each(partsForSelectedTintTestCases)("partsForSelectedTint returns correct parts", async (glassLocation, glassName, selectedTint, expectedResults) => { // Arrange store.getters.pageData.mockReset(); store.getters.pageData.mockReturnValueOnce({ partsOrQuestions: [ { - name: "Stationary", - location: "Rear", + glassName: "Stationary", + glassLocation: "Rear", parts: [ { partNumber: "Glass1", color: "Green Tint"}, { partNumber: "Glass2", color: "Blue Tint"}, @@ -168,14 +168,14 @@ describe("glass-part-question.vue", () => { ] }, { - name: "Single", - location: "Windshield", + glassName: "Single", + glassLocation: "Windshield", parts: [{ partNumber: "Windshield1", color: "Green Tint"}, { partNumber: "Windshield2", color: "Green Tint"}] } ]}); const { wrapper } = setupMocks({ - locationProp: location, - nameProp: name, + glassLocationProp: glassLocation, + glassNameProp: glassName, colorAnswersProp: [], }); @@ -189,9 +189,9 @@ describe("glass-part-question.vue", () => { -function setupMocks({ nameProp, locationProp, colorAnswersProp, modelValueProp }) { +function setupMocks({ glassNameProp, glassLocationProp, colorAnswersProp, modelValueProp }) { //Mock store - store.getters.pageData.mockReturnValueOnce({ partsOrQuestions: [{name: "Stationary", location: "Rear", parts: []}] }); + store.getters.pageData.mockReturnValueOnce({ partsOrQuestions: [{glassName: "Stationary", glassLocation: "Rear", parts: []}] }); store.getters.lineItems = { glassParts: {} } const mountOptions = getMountOptions({ @@ -206,8 +206,8 @@ function setupMocks({ nameProp, locationProp, colorAnswersProp, modelValueProp } }); mountOptions.propsData = { - name: nameProp, - location: locationProp, + glassName: glassNameProp, + glassLocation: glassLocationProp, colorAnswers: colorAnswersProp, modelValue: modelValueProp }; diff --git a/src/layouts/vehicle-parts/glass-part-question/glass-part-question.vue b/src/layouts/vehicle-parts/glass-part-question/glass-part-question.vue index 8154f2ca4..10233d4d8 100644 --- a/src/layouts/vehicle-parts/glass-part-question/glass-part-question.vue +++ b/src/layouts/vehicle-parts/glass-part-question/glass-part-question.vue @@ -12,7 +12,7 @@ :isWide="true" altText="" isRequired - :groupName="`${location}-${name}`" + :groupName="`${glassLocation}-${glassName}`" @isCheckedChanged="ResetTintAndPartSelections" :validationRules="tintValidationRules" > @@ -27,7 +27,7 @@ textPosition="text-start" :loaderEnabled="false" isRequired - :groupName="`${location}-${name}-${selectedTint}`" + :groupName="`${glassLocation}-${glassName}-${selectedTint}`" :validationRules="partValidationRules" />
@@ -60,8 +60,8 @@ export default { }; }, props: { - name: String, - location: String, + glassName: String, + glassLocation: String, colorAnswers: Array, modelValue: Object, alreadyPopulatedPartsData: Array @@ -74,19 +74,19 @@ export default { }, computed: { tintValidationRules() { - const validationRuleName = `${this.location}-${this.name}-tint-required`; + const validationRuleName = `${this.glassLocation}-${this.glassName}-tint-required`; defineRule(validationRuleName, required(errorMessages.OPTION_REQUIRED)); return validationRuleName; }, partValidationRules() { - const validationRuleName = `${this.location}-${this.name}-part-required`; + const validationRuleName = `${this.glassLocation}-${this.glassName}-part-required`; defineRule(validationRuleName, required(errorMessages.OPTION_REQUIRED)); return validationRuleName; }, colorQuestionText() { return getCustomTransformValue( this.glassColorQuestion, - `${this.location} ${this.name}` + `${this.glassLocation} ${this.glassName}` ); }, @@ -98,7 +98,7 @@ export default { Name: tintOption, Text: tintOption, AnswerImageUrl: require(`@/assets/img/tints/${this.getTintSourceImage( - this.location, + this.glassLocation, tintOption )}`), }); @@ -117,9 +117,9 @@ export default { }, partsForSelectedTint() { - const matchingGlass = this.PartDataFromApi.partsOrQuestions?.filter(dataForlocationAndName => - dataForlocationAndName.name == this.name && - dataForlocationAndName.location == this.location); + const matchingGlass = this.PartDataFromApi.partsOrQuestions?.filter(dataForGlassLocationAndName => + dataForGlassLocationAndName.glassName == this.glassName && + dataForGlassLocationAndName.glassLocation == this.glassLocation); const matchingGlassParts = matchingGlass?.length == 1 ? matchingGlass[0].parts : []; return matchingGlassParts.filter(part => part.color == this.selectedTint) ?? []; }, @@ -167,8 +167,8 @@ export default { // Gets tint images based on the glass type, and tint name. // Returns an empty string if the src or object is undefined. - getTintSourceImage(location, tintColor) { - const tintSourceObject = getTintImage(location, tintColor); + getTintSourceImage(glassLocation, tintColor) { + const tintSourceObject = getTintImage(glassLocation, tintColor); if ( tintSourceObject === undefined || diff --git a/src/layouts/vehicle-parts/vehicle-parts.spec.js b/src/layouts/vehicle-parts/vehicle-parts.spec.js index 3f54b300c..2fce952c2 100644 --- a/src/layouts/vehicle-parts/vehicle-parts.spec.js +++ b/src/layouts/vehicle-parts/vehicle-parts.spec.js @@ -41,8 +41,8 @@ store.getters = { const basePartResponse = { partsOrQuestions: [ { - name: "Stationary", - location: "Rear", + glassName: "Stationary", + glassLocation: "Rear", parts: [ { partNumber: "DB12209GTYN", @@ -207,8 +207,8 @@ describe("vehicle-parts.vue", () => { return { partsOrQuestions: [ { - name: "Stationary", - location: "Rear", + glassName: "Stationary", + glassLocation: "Rear", parts: null, partQuestions: [{ testProperty: "some value" @@ -287,8 +287,8 @@ describe("vehicle-parts.vue", () => { store.getters.pageData.mockReturnValueOnce({ partsOrQuestions: [ { - name: "Single", - location: "Windshield", + glassName: "Single", + glassLocation: "Windshield", parts: [ { "partNumber": "FW03861GTYN", @@ -365,8 +365,8 @@ describe("vehicle-parts.vue", () => { store.getters.pageData.mockReturnValueOnce({ partsOrQuestions: [ { - name: "Single", - location: "Windshield", + glassName: "Single", + glassLocation: "Windshield", parts: [ { partNumber: "DB12209GTYN", diff --git a/src/layouts/vehicle-parts/vehicle-parts.vue b/src/layouts/vehicle-parts/vehicle-parts.vue index 2c4583685..6116e5391 100644 --- a/src/layouts/vehicle-parts/vehicle-parts.vue +++ b/src/layouts/vehicle-parts/vehicle-parts.vue @@ -29,10 +29,10 @@
@@ -125,8 +125,8 @@ export default { // Map API result data, to vehicle-parts data structure const mappedData = partsData.partsOrQuestions.map((g) => { return { - name: g.name, - location: g.location, + glassName: g.glassName, + glassLocation: g.glassLocation, colorAnswers: g.parts?.reduce((arr, p) => { arr.push({ ColorAnswerText: p.color, @@ -175,8 +175,8 @@ export default { if (isMatched) { matchedParts.push({ - location: value.location, - name: value.name, + glassLocation: value.glassLocation, + glassName: value.glassName, parts: [currentPart] }); } @@ -207,8 +207,8 @@ export default { const partNumber = alreadyPopulatedPartsData[key].partNumber; g.parts.forEach((p) => { if (p.partNumber === partNumber) { - this.selectedGlassParts[g.location + "-" + g.name] = { - [g.location]: [partNumber], + this.selectedGlassParts[g.glassLocation + "-" + g.glassName] = { + [g.glassLocation]: [partNumber], }; } }); diff --git a/src/mixins/vehicle-questions-mixin.js b/src/mixins/vehicle-questions-mixin.js index 5ac1c7758..9884117d7 100644 --- a/src/mixins/vehicle-questions-mixin.js +++ b/src/mixins/vehicle-questions-mixin.js @@ -65,20 +65,20 @@ export default { return this.comparePageIndices(currentPage, fmgPage) > 0; }, setupInitialData(glass, i, alreadyAnsweredQuestions, vm) { - glass.key = glass.location + "-" + glass.name; + glass.key = glass.glassLocation + "-" + glass.glassName; const self = vm ?? this; // clear answerData if no questions are already answered if (!alreadyAnsweredQuestions) { glass.answerData = null } alreadyAnsweredQuestions?.forEach((answeredGlass) => { // if answeredGlass lacks any of these properties then exit - if (!answeredGlass.location || - !answeredGlass.name || + if (!answeredGlass.glassLocation || + !answeredGlass.glassName || !answeredGlass.answeredQuestions || !answeredGlass.result && !answeredGlass.partNum) { return } // test if glass parts match - if (glass.location === answeredGlass.location && glass.name === answeredGlass.name) { + if (glass.glassLocation === answeredGlass.glassLocation && glass.glassName === answeredGlass.glassName) { let answerString = ""; // loop through answeredQuestions for matches @@ -118,7 +118,7 @@ export default { // Set up watch for each set of glass questions // (updated when all questions for a glass have been answered in question-chain) - self.$watch("selectedAnswers." + glass.location + '-' + glass.name, (newValue) => { + self.$watch("selectedAnswers." + glass.glassLocation + '-' + glass.glassName, (newValue) => { if (newValue) { self.handleAnswerUpdates(newValue); } diff --git a/src/mixins/vehicle-questions-mixin.spec.js b/src/mixins/vehicle-questions-mixin.spec.js index b2dab9645..e5a579f02 100644 --- a/src/mixins/vehicle-questions-mixin.spec.js +++ b/src/mixins/vehicle-questions-mixin.spec.js @@ -71,8 +71,8 @@ describe("vehicle-questions-mixin", () => { // Act const hasGlassLocationWithMultipleParts = wrapper.vm.hasGlassLocationWithMultipleParts([ { - name: "Something", - location: "somewhere", + glassName: "Something", + glassLocation: "somewhere", parts: [{ partNumber: "1234567" }] @@ -90,22 +90,22 @@ describe("vehicle-questions-mixin", () => { // Act const hasGlassLocationWithMultipleParts = wrapper.vm.hasGlassLocationWithMultipleParts([ { - name: "Something", - location: "somewhere", + glassName: "Something", + glassLocation: "somewhere", parts: [{ partNumber: "1234567" }] }, { - name: "Another glass", - location: "somewhere else", + glassName: "Another glass", + glassLocation: "somewhere else", parts: [{ partNumber: "1234568" }] }, { - name: "Special glass", - location: "Another where", + glassName: "Special glass", + glassLocation: "Another where", parts: [{ partNumber: "1234569" }] @@ -123,22 +123,22 @@ describe("vehicle-questions-mixin", () => { // Act const hasGlassLocationWithMultipleParts = wrapper.vm.hasGlassLocationWithMultipleParts([ { - name: "Something", - location: "somewhere", + glassName: "Something", + glassLocation: "somewhere", parts: [{ partNumber: "1234567" }] }, { - name: "Another glass", - location: "somewhere else", + glassName: "Another glass", + glassLocation: "somewhere else", parts: [{ partNumber: "1234568" }] }, { - name: "Special glass", - location: "Another where", + glassName: "Special glass", + glassLocation: "Another where", parts: [ { partNumber: "1234569" @@ -321,8 +321,8 @@ describe("vehicle-questions-mixin", () => { // Arrange const { wrapper } = setupMocks({}); const glass = { - "name": "Single", - "location": "Windshield", + "glassName": "Single", + "glassLocation": "Windshield", }; const i = 0; @@ -338,8 +338,8 @@ describe("vehicle-questions-mixin", () => { test("should return glass with answerData of null", async () => { // Arrange const glass = { - "name": "Single", - "location": "Windshield" + "glassName": "Single", + "glassLocation": "Windshield" }; const i = 0; const { wrapper } = setupMocks({}); @@ -356,8 +356,8 @@ describe("vehicle-questions-mixin", () => { test("should return glass with answerResult within answerData", async () => { // Arrange const glass = { - "name": "Single", - "location": "Windshield", + "glassName": "Single", + "glassLocation": "Windshield", "questions": [ { "questionSequence": 1, @@ -380,8 +380,8 @@ describe("vehicle-questions-mixin", () => { const i = 0; const alreadyAnsweredQuestions = [ { - "location": "Windshield", - "name": "Single", + "glassLocation": "Windshield", + "glassName": "Single", "partNum": "WKT D1106 C", "answeredQuestions": [ { @@ -409,8 +409,8 @@ describe("vehicle-questions-mixin", () => { // Arrange const partsOrQuestions = [ { - "name": "Single", - "location": "Windshield", + "glassName": "Single", + "glassLocation": "Windshield", "parts": null, "partQuestions": [ { @@ -449,8 +449,8 @@ describe("vehicle-questions-mixin", () => { // Arrange const partsOrQuestions = [ { - "name": "Single", - "location": "Windshield", + "glassName": "Single", + "glassLocation": "Windshield", "parts": null, "partQuestions": [ { @@ -472,8 +472,8 @@ describe("vehicle-questions-mixin", () => { ] }, { - "name": "Front", - "location": "Driver", + "glassName": "Front", + "glassLocation": "Driver", "parts": [ { "partNumber": "DD08158GTYN", @@ -487,8 +487,8 @@ describe("vehicle-questions-mixin", () => { "partQuestions": null }, { - "name": "Quarter", - "location": "Driver", + "glassName": "Quarter", + "glassLocation": "Driver", "parts": [ { "partNumber": "DQ08162GTYN", @@ -502,8 +502,8 @@ describe("vehicle-questions-mixin", () => { "partQuestions": null }, { - "name": "SideDoor", - "location": "Driver", + "glassName": "SideDoor", + "glassLocation": "Driver", "parts": null, "partQuestions": [ { @@ -525,8 +525,8 @@ describe("vehicle-questions-mixin", () => { ] }, { - "name": "Stationary", - "location": "Rear", + "glassName": "Stationary", + "glassLocation": "Rear", "parts": [ { "partNumber": "DB08165GTNN", @@ -557,8 +557,8 @@ describe("vehicle-questions-mixin", () => { // Arrange const partsOrQuestions = [ { - "name": "Single", - "location": "Windshield", + "glassName": "Single", + "glassLocation": "Windshield", "parts": null, "partQuestions": [ { @@ -580,8 +580,8 @@ describe("vehicle-questions-mixin", () => { ] }, { - "name": "Front", - "location": "Driver", + "glassName": "Front", + "glassLocation": "Driver", "parts": [ { "partNumber": "DD08158GTYN", @@ -595,8 +595,8 @@ describe("vehicle-questions-mixin", () => { "partQuestions": null }, { - "name": "Quarter", - "location": "Driver", + "glassName": "Quarter", + "glassLocation": "Driver", "parts": [ { "partNumber": "DQ08162GTYN", @@ -610,8 +610,8 @@ describe("vehicle-questions-mixin", () => { "partQuestions": null }, { - "name": "SideDoor", - "location": "Driver", + "glassName": "SideDoor", + "glassLocation": "Driver", "parts": [ { "partNumber": "DD08160GTYN", @@ -625,8 +625,8 @@ describe("vehicle-questions-mixin", () => { "partQuestions": null }, { - "name": "Stationary", - "location": "Rear", + "glassName": "Stationary", + "glassLocation": "Rear", "parts": [ { "partNumber": "DB08165GTNN", @@ -657,8 +657,8 @@ describe("vehicle-questions-mixin", () => { // Arrange const partsOrQuestions = [ { - "name": "Single", - "location": "Windshield", + "glassName": "Single", + "glassLocation": "Windshield", "parts": null, "partQuestions": [ { @@ -680,8 +680,8 @@ describe("vehicle-questions-mixin", () => { ] }, { - "name": "Front", - "location": "Driver", + "glassName": "Front", + "glassLocation": "Driver", "parts": [ { "partNumber": "DD08158GTYN", @@ -695,8 +695,8 @@ describe("vehicle-questions-mixin", () => { "partQuestions": null }, { - "name": "Quarter", - "location": "Driver", + "glassName": "Quarter", + "glassLocation": "Driver", "parts": [ { "partNumber": "DQ08162GTYN", @@ -718,8 +718,8 @@ describe("vehicle-questions-mixin", () => { "partQuestions": null }, { - "name": "SideDoor", - "location": "Driver", + "glassName": "SideDoor", + "glassLocation": "Driver", "parts": [ { "partNumber": "DD08160GTYN", @@ -741,8 +741,8 @@ describe("vehicle-questions-mixin", () => { "partQuestions": null }, { - "name": "Stationary", - "location": "Rear", + "glassName": "Stationary", + "glassLocation": "Rear", "parts": [ { "partNumber": "DB08165GTNN", @@ -807,8 +807,8 @@ describe("vehicle-questions-mixin", () => { // Arrange const partsOrQuestions = [ { - "name": "Stationary", - "location": "Rear", + "glassName": "Stationary", + "glassLocation": "Rear", "parts": [ { "partNumber": "FB25724GTYN", @@ -847,8 +847,8 @@ describe("vehicle-questions-mixin", () => { // Arrange const partsOrQuestions = [ { - "name": "Single", - "location": "Windshield", + "glassName": "Single", + "glassLocation": "Windshield", "parts": [ { "partNumber": "FW03647GTNN", @@ -868,8 +868,8 @@ describe("vehicle-questions-mixin", () => { "partQuestions": null }, { - "name": "Back", - "location": "Driver", + "glassName": "Back", + "glassLocation": "Driver", "parts": [ { "partNumber": "FD25747GTYN", @@ -883,8 +883,8 @@ describe("vehicle-questions-mixin", () => { "partQuestions": null }, { - "name": "Front", - "location": "Driver", + "glassName": "Front", + "glassLocation": "Driver", "parts": [ { "partNumber": "FD25719GTYN", @@ -898,8 +898,8 @@ describe("vehicle-questions-mixin", () => { "partQuestions": null }, { - "name": "Vent", - "location": "Driver", + "glassName": "Vent", + "glassLocation": "Driver", "parts": [ { "partNumber": "FV25749GTNN", @@ -913,8 +913,8 @@ describe("vehicle-questions-mixin", () => { "partQuestions": null }, { - "name": "Stationary", - "location": "Rear", + "glassName": "Stationary", + "glassLocation": "Rear", "parts": [ { "partNumber": "FB25724GTYN", @@ -953,8 +953,8 @@ describe("vehicle-questions-mixin", () => { // Arrange const partsOrQuestions = [ { - "name": "Single", - "location": "Windshield", + "glassName": "Single", + "glassLocation": "Windshield", "parts": [ { "partNumber": "DW02101GTYN", @@ -968,8 +968,8 @@ describe("vehicle-questions-mixin", () => { "partQuestions": null }, { - "name": "Back", - "location": "Driver", + "glassName": "Back", + "glassLocation": "Driver", "parts": [ { "partNumber": "DD12202GTYN", @@ -991,8 +991,8 @@ describe("vehicle-questions-mixin", () => { "partQuestions": null }, { - "name": "Front", - "location": "Driver", + "glassName": "Front", + "glassLocation": "Driver", "parts": [ { "partNumber": "DD12198GTYN", @@ -1014,8 +1014,8 @@ describe("vehicle-questions-mixin", () => { "partQuestions": null }, { - "name": "Quarter", - "location": "Driver", + "glassName": "Quarter", + "glassLocation": "Driver", "parts": [ { "partNumber": "DQ12204GTYNOEM", @@ -1085,8 +1085,8 @@ describe("vehicle-questions-mixin", () => { "partQuestions": null }, { - "name": "Stationary", - "location": "Rear", + "glassName": "Stationary", + "glassLocation": "Rear", "parts": [ { "partNumber": "DB12209GTYN", @@ -1127,8 +1127,8 @@ describe("vehicle-questions-mixin", () => { // Arrange const partsOrQuestions = [ { - "name": "Stationary", - "location": "Rear", + "glassName": "Stationary", + "glassLocation": "Rear", "parts": [ { "partNumber": "FB25724GTYN", @@ -1180,8 +1180,8 @@ describe("vehicle-questions-mixin", () => { // Arrange const partsOrQuestions = [ { - "name": "Single", - "location": "Windshield", + "glassName": "Single", + "glassLocation": "Windshield", "parts": [ { "partNumber": "FB25724GTYN", @@ -1216,8 +1216,8 @@ describe("vehicle-questions-mixin", () => { // Arrange const partsOrQuestions = [ { - "name": "Single", - "location": "Windshield", + "glassName": "Single", + "glassLocation": "Windshield", "parts": [ { "partNumber": "FW04186GTYN", @@ -1253,8 +1253,8 @@ describe("vehicle-questions-mixin", () => { // Arrange const partsOrQuestions = [ { - "name": "Single", - "location": "Windshield", + "glassName": "Single", + "glassLocation": "Windshield", "parts": [ { "partNumber": "FW04186GTYN", @@ -1274,8 +1274,8 @@ describe("vehicle-questions-mixin", () => { "partQuestions": null }, { - "name": "Back", - "location": "Driver", + "glassName": "Back", + "glassLocation": "Driver", "parts": [ { "partNumber": "FD25457GTYN", @@ -1289,8 +1289,8 @@ describe("vehicle-questions-mixin", () => { "partQuestions": null }, { - "name": "Front", - "location": "Driver", + "glassName": "Front", + "glassLocation": "Driver", "parts": [ { "partNumber": "FD27090GTYN", @@ -1304,8 +1304,8 @@ describe("vehicle-questions-mixin", () => { "partQuestions": null }, { - "name": "Vent", - "location": "Driver", + "glassName": "Vent", + "glassLocation": "Driver", "parts": [ { "partNumber": "FV25459GTNN", @@ -1319,8 +1319,8 @@ describe("vehicle-questions-mixin", () => { "partQuestions": null }, { - "name": "Stationary", - "location": "Rear", + "glassName": "Stationary", + "glassLocation": "Rear", "parts": [ { "partNumber": "FB25460GTYN", diff --git a/src/store/index.js b/src/store/index.js index 250971bd9..6dcfd0162 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -712,24 +712,22 @@ export const actions = { const zipCode = order.serviceLocation.zipCode; const vin = vehicle.vin; + // create a new array to avoid mutating state + const glassArrayForPayload = convertGlassPieceNamingForApi(glassArray); + const response = await globalMethods.callHttpClient({ method: endpoints.GetPartsOrQuestions.method, endpoint: endpoints.GetPartsOrQuestions.url, payload: { carId: carId, - glassPieces: glassArray ?? [], + glassPieces: glassArrayForPayload, zip: zipCode, vin: vin }, }); // Flatten location and name properties - response.data.partsOrQuestions.map(glass => { - glass.location = glass.glassPiece.location; - glass.name = glass.glassPiece.name; - delete glass.glassPiece; - return glass; - }); + response.data.partsOrQuestions = convertGlassPieceNamingFromApi(response.data.partsOrQuestions); return response; }, @@ -746,25 +744,24 @@ export const actions = { const zipCode = order.serviceLocation.zipCode; const vin = vehicle.vin; - // Flatten location and name properties + // create a new array to avoid mutating state + const glassArrayForPayload = convertGlassPieceNamingForApi(glassArray); + const resultsArrayForPayload = convertResultsForApi(resultsArray); + const response = await globalMethods.callHttpClient({ method: endpoints.GetParts.method, endpoint: endpoints.GetParts.url, payload: { carId: carId, - glassPieces: glassArray, - answerResults: resultsArray, + glassPieces: glassArrayForPayload, + answerResults: resultsArrayForPayload, zip: zipCode, vin: vin }, }); - - response.data.glassPieceParts.map(glass => { - glass.location = glass.glassPiece.location; - glass.name = glass.glassPiece.name; - delete glass.glassPiece; - return glass; - }); + + // Flatten location and name properties + response.data.glassPieceParts = convertGlassPieceNamingFromApi(response.data.glassPieceParts); return response; }, @@ -776,12 +773,12 @@ export const actions = { }) }, - getPartFromCapabilityQuestionAnswer(context, location) { + getPartFromCapabilityQuestionAnswer(context, glassLocation) { const pageData = context.getters.pageData(fmgPageValues.CAPABILITY_QUESTIONS); - const part = pageData.partsOrQuestions.find(x => x.location === location).parts[0]; + const part = pageData.partsOrQuestions.find(x => x.glassLocation === glassLocation).parts[0]; const capabilityQuestionAnswers = context.getters.damage.capabilityQuestionAnswers; - const capabilityQuestionAnswersForPart = capabilityQuestionAnswers.find(x => x.location === location); + const capabilityQuestionAnswersForPart = capabilityQuestionAnswers.find(x => x.glassLocation === glassLocation); return globalMethods.callHttpClient({ method: endpoints.GetPartFromCapabilityAnswer.method, @@ -801,6 +798,9 @@ export const actions = { const applicationUser = context.getters.applicationUser; const lineItems = context.state.order.lineItems; + // create a new array to avoid mutating state + const newGlassToReplace = convertGlassPieceNamingForApi(damage.glassToReplace); + return globalMethods.callHttpClient({ method: endpoints.SaveSession.method, endpoint: endpoints.SaveSession.url, @@ -824,7 +824,7 @@ export const actions = { }, damage: { numberOfChips: damage.numberOfChips, - glassToReplace: damage.glassToReplace, + glassToReplace: newGlassToReplace, isRepair: damage.isRepair }, customer: { @@ -851,6 +851,7 @@ export const actions = { }); }, loadSession(context, { referralNumber, referralDate, referralCorrelationId, accountNumber }) { + return globalMethods.callHttpClient({ method: endpoints.LoadSession.method, endpoint: endpoints.LoadSession.url, @@ -861,6 +862,15 @@ export const actions = { accountNumber: accountNumber?.toString() }, }).then((response) => { + // Flatten location and name properties + response.data.damage?.glassToReplace?.map(glass => { + glass.glassLocation = glass.location; + glass.glassName = glass.name; + delete glass.location; + delete glass.name; + return glass; + }); + // clear the state if the existing EON does not equal what is returned from loadSession if (context.state.order.eon && context.state.order.eon != response.data.eon) { context.commit(storeMutations.RESET_STATE); @@ -1167,4 +1177,39 @@ function sortArrayOfObjectsByPropertyValue(arrayOfObjects, propertyName) { else return 0; }) +} + +function convertGlassPieceNamingForApi(glassArray) { + if (!glassArray) return []; + const converted = []; + glassArray.forEach(glass => { + converted.push({ + location: glass.glassLocation, + name: glass.glassName + }) + }); + return converted; +} + +function convertResultsForApi(resultsArray) { + if (!resultsArray) return []; + const converted = []; + resultsArray.forEach(answer => { + converted.push({ + location: answer.glassLocation, + name: answer.glassName, + result: answer.result + }) + }); + return converted; +} + +function convertGlassPieceNamingFromApi(glassArray) { + glassArray.forEach(glass => { + glass.glassLocation = glass.glassPiece.location; + glass.glassName = glass.glassPiece.name; + delete glass.glassPiece; + return glass; + }); + return glassArray; } \ No newline at end of file