diff --git a/src/common-components/button-question/button-question.spec.js b/src/common-components/button-question/button-question.spec.js index 609981717..7296c66d2 100644 --- a/src/common-components/button-question/button-question.spec.js +++ b/src/common-components/button-question/button-question.spec.js @@ -21,3 +21,80 @@ describe("buttonQuestion.vue", () => { expect(wrapper.props().modelValue).toBe("2020"); }); }); + +describe("buttonQuestion.vue", () => { + it("Should show overflow classes on fieldset if isOverflowScrollable is true", async () => { + // Act + const wrapper = shallowMount(buttonQuestion); + await wrapper.setProps({ + isOverflowScrollable: true, + }); + // Assert + const fieldSet = wrapper.find('fieldset'); + expect(fieldSet.classes()).toContain("overflow-scroll"); + }); +}); + +describe("buttonQuestion.vue", () => { + it("Should show appropriate classes for button type", async () => { + // Act + const wrapper = shallowMount(buttonQuestion); + await wrapper.setProps({ + buttonType: "listCard", + }); + // Assert + const Div = wrapper.find('fieldset div'); + expect(Div.classes()).toContain("row"); + }); +}); + +describe("buttonQuestion.vue", () => { + it("Should trigger event modelValue change on select", async () => { + // Act + const wrapper = shallowMount(buttonQuestion); + await wrapper.setData({ + modelValueAnswers: ["Windshield"], + chosenAnswer: "Windshield" + }); + 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 one string value on select if checked is true and only one option is selected", async () => { + // Act + const wrapper = shallowMount(buttonQuestion); + await wrapper.setData({ + chosenAnswer: "Windshield" + }); + wrapper.vm.isItemChecked(true); + // Assert + expect(wrapper.emitted()["update:modelValue"][0]).toEqual(["Windshield"]); + }); +}); + +describe("buttonQuestion.vue", () => { + it("Should trigger event modelValue change with an array of string values on select if checked is true and multiple optiopns are chosen", async () => { + // Act + const wrapper = shallowMount(buttonQuestion); + await wrapper.setData({ + modelValueAnswers: ["Windshield", "BackDoor"] + }); + wrapper.vm.isItemChecked(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.vm.isItemChecked(false); + // Assert + expect(wrapper.emitted()["update:modelValue"][0]).toEqual([undefined]); + }); +}); \ No newline at end of file diff --git a/src/common-components/button-question/button-question.vue b/src/common-components/button-question/button-question.vue index 5edf5ab68..0e4212f50 100644 --- a/src/common-components/button-question/button-question.vue +++ b/src/common-components/button-question/button-question.vue @@ -12,6 +12,7 @@  { return {}; }, {virtual: true}); + +describe("replace-options-question.vue", () => { + test("Selected damage option is emitted upon selection.", async () => { + + //Arrange + const { wrapper } = setupMocks({ modelValueProp: ["Windshield"] }); + const damageToSelect = ["Backseat"]; + + //Act + wrapper.setValue({ modelValue: damageToSelect }); + await wrapper.vm.$nextTick(); + + //Assert + expect(wrapper.emitted()["update:modelValue"][0]).toEqual([{modelValue: ["Backseat"]}]); + }); + }); + + describe("replace-options-question.vue", () => { + test("Answers to display filtered by data from api.", async () => { + + //Arrange + const { wrapper, cmsContent, replaceOptions } = setupMocks({ dataFromStoreApi: ["Windshield", "FrontDoor"]}); + + //Act + replaceOptionsQuestion.methods.initializeComponent.call(wrapper.vm, cmsContent, replaceOptions, "car-group"); + + //Assert + expect(wrapper.vm.answersToDisplay).toStrictEqual([ { Name: 'car-Windshield' }, { Name: 'car-FrontDoor' } ]) + }); + }); + + function setupMocks({ + modelValueProp = ["Windshield"], + isAvailale = true, + isMultiSelect = false, + filterByVehicleCategory = false, + groupName = "damageQuestion", + cmsQuestionText = "CMS text goes here", + cmsAnswers = [{Name: "car-Windshield"}, {Name: "car-BackDoor"}, {Name: "car-FrontDoor"}], + dataFromStoreApi = [], + }) { + + //Mock store + store.dispatch = jest.fn(() => dataFromStoreApi); + store.getters = { vehicle: {year: 2019, make: 'honda', model: 'civc', style: '2 Door', category: 'CAR'} }; + const mountOptions = getMountOptions({ + store: { + dispatch: store.dispatch, + getters: store.getters, + }, + }); + + //Mock props + mountOptions.propsData = { + modelValue: modelValueProp, + isAvailable: isAvailale, + isMultiSelect: isMultiSelect, + filterByVehicleCategory: filterByVehicleCategory + }; + + const wrapper = shallowMount(replaceOptionsQuestion, mountOptions); + + //Mock CMS content + const cmsContent = { + groupName: groupName, + QuestionText: cmsQuestionText, + Answers: cmsAnswers, + }; + const replaceOptions = dataFromStoreApi; + return { wrapper, cmsContent, replaceOptions }; + } \ No newline at end of file diff --git a/src/layouts/vehicle-damage/replace-options-question/replace-options-question.vue b/src/layouts/vehicle-damage/replace-options-question/replace-options-question.vue index 9ecd426f4..f01f0cd90 100644 --- a/src/layouts/vehicle-damage/replace-options-question/replace-options-question.vue +++ b/src/layouts/vehicle-damage/replace-options-question/replace-options-question.vue @@ -1,15 +1,17 @@ + + diff --git a/src/router/router-constants/navigation-scenarios.js b/src/router/router-constants/navigation-scenarios.js index 9f6fa4e92..48e36996b 100644 --- a/src/router/router-constants/navigation-scenarios.js +++ b/src/router/router-constants/navigation-scenarios.js @@ -3,7 +3,6 @@ const navigationScenarios = { SELECTED_MODEL: "SELECTED_MODEL", SELECTED_MAKE: "SELECTED_MAKE", SELECTED_STYLE: "SELECTED_STYLE", - VEHICLE_DAMAGE: "VEHICLE_DAMAGE", CLICKED_BACK: "CLICKED_BACK", }; 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 d03a042d7..4150b3d46 100644 --- a/src/ux-components/list-button-horizontal/list-button-horizontal.vue +++ b/src/ux-components/list-button-horizontal/list-button-horizontal.vue @@ -1,6 +1,6 @@