Adding test todos
This commit is contained in:
parent
2d97232d40
commit
c05ff7b35a
3 changed files with 1 additions and 391 deletions
|
|
@ -0,0 +1 @@
|
|||
// TODO finish
|
||||
|
|
@ -2,394 +2,3 @@
|
|||
import contactDetails from '@/layouts/contact-details/contact-details.vue';
|
||||
|
||||
// TODO finish this file
|
||||
|
||||
// Supporting Files
|
||||
import { shallowMount } from '@vue/test-utils';
|
||||
import { getMountOptions } from '@/helpers/unit-test-helper';
|
||||
import { useMainStore } from '@/store';
|
||||
import vehicleQuestionsMixin from '@/mixins/vehicle-questions-mixin';
|
||||
import { nextTick } from 'vue';
|
||||
import { vi } from 'vitest';
|
||||
import baseMixin from '../../mixins/base-mixin';
|
||||
|
||||
// Mock our module for promises.
|
||||
vi.mock('@/helpers/layout-helper.js', () =>
|
||||
({
|
||||
settleAllPromises: vi.fn()
|
||||
}));
|
||||
|
||||
// Mock fetchCmsContentForPage
|
||||
vi.mock('@/helpers/cms-content-helper', () =>
|
||||
({
|
||||
fetchCmsContentForPage: vi.fn()
|
||||
}));
|
||||
|
||||
const baseStoreGettersPageData = () =>
|
||||
({
|
||||
partsOrQuestions: [
|
||||
{
|
||||
parts: [
|
||||
{
|
||||
childPartQuestions: []
|
||||
}
|
||||
],
|
||||
contactDetails: [
|
||||
{
|
||||
questionSequence: 1,
|
||||
questionText:
|
||||
'Is your vehicle equipped with the optional Lane-Keeping System which tugs on the steering wheel and/or beeps to alert you if you drift too close to the edge of the lane?',
|
||||
answers: [
|
||||
{
|
||||
answerResult1: 'DYNAMIC',
|
||||
answerResult2: '1',
|
||||
answerText: 'Yes',
|
||||
nextQuestionSequence: null,
|
||||
answerResult: 'DYNAMIC'
|
||||
},
|
||||
{
|
||||
answerResult1: 'Unknown',
|
||||
answerResult2: '0',
|
||||
answerText: 'No',
|
||||
nextQuestionSequence: null,
|
||||
answerResult: 'Unknown'
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
partQuestions: [],
|
||||
questions: [],
|
||||
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?',
|
||||
selectedAnswer: '1|nextQuestion|3|Yes',
|
||||
selectedAnswerText: 'Yes',
|
||||
questionNum: 1
|
||||
},
|
||||
{
|
||||
questionText:
|
||||
'Is your vehicle equipped with a heated windshield that melts snow and ice from underneath the windshield wiper blades?',
|
||||
selectedAnswer: '2|nextQuestion|3|Yes',
|
||||
selectedAnswerText: 'Yes',
|
||||
questionNum: 2
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
});
|
||||
useMainStore().pageData = baseStoreGettersPageData;
|
||||
useMainStore().damage = baseStoreGettersDamage;
|
||||
|
||||
describe('contactDetails.vue', () => {
|
||||
describe('method arePagePrerequisitesValid...', () => {
|
||||
test('Should return true for valid page requisites if pageData exists', () => {
|
||||
// Arrange
|
||||
const { wrapper } = setupMocks({});
|
||||
|
||||
// Act
|
||||
const result = wrapper.vm.arePagePrerequisitesValid();
|
||||
|
||||
// Assert
|
||||
expect(result).toBe(true);
|
||||
|
||||
wrapper.unmount();
|
||||
});
|
||||
|
||||
test('Should return false for valid page requisites if partsOrQuestions in pageData is missing', () => {
|
||||
// Arrange
|
||||
const { wrapper } = setupMocks({});
|
||||
useMainStore().pageData = vi.fn(() =>
|
||||
undefined);
|
||||
|
||||
// Act
|
||||
const result = wrapper.vm.arePagePrerequisitesValid();
|
||||
|
||||
// Assert
|
||||
expect(result).toBeFalsy();
|
||||
|
||||
wrapper.unmount();
|
||||
});
|
||||
|
||||
test('Should be at least one item in partsOrQuestions', () => {
|
||||
// Arrange
|
||||
useMainStore().pageData = vi.fn(() =>
|
||||
({
|
||||
partsOrQuestions: []
|
||||
}));
|
||||
useMainStore().damage = baseStoreGettersDamage;
|
||||
|
||||
const { wrapper } = setupMocks({});
|
||||
|
||||
// Act
|
||||
const result = wrapper.vm.arePagePrerequisitesValid();
|
||||
|
||||
// Assert
|
||||
expect(result).toBeFalsy();
|
||||
|
||||
wrapper.unmount();
|
||||
});
|
||||
});
|
||||
|
||||
describe('watch on selectedAnswers should be set up...', () => {
|
||||
test('Should trigger handleAnswerUpdates if watched data changes', async () => {
|
||||
// Arrange
|
||||
useMainStore().pageData = baseStoreGettersPageData;
|
||||
useMainStore().damage = baseStoreGettersDamage;
|
||||
const { wrapper } = setupMocks({});
|
||||
const spy = vi.spyOn(wrapper.vm, 'handleAnswerUpdates');
|
||||
|
||||
// Act
|
||||
wrapper.setData({
|
||||
selectedAnswers: {
|
||||
'Windshield-Single': {
|
||||
answerResult: 'FW04848',
|
||||
answeredQuestions: [
|
||||
{
|
||||
questionText:
|
||||
'Is your vehicle equipped with the Panoramic Sunroof which can be identified by having a glass panel over the rear seats?',
|
||||
selectedAnswer: '1|nextQuestion|3|Yes',
|
||||
selectedAnswerText: 'Yes',
|
||||
questionNum: 1
|
||||
},
|
||||
{
|
||||
questionText:
|
||||
'Is your vehicle equipped with a heated windshield that melts snow and ice from underneath the windshield wiper blades?',
|
||||
selectedAnswer: '2|nextQuestion|3|Yes',
|
||||
selectedAnswerText: 'Yes',
|
||||
questionNum: 2
|
||||
}
|
||||
],
|
||||
index: 0
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
await nextTick();
|
||||
|
||||
// Assert
|
||||
expect(spy).toHaveBeenCalled();
|
||||
|
||||
wrapper.unmount();
|
||||
});
|
||||
});
|
||||
|
||||
describe('forwardButtonAction', () => {
|
||||
test('Should clear out answerData', () => {
|
||||
// Arrange
|
||||
const { wrapper } = setupMocks({});
|
||||
|
||||
wrapper.vm.questionsData = [
|
||||
{
|
||||
glassLocation: 'Windshield',
|
||||
glassName: 'Single',
|
||||
answerData: {
|
||||
answerResult: 'FW04848',
|
||||
answeredQuestions: []
|
||||
},
|
||||
questions: [],
|
||||
parts: [
|
||||
{
|
||||
childPartQuestions: [{}]
|
||||
}
|
||||
]
|
||||
}
|
||||
];
|
||||
wrapper.vm.dispatchStoreAction = vi.fn(() =>
|
||||
({
|
||||
data: []
|
||||
}));
|
||||
|
||||
// Act
|
||||
wrapper.vm.forwardButtonAction();
|
||||
|
||||
// Assert
|
||||
expect(wrapper.vm.questionsData[0].answerData).toEqual({});
|
||||
|
||||
wrapper.unmount();
|
||||
});
|
||||
|
||||
test('Should save to pinia store', async () => {
|
||||
// Arrange
|
||||
const { wrapper } = setupMocks({});
|
||||
|
||||
wrapper.vm.questionsData = [
|
||||
{
|
||||
glassLocation: 'Windshield',
|
||||
glassName: 'Single',
|
||||
answerData: {
|
||||
answerResult: 'FW04848',
|
||||
answeredQuestions: []
|
||||
},
|
||||
questions: [],
|
||||
parts: [
|
||||
{
|
||||
childPartQuestions: []
|
||||
}
|
||||
]
|
||||
}
|
||||
];
|
||||
useMainStore().getPartsOrQuestions = vi.fn(() =>
|
||||
({
|
||||
data: {
|
||||
partsOrQuestions: []
|
||||
}
|
||||
}));
|
||||
|
||||
// Act
|
||||
wrapper.vm.forwardButtonAction();
|
||||
|
||||
await nextTick();
|
||||
|
||||
// Assert
|
||||
expect(wrapper.vm.saveCapabilityQuestionAnswers).toHaveBeenCalled;
|
||||
wrapper.unmount();
|
||||
});
|
||||
test('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 = vi.fn(() =>
|
||||
({
|
||||
data: []
|
||||
}));
|
||||
|
||||
// Act
|
||||
wrapper.vm.forwardButtonAction();
|
||||
|
||||
await nextTick();
|
||||
|
||||
// Assert
|
||||
expect(wrapper.vm.getPartFromCapabilityQuestionAnswer).toHaveBeenCalled;
|
||||
|
||||
wrapper.unmount();
|
||||
});
|
||||
|
||||
test('Should trigger navigateForward', async () => {
|
||||
// Arrange
|
||||
const { wrapper } = setupMocks({});
|
||||
|
||||
wrapper.vm.questionsData = [
|
||||
{
|
||||
glassLocation: 'Windshield',
|
||||
glassName: 'Single',
|
||||
answerData: {
|
||||
answerResult: 'FW04848',
|
||||
answeredQuestions: []
|
||||
},
|
||||
questions: [],
|
||||
parts: [
|
||||
{
|
||||
childPartQuestions: []
|
||||
}
|
||||
]
|
||||
}
|
||||
];
|
||||
useMainStore().getPartsOrQuestions = vi.fn(() =>
|
||||
({
|
||||
data: {
|
||||
partsOrQuestions: []
|
||||
}
|
||||
}));
|
||||
wrapper.vm.navigateForward = vi.fn();
|
||||
|
||||
// Act
|
||||
await wrapper.vm.forwardButtonAction();
|
||||
|
||||
// Assert
|
||||
expect(wrapper.vm.navigateForward).toHaveBeenCalled();
|
||||
|
||||
wrapper.unmount();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
function setupMocks({
|
||||
mountOptionsMockData = {
|
||||
router: {
|
||||
navigate: vi.fn()
|
||||
},
|
||||
actionList: [
|
||||
{
|
||||
actionName: 'saveCapabilityQuestionAnswers',
|
||||
data: {}
|
||||
},
|
||||
{
|
||||
actionName: 'getPartsOrQuestions',
|
||||
data: {}
|
||||
}
|
||||
],
|
||||
route: {
|
||||
query: {
|
||||
issPage: 'capability-questions'
|
||||
}
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
computedSwitcher: [
|
||||
{
|
||||
glassLocation: 'Windshield',
|
||||
glassName: 'Single',
|
||||
answerData: {
|
||||
answerResult: 'FW04848',
|
||||
answeredQuestions: []
|
||||
}
|
||||
}
|
||||
]
|
||||
};
|
||||
},
|
||||
questionsData: {
|
||||
get() {
|
||||
return this.computedSwitcher;
|
||||
},
|
||||
set(val) {
|
||||
this.computedSwitcher = val;
|
||||
}
|
||||
}
|
||||
}
|
||||
}) {
|
||||
useMainStore().getPartsOrQuestions = vi.fn(() =>
|
||||
({
|
||||
data: {
|
||||
partsOrQuestions: []
|
||||
}
|
||||
}));
|
||||
const mountOptions = getMountOptions({
|
||||
...mountOptionsMockData,
|
||||
mixins: [baseMixin, vehicleQuestionsMixin]
|
||||
});
|
||||
mountOptions.attachTo = document.body;
|
||||
|
||||
const wrapper = shallowMount(contactDetails, mountOptions);
|
||||
|
||||
return { wrapper };
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue