diff --git a/src/layouts/service-location/service-zip-modal-question/service-zip-modal-question.spec.js b/src/layouts/service-location/service-zip-modal-question/service-zip-modal-question.spec.js index a81727c73..4f18fd52a 100644 --- a/src/layouts/service-location/service-zip-modal-question/service-zip-modal-question.spec.js +++ b/src/layouts/service-location/service-zip-modal-question/service-zip-modal-question.spec.js @@ -1,3 +1,81 @@ +import { mount } from "@vue/test-utils"; +import serviceZipModalQuestion from "./service-zip-modal-question"; +import crypto from "crypto"; +global.crypto = crypto; + +jest.mock('@/digital-components/textbox-question/textbox-question', () => ({ + getCmsContent: jest.fn((widgetName, cmsFieldName) => { + return widgetName[cmsFieldName]; + }), +})); + +const linkWidgetName = "linkWidgetName"; +const modalWidgetName = "modalWidgetName"; +const textboxQuestionWidgetName = "textboxQuestionWidgetName"; + +const mockLinkCmsContent = { + BodyText: "Sample link body text here.", +}; + +const mockModalCmsContent = { + FooterText: "Sample modal footer text here.", +}; + +const mockTextboxQuestionCmsContent = { + QuestionText: "Sample question text here." +}; + +const mockMixin = { + methods: { + getCmsContent: jest.fn((widgetName, cmsFieldName) => { + if (widgetName === linkWidgetName) + return mockLinkCmsContent[cmsFieldName]; + + if (widgetName === modalWidgetName) + return mockModalCmsContent[cmsFieldName]; + + if (widgetName === textboxQuestionWidgetName) + return mockTextboxQuestionCmsContent[cmsFieldName]; + + return null; + }), + + getZipCodeData: jest.fn((zip) => { + return { + isValid: true, + state: "OH", + isServiceable: true, + }; + }), + }, +}; + describe("service-zip-modal-question.vue", () => { - test.todo("test this"); + + it("Should display text from textboxQuestionWidget", async () => { + const wrapper = mount(serviceZipModalQuestion, { + mixins: [mockMixin], + props: { + linkWidgetName: linkWidgetName, + modalWidgetName: modalWidgetName, + textboxQuestionWidgetName: textboxQuestionWidgetName, + }, + attachTo: document.body, + }); + expect(wrapper.html()).toEqual(expect.stringContaining(mockTextboxQuestionCmsContent["QuestionText"])); + }); + + it("Should display footer text from modalWidget", async () => { + const wrapper = mount(serviceZipModalQuestion, { + mixins: [mockMixin], + props: { + linkWidgetName: linkWidgetName, + modalWidgetName: modalWidgetName, + textboxQuestionWidgetName: textboxQuestionWidgetName, + }, + attachTo: document.body, + }); + expect(wrapper.html()).toEqual(expect.stringContaining(mockModalCmsContent["FooterText"])); + }); + });