From 64e08af52b2531f800a99ffd629368586ec720ba Mon Sep 17 00:00:00 2001 From: Kulbhushan Kaushik Date: Tue, 25 Oct 2022 09:02:01 -0400 Subject: [PATCH] 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