From 92dfa35521ca33fa3bb5b3476f286188a5174b70 Mon Sep 17 00:00:00 2001 From: Kulbhushan Kaushik Date: Tue, 25 Oct 2022 08:25:11 -0400 Subject: [PATCH 01/10] commit --- .../button-question/button-question.spec.js | 190 +++++++++++++ .../button-question/button-question.vue | 253 ++++++++++++++++++ .../list-button-horizontal.spec.js | 0 .../list-button-horizontal.vue | 0 src/ux-components/list-button/list-button-vue | 0 .../list-button/list-button.spec.js | 0 src/ux-components/list-card/list-card.spec.js | 0 src/ux-components/list-card/list-card.vue | 0 src/ux-components/radio/radio.spec.js | 0 src/ux-components/radio/radio.vue | 0 10 files changed, 443 insertions(+) create mode 100644 src/common-components/button-question/button-question.spec.js create mode 100644 src/common-components/button-question/button-question.vue create mode 100644 src/ux-components/list-button-horizontal/list-button-horizontal.spec.js create mode 100644 src/ux-components/list-button-horizontal/list-button-horizontal.vue create mode 100644 src/ux-components/list-button/list-button-vue create mode 100644 src/ux-components/list-button/list-button.spec.js create mode 100644 src/ux-components/list-card/list-card.spec.js create mode 100644 src/ux-components/list-card/list-card.vue create mode 100644 src/ux-components/radio/radio.spec.js create mode 100644 src/ux-components/radio/radio.vue diff --git a/src/common-components/button-question/button-question.spec.js b/src/common-components/button-question/button-question.spec.js new file mode 100644 index 00000000..3002920e --- /dev/null +++ b/src/common-components/button-question/button-question.spec.js @@ -0,0 +1,190 @@ +import { shallowMount } from "@vue/test-utils"; +import buttonQuestion from "@/common-components/button-question/button-question"; +import { getMountOptions } from "@/helpers/unit-test-helper.js"; + +jest.mock("@/store", () => { return {}; }, { virtual: true }); + +describe("buttonQuestion.vue", () => { + it("Should show overflow classes on fieldset if isOverflowScrollable is true", () => { + // Act + const wrapper = shallowMount(buttonQuestion, { + propsData: { + isOverflowScrollable: true, + groupName: "group-name" + } + }); + + // Assert + const fieldSet = wrapper.find('fieldset'); + expect(fieldSet.classes()).toContain("overflow-scroll"); + }); +}); + +describe("buttonQuestion.vue", () => { + it("Fieldset classes should contain row if button type is listCard", () => { + // Act + const wrapper = shallowMount(buttonQuestion, { + propsData: { + buttonType: "listCard", + groupName: "group-name" + } + }); + // Assert + const Div = wrapper.find('fieldset div'); + expect(Div.classes()).toContain("row"); + }); +}); + +describe("buttonQuestion.vue", () => { + it("Fieldset classes should contain d-flex if button type is listButtonHorizontal", () => { + // Act + const wrapper = shallowMount(buttonQuestion, { + propsData: { + buttonType: "listButtonHorizontal", + groupName: "group-name" + } + }); + // Assert + const Div = wrapper.find('fieldset div'); + expect(Div.classes()).toContain("d-flex"); + }); +}); + +describe("buttonQuestion.vue", () => { + it("Fieldset classes should contain ui-radio if button type is radio", () => { + // Act + const wrapper = shallowMount(buttonQuestion, { + propsData: { + buttonType: "radio", + groupName: "group-name" + } + }); + // Assert + const Div = wrapper.find('fieldset div'); + expect(Div.classes()).toContain("ui-radio"); + }); +}); + + +// testing a computed property +describe("buttonQuestion.vue", () => { + it("getColLength should return '12' if prop isWide is set to true", () => { + // Act + const localThis = { isWide: true } + + expect(buttonQuestion.computed.getColLength.call(localThis)).toBe("12"); + }); +}); + +describe("buttonQuestion.vue", () => { + it("getColLength should return '' if prop isWide is set to false", () => { + // Act + const localThis = { + isWide: false, + answers: ['a', 'b'], + groupName: "group-name" + } + + expect(buttonQuestion.computed.getColLength.call(localThis)).toBe(""); + }); +}); + +describe("buttonQuestion.vue", () => { + it("Should return answer.Text if prop useTextForValue is true", async () => { + // Act + const localThis = { useTextForValue: true }; + const answer = { 'Name': 'testName', 'Text': 'testText' }; + + // Assert + expect(buttonQuestion.methods.getValue.call(localThis, answer)).toBe('testText'); + }); +}); + +describe("buttonQuestion.vue", () => { + it("Should return answer.Name if prop useTextForValue is false and answer.Name exists", async () => { + // Act + const localThis = { useTextForValue: false }; + const answer = { 'Name': 'testName', 'Text': 'testText' }; + + // Assert + expect(buttonQuestion.methods.getValue.call(localThis, answer)).toBe('testName'); + }); +}); + +describe("buttonQuestion.vue", () => { + it("Should trigger event modelValue change to new value on when radio button selected", async () => { + // Act + const wrapper = shallowMount(buttonQuestion, setupMocks({propsData: {groupName: "group-name"}})); + await wrapper.setProps({ + answers: ["2022", "2021", "2020"], + isMultiSelect: false, + modelValue: [] + }); + const val = { checkValue: true, value: "2021", } + wrapper.vm.handleCheckedChanged(val); + // Assert + expect(wrapper.emitted()["update:modelValue"][0]).toEqual([["2021"]]); + }); +}); + +describe("buttonQuestion.vue", () => { + it("Should add values to array on checkbox click", () => { + // Act + const wrapper = shallowMount(buttonQuestion, setupMocks({ + propsData: { + modelValue: ["2022", "2021", "2020"], + isMultiSelect: true, + groupName: "group-name" + } + })); + const val = { checkValue: true, value: "2019", } + wrapper.vm.handleCheckedChanged(val); + // Assert + expect(wrapper.emitted()["update:modelValue"][0]).toEqual([["2022", "2021", "2020", "2019"]]); + }); +}); + +describe("buttonQuestion.vue", () => { + it("Should add a value to this.selectedValues if prop isMultiSelect is true, checkValue is true and this.selectedValues already exists", () => { + // Act + const wrapper = shallowMount(buttonQuestion, setupMocks({ + propsData: { + isMultiSelect: true, + modelValue: ['a', 'b'], + groupName: "group-name" + } + })); + const val = { checkValue: true, value: "2021", } + wrapper.vm.handleCheckedChanged(val); + + // Assert + expect(wrapper.vm.selectedValues).toEqual(["a", "b", "2021"]); + }); +}); + +describe("buttonQuestion.vue", () => { + it("Should remove a value to this.selectedValues if prop isMultiSelect is true, checkValue is false and this.selectedValues already exists", () => { + // Act + const wrapper = shallowMount(buttonQuestion, setupMocks({ + propsData: { + isMultiSelect: true, + modelValue: ['a', 'b'], + groupName: "group-name" + } + })); + + const val = { checkValue: false, value: "a", } + wrapper.vm.handleCheckedChanged(val); + + // Assert + expect(wrapper.vm.selectedValues).toEqual(["b"]); + }); +}); + +function setupMocks(mountOptionsMockData = {}) { + const defaultMountOptions = { route: { query: { fmgPage: 'page-name' } } }; + const baseMountOptions = getMountOptions(Object.assign(defaultMountOptions, mountOptionsMockData)); + const allMountOptions = Object.assign(defaultMountOptions, baseMountOptions); + + return allMountOptions; +} diff --git a/src/common-components/button-question/button-question.vue b/src/common-components/button-question/button-question.vue new file mode 100644 index 00000000..10337778 --- /dev/null +++ b/src/common-components/button-question/button-question.vue @@ -0,0 +1,253 @@ + + + + + + \ No newline at end of file diff --git a/src/ux-components/list-button-horizontal/list-button-horizontal.spec.js b/src/ux-components/list-button-horizontal/list-button-horizontal.spec.js new file mode 100644 index 00000000..e69de29b diff --git a/src/ux-components/list-button-horizontal/list-button-horizontal.vue b/src/ux-components/list-button-horizontal/list-button-horizontal.vue new file mode 100644 index 00000000..e69de29b diff --git a/src/ux-components/list-button/list-button-vue b/src/ux-components/list-button/list-button-vue new file mode 100644 index 00000000..e69de29b diff --git a/src/ux-components/list-button/list-button.spec.js b/src/ux-components/list-button/list-button.spec.js new file mode 100644 index 00000000..e69de29b diff --git a/src/ux-components/list-card/list-card.spec.js b/src/ux-components/list-card/list-card.spec.js new file mode 100644 index 00000000..e69de29b diff --git a/src/ux-components/list-card/list-card.vue b/src/ux-components/list-card/list-card.vue new file mode 100644 index 00000000..e69de29b diff --git a/src/ux-components/radio/radio.spec.js b/src/ux-components/radio/radio.spec.js new file mode 100644 index 00000000..e69de29b diff --git a/src/ux-components/radio/radio.vue b/src/ux-components/radio/radio.vue new file mode 100644 index 00000000..e69de29b From 79f81fab573055d871af50a9a2d730d26bf148d4 Mon Sep 17 00:00:00 2001 From: Kulbhushan Kaushik Date: Tue, 25 Oct 2022 08:29:28 -0400 Subject: [PATCH 02/10] commit --- src/ux-components/radio/radio.spec.js | 111 ++++++++++++++++++++ src/ux-components/radio/radio.vue | 139 ++++++++++++++++++++++++++ 2 files changed, 250 insertions(+) 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 From 64e08af52b2531f800a99ffd629368586ec720ba Mon Sep 17 00:00:00 2001 From: Kulbhushan Kaushik Date: Tue, 25 Oct 2022 09:02:01 -0400 Subject: [PATCH 03/10] commit --- .../list-button-horizontal.spec.js | 264 ++++++++++++ .../list-button-horizontal.vue | 344 +++++++++++++++ src/ux-components/list-button/list-button-vue | 0 .../list-button/list-button.spec.js | 256 +++++++++++ src/ux-components/list-button/list-button.vue | 241 +++++++++++ src/ux-components/list-card/list-card.spec.js | 329 +++++++++++++++ src/ux-components/list-card/list-card.vue | 399 ++++++++++++++++++ 7 files changed, 1833 insertions(+) delete mode 100644 src/ux-components/list-button/list-button-vue create mode 100644 src/ux-components/list-button/list-button.vue diff --git a/src/ux-components/list-button-horizontal/list-button-horizontal.spec.js b/src/ux-components/list-button-horizontal/list-button-horizontal.spec.js index e69de29b..0d51bf57 100644 --- a/src/ux-components/list-button-horizontal/list-button-horizontal.spec.js +++ b/src/ux-components/list-button-horizontal/list-button-horizontal.spec.js @@ -0,0 +1,264 @@ +import { shallowMount } from "@vue/test-utils"; +import listButtonHorizontal from "./list-button-horizontal"; +import { nextTick } from "vue"; + +describe("list-button-horizontal.vue", () => { + it("Should return input type checkbox if isMultiSelect is true", async () => { + // Act + const wrapper = shallowMount(listButtonHorizontal, { + propsData: { + isMultiSelect: true, + }, + }); + + // Assert + const input = wrapper.find("input"); + + expect(input.attributes().type).toEqual("checkbox"); + }); + + it("Should return input type radio if isMultiSelect is false or not specified", async () => { + // Act + const wrapper = shallowMount(listButtonHorizontal, { + propsData: { + isMultiSelect: false, + }, + }); + + // Assert + const input = wrapper.find("input"); + + expect(input.attributes().type).toEqual("radio"); + }); + + it("Should return primary label text (buttonID)", async () => { + // Act + const wrapper = shallowMount(listButtonHorizontal, { + propsData: { + buttonID: "List Card Checkbox", + }, + }); + + // Assert + const label = wrapper.find("label"); + + expect(label.attributes().for).toEqual("List Card Checkbox"); + }); + + it("Should return screen reader text", async () => { + // Act + const wrapper = shallowMount(listButtonHorizontal, { + propsData: { + screenReaderOnlyText: "Screen Reader Only Text", + }, + }); + + // Assert + const paragraph = wrapper.find("span.sr-only"); + + expect(paragraph.text()).toEqual("Screen Reader Only Text"); + }); + + it("Should return text alignment class", async () => { + // Act + const wrapper = shallowMount(listButtonHorizontal, { + propsData: { + textPosition: "text-center", + }, + }); + + // Assert + const paragraph = wrapper.find("span.m-0"); + + expect(paragraph.attributes("class")).toContain("text-center"); + }); + + it("Should return aria-required state", async () => { + // Act + const wrapper = shallowMount(listButtonHorizontal, { + propsData: { + isRequired: true, + }, + }); + + // Assert + const input = wrapper.find("input"); + + expect(input.attributes()["aria-required"]).toEqual("true"); + }); + + it("Should return loader enabled true", async () => { + // Act + const wrapper = shallowMount(listButtonHorizontal, { + global: { + mocks: { + '$route': { query: { issPage: 'page-name' } }, + } + }, + propsData: { + selectingInitiatesLoad: true, + }, + }); + + // Assert + + const label = wrapper.find("label"); + + wrapper.vm.handleCheckChange = jest.fn(); + wrapper.vm.triggerButton(); + + await nextTick(); + + const loader = wrapper.find("loader-stub"); + + expect(loader.exists()).toBe(true); + }); + + it("Should return loader color", async () => { + // Act + const wrapper = shallowMount(listButtonHorizontal, { + global: { + mocks: { + '$route': { query: { issPage: 'page-name' } }, + } + }, + propsData: { + loaderColor: "blue", + selectingInitiatesLoad: true, + }, + }); + + // Assert + + const label = wrapper.find("label"); + + wrapper.vm.handleCheckChange = jest.fn(); + wrapper.vm.triggerButton(); + + await nextTick(); + + const loader = wrapper.find("loader-stub"); + + expect(loader.attributes("class")).toContain("blue"); + }); + + it("Should return loader position", async () => { + // Act + const wrapper = shallowMount(listButtonHorizontal, { + global: { + mocks: { + '$route': { query: { issPage: 'page-name' } }, + } + }, + propsData: { + loaderPosition: "right", + selectingInitiatesLoad: true, + }, + }); + + // Assert + + const label = wrapper.find("label"); + + wrapper.vm.handleCheckChange = jest.fn(); + wrapper.vm.triggerButton(); + + await nextTick(); + + const loader = wrapper.find("loader-stub"); + + expect(loader.attributes("class")).toContain("right"); + }); + + it("Should emit button value on click", async () => { + // Act + const wrapper = shallowMount(listButtonHorizontal, { + propsData: { + isRadioHorizontal: true, + buttonLabel: "Windshield", + value: "List Card Checkbox", + groupID: "radio-demo-1", + groupName: "radio 1", + buttonImage: "windshield-damage.svg", + isRequired: true, + isWide: false, + modelValue: ["List Card Checkbox"], + }, + }); + wrapper.vm.handleCheckChange(); + // Assert + expect(wrapper.emitted()["isCheckedChanged"][0]).toEqual([{value: "List Card Checkbox", checkValue: Boolean, buttonId: undefined, checkValue: false}]); + }); + + it("Should set checkValue data if selectedButtonIDs has value(s)", async () => { + // Act + const wrapper = shallowMount(listButtonHorizontal, { + propsData: { + isRadioHorizontal: true, + buttonLabel: "Windshield", + buttonID: "List Card Checkbox", + groupID: "radio-demo-1", + groupName: "radio 1", + buttonImage: "windshield-damage.svg", + isRequired: true, + isWide: false, + modelValue: ["List Card Checkbox"], + isMultiSelect: false, + value: "Car-Front", + selectedValues: ["Car-Front"] + }, + }); + // Assert + expect(wrapper.vm.checkValue).toEqual(true); + }); + + it("Should run handleCheckChange if selectingInitiatesLoad is false and handleInputChange is triggered", async () => { + // Act + const wrapper = shallowMount(listButtonHorizontal, { + propsData: { + selectingInitiatesLoad: false, + }, + }); + + // Assert + wrapper.vm.handleInputChange(); + + await nextTick(); + + expect(wrapper.vm.handleCheckChange).toBeCalled; + }); + + it("Should do nothing if isMultiSelect is true and handleKeyupArrow is triggered", async () => { + // Act + const wrapper = shallowMount(listButtonHorizontal, { + propsData: { + isMultiSelect: true, + }, + }); + + // Assert + wrapper.vm.handleKeyupArrow(); + + await nextTick(); + + expect(wrapper.vm.handleKeyupArrow).toHaveReturned; + }); + + it("Should run handleCheckChange if selectingInitiatesLoad is false and handleKeyupArrow is triggered", async () => { + // Act + const wrapper = shallowMount(listButtonHorizontal, { + propsData: { + selectingInitiatesLoad: false, + isMultiSelect: false, + }, + }); + + // Assert + wrapper.vm.handleKeyupArrow(); + + await nextTick(); + + expect(wrapper.vm.handleCheckChange).toBeCalled; + }); + +}); diff --git a/src/ux-components/list-button-horizontal/list-button-horizontal.vue b/src/ux-components/list-button-horizontal/list-button-horizontal.vue index e69de29b..534448b7 100644 --- a/src/ux-components/list-button-horizontal/list-button-horizontal.vue +++ b/src/ux-components/list-button-horizontal/list-button-horizontal.vue @@ -0,0 +1,344 @@ + + + + + + \ No newline at end of file diff --git a/src/ux-components/list-button/list-button-vue b/src/ux-components/list-button/list-button-vue deleted file mode 100644 index e69de29b..00000000 diff --git a/src/ux-components/list-button/list-button.spec.js b/src/ux-components/list-button/list-button.spec.js index e69de29b..e54710ed 100644 --- a/src/ux-components/list-button/list-button.spec.js +++ b/src/ux-components/list-button/list-button.spec.js @@ -0,0 +1,256 @@ +import { shallowMount } from "@vue/test-utils"; +import listButton from "./list-button"; +import { nextTick } from "vue"; + +describe("list-button.vue", () => { + it("Should return input type checkbox if isMultiSelect is true", async () => { + // Act + const wrapper = shallowMount(listButton, { + propsData: { + isMultiSelect: true, + }, + }); + + // Assert + const input = wrapper.find("input"); + + expect(input.attributes().type).toEqual("checkbox"); + }); + + it("Should return input type radio if isMultiSelect is false or not specified", async () => { + // Act + const wrapper = shallowMount(listButton, { + propsData: { + isMultiSelect: false, + }, + }); + + // Assert + const input = wrapper.find("input"); + + expect(input.attributes().type).toEqual("radio"); + }); + + it("Should return primary label text (buttonID)", async () => { + // Act + const wrapper = shallowMount(listButton, { + propsData: { + buttonID: "List Card Checkbox", + }, + }); + + // Assert + const label = wrapper.find("label"); + + expect(label.attributes().for).toEqual("List Card Checkbox"); + }); + + it("Should return screen reader text", async () => { + // Act + const wrapper = shallowMount(listButton, { + propsData: { + screenReaderOnlyText: "Screen Reader Only Text", + }, + }); + + // Assert + const paragraph = wrapper.find("span.sr-only"); + + expect(paragraph.text()).toEqual("Screen Reader Only Text"); + }); + + it("Should return text alignment class", async () => { + // Act + const wrapper = shallowMount(listButton, { + propsData: { + textPosition: "text-center", + }, + }); + + // Assert + const paragraph = wrapper.find("span.m-0"); + + expect(paragraph.attributes("class")).toContain("text-center"); + }); + + it("Should return aria-required state", async () => { + // Act + const wrapper = shallowMount(listButton, { + propsData: { + isRequired: true, + }, + }); + + // Assert + const input = wrapper.find("input"); + + expect(input.attributes()["aria-required"]).toEqual("true"); + }); + + it("Should return loader enabled true", async () => { + // Act + const wrapper = shallowMount(listButton, { + global: { + mocks: { + '$route': { query: { issPage: 'page-name' } }, + } + }, + propsData: { + selectingInitiatesLoad: true, + }, + }); + + // Assert + wrapper.vm.handleCheckChange = jest.fn(); + wrapper.vm.triggerButton(); + + await nextTick(); + + const loader = wrapper.find("loader-stub"); + + expect(loader.exists()).toBe(true); + }); + + it("Should return loader color", async () => { + // Act + const wrapper = shallowMount(listButton, { + global: { + mocks: { + '$route': { query: { issPage: 'page-name' } }, + } + }, + propsData: { + loaderColor: "blue", + selectingInitiatesLoad: true, + }, + }); + + // Assert + wrapper.vm.handleCheckChange = jest.fn(); + wrapper.vm.triggerButton(); + await nextTick(); + + const loader = wrapper.find("loader-stub"); + + expect(loader.attributes("class")).toContain("blue"); + }); + + it("Should return loader position", async () => { + // Act + const wrapper = shallowMount(listButton, { + global: { + mocks: { + '$route': { query: { issPage: 'page-name' } }, + } + }, + propsData: { + loaderPosition: "right", + selectingInitiatesLoad: true, + }, + }); + + // Assert + wrapper.vm.handleCheckChange = jest.fn(); + wrapper.vm.triggerButton(); + + await nextTick(); + + const loader = wrapper.find("loader-stub"); + + expect(loader.attributes("class")).toContain("right"); + }); + + it("Should emit button value on click", async () => { + // Act + const wrapper = shallowMount(listButton, { + propsData: { + isRadioHorizontal: true, + buttonLabel: "Windshield", + value: "List Card Checkbox", + groupID: "radio-demo-1", + groupName: "radio 1", + buttonImage: "windshield-damage.svg", + isRequired: true, + isWide: false, + modelValue: ["List Card Checkbox"], + buttonID: 'list-card-id' + }, + }); + + wrapper.vm.handleCheckChange(); + + // Assert + expect(wrapper.emitted()["isCheckedChanged"][0]).toEqual([{value: "List Card Checkbox", checkValue: false, buttonId: 'list-card-id'}]); + + }); + + it("Should set checkValue data if selectedButtonIDs has value(s)", async () => { + // Act + const wrapper = shallowMount(listButton, { + propsData: { + isRadioHorizontal: true, + buttonLabel: "Windshield", + buttonID: "List Card Checkbox", + groupID: "radio-demo-1", + groupName: "radio 1", + buttonImage: "windshield-damage.svg", + isRequired: true, + isWide: false, + modelValue: ["List Card Checkbox"], + selectedValues: "Car-Front" + }, + }); + // Assert + expect(wrapper.componentVM.checkValue).toEqual(false); + }); + + it("Should run handleCheckChange if selectingInitiatesLoad is false and handleInputChange is triggered", async () => { + // Act + const wrapper = shallowMount(listButton, { + propsData: { + selectingInitiatesLoad: false, + }, + }); + + // Assert + wrapper.vm.handleInputChange(); + + await nextTick(); + + expect(wrapper.vm.handleCheckChange).toBeCalled; + }); + + it("Should do nothing if isMultiSelect is true and handleKeyupArrow is triggered", async () => { + // Act + const wrapper = shallowMount(listButton, { + propsData: { + isMultiSelect: true, + }, + }); + + // Assert + wrapper.vm.handleKeyupArrow(); + + await nextTick(); + + expect(wrapper.vm.handleKeyupArrow).toHaveReturned; + }); + + it("Should run handleCheckChange if selectingInitiatesLoad is false and handleKeyupArrow is triggered", async () => { + // Act + const wrapper = shallowMount(listButton, { + propsData: { + selectingInitiatesLoad: false, + isMultiSelect: false, + }, + }); + + // Assert + wrapper.vm.handleKeyupArrow(); + + await nextTick(); + + expect(wrapper.vm.handleCheckChange).toBeCalled; + }); + +}); diff --git a/src/ux-components/list-button/list-button.vue b/src/ux-components/list-button/list-button.vue new file mode 100644 index 00000000..c789060e --- /dev/null +++ b/src/ux-components/list-button/list-button.vue @@ -0,0 +1,241 @@ + + + + + + \ No newline at end of file diff --git a/src/ux-components/list-card/list-card.spec.js b/src/ux-components/list-card/list-card.spec.js index e69de29b..9c9e1986 100644 --- a/src/ux-components/list-card/list-card.spec.js +++ b/src/ux-components/list-card/list-card.spec.js @@ -0,0 +1,329 @@ +import { shallowMount } from "@vue/test-utils"; +import listCard from "./list-card"; +import { nextTick } from "vue"; + +describe("list-card.vue", () => { + it("Should return input type checkbox if isMultiSelect is true", async () => { + // Act + const wrapper = shallowMount(listCard, { + propsData: { + isMultiSelect: true, + buttonLabel: "Windshield", + buttonID: "List Card Checkbox", + groupID: "checkbox-demo-1", + groupName: "Checkbox 1", + buttonImage: "windshield-damage.svg", + }, + }); + + // Assert + const input = wrapper.find("input"); + expect(input.attributes().type).toEqual("checkbox"); + }); + + it("Should return primary label text", async () => { + // Act + const wrapper = shallowMount(listCard, { + propsData: { + isRadioHorizontal: true, + buttonLabel: "Windshield", + buttonID: "List Card Checkbox", + groupID: "radio-demo-1", + groupName: "radio 1", + buttonImage: "windshield-damage.svg", + }, + }); + + // Assert + const paragraph = wrapper.find("p"); + expect(paragraph.text()).toEqual("Windshield"); + }); + + it("Should return secondary (sub) label text", async () => { + // Act + const wrapper = shallowMount(listCard, { + propsData: { + isRadioHorizontal: true, + buttonLabel: "Windshield", + buttonID: "List Card Checkbox", + groupID: "radio-demo-1", + groupName: "radio 1", + buttonImage: "windshield-damage.svg", + buttonLabelSubCopy: "Test", + }, + }); + + // Assert + const paragraph = wrapper.find("p:nth-of-type(2)"); + expect(paragraph.text()).toEqual("Test"); + }); + + it("Should return value used for various text settings including the label 'for' and input id", async () => { + // Act + const wrapper = shallowMount(listCard, { + propsData: { + isRadioHorizontal: true, + buttonLabel: "Windshield", + buttonID: "List Card Checkbox", + groupID: "radio-demo-1", + groupName: "radio 1", + buttonImage: "windshield-damage.svg", + buttonLabelSubCopy: "Test", + }, + }); + + // Assert + const label = wrapper.find("label"); + expect(label.attributes().for).toEqual("List Card Checkbox"); + }); + + it("Should return input group name used for radio or checkbox", async () => { + // Act + const wrapper = shallowMount(listCard, { + propsData: { + isRadioHorizontal: true, + buttonLabel: "Windshield", + buttonID: "List Card Checkbox", + groupID: "radio-demo-1", + groupName: "radio 1", + buttonImage: "windshield-damage.svg", + buttonLabelSubCopy: "Test", + }, + }); + + // Assert + const input = wrapper.find("input"); + expect(input.attributes().name).toEqual("radio 1"); + }); + + it("Should return aria-required state", async () => { + // Act + const wrapper = shallowMount(listCard, { + propsData: { + isRadioHorizontal: true, + buttonLabel: "Windshield", + buttonID: "List Card Checkbox", + groupID: "radio-demo-1", + groupName: "radio 1", + buttonImage: "windshield-damage.svg", + isRequired: true, + }, + }); + + // Assert + const input = wrapper.find("input"); + expect(input.attributes()["aria-required"]).toEqual("true"); + }); + + it("Should return flex row classes if isWide is true", async () => { + // Act + const wrapper = shallowMount(listCard, { + propsData: { + isRadioHorizontal: true, + buttonLabel: "Windshield", + buttonID: "List Card Checkbox", + groupID: "radio-demo-1", + groupName: "radio 1", + buttonImage: "windshield-damage.svg", + isRequired: true, + isWide: true, + buttonLabelSubCopy: "", + }, + }); + + // Assert + const label = wrapper.find("label"); + expect(label.classes()).toEqual(["d-flex", "w-100", "align-items-center", "px-2", "h-100", "flex-row", "py-2", "ps-4", "pe-4"]); + }); + + it("Should return flex row classes if isWide is true and checkboxTop if buttonLabelSubCopy is true", async () => { + // Act + const wrapper = shallowMount(listCard, { + propsData: { + isRadioHorizontal: true, + buttonLabel: "Windshield", + buttonID: "List Card Checkbox", + groupID: "radio-demo-1", + groupName: "radio 1", + buttonImage: "windshield-damage.svg", + isRequired: true, + isWide: true, + buttonLabelSubCopy: "Button Subcopy", + }, + }); + + // Assert + const label = wrapper.find("label"); + expect(label.classes()).toEqual(["d-flex", "w-100", "align-items-center", "px-2", "h-100", "flex-row", "py-2", "ps-4", "pe-4", "checkboxTop"]); + }); + + it("Should return flex column classes if isWide is false", async () => { + // Act + const wrapper = shallowMount(listCard, { + propsData: { + isRadioHorizontal: true, + buttonLabel: "Windshield", + buttonID: "List Card Checkbox", + groupID: "radio-demo-1", + groupName: "radio 1", + buttonImage: "windshield-damage.svg", + isRequired: true, + isWide: false, + }, + }); + + // Assert + const label = wrapper.find("label"); + expect(label.classes()).toEqual(["d-flex", "w-100", "align-items-center", "px-2", "h-100", "flex-column", "pt-4", "pb-3"]); + }); + + it("Should emit button value on click", async () => { + // Act + const wrapper = shallowMount(listCard, { + propsData: { + isRadioHorizontal: true, + buttonLabel: "Windshield", + value: "List Card Checkbox", + groupID: "radio-demo-1", + groupName: "radio 1", + buttonImage: "windshield-damage.svg", + isRequired: true, + isWide: false, + buttonID: 'list-card-id', + selectedValues: "List Card Checkbox" + }, + }); + wrapper.vm.handleCheckChange(); + // Assert + expect(wrapper.emitted()["isCheckedChanged"][0]).toEqual([{value: "List Card Checkbox", checkValue: true, buttonId: 'list-card-id'}]); + }); + + it("Should set checkValue data if selectedButtonIDs has value(s)", async () => { + // Act + const wrapper = shallowMount(listCard, { + propsData: { + isRadioHorizontal: true, + buttonLabel: "Windshield", + value: "List Card Checkbox", + groupID: "radio-demo-1", + groupName: "radio 1", + buttonImage: "windshield-damage.svg", + isRequired: true, + isWide: false, + selectedValues: "Car-Front" + }, + }); + // Assert + expect(wrapper.componentVM.checkValue).toEqual(false); + }); + + it("Should set an initial value for validation if selectedValues include the value", async () => { + // Arrange + const wrapper = shallowMount(listCard, { + propsData: { + value: "Windshield", + groupName: "radio 1", + selectedValues: ["Windshield"], + }, + }); + + // Assert + expect(wrapper.vm.fieldOptions.initialValue).toEqual([ 'Windshield' ]); + }); + + it("Should run handleCheckChange if selectingInitiatesLoad is false and handleInputChange is triggered", async () => { + // Act + const wrapper = shallowMount(listCard, { + propsData: { + selectingInitiatesLoad: false, + }, + }); + + // Assert + wrapper.vm.handleInputChange(); + + await nextTick(); + + expect(wrapper.vm.handleCheckChange).toBeCalled; + }); + + it("Should do nothing if isMultiSelect is true and handleKeyupArrow is triggered", async () => { + // Act + const wrapper = shallowMount(listCard, { + propsData: { + isMultiSelect: true, + }, + }); + + // Assert + wrapper.vm.handleKeyupArrow(); + + await nextTick(); + + expect(wrapper.vm.handleKeyupArrow).toHaveReturned; + }); + + it("Should run handleCheckChange if selectingInitiatesLoad is false and handleKeyupArrow is triggered", async () => { + // Act + const wrapper = shallowMount(listCard, { + propsData: { + selectingInitiatesLoad: false, + isMultiSelect: false, + }, + }); + + // Assert + wrapper.vm.handleKeyupArrow(); + + await nextTick(); + + expect(wrapper.vm.handleCheckChange).toBeCalled; + }); + + it("Should run handleChange if triggerButton is triggered", async () => { + + // Act + const wrapper = shallowMount(listCard, { + global: { + mocks: { + '$route': { query: { issPage: 'page-name' } }, + } + }, + propsData: { + selectingInitiatesLoad: false, + }, + }); + + // Assert + wrapper.vm.triggerButton(); + + await nextTick(); + + expect(wrapper.vm.handleChange).toBeCalled; + expect(wrapper.vm.handleCheckChange).not.toBeCalled; + expect(wrapper.vm.displayLoader).not.toBeCalled; + }); + + it("Should run handleCheckChange and displayLoader if triggerButton is triggered and seletingInitiatesLoad is true", async () => { + // Act + const wrapper = shallowMount(listCard, { + global: { + mocks: { + '$route': { query: { issPage: 'page-name' } }, + } + }, + propsData: { + selectingInitiatesLoad: true, + }, + }); + + // Assert + wrapper.vm.triggerButton(); + + await nextTick(); + + expect(wrapper.vm.handleCheckChange).toBeCalled; + expect(wrapper.vm.displayLoader).toBeCalled; + }); + +}); diff --git a/src/ux-components/list-card/list-card.vue b/src/ux-components/list-card/list-card.vue index e69de29b..eb2897b2 100644 --- a/src/ux-components/list-card/list-card.vue +++ b/src/ux-components/list-card/list-card.vue @@ -0,0 +1,399 @@ + + + + + + \ No newline at end of file From 2876a8cc645e6a7fdc4e086ff6aa3428ecf65da8 Mon Sep 17 00:00:00 2001 From: Kulbhushan Kaushik Date: Tue, 25 Oct 2022 09:07:40 -0400 Subject: [PATCH 04/10] commit --- src/ux-components/loader/loader.vue | 90 +++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 src/ux-components/loader/loader.vue diff --git a/src/ux-components/loader/loader.vue b/src/ux-components/loader/loader.vue new file mode 100644 index 00000000..66dfe762 --- /dev/null +++ b/src/ux-components/loader/loader.vue @@ -0,0 +1,90 @@ + + + + + + \ No newline at end of file From 7ed248734e18ccffed7d2769aad86e8e21404dc7 Mon Sep 17 00:00:00 2001 From: Kulbhushan Kaushik Date: Tue, 25 Oct 2022 09:11:43 -0400 Subject: [PATCH 05/10] commit --- src/layouts/vehicle-year/vehicle-year.spec.js | 0 src/layouts/vehicle-year/year-question/year-question.spec.js | 0 src/layouts/vehicle-year/year-question/year-question.vue | 0 3 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 src/layouts/vehicle-year/vehicle-year.spec.js create mode 100644 src/layouts/vehicle-year/year-question/year-question.spec.js create mode 100644 src/layouts/vehicle-year/year-question/year-question.vue diff --git a/src/layouts/vehicle-year/vehicle-year.spec.js b/src/layouts/vehicle-year/vehicle-year.spec.js new file mode 100644 index 00000000..e69de29b diff --git a/src/layouts/vehicle-year/year-question/year-question.spec.js b/src/layouts/vehicle-year/year-question/year-question.spec.js new file mode 100644 index 00000000..e69de29b diff --git a/src/layouts/vehicle-year/year-question/year-question.vue b/src/layouts/vehicle-year/year-question/year-question.vue new file mode 100644 index 00000000..e69de29b From 2ad0c1e8a8bb5f173f435d0e4f3a913c462ca47f Mon Sep 17 00:00:00 2001 From: Kulbhushan Kaushik Date: Tue, 25 Oct 2022 09:22:29 -0400 Subject: [PATCH 06/10] commit --- src/constants/endpoints.js | 4 ++ .../year-question/year-question.vue | 60 +++++++++++++++++++ src/store/index.js | 9 +++ 3 files changed, 73 insertions(+) diff --git a/src/constants/endpoints.js b/src/constants/endpoints.js index 19833112..2aeaf26a 100644 --- a/src/constants/endpoints.js +++ b/src/constants/endpoints.js @@ -11,6 +11,10 @@ const endpoints = { url: (applicationAbbreviation, pageName) => `/content/api/v1/content/${applicationAbbreviation}/${pageName}`, method: "GET", }, + GetVehicleYears: { + url: "/vehicle/api/v1/vehicle/years", + method: "GET", + }, }; export { endpoints }; diff --git a/src/layouts/vehicle-year/year-question/year-question.vue b/src/layouts/vehicle-year/year-question/year-question.vue index e69de29b..7b7ef327 100644 --- a/src/layouts/vehicle-year/year-question/year-question.vue +++ b/src/layouts/vehicle-year/year-question/year-question.vue @@ -0,0 +1,60 @@ + + + + \ No newline at end of file diff --git a/src/store/index.js b/src/store/index.js index 56668172..25e1c8b1 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -74,6 +74,15 @@ export const useMainStore = defineStore({ }); }, + // Vehicle API Actions + getVehicleYears() { + return globalMethods.callHttpClient({ + method: endpoints.GetVehicleYears.method, + endpoint: endpoints.GetVehicleYears.url, + payload: {}, + }); + }, + // Vehicle API Actions updateVehicleYear(year) { From 9b682610a454a8e705c141131e1be74b13b1fbdb Mon Sep 17 00:00:00 2001 From: Kulbhushan Kaushik Date: Tue, 25 Oct 2022 10:29:02 -0400 Subject: [PATCH 07/10] commit --- src/layouts/vehicle-year/year-question/year-question.vue | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/layouts/vehicle-year/year-question/year-question.vue b/src/layouts/vehicle-year/year-question/year-question.vue index 7b7ef327..c7f1539a 100644 --- a/src/layouts/vehicle-year/year-question/year-question.vue +++ b/src/layouts/vehicle-year/year-question/year-question.vue @@ -14,9 +14,7 @@ \ No newline at end of file + ]; + + let resultMap = await settleAllPromises(promiseResultMap); + + // Call the "next" function to complete the transition to this page. + next((vm) => { + vm.setCmsContent(resultMap.cmsContent); + vm.$refs.yearQuestion.initializeComponent( + resultMap.yearQuestionInitialData + ); + }); + }, + + components: { + yearQuestion, + siteHeader, + siteSubHeader, + }, + }; + + \ No newline at end of file diff --git a/src/layouts/vehicle-year/year-question/year-question.vue b/src/layouts/vehicle-year/year-question/year-question.vue index c7f1539a..0cd35425 100644 --- a/src/layouts/vehicle-year/year-question/year-question.vue +++ b/src/layouts/vehicle-year/year-question/year-question.vue @@ -14,6 +14,7 @@