Merge pull request #778 from Safelite/bug/brydon/SSR-1224

Bug/brydon/ssr 1224
This commit is contained in:
michaela-brydon-safelite 2024-07-01 15:07:24 -04:00 committed by GitHub
commit 1379a863c6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 64 additions and 60 deletions

View file

@ -8,11 +8,10 @@ import { useMainStore } from '@/store';
import vehicleQuestionsMixin from '@/mixins/vehicle-questions-mixin'; import vehicleQuestionsMixin from '@/mixins/vehicle-questions-mixin';
import { nextTick } from 'vue'; import { nextTick } from 'vue';
import baseMixin from '@/mixins/base-mixin'; import baseMixin from '@/mixins/base-mixin';
import settleAllPromises from '@/helpers/layout-helper.js';
// Mock our module for promises. // Mock our module for promises.
jest.mock('@/helpers/layout-helper.js', () => ({ jest.mock('@/helpers/layout-helper.js', () => jest.fn());
settleAllPromises: jest.fn()
}));
// Mock fetchCmsContentForPage // Mock fetchCmsContentForPage
jest.mock('@/helpers/cms-content-helper', () => ({ jest.mock('@/helpers/cms-content-helper', () => ({
@ -244,7 +243,8 @@ describe('capabilityQuestions.vue', () => {
}); });
describe('forwardButtonAction', () => { describe('forwardButtonAction', () => {
test('Should clear out answerData', () => { settleAllPromises.mockImplementation(() => []);
test('Should clear out answerData', async () => {
// Arrange // Arrange
const { wrapper } = setupMocks({}); const { wrapper } = setupMocks({});
@ -269,7 +269,7 @@ describe('capabilityQuestions.vue', () => {
})); }));
// Act // Act
wrapper.vm.forwardButtonAction(); await wrapper.vm.forwardButtonAction();
// Assert // Assert
expect(wrapper.vm.questionsData[0].answerData).toEqual({}); expect(wrapper.vm.questionsData[0].answerData).toEqual({});
@ -277,8 +277,7 @@ describe('capabilityQuestions.vue', () => {
wrapper.unmount(); wrapper.unmount();
}); });
// TODO: Add () to toHaveBeenCalled and ensure test passes. test('Should save to pinia store', async () => {
test.skip('Should save to pinia store', async () => {
// Arrange // Arrange
const { wrapper } = setupMocks({}); const { wrapper } = setupMocks({});
@ -303,18 +302,17 @@ describe('capabilityQuestions.vue', () => {
partsOrQuestions: [] partsOrQuestions: []
} }
})); }));
const saveCapabilityQuestionAnswersSpy = jest.spyOn(useMainStore(), 'saveCapabilityQuestionAnswers');
// Act // Act
wrapper.vm.forwardButtonAction(); await wrapper.vm.forwardButtonAction();
await nextTick();
// Assert // Assert
expect(wrapper.vm.saveCapabilityQuestionAnswers).toHaveBeenCalled; expect(saveCapabilityQuestionAnswersSpy).toHaveBeenCalled();
wrapper.unmount(); wrapper.unmount();
}); });
// TODO: Add () to toHaveBeenCalled and ensure test passes.
test.skip('Should call GET_PART_FROM_CAPABILITY_QUESTION_ANSWER API', async () => { test('Should call updatePartFromCapabilityQuestionAnswer', async () => {
// Arrange // Arrange
const { wrapper } = setupMocks({}); const { wrapper } = setupMocks({});
@ -334,18 +332,19 @@ describe('capabilityQuestions.vue', () => {
] ]
} }
]; ];
wrapper.vm.dispatchStoreAction = jest.fn(() => ({ useMainStore().getPartsOrQuestions = jest.fn(() => ({
data: [] data: {
partsOrQuestions: []
}
})); }));
const updatePartFromCapabilityQuestionAnswerSpy = jest.spyOn(useMainStore(), 'updatePartFromCapabilityQuestionAnswer');
updatePartFromCapabilityQuestionAnswerSpy.mockClear();
// Act // Act
wrapper.vm.forwardButtonAction(); await wrapper.vm.forwardButtonAction();
await nextTick();
// Assert // Assert
expect(wrapper.vm.getPartFromCapabilityQuestionAnswer).toHaveBeenCalled; expect(updatePartFromCapabilityQuestionAnswerSpy).toHaveBeenCalledTimes(1);
wrapper.unmount(); wrapper.unmount();
}); });

View file

