diff --git a/.eslintrc.js b/.eslintrc.js index 4f01a690..e2c6119a 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -19,7 +19,7 @@ module.exports = { 'object-curly-newline': ['error', { consistent: true }], 'function-paren-newline': ['error', 'never'], 'operator-linebreak': ['error', 'before'], - 'implicit-arrow-linebreak': ['error', 'beside'], + 'implicit-arrow-linebreak': ['off'], 'comma-dangle': ['error', 'never'], indent: ['error', 4], 'max-len': ['error', { code: 140 }], diff --git a/src/layouts/part-questions/part-questions.spec.js b/src/layouts/part-questions/part-questions.spec.js index e314be66..8952460f 100644 --- a/src/layouts/part-questions/part-questions.spec.js +++ b/src/layouts/part-questions/part-questions.spec.js @@ -19,64 +19,122 @@ jest.mock('@/helpers/cms-content-helper', () => ({ fetchCmsContentForPage: jest.fn() })); - -const baseStoreGettersPageData = () => { - return { - partsOrQuestions: [ +function setupMocks({ + mountOptionsMockData = { + router: { + navigate: jest.fn(), + navigateWithSaving: jest.fn(), + navigateWithoutSaving: jest.fn() + }, + actionList: [ { - parts: null, - partQuestions: [ - { - questionSequence: 1, - questionText: - 'Is your vehicle equipped with the Panoramic Sunroof which can be identified by having a glass panel over the rear seats?', - answers: [ - { - answerResult: '', - answerText: 'Yes', - nextQuestionSequence: 2 - }, - { - answerResult: '', - answerText: 'No', - nextQuestionSequence: 3 - } - ] - } - ], - glassLocation: 'Windshield', - glassName: 'Single', - answerKey: 'Windshield-Single', - answerData: null + actionName: 'savePartQuestionAnswers', + data: {} + }, + { + actionName: 'getParts', + data: {} } - ] - }; -}; -const baseStoreGettersDamage = () => { - return { - partsQuestionAnswers: [ - { - glassLocation: 'Windshield', - glassName: 'Single', - result: 'FW04848', - answeredQuestions: [ + ], + route: { + query: { + issPage: 'part-questions' + } + }, + data() { + return { + computedSwitcher: [ { - questionText: - 'Is your vehicle equipped with the Panoramic Sunroof which can be identified by having a glass panel over the rear seats?', - selectedAnswerText: 'Yes', - questionNum: 1 - }, - { - questionText: - 'Is your vehicle equipped with a heated windshield that melts snow and ice from underneath the windshield wiper blades?', - selectedAnswerText: 'Yes', - questionNum: 2 + glassLocation: 'Windshield', + glassName: 'Single', + answerData: { + answerResult: 'FW04848', + answeredQuestions: [] + } } ] + }; + }, + questionsData: { + get() { + return this.computedSwitcher; + }, + set(val) { + this.computedSwitcher = val; } - ] - }; -}; + } + } +}) { + useMainStore().getParts = jest.fn(() => ({ + data: { + glassPieceParts: [] + } + })); + + const mountOptions = getMountOptions({ + ...mountOptionsMockData, + mixins: [baseMixin, vehicleQuestionsMixin] + }); + mountOptions.attachTo = document.body; + + const wrapper = shallowMount(partQuestions, mountOptions); + + return { wrapper }; +} + +const baseStoreGettersPageData = () => ({ + partsOrQuestions: [ + { + parts: null, + partQuestions: [ + { + questionSequence: 1, + questionText: + 'Is your vehicle equipped with the Panoramic Sunroof which can be identified by having a glass panel over the rear seats?', + answers: [ + { + answerResult: '', + answerText: 'Yes', + nextQuestionSequence: 2 + }, + { + answerResult: '', + answerText: 'No', + nextQuestionSequence: 3 + } + ] + } + ], + glassLocation: 'Windshield', + glassName: 'Single', + answerKey: 'Windshield-Single', + answerData: null + } + ] +}); +const baseStoreGettersDamage = () => ({ + partsQuestionAnswers: [ + { + glassLocation: 'Windshield', + glassName: 'Single', + result: 'FW04848', + answeredQuestions: [ + { + questionText: + 'Is your vehicle equipped with the Panoramic Sunroof which can be identified by having a glass panel over the rear seats?', + selectedAnswerText: 'Yes', + questionNum: 1 + }, + { + questionText: + 'Is your vehicle equipped with a heated windshield that melts snow and ice from underneath the windshield wiper blades?', + selectedAnswerText: 'Yes', + questionNum: 2 + } + ] + } + ] +}); useMainStore().pageData = baseStoreGettersPageData; useMainStore().damage = baseStoreGettersDamage; @@ -99,9 +157,7 @@ describe('partQuestions.vue...', () => { test('Should return false for valid page requisites if partsOrQuestions in pageData is missing', () => { // Arrange const { wrapper } = setupMocks({}); - useMainStore().pageData = jest.fn(() => { - return undefined; - }); + useMainStore().pageData = jest.fn(() => undefined); // Act const result = wrapper.vm.arePagePrerequisitesValid(); @@ -114,11 +170,9 @@ describe('partQuestions.vue...', () => { test('Should be at least one item in partsOrQuestions', () => { // Arrange - useMainStore().pageData = jest.fn(() => { - return { - partsOrQuestions: [] - }; - }); + useMainStore().pageData = jest.fn(() => ({ + partsOrQuestions: [] + })); useMainStore().damage = baseStoreGettersDamage; const { wrapper } = setupMocks({}); @@ -212,13 +266,11 @@ describe('partQuestions.vue...', () => { ] }); - wrapper.vm.getParts = jest.fn(() => { - return { - data: { - glassPieceParts: [] - } - }; - }); + wrapper.vm.getParts = jest.fn(() => ({ + data: { + glassPieceParts: [] + } + })); // Act wrapper.vm.forwardButtonAction(); @@ -246,13 +298,11 @@ describe('partQuestions.vue...', () => { } ]; - useMainStore().getParts = jest.fn(() => { - return { - data: { - glassPieceParts: [] - } - }; - }); + useMainStore().getParts = jest.fn(() => ({ + data: { + glassPieceParts: [] + } + })); // Act wrapper.vm.forwardButtonAction(); @@ -278,13 +328,11 @@ describe('partQuestions.vue...', () => { } } ]; - useMainStore().getParts = jest.fn(() => { - return { - data: { - glassPieceParts: [] - } - }; - }); + useMainStore().getParts = jest.fn(() => ({ + data: { + glassPieceParts: [] + } + })); // Act wrapper.vm.forwardButtonAction(); @@ -311,13 +359,11 @@ describe('partQuestions.vue...', () => { } } ]; - useMainStore().getParts = jest.fn(() => { - return { - data: { - glassPieceParts: [] - } - }; - }); + useMainStore().getParts = jest.fn(() => ({ + data: { + glassPieceParts: [] + } + })); wrapper.vm.navigateForward = jest.fn(); // Act @@ -330,68 +376,3 @@ describe('partQuestions.vue...', () => { }); }); }); - -function setupMocks({ - mountOptionsMockData = { - router: { - navigate: jest.fn(), - navigateWithSaving: jest.fn(), - navigateWithoutSaving: jest.fn() - }, - actionList: [ - { - actionName: 'savePartQuestionAnswers', - data: {} - }, - { - actionName: 'getParts', - data: {} - } - ], - route: { - query: { - issPage: 'part-questions' - } - }, - data() { - return { - computedSwitcher: [ - { - glassLocation: 'Windshield', - glassName: 'Single', - answerData: { - answerResult: 'FW04848', - answeredQuestions: [] - } - } - ] - }; - }, - questionsData: { - get() { - return this.computedSwitcher; - }, - set(val) { - this.computedSwitcher = val; - } - } - } -}) { - useMainStore().getParts = jest.fn(() => { - return { - data: { - glassPieceParts: [] - } - }; - }); - - const mountOptions = getMountOptions({ - ...mountOptionsMockData, - mixins: [baseMixin, vehicleQuestionsMixin] - }); - mountOptions['attachTo'] = document.body; - - const wrapper = shallowMount(partQuestions, mountOptions); - - return { wrapper }; -} diff --git a/src/layouts/part-questions/part-questions.vue b/src/layouts/part-questions/part-questions.vue index 350d756e..dcbe6a0e 100644 --- a/src/layouts/part-questions/part-questions.vue +++ b/src/layouts/part-questions/part-questions.vue @@ -1,16 +1,20 @@ @@ -30,6 +34,10 @@ import globalRules from '@/constants/global-rules'; export default { name: 'part-questions', + components: { + Form, + questionsPageLayout + }, mixins: [BaseFormMixin, vehicleQuestionsMixin], async beforeRouteEnter(to, from, next) { // Call APIs @@ -80,22 +88,20 @@ export default { .map((glass, index) => { // NOTE: questions for property "questions" can differ between layouts glass.questions = glass.partQuestions; - glass.answerKey = glass.glassLocation + '-' + glass.glassName; + glass.answerKey = `${glass.glassLocation}-${glass.glassName}`; // reset selectedAnswers for this glass this.selectedAnswers[glass.answerKey] = []; const updatedGlass = this.setupInitialData(glass, index, alreadyAnsweredQuestions); // Set up watch for each set of glass questions - this.$watch( - 'selectedAnswers.' + glass.answerKey, + this.$watch(`selectedAnswers.${glass.answerKey}`, (newValue) => { if (newValue && Object.keys(newValue).length > 0) { this.handleAnswerUpdates(newValue, glass.answerKey); } }, - { deep: true } - ); + { deep: true }); return updatedGlass; }); @@ -104,20 +110,18 @@ export default { arePagePrerequisitesValid() { const partQuestionsFromPageData = useMainStore().pageData(issPageValues.PART_QUESTIONS); return ( - partQuestionsFromPageData && - Object.keys(partQuestionsFromPageData.partsOrQuestions).length > 0 + partQuestionsFromPageData + && Object.keys(partQuestionsFromPageData.partsOrQuestions).length > 0 ); }, async forwardButtonAction() { - const questionAnswersArray = this.questionsData.map((glass) => { - return { - glassLocation: glass.glassLocation, - glassName: glass.glassName, - result: (glass.answerData && glass.answerData.answerResult) || '', - answeredQuestions: glass.answerData?.answeredQuestions, - isSuppressedPart: glass.isSuppressedPart - }; - }); + const questionAnswersArray = this.questionsData.map((glass) => ({ + glassLocation: glass.glassLocation, + glassName: glass.glassName, + result: (glass.answerData && glass.answerData.answerResult) || '', + answeredQuestions: glass.answerData?.answeredQuestions, + isSuppressedPart: glass.isSuppressedPart + })); // clear out answerData for future page loads; must occur prior to store save this.questionsData.forEach((glass) => { @@ -137,10 +141,6 @@ export default { // TODO KO delete for quote mvp this.navigateForward(glassPartsForStore, null); } - }, - components: { - Form, - questionsPageLayout } }; diff --git a/src/layouts/payment-page/payment-page.vue b/src/layouts/payment-page/payment-page.vue index 5f5beaa4..6a892fef 100644 --- a/src/layouts/payment-page/payment-page.vue +++ b/src/layouts/payment-page/payment-page.vue @@ -1,17 +1,20 @@