diff --git a/src/common-components/button-question/button-question.spec.js b/src/common-components/button-question/button-question.spec.js index 67e2f010e..d5608cd62 100644 --- a/src/common-components/button-question/button-question.spec.js +++ b/src/common-components/button-question/button-question.spec.js @@ -1,5 +1,6 @@ import { shallowMount } from "@vue/test-utils"; import buttonQuestion from "@/common-components/button-question/button-question"; +import { nextTick } from "vue"; describe("buttonQuestion.vue", () => { it("Should show overflow classes on fieldset if isOverflowScrollable is true", async () => { @@ -41,44 +42,32 @@ describe("buttonQuestion.vue", () => { }); describe("buttonQuestion.vue", () => { - it("Should trigger event modelValue change on select", async () => { + it("Should trigger event modelValue change to new value on when radio button selected", async () => { // Act const wrapper = shallowMount(buttonQuestion); - await wrapper.setData({ - modelValueAnswers: ["Windshield"], - chosenAnswer: "Windshield" + await wrapper.setProps({ + answers: ["2022", "2021", "2020"], + isMultiSelect: false }); - wrapper.setValue({ answer: wrapper.vm.chosenAnswer }); - await wrapper.vm.$nextTick(); - // Assert - expect(wrapper.emitted()["update:modelValue"][0]).toEqual([{answer: "Windshield"}]); - }); -}); - -describe("buttonQuestion.vue", () => { - it("Should trigger event modelValue change with an array of string values on select if checked is true and multiple options are chosen", async () => { - // Act - const wrapper = shallowMount(buttonQuestion); - await wrapper.setData({ - modelValueAnswers: ["Windshield", "BackDoor"] - }); - wrapper.vm.handleCheckedChanged(true); - // Assert - expect(typeof wrapper.emitted()["update:modelValue"][0]).toEqual('object'); - }); -}); - -describe("buttonQuestion.vue", () => { - it("Should not trigger event modelValue change on select if checked is false", async () => { - // Act - const wrapper = shallowMount(buttonQuestion); - wrapper.setData({ - modelValueAnswers: ["Front-door"] - }) - const val = {isChecked : false, buttonId: "Front-door"} + const val = {isChecked: true, buttonId: "2021", } wrapper.vm.handleCheckedChanged(val); // Assert - expect(wrapper.emitted()["update:modelValue"][0]).toEqual([undefined]); + expect(wrapper.emitted()["update:modelValue"][0]).toEqual([["2021"]]); + }); +}); + +describe("buttonQuestion.vue", () => { + it("Should add values to array on checkbox click", async () => { + // Act + const wrapper = shallowMount(buttonQuestion); + await wrapper.setProps({ + modelValue: ["2022", "2021", "2020"], + isMultiSelect: true + }); + const val = {isChecked: true, buttonId: "2019", } + wrapper.vm.handleCheckedChanged(val); + // Assert + expect(wrapper.emitted()["update:modelValue"][0]).toEqual([["2022", "2021", "2020", "2019"]]); }); }); diff --git a/src/common-components/button-question/button-question.vue b/src/common-components/button-question/button-question.vue index 49955db5f..bc707ebac 100644 --- a/src/common-components/button-question/button-question.vue +++ b/src/common-components/button-question/button-question.vue @@ -31,7 +31,7 @@ :altText="answer.Name ? answer.Name : answer" screenReaderOnlyText="(opens new window)" :colLength="this.answers.length < 3 ? '' : '-4'" - v-model="selectedValues" + :selectedButtonIDs="selectedValues" data-test="button" :validationRules="validationRules" /> @@ -116,15 +116,11 @@ export default { } }, }, - data(){ - return { - modelValueAnswers: [], - } - }, mounted(){ if(Array.isArray(this.answers) && this.answers.length === 1) { - this.modelValueAnswers.push(typeof(this.answers[0]) === 'object' ? this.answers[0].Name : this.answers[0]); - this.$emit("update:modelValue", this.modelValueAnswers); + const newSelectedValues = this.selectedValues; + newSelectedValues.push(typeof(this.answers[0]) === 'object' ? this.answers[0].Name : this.answers[0]); + this.selectedValues = newSelectedValues; } }, methods: { @@ -133,13 +129,14 @@ export default { this.$emit("update:modelValue", answer); }, handleCheckedChanged(val) { - - console.log('meta is now ', this.meta) - - // Add or remove item to array of data to emit - val.isChecked ? this.modelValueAnswers.push(val.buttonId) : this.modelValueAnswers.splice(this.modelValueAnswers.indexOf(val.buttonId), 1); - const answersToEmit = this.modelValueAnswers.length ? this.modelValueAnswers : undefined; - this.$emit("update:modelValue", answersToEmit); + if(this.isMultiSelect) { + // Add or remove item to array of data to emit + const newSelectedValues = this.selectedValues; + val.isChecked ? newSelectedValues.push(val.buttonId) : newSelectedValues.splice(newSelectedValues.indexOf(val.buttonId), 1); + this.selectedValues = newSelectedValues; + } else { + this.selectedValues = [val.buttonId] + } }, }, components: { diff --git a/src/common-components/funnel-footer/funnel-footer.spec.js b/src/common-components/funnel-footer/funnel-footer.spec.js index f1a885dfd..791cd0961 100644 --- a/src/common-components/funnel-footer/funnel-footer.spec.js +++ b/src/common-components/funnel-footer/funnel-footer.spec.js @@ -5,9 +5,17 @@ describe("funnel-footer.vue", () => { it("Should return footer-link class", async () => { // Act - try { + + const r = { + test:"testing", + clientHeight: 10, + classList: { + add: jest.fn(() => ''), + remove: jest.fn() + }, + }; global.document.getElementById = jest.fn().mockImplementation(()=> { - return {} + return r; }); const wrapper = mount(funnelFooter, { @@ -22,9 +30,8 @@ describe("funnel-footer.vue", () => { // Expect expect(link.attributes('class')).toContain("footer-link"); expect(global.document.getElementById).toBeCalled(); - } catch(error) { - console.log(error); - } + expect(r.classList.add).toBeCalledWith("justify-content-end"); + expect(r.classList.remove).toBeCalledWith("justify-content-start"); }); @@ -57,4 +64,32 @@ describe("funnel-footer.vue", () => { expect(input.attributes("class")).toContain("btn-primary"); }); + it("Should return class justify-content-end if paddingHeight < 80px", async () => { + + global.document.getElementById = jest.fn().mockImplementation(()=> { + return { + test:"testing", + clientHeight: 10, + classList: { + add: jest.fn(), + remove: jest.fn() + } + } + }); + + // Act + const wrapper = mount(funnelFooter, { + propsData: { + footer: true + }, + }); + const infoBox = document.getElementById('infoBox'); + // Assert + const stacked = wrapper.find("#stacked"); + wrapper.vm.paddingHeight = 100; + + // Expect + expect(stacked.attributes('class')).toContain("justify-content-end"); + }); + }); diff --git a/src/common-components/funnel-footer/funnel-footer.vue b/src/common-components/funnel-footer/funnel-footer.vue index 08ff0b799..c93501177 100644 --- a/src/common-components/funnel-footer/funnel-footer.vue +++ b/src/common-components/funnel-footer/funnel-footer.vue @@ -26,17 +26,18 @@