@ -131,22 +131,18 @@ export default {
}, },
async forwardButtonAction() { async forwardButtonAction() {
const questionAnswersArray = this.questionsData.map((glass) => { const questionAnswersArray = this.questionsData.map((glass) => {
// get answerResult2 of returned answer const { glassLocation, glassName, isSuppressedPart, answerData, questions } = glass;
let selectedAnswerResult2; const { answerResult, answeredQuestions } = answerData
glass.questions.forEach((q) => {
const idx = q.answers.findIndex((a) => a.answerResult === glass.answerData.answerResult);
if (idx !== -1) {
selectedAnswerResult2 = q.answers[idx].answerResult2;
}
});
return { return {
glassLocation: glass.glassLocation, glassLocation,
glassName: glass.glassName, glassName,
result: glass.answerData.answerResult, result: answerResult,
result1: glass.answerData.answerResult, result1: answerResult,
result2: selectedAnswerResult2, result2: questions
answeredQuestions: glass.answerData.answeredQuestions, .flatMap(q => q.answers)
isSuppressedPart: glass.isSuppressedPart .find(a => a.answerResult === answerData.answerResult)?.answerResult2,
answeredQuestions,
isSuppressedPart
}; };
}); });
// clear out answerData for future page loads; must occur prior to store save // clear out answerData for future page loads; must occur prior to store save
@ -155,7 +151,21 @@ export default {
}); });
// save to store as order.damage.moldingQuestionArrays (array) // save to store as order.damage.moldingQuestionArrays (array)
await this.mainStore.saveCapabilityQuestionAnswers(questionAnswersArray); await this.mainStore.saveCapabilityQuestionAnswers(questionAnswersArray);
// TODO call get parts from the capabilityQuestionAnswers endpoint
// set recalibration properties of parts based on capability question answers
const promiseResultMap = questionAnswersArray.map((answer, i) => {
const partData = this.partsOrQuestionsData.find(x => x.glassLocation === answer.glassLocation);
return {
resultKey: i,
promise: useMainStore().updatePartFromCapabilityQuestionAnswer(partData.parts[0], answer)
};
});
const resultMap = await settleAllPromises(promiseResultMap);
questionAnswersArray.forEach((answer, i) => {
const partData = this.partsOrQuestionsData.find((x) => x.glassLocation === answer.glassLocation);
partData.parts[0] = resultMap[i];
});
this.navigateForward(this.partsOrQuestionsData, null); this.navigateForward(this.partsOrQuestionsData, null);
} }
} }

View file

@ -11,10 +11,10 @@ export default {
return partsOrQuestions?.some((pq) => pq.parts?.length > 1); return partsOrQuestions?.some((pq) => pq.parts?.length > 1);
}, },
hasChildPartQuestions(partsOrQuestions) { hasChildPartQuestions(partsOrQuestions) {
return partsOrQuestions?.some((pq) => pq.parts?.some((part) => part.childPartQuestions?.length > 0)); return partsOrQuestions?.some((pq) => pq.parts?.some((part) => part?.childPartQuestions?.length > 0));
}, },
hasCapabilityQuestions(partsOrQuestions) { hasCapabilityQuestions(partsOrQuestions) {
return partsOrQuestions?.some((pq) => pq.parts?.some((part) => part.requiresCapabilityQuestions === true)); return partsOrQuestions?.some((pq) => pq.parts?.some((part) => part?.requiresCapabilityQuestions === true));
}, },
// method to only include keys listed for lineItems.glassParts in // method to only include keys listed for lineItems.glassParts in
@ -23,18 +23,20 @@ export default {
glassParts.forEach((glass) => { glassParts.forEach((glass) => {
if (Array.isArray(glass.parts) && glass.parts.length === 1) { if (Array.isArray(glass.parts) && glass.parts.length === 1) {
const singlePart = glass.parts[0]; const singlePart = glass.parts[0];
reducedGlassParts.push({ if (singlePart){
partNumber: singlePart.partNumber, reducedGlassParts.push({
description: singlePart.description, partNumber: singlePart.partNumber,
color: singlePart.color, description: singlePart.description,
partType: singlePart.partType, color: singlePart.color,
canSafeliteRecalibrate: singlePart.canSafeliteRecalibrate, partType: singlePart.partType,
requiresRecalibration: singlePart.requiresRecalibration, canSafeliteRecalibrate: singlePart.canSafeliteRecalibrate,
requiresCapabilityQuestions: singlePart.requiresCapabilityQuestions, requiresRecalibration: singlePart.requiresRecalibration,
recalibrationType: singlePart.recalibrationType, requiresCapabilityQuestions: singlePart.requiresCapabilityQuestions,
childParts: singlePart.childParts, recalibrationType: singlePart.recalibrationType,
price: singlePart.price childParts: singlePart.childParts,
}); price: singlePart.price
});
}
} }
}); });
return reducedGlassParts; return reducedGlassParts;

View file

@ -813,22 +813,15 @@ export const useMainStore = defineStore({
}); });
}, },
getPartFromCapabilityQuestionAnswer(glassLocation) { async updatePartFromCapabilityQuestionAnswer(part, capabilityQuestionAnswersForPart) {
const pageData = this.pageData(issPageValues.CAPABILITY_QUESTIONS); return (await globalMethods.callHttpClient({
const part = pageData.partsOrQuestions.find((x) => x.glassLocation === glassLocation)
.parts[0];
const { capabilityQuestionAnswers } = this.order.damage;
const capabilityQuestionAnswersForPart = capabilityQuestionAnswers.find((x) => x.glassLocation === glassLocation);
return globalMethods.callHttpClient({
method: endpoints.GetPartFromCapabilityAnswer.method, method: endpoints.GetPartFromCapabilityAnswer.method,
endpoint: endpoints.GetPartFromCapabilityAnswer.url, endpoint: endpoints.GetPartFromCapabilityAnswer.url,
payload: { payload: {
part, part,
capabilityAnswerResults: capabilityQuestionAnswersForPart capabilityAnswerResults: capabilityQuestionAnswersForPart
} }
}); })).data[0];
}, },
getMobilePremiumFee() { getMobilePremiumFee() {
const damageType = this.damage.isRepair ? 'Repair' : 'Replace'; const damageType = this.damage.isRepair ? 'Repair' : 'Replace';