Functionality for year radio buttons

This commit is contained in:
Max 2021-11-30 16:08:46 -05:00
parent f5f1897a41
commit 0b366db781
11 changed files with 49 additions and 63 deletions

View file

@ -7,7 +7,7 @@ const storeActions = {
GET_VEHICLE_STYLES: "getVehicleStyles", GET_VEHICLE_STYLES: "getVehicleStyles",
GET_EVOX_IMAGE: "getEvoxImage", GET_EVOX_IMAGE: "getEvoxImage",
LOOKUP_VEHICLE_BY_YMMS: "lookupVehicleByYmms", LOOKUP_VEHICLE_BY_YMMS: "lookupVehicleByYmms",
LOOKUP_VEHICLE_BY_VIN: "lookupVehicleByVin" LOOKUP_VEHICLE_BY_VIN: "lookupVehicleByVin",
}; };
export { storeActions }; export { storeActions };

View file

@ -0,0 +1,5 @@
const storeMutations = {
UPDATE_YEAR: "updateYear",
}
export { storeMutations };

View file

@ -73,7 +73,7 @@
<div role="radiogroup" aria-labelledby="select-year-radio-group" class="col my-3 d-flex align-items-center flex-column"> <div role="radiogroup" aria-labelledby="select-year-radio-group" class="col my-3 d-flex align-items-center flex-column">
<!-- The h3 and id must be included. The id must match the aria-labelledby of the parent div. --> <!-- The h3 and id must be included. The id must match the aria-labelledby of the parent div. -->
<h3 class="visually-hidden" id="select-year-radio-group">Select Vehicle Year</h3> <h3 class="visually-hidden" id="select-year-radio-group">Select Vehicle Year</h3>
<radioList <radio
groupName="demo" groupName="demo"
ariaLabelBy="vehicle-year" ariaLabelBy="vehicle-year"
radioID="2021" radioID="2021"
@ -81,7 +81,7 @@
loaderPosition="right" loaderPosition="right"
sizeInRem="1.5" sizeInRem="1.5"
/> />
<radioList <radio
groupName="demo" groupName="demo"
ariaLabelBy="vehicle-year" ariaLabelBy="vehicle-year"
radioID="2020" radioID="2020"
@ -89,7 +89,7 @@
loaderPosition="right" loaderPosition="right"
sizeInRem="1.5" sizeInRem="1.5"
/> />
<radioList <radio
groupName="demo" groupName="demo"
ariaLabelBy="vehicle-year" ariaLabelBy="vehicle-year"
radioID="2019" radioID="2019"
@ -244,7 +244,7 @@
import buttonSecondary from "@/ux-components/button-secondary/button-secondary"; import buttonSecondary from "@/ux-components/button-secondary/button-secondary";
import radioCard from "@/ux-components/radio-card/radio-card"; import radioCard from "@/ux-components/radio-card/radio-card";
import listButton from "@/ux-components/list-button/list-button"; import listButton from "@/ux-components/list-button/list-button";
import radioList from "@/ux-components/radio-list/radio-list"; import radio from "@/ux-components/radio/radio";
import alert from "@/ux-components/alert/alert"; import alert from "@/ux-components/alert/alert";
import vehicleBanner from "@/common-components/vehicle-banner/vehicle-banner"; import vehicleBanner from "@/common-components/vehicle-banner/vehicle-banner";
export default { export default {
@ -254,7 +254,7 @@
buttonSecondary, buttonSecondary,
radioCard, radioCard,
listButton, listButton,
radioList, radio,
alert, alert,
vehicleBanner vehicleBanner
}, },

View file

@ -21,7 +21,6 @@ export default {
radioQuestionWidgets: {}, radioQuestionWidgets: {},
}; };
}, },
computed: {},
async created() { async created() {
const pageContent = await this.GetContentFromCms(); const pageContent = await this.GetContentFromCms();

View file

@ -2,6 +2,7 @@ import { shallowMount, flushPromises } from "@vue/test-utils";
import { getMountOptions } from "@/helpers/unit-test-helper.js"; import { getMountOptions } from "@/helpers/unit-test-helper.js";
import { storeActions } from "@/constants/store-actions.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";
describe('year-question.vue', () => { describe('year-question.vue', () => {
@ -19,10 +20,12 @@ describe('year-question.vue', () => {
const wrapper = shallowMount(yearQuestion, mountOptions); const wrapper = shallowMount(yearQuestion, mountOptions);
await wrapper.setProps({questionText: 'What year is your vehicle?'}) await wrapper.setProps({questionText: 'What year is your vehicle?'})
await flushPromises(); await flushPromises();
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);
}); });
}); });

View file

@ -1,5 +1,9 @@
<template> <template>
<radioQuestion class="radioQuestion" :questionText="questionText" :answers="years" /> <radioQuestion class="radioQuestion"
:questionText="questionText"
:answers="years"
:chooseAnswer="selectYear"
/>
</template> </template>
<script> <script>
@ -24,6 +28,9 @@ export default {
radioQuestion, radioQuestion,
}, },
methods: { methods: {
selectYear(year){
this.$store.commit(this.storeMutations.UPDATE_YEAR, year);
}
}, },
}; };
</script> </script>

View file

@ -1,4 +1,5 @@
import { storeActions } from "@/constants/store-actions.js"; import { storeActions } from "@/constants/store-actions.js";
import { storeMutations } from "@/constants/store-mutations.js";
import { widgetNames } from "@/constants/widget-names.js"; import { widgetNames } from "@/constants/widget-names.js";
export default { export default {
@ -53,6 +54,9 @@ export default {
storeActions() { storeActions() {
return storeActions; return storeActions;
}, },
storeMutations() {
return storeMutations;
},
widgetNames() { widgetNames() {
return widgetNames; return widgetNames;
}, },

View file

@ -64,6 +64,9 @@ export default createStore({
} }
}, },
mutations: { mutations: {
updateYear(state, year){
state.order.vehicle.year = year;
},
updateVehicleImage(state, data) { updateVehicleImage(state, data) {
state.order.vehicle.imageSrc = data.imgSrc; state.order.vehicle.imageSrc = data.imgSrc;
}, },
@ -138,6 +141,6 @@ export default createStore({
endpoint: relativeUrl, endpoint: relativeUrl,
payload: {}, payload: {},
}); });
}, }
}, },
}); });

View file

@ -14,7 +14,6 @@ describe("Actions", () => {
await store.dispatch('getVehicleYears') await store.dispatch('getVehicleYears')
.then( (response) => { .then( (response) => {
years = response.data; years = response.data;
console.log(response);
}); });
// Assert // Assert
@ -109,4 +108,22 @@ describe("Actions", () => {
// Assert // Assert
expect(pageData).toBe('Page Info Data'); expect(pageData).toBe('Page Info Data');
}); });
}) })
describe("Mutations", () => {
it("Should update the year property in the store", () => {
// Act
store.commit('updateYear', 2020);
// Assert
expect(store.state.order.vehicle.year).toBe(2020);
});
it("Should update the vehicle image property in the store", () => {
// Act
store.commit('updateVehicleImage', {imgSrc: 'exampleimage@image.com'});
// Assert
expect(store.state.order.vehicle.imageSrc).toBe('exampleimage@image.com');
});
});

View file

@ -1 +0,0 @@
test.todo("some test to be written in the future");

View file

@ -1,51 +0,0 @@
<template>
<div class="radiogroup radio-list-button d-flex flex-column w-100">
<input type="radio"
v-bind:id="radioID"
v-bind:name="groupName"
v-bind:value="radioID">
<label role="radio" tabindex="0" aria-checked="false"
v-bind:for="radioID"
class="mb-2 d-flex align-items-center justify-content-between p-2"
@click='displayComponent'
>{{radioID}}
<loader
v-if="display"
v-bind:style="{width: `${sizeInRem}rem`, height: `${sizeInRem}rem`}"
v-bind:class="[this.loaderColor, this.loaderPosition]"
/>
</label>
<p class="small">{{errorMessage}}</p>
</div>
</template>
<script>
import loader from "@/ux-components/loader/loader";
export default {
name: "radioList",
props: [
"groupName",
"ariaLabelBy",
"radioID",
"errorMessage",
"loaderColor",
"loaderPosition",
"sizeInRem"
],
data() {
return {
isError: false,
display: false
};
},
methods: {
displayComponent() {
this.display = true;
},
},
components: {
loader,
},
};
</script>