From 5c9d7dc53cfd203203bc6d21e804d51b4604efd6 Mon Sep 17 00:00:00 2001 From: Scott Kiener Date: Thu, 1 Sep 2022 10:55:21 -0400 Subject: [PATCH 1/2] CSR-795 | Added unit tests to modal.vue --- src/common-components/modal/modal.spec.js | 61 +++++++++++++++++++++++ src/common-components/modal/modal.vue | 2 - 2 files changed, 61 insertions(+), 2 deletions(-) create mode 100644 src/common-components/modal/modal.spec.js diff --git a/src/common-components/modal/modal.spec.js b/src/common-components/modal/modal.spec.js new file mode 100644 index 000000000..717b6f895 --- /dev/null +++ b/src/common-components/modal/modal.spec.js @@ -0,0 +1,61 @@ +import { shallowMount } from "@vue/test-utils"; +import Modal from "./modal"; + + +describe("modal.vue", () => { + it("Should display header text when HeaderText is defined in the CMS", async () => { + // Act + const wrapper = shallowMount(Modal, { + mixins: [mockMixin] + }); + expect(wrapper.html()).toEqual(expect.stringContaining(mockCmsContent['HeaderText'])); + }); + + it("Should display subheader text when SubheaderText is defined in the CMS", async () => { + // Act + const wrapper = shallowMount(Modal, { + mixins: [mockMixin] + }); + expect(wrapper.html()).toEqual(expect.stringContaining(mockCmsContent['SubheaderText'])); + }); + + it("Should insert image url when Image is defined in the CMS", async () => { + // Act + const wrapper = shallowMount(Modal, { + mixins: [mockMixin] + }); + expect(wrapper.html()).toEqual(expect.stringContaining(mockCmsContent['Image'])); + }); + + it("Should display body text when BodyText is defined in the CMS", async () => { + // Act + const wrapper = shallowMount(Modal, { + mixins: [mockMixin] + }); + expect(wrapper.html()).toEqual(expect.stringContaining(mockCmsContent['BodyText'])); + }); + + it("Should display footer text when FooterText is defined in the CMS", async () => { + // Act + const wrapper = shallowMount(Modal, { + mixins: [mockMixin] + }); + expect(wrapper.html()).toEqual(expect.stringContaining(mockCmsContent['FooterText'])); + }); +}); + +const mockMixin = { + methods: { + getCmsContent: jest.fn((widgetName, cmsFieldName) => { + return mockCmsContent[cmsFieldName]; + }) + } +} + +const mockCmsContent = { + 'HeaderText': "Sample header text here.", + 'SubheaderText': "Sample subheader text here.", + 'Image': "https://www.sampleImage.sample", + 'BodyText': "Sample body text here.", + 'FooterText': "Sample footer text here.", +} diff --git a/src/common-components/modal/modal.vue b/src/common-components/modal/modal.vue index c03c0b12a..2ade08aeb 100644 --- a/src/common-components/modal/modal.vue +++ b/src/common-components/modal/modal.vue @@ -18,11 +18,9 @@