From e9a5f999ea447d44cd543d337bcc64a514277fc8 Mon Sep 17 00:00:00 2001 From: Max Date: Tue, 5 Apr 2022 10:01:07 -0400 Subject: [PATCH] More unit tests --- .../funnel-footer/funnel-footer.spec.js | 25 +- .../funnel-footer/funnel-footer.vue | 5 +- .../funnel-header/funnel-header.spec.js | 11 +- .../funnel-sub-header.spec.js | 19 +- .../funnel-sub-header/funnel-sub-header.vue | 8 +- .../vehicle-banner/vehicle-banner.spec.js | 47 +- .../damage-location-question.spec.js | 10 +- .../replace-options-question.spec.js | 12 +- .../side-door-options.spec.js | 8 +- .../vehicle-damage/vehicle-damage.spec.js | 1284 ++++++++--------- .../windshield-chip-count-question.spec.js | 23 +- .../windshield-damage-type-question.spec.js | 15 - .../make-question/make-question.spec.js | 27 +- src/layouts/vehicle-make/vehicle-make.spec.js | 114 +- .../model-question/model-question.spec.js | 30 +- .../vehicle-model/vehicle-model.spec.js | 109 +- .../vehicle-parts/vehicle-parts.spec.js | 118 +- .../style-question/style-question.spec.js | 31 +- .../vehicle-style/vehicle-style.spec.js | 120 +- src/layouts/vehicle-year/vehicle-year.spec.js | 89 +- .../year-question/year-question.spec.js | 29 +- src/mixins/base-mixin.js | 2 +- 22 files changed, 727 insertions(+), 1409 deletions(-) diff --git a/src/common-components/funnel-footer/funnel-footer.spec.js b/src/common-components/funnel-footer/funnel-footer.spec.js index 6b2bd8335..30dc14fd3 100644 --- a/src/common-components/funnel-footer/funnel-footer.spec.js +++ b/src/common-components/funnel-footer/funnel-footer.spec.js @@ -16,8 +16,8 @@ describe("funnel-footer.vue", () => { }); const wrapper = mount(funnelFooter, { + mixins: [mockMixin] }); - wrapper.vm.initializeComponent(cmsContent); // Assert const link = wrapper.find("a"); @@ -30,6 +30,7 @@ describe("funnel-footer.vue", () => { it("Should emit ForwardClicked on button click", async () => { // Act const wrapper = mount(funnelFooter, { + mixins: [mockMixin] }); wrapper.vm.buttonClick(); // Assert @@ -39,16 +40,28 @@ describe("funnel-footer.vue", () => { it("Should emit BackClicked on link click", async () => { // Act const wrapper = mount(funnelFooter, { + mixins: [mockMixin] }); wrapper.vm.linkClick(); // Assert expect(wrapper.emitted()["BackClicked"][0]).toHaveBeenCalled; }); + it("Should change button text when update button text is called", async () => { + // Act + const wrapper = mount(funnelFooter, { + mixins: [mockMixin] + }); + wrapper.vm.updateButtonText('newText'); + + // Assert + expect(wrapper.componentVM.customButtontext).toBe('newText'); + }); + }); -//Mock CMS content -const cmsContent = { - backLink: "text", - buttonText: "text", -}; +const mockMixin = { + methods: { + getCmsContent: jest.fn() + } +} \ No newline at end of file diff --git a/src/common-components/funnel-footer/funnel-footer.vue b/src/common-components/funnel-footer/funnel-footer.vue index 4d9a47ee6..62b7d9147 100644 --- a/src/common-components/funnel-footer/funnel-footer.vue +++ b/src/common-components/funnel-footer/funnel-footer.vue @@ -58,6 +58,7 @@ export default { data() { return { paddingHeight: 0, + customButtontext: '', } }, mounted() { @@ -74,7 +75,7 @@ export default { return this.getCmsContent(this.cmsWidgetName, 'BackButtonText'); }, buttonText(){ - return this.getCmsContent(this.cmsWidgetName, 'ForwardButtonText'); + return this.customButtontext ? this.customButtontext : this.getCmsContent(this.cmsWidgetName, 'ForwardButtonText'); } }, methods: { @@ -82,7 +83,7 @@ export default { this.paddingHeight = document.querySelector(".footer #infoBox").offsetHeight; }, updateButtonText(newText) { - this.buttonText = newText; + this.customButtontext = newText; }, removeLoader(){ this.$refs.buttonMain.removeLoader(); diff --git a/src/common-components/funnel-header/funnel-header.spec.js b/src/common-components/funnel-header/funnel-header.spec.js index ed60d5f73..a9b9535aa 100644 --- a/src/common-components/funnel-header/funnel-header.spec.js +++ b/src/common-components/funnel-header/funnel-header.spec.js @@ -10,8 +10,8 @@ describe("funnelHeader", () => { setData: { imageSrc: "image_url", }, + mixins: [mockMixin] }); - wrapper.vm.initializeComponent(cmsContent); // Assert expect(wrapper.find("img")).toBeTruthy(); @@ -19,7 +19,8 @@ describe("funnelHeader", () => { }); }); -//Mock CMS content -const cmsContent = { - imageSrc: "image_url", -}; +const mockMixin = { + methods: { + getCmsContent: jest.fn() + } +} diff --git a/src/common-components/funnel-sub-header/funnel-sub-header.spec.js b/src/common-components/funnel-sub-header/funnel-sub-header.spec.js index 08561ce67..ebcb9ca91 100644 --- a/src/common-components/funnel-sub-header/funnel-sub-header.spec.js +++ b/src/common-components/funnel-sub-header/funnel-sub-header.spec.js @@ -4,19 +4,18 @@ import FunnelSubHeader from "./funnel-sub-header"; describe("FunnelSubHeader.vue", () => { it("Should render the 'text' data value as a span value for the header span text value.", async () => { // Act - const wrapper = shallowMount(FunnelSubHeader); - await wrapper.setData({ - text: "FunnelSubHeader Content", + const wrapper = shallowMount(FunnelSubHeader, { + mixins: [mockMixin] }); - wrapper.vm.initializeComponent(cmsContent); + wrapper.vm.clickEvent(); // Assert - expect(wrapper.find("h5").text()).toContain("FunnelSubHeader Content"); - wrapper.unmount(); + expect(wrapper.emitted()).toEqual({"click-event": [[]]}); }); }); -//Mock CMS content -const cmsContent = { - HeaderText: "FunnelSubHeader Content", -}; +const mockMixin = { + methods: { + getCmsContent: jest.fn() + } +} diff --git a/src/common-components/funnel-sub-header/funnel-sub-header.vue b/src/common-components/funnel-sub-header/funnel-sub-header.vue index 0799e4744..155203e65 100644 --- a/src/common-components/funnel-sub-header/funnel-sub-header.vue +++ b/src/common-components/funnel-sub-header/funnel-sub-header.vue @@ -1,7 +1,7 @@