adding unit tests and refactoring dispatch functions
This commit is contained in:
parent
b6503025a4
commit
8a84eb6294
7 changed files with 93 additions and 44 deletions
|
|
@ -1 +1,18 @@
|
||||||
test.todo('some test to be written in the future');
|
import { shallowMount } from '@vue/test-utils';
|
||||||
|
import radioQuestion from './radioQuestion';
|
||||||
|
|
||||||
|
test('radioQuestion', () => {
|
||||||
|
// render the component
|
||||||
|
const wrapper = shallowMount(radioQuestion, {
|
||||||
|
propsData: {
|
||||||
|
questionText: 'testString',
|
||||||
|
chooseAnswer: function(){ console.log('test') }
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// test if questionText is a string
|
||||||
|
expect(typeof wrapper.props().questionText).toBe('string');
|
||||||
|
|
||||||
|
// test if chooseAnswer is a function
|
||||||
|
expect(typeof wrapper.props().chooseAnswer).toBe('function');
|
||||||
|
});
|
||||||
|
|
@ -5,7 +5,7 @@
|
||||||
</div>
|
</div>
|
||||||
<div class="car_list">
|
<div class="car_list">
|
||||||
<div v-for="answer in answers" :key="answer" class="mb-2">
|
<div v-for="answer in answers" :key="answer" class="mb-2">
|
||||||
<radio :text="answer" :value="answer" />
|
<radio :text="answer" :value="answer" @click="chooseAnswer(answer)" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -17,7 +17,8 @@ export default {
|
||||||
name: "radio-question",
|
name: "radio-question",
|
||||||
props: {
|
props: {
|
||||||
questionText: String,
|
questionText: String,
|
||||||
answers: Array
|
answers: Array,
|
||||||
|
chooseAnswer: Function
|
||||||
},
|
},
|
||||||
components: {
|
components: {
|
||||||
radio
|
radio
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@
|
||||||
<radioQuestion
|
<radioQuestion
|
||||||
:questionText="radioQuestion.Question"
|
:questionText="radioQuestion.Question"
|
||||||
:answers="this.years"
|
:answers="this.years"
|
||||||
|
:chooseAnswer="selectYear"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -18,6 +19,8 @@ import Header from "@/uxComponents/header/header";
|
||||||
import { endpoints } from "@/constants/endpoints.js";
|
import { endpoints } from "@/constants/endpoints.js";
|
||||||
import globalMethods from "@/global-methods";
|
import globalMethods from "@/global-methods";
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
|
import store from "@/store";
|
||||||
|
import router from "@/router";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "SelectCar",
|
name: "SelectCar",
|
||||||
|
|
@ -58,9 +61,11 @@ export default {
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
selectYear(year) {
|
selectYear(year) {
|
||||||
const listButtons = document.querySelectorAll('.list-button');
|
this.dispatchNonBlockingStoreAction("selectYear", { year: year }).then( (response) => {
|
||||||
globalMethods.disableItems(listButtons);
|
const makes = response;
|
||||||
this.dispatchNonBlockingStoreAction("selectYear", { year: year });
|
store.commit('updateYear', {year, makes});
|
||||||
|
router.push(`select-make?year=${year}`);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
components: {
|
components: {
|
||||||
|
|
|
||||||
|
|
@ -4,11 +4,11 @@ import { lazyLoadComponent } from "@/router/dynamic-routing/component-loader.js"
|
||||||
import ComponentTest from "@/layouts/componentTest/componentTest.vue";
|
import ComponentTest from "@/layouts/componentTest/componentTest.vue";
|
||||||
import NotFound from "@/layouts/notFound/notFound.vue";
|
import NotFound from "@/layouts/notFound/notFound.vue";
|
||||||
import store from "@/store";
|
import store from "@/store";
|
||||||
// import selectYear from "@/layouts/selectYear/selectYear.vue";
|
import selectYear from "@/layouts/selectYear/selectYear.vue";
|
||||||
// import selectMake from "@/layouts/selectMake/selectMake.vue";
|
import selectMake from "@/layouts/selectMake/selectMake.vue";
|
||||||
// import selectModel from "@/layouts/selectModel/selectModel.vue";
|
import selectModel from "@/layouts/selectModel/selectModel.vue";
|
||||||
// import selectStyle from "@/layouts/selectStyle/selectStyle.vue";
|
import selectStyle from "@/layouts/selectStyle/selectStyle.vue";
|
||||||
// import selectDamage from "@/layouts/selectDamage/selectDamage.vue";
|
import selectDamage from "@/layouts/selectDamage/selectDamage.vue";
|
||||||
|
|
||||||
const routes = [
|
const routes = [
|
||||||
{
|
{
|
||||||
|
|
@ -66,31 +66,31 @@ const routes = [
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
// {
|
{
|
||||||
// path: "/select-year",
|
path: "/select-year",
|
||||||
// name: "selectYear",
|
name: "selectYear",
|
||||||
// component: selectYear,
|
component: selectYear,
|
||||||
// },
|
},
|
||||||
// {
|
{
|
||||||
// path: "/select-make",
|
path: "/select-make",
|
||||||
// name: "selectMake",
|
name: "selectMake",
|
||||||
// component: selectMake,
|
component: selectMake,
|
||||||
// },
|
},
|
||||||
// {
|
{
|
||||||
// path: "/select-model",
|
path: "/select-model",
|
||||||
// name: "selectModel",
|
name: "selectModel",
|
||||||
// component: selectModel,
|
component: selectModel,
|
||||||
// },
|
},
|
||||||
// {
|
{
|
||||||
// path: "/select-style",
|
path: "/select-style",
|
||||||
// name: "selectStyle",
|
name: "selectStyle",
|
||||||
// component: selectStyle,
|
component: selectStyle,
|
||||||
// },
|
},
|
||||||
// {
|
{
|
||||||
// path: "/select-damage",
|
path: "/select-damage",
|
||||||
// name: "selectDamage",
|
name: "selectDamage",
|
||||||
// component: selectDamage,
|
component: selectDamage,
|
||||||
// },
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
const router = createRouter({
|
const router = createRouter({
|
||||||
|
|
|
||||||
|
|
@ -61,15 +61,10 @@ export default createStore({
|
||||||
payload:{
|
payload:{
|
||||||
"Year": year
|
"Year": year
|
||||||
}
|
}
|
||||||
})
|
|
||||||
.then( (response) => {
|
|
||||||
const makes = response;
|
|
||||||
context.commit('updateYear', {year, makes});
|
|
||||||
router.push(`select-make?year=${year}`);
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
selectMake({ commit, state }, { make }) {
|
selectMake({ commit, state }, { make }) {
|
||||||
return globalMethods.callHttpClient({
|
globalMethods.callHttpClient({
|
||||||
method: endpoints.GetModels.method,
|
method: endpoints.GetModels.method,
|
||||||
endpoint: endpoints.GetModels.url,
|
endpoint: endpoints.GetModels.url,
|
||||||
payload:{
|
payload:{
|
||||||
|
|
|
||||||
|
|
@ -1 +1,15 @@
|
||||||
test.todo('some test to be written in the future');
|
import { shallowMount } from '@vue/test-utils';
|
||||||
|
import Header from './header';
|
||||||
|
|
||||||
|
test('Header', () => {
|
||||||
|
// render the component
|
||||||
|
const wrapper = shallowMount(Header, {
|
||||||
|
propsData: {
|
||||||
|
text: 'testString'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// test if text is a string
|
||||||
|
expect(typeof wrapper.props().text).toBe('string');
|
||||||
|
|
||||||
|
});
|
||||||
|
|
@ -1 +1,18 @@
|
||||||
test.todo('some test to be written in the future');
|
import { shallowMount } from '@vue/test-utils';
|
||||||
|
import radio from './radio';
|
||||||
|
|
||||||
|
test('radioQuestion', () => {
|
||||||
|
// render the component
|
||||||
|
const wrapper = shallowMount(radio, {
|
||||||
|
propsData: {
|
||||||
|
value: 'testString',
|
||||||
|
text: 'testString2'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// test if value is a string
|
||||||
|
expect(typeof wrapper.props().value).toBe('string');
|
||||||
|
|
||||||
|
// test if text is a string
|
||||||
|
expect(typeof wrapper.props().text).toBe('string');
|
||||||
|
});
|
||||||
Loading…
Reference in a new issue