From 1639045d748524cf8ce9f0b7add773d8cae741a0 Mon Sep 17 00:00:00 2001 From: Leah Schumann Date: Wed, 29 Mar 2023 07:46:42 -0400 Subject: [PATCH] Unit tests completed --- .../service-type-question.spec.js | 186 +++++++++++++++++- .../modal-button-main.spec.js | 2 +- 2 files changed, 186 insertions(+), 2 deletions(-) diff --git a/src/layouts/service-location/service-type-question/service-type-question.spec.js b/src/layouts/service-location/service-type-question/service-type-question.spec.js index 3d0843e10..13b727c54 100644 --- a/src/layouts/service-location/service-type-question/service-type-question.spec.js +++ b/src/layouts/service-location/service-type-question/service-type-question.spec.js @@ -1 +1,185 @@ -test.todo("some test to be written in the future"); +import { shallowMount } from "@vue/test-utils"; +import { getMountOptions } from "@/helpers/unit-test-helper.js"; +import serviceTypeQuestion from "./service-type-question"; + +const mockCmsContent = { + QuestionText: "Choose a service option:", + Answers: [ + { + AnswerImageUrl: "", + Name: "Mobile", + SubText: "", + SubWidgetName: "", + Text: "Mobile", + }, + { + AnswerImageUrl: "", + Name: "Inshop", + SubText: "", + SubWidgetName: "", + Text: "In-shop", + }, + { + AnswerImageUrl: "", + Name: "DropOff", + SubText: "", + SubWidgetName: "", + Text: "Drop-off", + }, + ], +}; + +const cmsWidgetName = "ServiceTypeQuestionWidget"; +const mockMixin = { + methods: { + getCmsContent: jest.fn((widgetName, cmsFieldName) => { + if (widgetName === cmsWidgetName) { + return mockCmsContent[cmsFieldName]; + } + + return null; + }), + }, +}; + +describe("service-type-question.vue", () => { + it("Should display all options if both in-shop and mobile are available", async () => { + // Arrange/Act + const { wrapper } = setupMocks({ + mixins: [mockMixin], + props: { + cmsWidgetName: cmsWidgetName, + isGlassServiceableInshop: true, + isRecalibrationServiceableInshop: true, + isGlassServiceableMobile: true, + isRecalibrationServiceableMobile: true, + }, + mountOptions: { + attachTo: document.body, + }, + }); + + // Assert + expect(wrapper.vm.answersToDisplay).toEqual([ + { + AnswerImageUrl: "", + Name: "Mobile", + SubText: "", + SubWidgetName: "", + Text: "Mobile", + }, + { + AnswerImageUrl: "", + Name: "Inshop", + SubText: "", + SubWidgetName: "", + Text: "In-shop", + }, + { + AnswerImageUrl: "", + Name: "DropOff", + SubText: "", + SubWidgetName: "", + Text: "Drop-off", + }, + ]); + }); + + it("Should display only the In-Shop and Drop-Off answers when only in-shop service is available", async () => { + // Arrange/Act + const { wrapper } = setupMocks({ + mixins: [mockMixin], + props: { + cmsWidgetName: cmsWidgetName, + isGlassServiceableInshop: true, + isRecalibrationServiceableInshop: true, + isGlassServiceableMobile: false, + isRecalibrationServiceableMobile: false, + }, + mountOptions: { + attachTo: document.body, + }, + }); + + // Assert + expect(wrapper.vm.answersToDisplay).toEqual([ + { + AnswerImageUrl: "", + Name: "Inshop", + SubText: "", + SubWidgetName: "", + Text: "In-shop", + }, + { + AnswerImageUrl: "", + Name: "DropOff", + SubText: "", + SubWidgetName: "", + Text: "Drop-off", + }, + ]); + }); + + it("Should display only the Mobile answer when only mobile service is available", async () => { + // Arrange/Act + const { wrapper } = setupMocks({ + mixins: [mockMixin], + props: { + cmsWidgetName: cmsWidgetName, + isGlassServiceableInshop: false, + isRecalibrationServiceableInshop: false, + isGlassServiceableMobile: true, + isRecalibrationServiceableMobile: true, + }, + mountOptions: { + attachTo: document.body, + }, + }); + + // Assert + expect(wrapper.vm.answersToDisplay).toEqual([ + { + AnswerImageUrl: "", + Name: "Mobile", + SubText: "", + SubWidgetName: "", + Text: "Mobile", + }, + ]); + }); + + it("Should display no answers if neither in-shop nor mobile service are available", async () => { + // Arrange/Act + const { wrapper } = setupMocks({ + mixins: [mockMixin], + props: { + cmsWidgetName: cmsWidgetName, + isGlassServiceableInshop: false, + isRecalibrationServiceableInshop: false, + isGlassServiceableMobile: false, + isRecalibrationServiceableMobile: false, + }, + mountOptions: { + attachTo: document.body, + }, + }); + + // Assert + expect(wrapper.vm.answersToDisplay).toEqual([]); + }); +}); + +function setupMocks({ mountOptions, mixins, props, isShallowMount = true }) { + const resultingMountOptions = getMountOptions({ + ...mountOptions, + mixins, + }); + + if (props) resultingMountOptions.propsData = props; + + const wrapper = isShallowMount + ? shallowMount(serviceTypeQuestion, resultingMountOptions) + : mount(serviceTypeQuestion, resultingMountOptions); + + return { wrapper }; +} diff --git a/src/ux-components/modal-button-main/modal-button-main.spec.js b/src/ux-components/modal-button-main/modal-button-main.spec.js index bd3587f22..f212d8ec3 100644 --- a/src/ux-components/modal-button-main/modal-button-main.spec.js +++ b/src/ux-components/modal-button-main/modal-button-main.spec.js @@ -15,7 +15,7 @@ describe("modal-button-main.vue", () => { }) ); const button = wrapper.find("button"); - + // Assert expect(button.attributes("class")).toContain("btn-primary"); });