Updating unit testing

This commit is contained in:
Max 2021-12-02 16:16:00 -05:00
parent a74a61aa02
commit bfe800de38
3 changed files with 15 additions and 32 deletions

View file

@ -16,6 +16,7 @@
sizeInRem="1.5"
data-test="radio"
groupName="radio-list"
textPosition="text-start"
/>
</div>
</div>

View file

@ -1,31 +1,23 @@
import { shallowMount, flushPromises } from "@vue/test-utils";
import { getMountOptions } from "@/helpers/unit-test-helper.js";
import { storeActions } from "@/constants/store-actions.js";
import { shallowMount } from "@vue/test-utils";
import yearQuestion from "@/layouts/vehicle-year/year-question/year-question";
import store from "@/store";
describe('year-question.vue', () => {
test('year-question should call API to get years', async () => {
// Arrange
const mockDataAndAction = {
actionList: [{ actionName: storeActions.GET_VEHICLE_YEARS, data: ["2023", "2022", "2021"],
},
],
};
const mountOptions = getMountOptions(mockDataAndAction);
test('year-question should take a prop for years and questionText, and trigger a selectYear function when an option is clicked.', async () => {
// Act
const wrapper = shallowMount(yearQuestion, mountOptions);
await wrapper.setProps({questionText: 'What year is your vehicle?'})
await flushPromises();
const wrapper = shallowMount(yearQuestion, global);
await wrapper.setProps({
questionText: 'What year is your vehicle?',
years: ['2023', '2022', '2021']
});
wrapper.vm.selectYear(2020);
// Assert
const radioQuestion = await wrapper.findComponent({name: 'radioQuestion'});
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);
});
});

View file

@ -8,6 +8,9 @@
<script>
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 {
name: "year-question",
@ -22,21 +25,8 @@ export default {
},
methods: {
selectYear(year){
const awaitYearUpdate = new Promise((resolve, reject) => {
this.$store.commit(this.storeMutations.UPDATE_YEAR, year);
if(this.$store.state.order.vehicle.year !== null) {
resolve('ok');
} else {
reject('error occured');
}
});
awaitYearUpdate.then(() => {
this.$router.push('?fmgPage=vehicle-make');
}).catch((error) => {
console.log(error);
});
store.commit(storeMutations.UPDATE_YEAR, year);
router.push('?fmgPage=vehicle-make');
}
},
};