diff --git a/src/layouts/review/review-sections/service-location-review/service-location-review.spec.js b/src/layouts/review/review-sections/service-location-review/service-location-review.spec.js index e69de29bb..5ddcffc86 100644 --- a/src/layouts/review/review-sections/service-location-review/service-location-review.spec.js +++ b/src/layouts/review/review-sections/service-location-review/service-location-review.spec.js @@ -0,0 +1,123 @@ +import { shallowMount } from "@vue/test-utils"; +import { getMountOptions } from "@/helpers/unit-test-helper.js"; +import serviceLocationReview from "@/layouts/review/review-sections/service-location-review/service-location-review"; + +import { AppointmentTypeStrings } from "@/constants/schedule-constants"; + +const cmsContent = { + ServiceLocationTitleWidget: { + Text: "Title Text", + }, +}; + +describe("Service Location Review Block", () => { + it("Should render mobile address if mobile appointment", async () => { + // Arrange + const props = generateDefaultProps(); + + const { wrapper } = setupMocks({ + propsData: props + }); + + // Act + await wrapper.vm.$nextTick(); + + // Assert + expect(wrapper.vm.displayContent).toEqual(["Mobile Address 1, Mobile Address 2, Mobile City, MO 11111"]); + }); + + it("Should render service location address if inshop appointment.", async () => { + // Arrange + let props = generateDefaultProps(); + + props.serviceLocation.appointmentType = AppointmentTypeStrings.IN_SHOP; + + const { wrapper } = setupMocks({ + propsData: props + }); + + // Act + await wrapper.vm.$nextTick(); + + // Assert + expect(wrapper.vm.displayContent).toEqual(["Service Location Address, Service Location City, SL 22222"]); + }); + + it("Should render service location address if drop-off appointment", async () => { + // Arrange + let props = generateDefaultProps(); + + props.serviceLocation.appointmentType = AppointmentTypeStrings.DROP_OFF; + + const { wrapper } = setupMocks({ + propsData: props + }); + + // Act + await wrapper.vm.$nextTick(); + + // Assert + expect(wrapper.vm.displayContent).toEqual(["Service Location Address, Service Location City, SL 22222"]); + }); + + it("Should not add comma or any text if address2 is null", async () => { + // Arrange + let props = generateDefaultProps(); + + props.serviceLocation.address2 = null; + + const { wrapper } = setupMocks({ + propsData: props + }); + + // Act + await wrapper.vm.$nextTick(); + + // Assert + expect(wrapper.vm.displayContent).toEqual(["Mobile Address 1, Mobile City, MO 11111"]); + }); +}); + +function generateDefaultProps() { + return { + cmsWidgetName: "ServiceLocationTitleWidget", + serviceLocation: { + address: "Mobile Address 1", + address2: "Mobile Address 2", + city: "Mobile City", + state: "MO", + zipCode: "11111", + zipCodeCtu: "", + appointmentType: AppointmentTypeStrings.MOBILE, + isVehicleProtected: false, + provider: { + providerNumber: "", + address: { + streetAddress: "Service Location Address", + city: "Service Location City", + state: "SL", + zipCode: "22222", + zipCodeCtu: "", + }, + }, + }, + }; +} + +function setupMocks(customMountOptions) { + const mountOptions = getMountOptions(customMountOptions); + + const mockMixin = { + methods: { + getCmsContent: jest.fn((widgetName, cmsFieldName) => { + return cmsContent?.[widgetName]?.[cmsFieldName] ?? ""; + }), + }, + }; + + mountOptions.global.mixins = [mockMixin]; + + const wrapper = shallowMount(serviceLocationReview, mountOptions); + wrapper.vm.setCmsContent = jest.fn(); + return { wrapper }; +} \ No newline at end of file