From afa94625f70b2a0170361e59191a73051180dd8a Mon Sep 17 00:00:00 2001 From: Katie Date: Tue, 11 Oct 2022 16:52:07 -0400 Subject: [PATCH] CSR-762 Fix tests --- .../base-input-button.spec.js | 78 ++++++++++--------- .../base-input-button/base-input-button.vue | 2 +- .../replace-options-question.spec.js | 2 +- .../vehicle-parts/vehicle-parts.spec.js | 13 +++- src/ux-components/list-card/list-card.spec.js | 8 ++ src/ux-components/radio/radio.spec.js | 36 +++++---- 6 files changed, 86 insertions(+), 53 deletions(-) diff --git a/src/common-components/base-input-button/base-input-button.spec.js b/src/common-components/base-input-button/base-input-button.spec.js index 37e6ccc19..190448df9 100644 --- a/src/common-components/base-input-button/base-input-button.spec.js +++ b/src/common-components/base-input-button/base-input-button.spec.js @@ -215,33 +215,28 @@ describe("baseInputButton.vue", () => { ); }); - test( - "focus and click enter on a radio button => inputButtonClicked is emitted with correct value", - async () => { - // Arrange - const { wrapper } = setupMocks({ - mockData: { - propsData: { - isMultiSelect: false, - value: "Hi", - }, + test("focus and click enter on a radio button => inputButtonClicked is emitted with correct value", async () => { + // Arrange + const { wrapper } = setupMocks({ + mockData: { + propsData: { + isMultiSelect: false, + value: "Hi", }, - }); + }, + }); - const input = wrapper.find("input"); + const input = wrapper.find("input"); - // Act - await input.trigger("keypress", { key: "enter" }); + // Act + await input.trigger("keypress", { key: "enter" }); - // Assert - expect(wrapper.emitted()).toHaveProperty( - "inputButtonClicked" - ); - expect( - wrapper.emitted()["inputButtonClicked"][0][0] - ).toEqual("Hi"); - } - ); + // Assert + expect(wrapper.emitted()).toHaveProperty("inputButtonClicked"); + expect(wrapper.emitted()["inputButtonClicked"][0][0]).toEqual( + "Hi" + ); + }); }); }); @@ -249,27 +244,33 @@ describe("baseInputButton.vue", () => { describe("handleEventAction", () => {}); describe("handleSelectionChange", () => { - test.todo("handleChange is called with valueToEmit") + test.todo("handleChange is called with valueToEmit"); describe("checkbox", () => { - test.todo("modelValue is null => valueToEmit is correct value") + test.todo("modelValue is null => valueToEmit is correct value"); - test.todo("modelValue is undefined => valueToEmit is correct value") - test.todo("modelValue is empty => valueToEmit is correct value") + test.todo( + "modelValue is undefined => valueToEmit is correct value" + ); + test.todo( + "modelValue is empty => valueToEmit is correct value" + ); - test.todo("modelValue is not empty and does not contain this button's value => valueToEmit is correct value") - test.todo("modelValue is not empty and does contain this button's value => valueToEmit is correct value") - }) + test.todo( + "modelValue is not empty and does not contain this button's value => valueToEmit is correct value" + ); + test.todo( + "modelValue is not empty and does contain this button's value => valueToEmit is correct value" + ); + }); - describe("radio", () => { - - }) + describe("radio", () => {}); }); describe("handleClick", () => { - test.todo("handleSelectChange is also called") + test.todo("handleSelectChange is also called"); - test.todo("inputButtonClicked is emitted with valueToEmit") + test.todo("inputButtonClicked is emitted with valueToEmit"); }); }); @@ -490,6 +491,7 @@ function setupMocks({ mockData = {}, shouldShallowMount = true }) { groupName: "groupName", modelValue: mockData.propsData?.isMultiSelect ? [] : "", value: "5", + setLastValuePushedToGa: () => {}, // should override the above if they exist ...mockData.propsData, }, @@ -499,6 +501,12 @@ function setupMocks({ mockData = {}, shouldShallowMount = true }) { ? shallowMount(baseInputButton, mountMockData) : mount(baseInputButton, mountMockData); + wrapper.vm.pushEventToGA = jest.fn(); + wrapper.vm.$route = { + query: {}, + }; + wrapper.vm.GaActions = {} + return { wrapper }; } diff --git a/src/common-components/base-input-button/base-input-button.vue b/src/common-components/base-input-button/base-input-button.vue index c17d6c6d3..8cd50278e 100644 --- a/src/common-components/base-input-button/base-input-button.vue +++ b/src/common-components/base-input-button/base-input-button.vue @@ -185,7 +185,7 @@ export default { }, buttonId() { return `${this.groupName?.replace(" ", "-")}-${this.value - .toString() + ?.toString() ?.replace(" ", "-")}`; }, isValueSelectedOnClick() { diff --git a/src/layouts/vehicle-damage/replace-options-question/replace-options-question.spec.js b/src/layouts/vehicle-damage/replace-options-question/replace-options-question.spec.js index 411bf4e90..aa6ecb06d 100644 --- a/src/layouts/vehicle-damage/replace-options-question/replace-options-question.spec.js +++ b/src/layouts/vehicle-damage/replace-options-question/replace-options-question.spec.js @@ -56,7 +56,7 @@ describe("replace-options-question.vue", () => { //Act wrapper.vm.$options.methods.updateSelectedValues.call(wrapper.vm); - expect(wrapper.vm.selectedReplaceOptions).toEqual([]); + expect(wrapper.vm.selectedValues).toEqual([]); }); }); diff --git a/src/layouts/vehicle-parts/vehicle-parts.spec.js b/src/layouts/vehicle-parts/vehicle-parts.spec.js index d1eaa8df6..62d54c71f 100644 --- a/src/layouts/vehicle-parts/vehicle-parts.spec.js +++ b/src/layouts/vehicle-parts/vehicle-parts.spec.js @@ -183,7 +183,16 @@ describe("vehicle-parts.vue", () => { await nextTick(); //Assert - expect(wrapper.vm.glassParts).toEqual({ "Rear-Stationary": { "Rear": ['DB12209YPYNOEM'] } }); + expect(wrapper.vm.glassParts).toEqual({ + "Rear-Stationary": { + partNumber: "DB12209YPYNOEM", + description: "heated glass, solar, 1 hole", + color: "Gray Tint Privacy", + requiresRecalibration: false, + requiresCapabilityQuestions: false, + childParts: null + } + }); }); test("User had part questions > BackButtonAction triggers a router.navigateWithoutSaving change with correct scenario", async () => { @@ -509,6 +518,8 @@ function setupMocks({ pageHeaderWidgetHeaderText = {}, mountOptionsMockData = {} wrapper.vm.setCmsContent = baseMixin.methods.setCmsContent; wrapper.vm.$refs.funnelFooter.removeLoader = jest.fn(); wrapper.vm.$refs.loadingModal.showModal = jest.fn(); + // wrapper.vm.$refs.onSubmit = jest.fn(); + // wrapper.vm.$refs.onInvalidSubmit = jest.fn(); return { wrapper, apiPromise }; } diff --git a/src/ux-components/list-card/list-card.spec.js b/src/ux-components/list-card/list-card.spec.js index 19c5d01c2..41d3555e2 100644 --- a/src/ux-components/list-card/list-card.spec.js +++ b/src/ux-components/list-card/list-card.spec.js @@ -14,6 +14,7 @@ describe("list-card.vue", () => { groupID: "checkbox-demo-1", groupName: "Checkbox 1", buttonImage: "windshield-damage.svg", + value: "test value", }, }); @@ -32,6 +33,7 @@ describe("list-card.vue", () => { groupID: "radio-demo-1", groupName: "radio 1", buttonImage: "windshield-damage.svg", + value: "test value", }, }); @@ -51,6 +53,7 @@ describe("list-card.vue", () => { groupName: "radio 1", buttonImage: "windshield-damage.svg", buttonLabelSubCopy: "Test", + value: "test value", }, }); @@ -70,6 +73,7 @@ describe("list-card.vue", () => { groupName: "radio 1", buttonImage: "windshield-damage.svg", buttonLabelSubCopy: "Test", + value: "test value", }, }); @@ -89,6 +93,7 @@ describe("list-card.vue", () => { groupName: "radio 1", buttonImage: "windshield-damage.svg", isRequired: true, + value: "test value", }, }); @@ -110,6 +115,7 @@ describe("list-card.vue", () => { isRequired: true, isWide: true, buttonLabelSubCopy: "", + value: "test value", }, }); @@ -134,6 +140,7 @@ describe("list-card.vue", () => { isRequired: true, isWide: true, buttonLabelSubCopy: "Button Subcopy", + value: "test value", }, }); @@ -159,6 +166,7 @@ describe("list-card.vue", () => { buttonImage: "windshield-damage.svg", isRequired: true, isWide: false, + value: "test value", }, }); diff --git a/src/ux-components/radio/radio.spec.js b/src/ux-components/radio/radio.spec.js index 520fd9daf..83cc22b5a 100644 --- a/src/ux-components/radio/radio.spec.js +++ b/src/ux-components/radio/radio.spec.js @@ -6,12 +6,16 @@ import inputButtonWrapperMixin from "@/mixins/input-button-wrapper-mixin"; describe("radio.vue", () => { it("Should have correct group name", async () => { // Arrange - let { wrapper } = setupMocks({}); + let { wrapper } = setupMocks({ + mountOptionsMockData: { + propsData: { + groupName: "radio-button-test", + value: "test value", + }, + }, + }); // Act - await wrapper.setProps({ - groupName: "radio-button-test", - }); const input = wrapper.find("input"); // Assert @@ -20,12 +24,16 @@ describe("radio.vue", () => { it("Should have correct label text", async () => { // Act - let { wrapper } = setupMocks({}); + let { wrapper } = setupMocks({ + mountOptionsMockData: { + propsData: { + buttonLabel: "label text", + value: "test value", + }, + }, + }); // Arrange - await wrapper.setProps({ - buttonLabel: "label text", - }); const paragraph = wrapper.find("p"); // Assert @@ -39,6 +47,7 @@ describe("radio.vue", () => { // Arrange await wrapper.setProps({ screenReaderOnlyText: "screenreader text", + value: "test value", }); const paragraph = wrapper.find(".sr-only"); @@ -48,13 +57,10 @@ describe("radio.vue", () => { }); function setupMocks({ mountOptionsMockData = {} }) { - const wrapper = mount( - radio, - getMountOptions({ - ...mountOptionsMockData, - mixins: [inputButtonWrapperMixin], - }) - ); + const wrapper = mount(radio, { + ...mountOptionsMockData, + mixins: [inputButtonWrapperMixin], + }); return { wrapper }; }