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

View file

@ -131,22 +131,18 @@ export default {
},
async forwardButtonAction() {
const questionAnswersArray = this.questionsData.map((glass) => {
// get answerResult2 of returned answer
let selectedAnswerResult2;
glass.questions.forEach((q) => {
const idx = q.answers.findIndex((a) => a.answerResult === glass.answerData.answerResult);
if (idx !== -1) {
selectedAnswerResult2 = q.answers[idx].answerResult2;
}
});
const { glassLocation, glassName, isSuppressedPart, answerData, questions } = glass;
const { answerResult, answeredQuestions } = answerData
return {
glassLocation: glass.glassLocation,
glassName: glass.glassName,
result: glass.answerData.answerResult,
result1: glass.answerData.answerResult,
result2: selectedAnswerResult2,
answeredQuestions: glass.answerData.answeredQuestions,
isSuppressedPart: glass.isSuppressedPart
glassLocation,
glassName,
result: answerResult,
result1: answerResult,
result2: questions
.flatMap(q => q.answers)
.find(a => a.answerResult === answerData.answerResult)?.answerResult2,
answeredQuestions,
isSuppressedPart
};
});
// 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)
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);
}
}

View file

@ -11,10 +11,10 @@ export default {
return partsOrQuestions?.some((pq) => pq.parts?.length > 1);
},
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) {
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
@ -23,18 +23,20 @@ export default {
glassParts.forEach((glass) => {
if (Array.isArray(glass.parts) && glass.parts.length === 1) {
const singlePart = glass.parts[0];
reducedGlassParts.push({
partNumber: singlePart.partNumber,
description: singlePart.description,
color: singlePart.color,
partType: singlePart.partType,
canSafeliteRecalibrate: singlePart.canSafeliteRecalibrate,
requiresRecalibration: singlePart.requiresRecalibration,
requiresCapabilityQuestions: singlePart.requiresCapabilityQuestions,
recalibrationType: singlePart.recalibrationType,
childParts: singlePart.childParts,
price: singlePart.price
});
if (singlePart){
reducedGlassParts.push({
partNumber: singlePart.partNumber,
description: singlePart.description,
color: singlePart.color,
partType: singlePart.partType,
canSafeliteRecalibrate: singlePart.canSafeliteRecalibrate,
requiresRecalibration: singlePart.requiresRecalibration,
requiresCapabilityQuestions: singlePart.requiresCapabilityQuestions,
recalibrationType: singlePart.recalibrationType,
childParts: singlePart.childParts,
price: singlePart.price
});
}
}
});
return reducedGlassParts;

View file

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