diff --git a/src/ux-components/radio/radio.spec.js b/src/ux-components/radio/radio.spec.js index e69de29b..e5e5c7d3 100644 --- a/src/ux-components/radio/radio.spec.js +++ b/src/ux-components/radio/radio.spec.js @@ -0,0 +1,111 @@ +import { shallowMount } from "@vue/test-utils"; +import radio from "./radio"; + +describe("radio.vue", () => { + it("Should return group name", async () => { + // Act + const wrapper = shallowMount(radio, { + propsData: { + groupName: "radio-button-test", + }, + }); + + // Assert + const input = wrapper.find("input"); + + // Expect + expect(input.attributes().name).toEqual("radio-button-test"); + }); + + it("Should return checkbox id", async () => { + // Act + const wrapper = shallowMount(radio, { + propsData: { + buttonID: "Radio ID", + }, + }); + + // Assert + const input = wrapper.find("input"); + + // Expect + expect(input.attributes().id).toEqual("Radio ID"); + }); + + it("Should return label text", async () => { + // Act + const wrapper = shallowMount(radio, { + propsData: { + buttonLabel: "label text", + }, + }); + + // Assert + const paragraph = wrapper.find("p"); + + expect(paragraph.text()).toEqual("label text"); + }); + + it("Should return label text", async () => { + // Act + const wrapper = shallowMount(radio, { + propsData: { + screenReaderOnlyText: "screenreader text", + }, + }); + + // Assert + const paragraph = wrapper.find("span"); + + expect(paragraph.text()).toEqual("screenreader text"); + }); + + it("Should emit button value on click", async () => { + // Act + const wrapper = shallowMount(radio, { + global: { + mocks: { + '$route': { query: { issPage: 'page-name' } }, + } + }, + propsData: { + buttonLabel: "Windshield", + value: "List Card Checkbox", + buttonID: "List Card Checkbox", + groupID: "radio-demo-1", + groupName: "radio 1", + isRequired: true, + isWide: false, + modelValue: ["List Card Checkbox"], + }, + }); + wrapper.vm.handleCheckChange(); + // Assert + expect(wrapper.emitted()["isCheckedChanged"][0]).toEqual([{"buttonID": "List Card Checkbox", value: "List Card Checkbox", checkValue: false}]);; + expect(wrapper.vm.pushEventToGA).toHaveBeenCalled(); + }); + + it("Should set checkValue data if selectedButtonIDs has value(s)", async () => { + // Act + const wrapper = shallowMount(radio, { + global: { + mocks: { + '$route': { query: { issPage: 'page-name' } }, + } + }, + propsData: { + buttonLabel: "Windshield", + buttonID: "List Card Checkbox", + groupID: "radio-demo-1", + groupName: "radio 1", + buttonImage: "windshield-damage.svg", + isRequired: true, + modelValue: ["List Card Checkbox"], + value: "Car-Front", + selectedValues: "Car-Front" + }, + }); + // Assert + expect(wrapper.componentVM.checkValue).toEqual(true); + }); +}); diff --git a/src/ux-components/radio/radio.vue b/src/ux-components/radio/radio.vue index e69de29b..1a0d52d7 100644 --- a/src/ux-components/radio/radio.vue +++ b/src/ux-components/radio/radio.vue @@ -0,0 +1,139 @@ + + + + + + \ No newline at end of file