From 0a4ffee4478fd0b683261abeb6a252e3f6e2be3d Mon Sep 17 00:00:00 2001 From: Scott Kiener Date: Thu, 29 Sep 2022 07:36:30 -0400 Subject: [PATCH 1/2] CSR-726 | Cash or Insurance Toggle Unit Tests Default selection logic Fix for list-button-horizontal --- .../cash-or-insurance-question.spec.js | 57 +++++++++++++++++++ .../cash-or-insurance-question.vue | 8 ++- src/layouts/quote/quote.vue | 30 +++++++++- .../list-button-horizontal.vue | 2 +- 4 files changed, 93 insertions(+), 4 deletions(-) create mode 100644 src/layouts/quote/cash-or-insurance-question/cash-or-insurance-question.spec.js diff --git a/src/layouts/quote/cash-or-insurance-question/cash-or-insurance-question.spec.js b/src/layouts/quote/cash-or-insurance-question/cash-or-insurance-question.spec.js new file mode 100644 index 000000000..7dbe32604 --- /dev/null +++ b/src/layouts/quote/cash-or-insurance-question/cash-or-insurance-question.spec.js @@ -0,0 +1,57 @@ +import { shallowMount } from "@vue/test-utils"; +import CashOrInsuranceQuestion from "./cash-or-insurance-question"; + + +describe("cash-or-insurance-question.vue", () => { + it("Should emit a false boolean value when selectedValues is 'CashAnswer' (update:modelValue)", async () => { + + //Arrange + const wrapper = shallowMount(CashOrInsuranceQuestion, { + propsData: mockProps, + mixins: [mockMixin] + }); + + //Act + wrapper.vm.selectedValues = "CashAnswer"; + await wrapper.vm.$nextTick(); + + //Assert + expect(wrapper.emitted()["update:modelValue"][0]).toEqual([false]); + expect(typeof wrapper.emitted()["update:modelValue"][0][0]).toBe("boolean"); + }); + it("Should return 'CashAnswer' from selectedValues when modelValue is set to false", async () => { + + //Arrange + const wrapper = shallowMount(CashOrInsuranceQuestion, { + propsData: mockProps, + mixins: [mockMixin] + }); + + //Act + wrapper.setProps({modelValue : false}); + await wrapper.vm.$nextTick(); + + //Assert + expect(wrapper.vm.selectedValues).toBe("CashAnswer"); + }); +}); + + /////////////// + // Constants // + /////////////// + +const mockMixin = { + methods: { + getCmsContent: jest.fn((widgetName, cmsFieldName) => { + return mockCmsContent[cmsFieldName]; + }) + } +} + +const mockProps = { + modelValue: true, +} + +const mockCmsContent = { + 'Text': "Sample text here.", +} diff --git a/src/layouts/quote/cash-or-insurance-question/cash-or-insurance-question.vue b/src/layouts/quote/cash-or-insurance-question/cash-or-insurance-question.vue index b2431406d..f745e8443 100644 --- a/src/layouts/quote/cash-or-insurance-question/cash-or-insurance-question.vue +++ b/src/layouts/quote/cash-or-insurance-question/cash-or-insurance-question.vue @@ -14,6 +14,9 @@