Adding tests

This commit is contained in:
Michaela Brydon 2024-06-26 18:31:05 -04:00
parent 498f36d50d
commit 74aa0ab15f
3 changed files with 11 additions and 46 deletions

View file

@ -6,7 +6,7 @@
* @param {*} capabilityAnswerResult
* @returns part
*/
export default function setPartRecalibrationProperties(part, capabilityAnswerResult) {
export function setPartRecalibrationProperties(part, capabilityAnswerResult) {
Object.assign(part, {
recalibrationType: capabilityAnswerResult.result1,
requiresRecalibration: capabilityAnswerResult.result2 !== "0"

View file

@ -8,7 +8,7 @@ import { useMainStore } from '@/store';
import vehicleQuestionsMixin from '@/mixins/vehicle-questions-mixin';
import { nextTick } from 'vue';
import baseMixin from '@/mixins/base-mixin';
import setPartRecalibrationProperties from '@/helpers/capability-question-helper';
import { setPartRecalibrationProperties } from '@/helpers/capability-question-helper.js';
// Mock our module for promises.
jest.mock('@/helpers/layout-helper.js', () => ({
@ -159,7 +159,7 @@ function setupMocks({
describe('capabilityQuestions.vue', () => {
describe('method arePagePrerequisitesValid...', () => {
test.only('Should return true for valid page requisites if pageData exists', () => {
test('Should return true for valid page requisites if pageData exists', () => {
// Arrange
const { wrapper } = setupMocks({});
@ -284,8 +284,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({});
@ -310,6 +309,7 @@ describe('capabilityQuestions.vue', () => {
partsOrQuestions: []
}
}));
const saveCapabilityQuestionAnswersSpy = jest.spyOn(useMainStore(), 'saveCapabilityQuestionAnswers');
// Act
wrapper.vm.forwardButtonAction();
@ -317,42 +317,7 @@ describe('capabilityQuestions.vue', () => {
await nextTick();
// Assert
expect(wrapper.vm.saveCapabilityQuestionAnswers).toHaveBeenCalled;
wrapper.unmount();
});
// TODO: Add () to toHaveBeenCalled and ensure test passes.
test.skip('Should call GET_PART_FROM_CAPABILITY_QUESTION_ANSWER API', async () => {
// Arrange
const { wrapper } = setupMocks({});
wrapper.vm.questionsData = [
{
glassLocation: 'Windshield',
glassName: 'Single',
answerData: {
answerResult: 'FW04848',
answeredQuestions: []
},
questions: [],
parts: [
{
childPartQuestions: []
}
]
}
];
wrapper.vm.dispatchStoreAction = jest.fn(() => ({
data: []
}));
// Act
wrapper.vm.forwardButtonAction();
await nextTick();
// Assert
expect(wrapper.vm.getPartFromCapabilityQuestionAnswer).toHaveBeenCalled;
expect(saveCapabilityQuestionAnswersSpy).toHaveBeenCalled();
wrapper.unmount();
});

View file

@ -31,7 +31,7 @@ import { useMainStore } from '@/store';
import globalRules from '@/constants/global-rules';
import vehicleQuestionsMixin from '@/mixins/vehicle-questions-mixin';
import questionsPageLayout from '@/iss-components/questions-page-layout/questions-page-layout.vue';
import setPartRecalibrationProperties from '@/helpers/capability-question-helper';
import { setPartRecalibrationProperties } from '@/helpers/capability-question-helper';
export default {
name: 'capability-questions',
@ -154,10 +154,10 @@ export default {
await this.mainStore.saveCapabilityQuestionAnswers(questionAnswersArray);
// set recalibration properties of parts based on capability question answers
// for (let answer of questionAnswersArray) {
// const partAssociatedWithAnswer = this.partsOrQuestionsData.find((x) => x.glassLocation === answer.glassLocation).parts[0];
// setPartRecalibrationProperties(partAssociatedWithAnswer, answer);
// }
for (let answer of questionAnswersArray) {
const partAssociatedWithAnswer = this.partsOrQuestionsData.find((x) => x.glassLocation === answer.glassLocation).parts[0];
setPartRecalibrationProperties(partAssociatedWithAnswer, answer);
}
this.navigateForward(this.partsOrQuestionsData, null);
}