Updating unit testing
This commit is contained in:
parent
a74a61aa02
commit
bfe800de38
3 changed files with 15 additions and 32 deletions
|
|
@ -16,6 +16,7 @@
|
||||||
sizeInRem="1.5"
|
sizeInRem="1.5"
|
||||||
data-test="radio"
|
data-test="radio"
|
||||||
groupName="radio-list"
|
groupName="radio-list"
|
||||||
|
textPosition="text-start"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -1,31 +1,23 @@
|
||||||
import { shallowMount, flushPromises } from "@vue/test-utils";
|
import { shallowMount } from "@vue/test-utils";
|
||||||
import { getMountOptions } from "@/helpers/unit-test-helper.js";
|
|
||||||
import { storeActions } from "@/constants/store-actions.js";
|
|
||||||
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 store from "@/store";
|
||||||
|
|
||||||
describe('year-question.vue', () => {
|
describe('year-question.vue', () => {
|
||||||
|
|
||||||
test('year-question should call API to get years', 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 mockDataAndAction = {
|
|
||||||
actionList: [{ actionName: storeActions.GET_VEHICLE_YEARS, data: ["2023", "2022", "2021"],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
};
|
|
||||||
|
|
||||||
const mountOptions = getMountOptions(mockDataAndAction);
|
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
const wrapper = shallowMount(yearQuestion, mountOptions);
|
const wrapper = shallowMount(yearQuestion, global);
|
||||||
await wrapper.setProps({questionText: 'What year is your vehicle?'})
|
await wrapper.setProps({
|
||||||
await flushPromises();
|
questionText: 'What year is your vehicle?',
|
||||||
|
years: ['2023', '2022', '2021']
|
||||||
|
});
|
||||||
wrapper.vm.selectYear(2020);
|
wrapper.vm.selectYear(2020);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
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(store.state.order.vehicle.year).toBe(2020);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,9 @@
|
||||||
|
|
||||||
<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",
|
||||||
|
|
@ -22,21 +25,8 @@ export default {
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
selectYear(year){
|
selectYear(year){
|
||||||
const awaitYearUpdate = new Promise((resolve, reject) => {
|
store.commit(storeMutations.UPDATE_YEAR, year);
|
||||||
this.$store.commit(this.storeMutations.UPDATE_YEAR, year);
|
router.push('?fmgPage=vehicle-make');
|
||||||
|
|
||||||
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);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue