Merge pull request #57 from Safelite/feature/CSR-121_radio-implementation

integrating updated radio buttons
This commit is contained in:
max-dempsey 2021-11-23 17:16:23 -05:00 committed by GitHub
commit ce5ddd27a8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 54 additions and 36 deletions

View file

@ -19,8 +19,7 @@ describe("radioQuestion.vue", () => {
"Question Text" "Question Text"
); );
const radioButtons = wrapper.findAllComponents('[data-test="radio"]'); const radioButtons = wrapper.findAllComponents('[data-test="radio"]');
expect(radioButtons[0].attributes("text")).toEqual("2023"); expect(radioButtons.length).toBe(3);
expect(radioButtons[2].attributes("text")).toEqual("2021");
expect(typeof wrapper.props().chooseAnswer).toBe("function"); expect(typeof wrapper.props().chooseAnswer).toBe("function");
}); });
}); });

View file

@ -5,14 +5,18 @@
questionText questionText
}}</span> }}</span>
</div> </div>
<div class="car_list overflow-scroll position-absolute"> <div class="w-100 d-flex justify-content-center">
<div v-for="answer in answers" :key="answer" class="mb-2"> <div class="car_list overflow-scroll position-absolute container-fluid pt-1" role="radiogroup" aria-labelledby="select-year-radio-group">
<radio <h3 class="visually-hidden" id="select-year-radio-group">*</h3>
:text="answer" <radio v-for="answer in answers" :key="answer" class="mb-2"
:value="answer" :radioID="answer"
@click="chooseAnswer(answer)" @click="chooseAnswer(answer)"
data-test="radio" loaderColor="blue"
/> loaderPosition="right"
sizeInRem="1.5"
data-test="radio"
groupName="radio-list"
/>
</div> </div>
</div> </div>
</div> </div>

View file

@ -2,22 +2,21 @@ import { shallowMount } from "@vue/test-utils";
import radio from "./radio"; import radio from "./radio";
describe("radio.vue", () => { describe("radio.vue", () => {
it("Should render the 'text' prop value as a span value for the radio button label and add the 'value' prop value as the radio button value and id.", () => { it("Should render the 'radioID' prop value as a span value for the radio button label.", () => {
// Act // Act
const wrapper = shallowMount(radio, { const wrapper = shallowMount(radio, {
propsData: { propsData: {
value: "2023", radioID: "2023",
text: "12", groupName: "TestGroup"
}, },
}); });
// Assert // Assert
expect(wrapper.find("span").text()).toEqual("12");
expect(wrapper.find("input").attributes()).toEqual({ expect(wrapper.find("input").attributes()).toEqual({
class: "position-absolute opacity-0",
id: "2023", id: "2023",
type: "radio", type: "radio",
value: "2023", value: "2023",
}); name: "TestGroup",
})
}); });
}); });

View file

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