Updating unit test so that mock data can be implemented
This commit is contained in:
parent
ba182117cf
commit
dc4bdd3782
3 changed files with 29 additions and 15 deletions
|
|
@ -1,5 +1,5 @@
|
||||||
import { storeActions } from "@/constants/store-actions";
|
import { storeActions } from "@/constants/store-actions";
|
||||||
import store from "@/store";
|
import { storeMutations } from "@/constants/store-mutations.js";
|
||||||
|
|
||||||
export function getMountOptions(mockData) {
|
export function getMountOptions(mockData) {
|
||||||
// Define our mocks to attached to the 'global' object for Vue/Jest.
|
// Define our mocks to attached to the 'global' object for Vue/Jest.
|
||||||
|
|
@ -18,12 +18,16 @@ export function getMountOptions(mockData) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Mock store actions from js file
|
// Mock const files
|
||||||
mocks.storeActions = storeActions;
|
mocks.storeActions = storeActions;
|
||||||
|
mocks.storeMutations = storeMutations;
|
||||||
|
|
||||||
|
// Mock $store and $router when accessing this.$store/$router
|
||||||
|
mocks.$store = mockData.store;
|
||||||
|
mocks.$router = mockData.router;
|
||||||
|
|
||||||
const global = {
|
const global = {
|
||||||
mocks: mocks,
|
mocks: mocks,
|
||||||
plugins: [store]
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return { global };
|
return { global };
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,26 @@
|
||||||
import { shallowMount } from "@vue/test-utils";
|
|
||||||
import yearQuestion from "@/layouts/vehicle-year/year-question/year-question";
|
import yearQuestion from "@/layouts/vehicle-year/year-question/year-question";
|
||||||
import store from "@/store";
|
import { shallowMount } from "@vue/test-utils";
|
||||||
|
import { getMountOptions } from "../../../helpers/unit-test-helper";
|
||||||
|
|
||||||
describe('year-question.vue', () => {
|
describe('year-question.vue', () => {
|
||||||
|
|
||||||
test('year-question should take a prop for years and questionText, and trigger a selectYear function when an option is clicked.', async () => {
|
test('year-question should take a prop for years and questionText, and trigger a selectYear function when an option is clicked.', async () => {
|
||||||
|
// Arrange
|
||||||
|
const mockData = {
|
||||||
|
store: {
|
||||||
|
commit: jest.fn(),
|
||||||
|
year: null
|
||||||
|
},
|
||||||
|
router: {
|
||||||
|
push: jest.fn()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
mockData.store.commit.mockImplementation((func, year) => {
|
||||||
|
mockData.store.year = year;
|
||||||
|
});
|
||||||
|
|
||||||
|
const mountOptions = getMountOptions(mockData);
|
||||||
// Act
|
// Act
|
||||||
const wrapper = shallowMount(yearQuestion, global);
|
const wrapper = shallowMount(yearQuestion, mountOptions);
|
||||||
await wrapper.setProps({
|
await wrapper.setProps({
|
||||||
questionText: 'What year is your vehicle?',
|
questionText: 'What year is your vehicle?',
|
||||||
years: ['2023', '2022', '2021']
|
years: ['2023', '2022', '2021']
|
||||||
|
|
@ -18,6 +31,6 @@ describe('year-question.vue', () => {
|
||||||
const radioQuestion = await wrapper.findComponent({name: 'radioQuestion'});
|
const radioQuestion = await wrapper.findComponent({name: 'radioQuestion'});
|
||||||
expect(radioQuestion.attributes('questiontext')).toBe("What year is your vehicle?");
|
expect(radioQuestion.attributes('questiontext')).toBe("What year is your vehicle?");
|
||||||
expect(radioQuestion.attributes('answers')).toBe("2023,2022,2021");
|
expect(radioQuestion.attributes('answers')).toBe("2023,2022,2021");
|
||||||
expect(store.state.order.vehicle.year).toBe(2020);
|
expect(mockData.store.year).toBe(2020);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
@ -8,9 +8,6 @@
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import radioQuestion from "@/common-components/radio-question/radio-question";
|
import radioQuestion from "@/common-components/radio-question/radio-question";
|
||||||
import store from "@/store";
|
|
||||||
import router from "@/router";
|
|
||||||
import { storeMutations } from "@/constants/store-mutations";
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "year-question",
|
name: "year-question",
|
||||||
|
|
@ -25,8 +22,8 @@ export default {
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
selectYear(year){
|
selectYear(year){
|
||||||
store.commit(storeMutations.UPDATE_YEAR, year);
|
this.$store.commit(this.storeMutations.UPDATE_YEAR, year);
|
||||||
router.push('?fmgPage=vehicle-make');
|
this.$router.push('?fmgPage=vehicle-make');
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue