diff --git a/src/layouts/order-confirmation/order-confirmation.spec.js b/src/layouts/order-confirmation/order-confirmation.spec.js index acf25001..504beb2d 100644 --- a/src/layouts/order-confirmation/order-confirmation.spec.js +++ b/src/layouts/order-confirmation/order-confirmation.spec.js @@ -5,7 +5,7 @@ import orderConfirmation from '@/layouts/order-confirmation/order-confirmation.v import { getMountOptions } from '@/helpers/unit-test-helper.js'; import { useMainStore } from '@/store/index.js'; import settleAllPromises from '@/helpers/layout-helper.js'; -import { fetchCmsContentForPage, getStringWithCustomValues } from '@/helpers/cms-content-helper'; +import { fetchCmsContentForPage, getStringWithCustomValues, processIfStatements } from '@/helpers/cms-content-helper'; import { mount } from '@vue/test-utils'; import { createTestingPinia } from '@pinia/testing'; import { nextTick } from 'vue'; @@ -22,11 +22,10 @@ jest.mock('@/helpers/cms-content-helper', () => ({ splitCopyOnCMSPlaceHolder: jest.fn(), getStringWithCustomValues: jest.fn() })); -const wordingText = 'wording text {custom:address}'; const mockMixin = { methods: { - getCmsContent: jest.fn().mockImplementation(() => wordingText), + getCmsContent: jest.fn(),//.mockImplementation(() => wordingText), setCmsContent: jest.fn() } }; @@ -137,30 +136,7 @@ const sessionStorage = { customerPortalLoginToken: 'token' }; -const sessionStorageMock = (() => { - let sessionStore = {}; - - return { - getItem(key) { - return sessionStore[key] || null; - }, - setItem(key, value) { - sessionStore[key] = value.toString(); - }, - removeItem(key) { - delete sessionStore[key]; - }, - clear() { - sessionStore = {}; - } - }; -})(); - -Object.defineProperty(window, 'sessionStorage', { - value: sessionStorageMock -}); - -function getMountedComponent(mainInitialState = {}, initialData = {}, methodToRun = () => {}) { +function getMountedComponent(mainInitialState = {}, initialData = {}, methodToRun = () => {}, mixin = mockMixin) { const mountOptions = getMountOptions({ router: { navigate: jest.fn(), @@ -185,7 +161,7 @@ function getMountedComponent(mainInitialState = {}, initialData = {}, methodToRu mountOptions.global.mixins[0].methods.getSettingValue = jest.fn(() => 'false'); mountOptions.global.plugins = [testingPinia]; - mountOptions.mixins = [mockMixin]; + mountOptions.mixins = [mixin]; mountOptions.data = () => ( initialData ); @@ -202,20 +178,13 @@ function getMountedComponent(mainInitialState = {}, initialData = {}, methodToRu } describe('OrderConfirmation.vue', () => { - beforeEach(() => { - window.sessionStorage.clear(); - }); - afterEach(() => { - window.sessionStorage.removeItem('submittedOrder'); - }); describe('Page pre-requisites', () => { - // TODO fix - test.skip('If submitted order saved to store, page pre-reqs return true', async () => { + test('If submitted order saved to store, page pre-reqs return true', async () => { // Arrange const mockStoreActions = () => { useMainStore().getSubmittedOrder = jest.fn().mockImplementation(() => sessionStorage); }; - const { wrapper } = getMountedComponent({}, {}, mockStoreActions); + const { wrapper } = getMountedComponent(initialStore, {}, mockStoreActions); // Act const arePagePrerequisitesValid = wrapper.vm.arePagePrerequisitesValid(); @@ -226,11 +195,14 @@ describe('OrderConfirmation.vue', () => { }); }); describe('Rendering', () => { + let wrapper; + beforeEach(() => { + const mockStoreActions = () => { + useMainStore().getSubmittedOrder = jest.fn().mockImplementation(() => sessionStorage); + }; + wrapper = getMountedComponent({}, {}, mockStoreActions).wrapper; + }); test('Should render Site Header', () => { - // Arrange - window.sessionStorage.setItem('submittedOrder', JSON.stringify(sessionStorage)); - const { wrapper } = getMountedComponent(initialStore); - // Act const siteHeader = wrapper.findComponent(headerStub); @@ -238,10 +210,6 @@ describe('OrderConfirmation.vue', () => { expect(siteHeader.exists()).toBe(true); }); test('Should render Vehicle Banner', () => { - // Arrange - window.sessionStorage.setItem('submittedOrder', JSON.stringify(sessionStorage)); - const { wrapper } = getMountedComponent(initialStore); - // Act const vehicleBanner = wrapper.findComponent(vehicleBannerStub); @@ -250,7 +218,9 @@ describe('OrderConfirmation.vue', () => { }); test('If Advanced flow, should display Site Footer', () => { // Arrange - window.sessionStorage.setItem('submittedOrder', JSON.stringify(sessionStorage)); + const mockStoreActions = () => { + useMainStore().getSubmittedOrder = jest.fn().mockImplementation(() => sessionStorage); + }; const testStore = { order: { schedule: { @@ -265,7 +235,7 @@ describe('OrderConfirmation.vue', () => { successReturnURL: 'testURL' } }; - const { wrapper } = getMountedComponent(testStore); + wrapper = getMountedComponent(testStore, {}, mockStoreActions).wrapper; // Act const siteFooter = wrapper.findComponent({ ref: 'siteFooter' }); @@ -274,10 +244,6 @@ describe('OrderConfirmation.vue', () => { expect(siteFooter.exists()).toBe(true); }); test('If Essential flow, should not display Site Footer', () => { - // Arrange - window.sessionStorage.setItem('submittedOrder', JSON.stringify(sessionStorage)); - const { wrapper } = getMountedComponent(initialStore); - // Act const siteFooter = wrapper.findComponent({ ref: 'siteFooter' }); @@ -289,6 +255,9 @@ describe('OrderConfirmation.vue', () => { test('If Advanced flow, forward button action navigates to carrier URL', () => { // Arrange window.sessionStorage.setItem('submittedOrder', JSON.stringify(sessionStorage)); + const mockStoreActions = () => { + useMainStore().getSubmittedOrder = jest.fn().mockImplementation(() => sessionStorage); + }; const carrierReturnUrl = 'testURL'; const testStore = { order: { @@ -304,7 +273,7 @@ describe('OrderConfirmation.vue', () => { successReturnURL: carrierReturnUrl } }; - const { wrapper } = getMountedComponent(testStore); + const { wrapper } = getMountedComponent(testStore, {}, mockStoreActions); // Act wrapper.vm.forwardButtonAction(); @@ -313,8 +282,8 @@ describe('OrderConfirmation.vue', () => { expect(wrapper.vm.$router.navigateToExternalUrl).toHaveBeenCalledWith(carrierReturnUrl); }); }); - describe('Computed properties', () => { - describe.skip('customValueMap', () =>{ + describe.only('Computed properties', () => { + describe('customValueMap', () =>{ test.each([ 'inShopAppointment', 'dropOffAppointment', @@ -380,36 +349,33 @@ describe('OrderConfirmation.vue', () => { expect(actualEmail).toBe(emailAddress); }); }) - describe.only('confirmationEmailText', () => { + describe('confirmationEmailText', () => { const greaterId = ">"; const lessId = "<"; test.each([ ['test', 'test'], - // [`te${greaterId}st`, 'te>st'], - // [`${greaterId}test${greaterId}`, '>test>'], - // [`te${greaterId}st ${greaterId}`, 'te>st >'], - // [`${lessId} test`, '< test'], - // [`t${lessId}e${lessId}st`, 'tt<'] + [`te${greaterId}st`, 'te>st'], + [`${greaterId}test${greaterId}`, '>test>'], + [`te${greaterId}st ${greaterId}`, 'te>st >'], + [`${lessId} test`, '< test'], + [`t${lessId}e${lessId}st`, 'tt<'] ])('given %p returned from cms, returns %p', (rawCms, expected) => { // Arrange const mockStoreActions = () => { useMainStore().getSubmittedOrder = jest.fn().mockImplementation(() => sessionStorage); }; + getStringWithCustomValues.mockImplementation(() => rawCms); const { wrapper } = getMountedComponent(initialStore, {}, mockStoreActions); - // TODO mock return of cms - getStringWithCustomValues.mockImplementationOnce(() => "test 1"); - // Act const text = wrapper.vm.confirmationEmailText; // Assert expect(text).toBe(expected); }); - test('replaces all ">" with >', () => {}); }); - describe.skip('appointmentTimeText', () => { + describe('appointmentTimeText', () => { test.each([ ['Between 9 AM - 10 AM', '09:00', '10:00'], ['Between 1 PM - 5 PM', '13:00', '17:00'], @@ -483,423 +449,488 @@ describe('OrderConfirmation.vue', () => { }); }); describe('appointmentLocation', () => { - test('mobile location returns service location', () => {}); - test('in shop appointment location returns shop location', () => {}); - test('drop off appointment location returns shop location', () => {}); - test('unknown appointment type returns null', () => {}); - }); - describe('serviceLocationFullAddress', () => { - // TODO - test('serviceLocationFullAddress should return text in expected format', () => { - // Arrange - const testSessionStorage = { - schedule: { - date: '2019-01-01', - startTime: '09:00', - endTime: '10:00' - }, - serviceLocation: { - address: '123 Test Way', - address2: '#1', - city: 'Mesa', - state: 'AZ', - zipCode: '12345', - appointmentType: 'Mobile' - }, - insuranceCoverage: { - coverageStatus: coverageStatuses.VERIFIED, - coverageType: coverageType.Deductible - }, - payment: { - isPayInAdvance: false - }, - lineItems: { - vaps: [] - }, - policy: {}, - damage: {} - }; - window.sessionStorage.setItem('submittedOrder', JSON.stringify(testSessionStorage)); - const { wrapper } = getMountedComponent(); - - // Act - const testValue = wrapper.vm.serviceLocationFullAddress; - - // Assert - expect(testValue).toEqual('123 Test Way, #1,
Mesa, AZ 12345'); - }); - }); - describe('providerFullAddress', () => { - // TODO - test('providerFullAddress should return text in expected format', () => { - // Arrange - const testSessionStorage = { - schedule: { - date: '2019-01-01', - startTime: '09:00', - endTime: '10:00' - }, - serviceLocation: { - provider: { - address: { - streetAddress: '123 Safelite Street', - city: 'Mesa', - state: 'AZ', - zipCode: '12345' - } - }, - appointmentType: 'Inshop' - }, - insuranceCoverage: { - coverageStatus: coverageStatuses.VERIFIED, - coverageType: coverageType.Deductible - }, - payment: { - isPayInAdvance: false - }, - lineItems: { - vaps: [] - }, - policy: {}, - damage: {} - }; - window.sessionStorage.setItem('submittedOrder', JSON.stringify(testSessionStorage)); - const { wrapper } = getMountedComponent(); - - // Act - const testValue = wrapper.vm.providerFullAddress; - - // Assert - expect(testValue).toEqual('123 Safelite Street,
Mesa, AZ 12345'); - }); - }); - describe('appointmentWordingText', () => { - test('mobile location returns mobile wording', () => {}); - test('in shop appointment location returns non mobile wording', () => {}); - test('drop off appointment location returns non mobile wording', () => {}); - test('unknown appointment type returns null', () => {}); - }); - describe('appointmentWordingText2', () => { - test('mobile location returns mobile wording 2', () => {}); - test('in shop appointment location returns non mobile wording 2', () => {}); - test('drop off appointment location returns non mobile wording 2', () => {}); - test('unknown appointment type returns null', () => {}); - }); - describe('isMobileAppointment', () => { + var order = deepClone(sessionStorage); + order.serviceLocation = { + address: "123 Service Rd.", + address2: "Box 4", + city: "Columbus", + state: "OH", + zipCode: "12345", + provider: { + address: { + streetAddress: "304 provider Ln.", + city: "pittsburg", + state: "PA", + zipCode: "16001" + } + } + }; + const expectedServiceLocation = '123 Service Rd., Box 4,
Columbus, OH 12345'; + const expectedShopLocation = '304 Provider Ln.,
Pittsburg, PA 16001'; test.each([ AppointmentTypeStrings.MOBILE, AppointmentTypeStrings.MOBILE_NOT_ITAC_AND_NOT_NOCOMP - ])('mobile appointment type %p returns true', (type) => { - + ])('mobile location %p returns service location', (type) => { + // Arrange + order.serviceLocation.appointmentType = type; + const mockStoreActions = () => { + useMainStore().getSubmittedOrder = jest.fn().mockImplementation(() => order); + }; + const { wrapper } = getMountedComponent({}, {}, mockStoreActions); + + // Act + const text = wrapper.vm.appointmentLocation; + + // Assert + expect(text).toBe(expectedServiceLocation); }); test.each([ AppointmentTypeStrings.IN_SHOP, - AppointmentTypeStrings.DROP_OFF, - 'invalid type', - null, - undefined - ])('non mobile appointment type %p returns false', (type) => { + AppointmentTypeStrings.DROP_OFF + ])('%p appointment location returns shop location', (type) => { + // Arrange + order.serviceLocation.appointmentType = type; + const mockStoreActions = () => { + useMainStore().getSubmittedOrder = jest.fn().mockImplementation(() => order); + }; + const { wrapper } = getMountedComponent({}, {}, mockStoreActions); + + // Act + const text = wrapper.vm.appointmentLocation; + + // Assert + expect(text).toBe(expectedShopLocation); + }); + test.each( + ['turtle', undefined, null] + )('unknown appointment type %p returns null', (type) => { + // Arrange + order.serviceLocation.appointmentType = type; + const mockStoreActions = () => { + useMainStore().getSubmittedOrder = jest.fn().mockImplementation(() => order); + }; + const { wrapper } = getMountedComponent({}, {}, mockStoreActions); + + // Act + const text = wrapper.vm.appointmentLocation; + + // Assert + expect(text).toBeNull(); + }); + }); + describe('serviceLocationFullAddress', () => { + var order = deepClone(sessionStorage); + beforeEach(() => { + order.serviceLocation = { + address: "123 Service Rd.", + address2: "Box 4", + city: "Columbus", + state: "OH", + zipCode: "12345", + provider: { + address: { + streetAddress: "304 provider Ln.", + city: "pittsburg", + state: "PA", + zipCode: "16001" + } + } + }; + }); + test('returns expected when all defined', () => { + const mockStoreActions = () => { + useMainStore().getSubmittedOrder = jest.fn().mockImplementation(() => order); + }; + const { wrapper } = getMountedComponent({}, {}, mockStoreActions); + const expected = "123 Service Rd., Box 4,
Columbus, OH 12345"; + + // Act + const text = wrapper.vm.serviceLocationFullAddress; + + // Assert + expect(text).toBe(expected); + }); + test('returns expected when address null', () => { + order.serviceLocation.address = null; + const mockStoreActions = () => { + useMainStore().getSubmittedOrder = jest.fn().mockImplementation(() => order); + }; + const { wrapper } = getMountedComponent({}, {}, mockStoreActions); + const expected = ", Box 4,
Columbus, OH 12345"; + + // Act + const text = wrapper.vm.serviceLocationFullAddress; + + // Assert + expect(text).toBe(expected); + }); + test('returns expected when address2 null', () => { + order.serviceLocation.address2 = null; + const mockStoreActions = () => { + useMainStore().getSubmittedOrder = jest.fn().mockImplementation(() => order); + }; + const { wrapper } = getMountedComponent({}, {}, mockStoreActions); + const expected = "123 Service Rd.,
Columbus, OH 12345"; + + // Act + const text = wrapper.vm.serviceLocationFullAddress; + + // Assert + expect(text).toBe(expected); + }); + test('returns expected when city null', () => { + order.serviceLocation.city = null; + const mockStoreActions = () => { + useMainStore().getSubmittedOrder = jest.fn().mockImplementation(() => order); + }; + const { wrapper } = getMountedComponent({}, {}, mockStoreActions); + const expected = "123 Service Rd., Box 4,
, OH 12345"; + + // Act + const text = wrapper.vm.serviceLocationFullAddress; + + // Assert + expect(text).toBe(expected); + }); + test('returns expected when state null', () => { + order.serviceLocation.state = null; + const mockStoreActions = () => { + useMainStore().getSubmittedOrder = jest.fn().mockImplementation(() => order); + }; + const { wrapper } = getMountedComponent({}, {}, mockStoreActions); + const expected = "123 Service Rd., Box 4,
Columbus, 12345"; + + // Act + const text = wrapper.vm.serviceLocationFullAddress; + + // Assert + expect(text).toBe(expected); + }); + test('returns expected when zipCode null', () => { + order.serviceLocation.zipCode = null; + const mockStoreActions = () => { + useMainStore().getSubmittedOrder = jest.fn().mockImplementation(() => order); + }; + const { wrapper } = getMountedComponent({}, {}, mockStoreActions); + const expected = "123 Service Rd., Box 4,
Columbus, OH "; + + // Act + const text = wrapper.vm.serviceLocationFullAddress; + + // Assert + expect(text).toBe(expected); + }); + test('returns expected when all null', () => { + order.serviceLocation.address = null; + order.serviceLocation.address2 = null; + order.serviceLocation.city = null; + order.serviceLocation.state = null; + order.serviceLocation.zipCode = null; + const mockStoreActions = () => { + useMainStore().getSubmittedOrder = jest.fn().mockImplementation(() => order); + }; + const { wrapper } = getMountedComponent({}, {}, mockStoreActions); + const expected = ",
, "; + + // Act + const text = wrapper.vm.serviceLocationFullAddress; + + // Assert + expect(text).toBe(expected); + }); + }); + describe('providerFullAddress', () => { + var order = deepClone(sessionStorage); + beforeEach(() => { + order.serviceLocation = { + address: "123 Service Rd.", + address2: "Box 4", + city: "Columbus", + state: "OH", + zipCode: "12345", + provider: { + address: { + streetAddress: "304 provider Ln.", + city: "pittsburg", + state: "PA", + zipCode: "16001" + } + } + }; + }); + test('returns expected when all properties defined', () => { + const mockStoreActions = () => { + useMainStore().getSubmittedOrder = jest.fn().mockImplementation(() => order); + }; + const { wrapper } = getMountedComponent({}, {}, mockStoreActions); + const expected = "304 Provider Ln.,
Pittsburg, PA 16001"; + + // Act + const text = wrapper.vm.providerFullAddress; + + // Assert + expect(text).toBe(expected); + }); + test('returns expected when streetAddress null', () => { + order.serviceLocation.provider.address.streetAddress = null; + const mockStoreActions = () => { + useMainStore().getSubmittedOrder = jest.fn().mockImplementation(() => order); + }; + const { wrapper } = getMountedComponent({}, {}, mockStoreActions); + const expected = ""; + + // Act + const text = wrapper.vm.providerFullAddress; + + // Assert + expect(text).toBe(expected); + }); + test('returns expected when city null', () => { + order.serviceLocation.provider.address.city = null; + const mockStoreActions = () => { + useMainStore().getSubmittedOrder = jest.fn().mockImplementation(() => order); + }; + const { wrapper } = getMountedComponent({}, {}, mockStoreActions); + const expected = "304 Provider Ln.,
, PA 16001"; + + // Act + const text = wrapper.vm.providerFullAddress; + + // Assert + expect(text).toBe(expected); + }); + test('returns expected when state null', () => { + order.serviceLocation.provider.address.state = null; + const mockStoreActions = () => { + useMainStore().getSubmittedOrder = jest.fn().mockImplementation(() => order); + }; + const { wrapper } = getMountedComponent({}, {}, mockStoreActions); + const expected = "304 Provider Ln.,
Pittsburg, 16001"; + + // Act + const text = wrapper.vm.providerFullAddress; + + // Assert + expect(text).toBe(expected); + }); + test('returns expected when zipCode null', () => { + order.serviceLocation.provider.address.zipCode = null; + const mockStoreActions = () => { + useMainStore().getSubmittedOrder = jest.fn().mockImplementation(() => order); + }; + const { wrapper } = getMountedComponent({}, {}, mockStoreActions); + const expected = "304 Provider Ln.,
Pittsburg, PA "; + + // Act + const text = wrapper.vm.providerFullAddress; + + // Assert + expect(text).toBe(expected); + }); + test('returns expected when all null', () => { + order.serviceLocation.provider.address.streetAddress = null; + order.serviceLocation.provider.address.city = null; + order.serviceLocation.provider.address.state = null; + order.serviceLocation.provider.address.zipCode = null; + const mockStoreActions = () => { + useMainStore().getSubmittedOrder = jest.fn().mockImplementation(() => order); + }; + const { wrapper } = getMountedComponent({}, {}, mockStoreActions); + const expected = ""; + + // Act + const text = wrapper.vm.providerFullAddress; + + // Assert + expect(text).toBe(expected); + }); + }); + describe('appointmentWordingText', () => { + const mobileWording = "Mobile wording"; + const nonMobileWording = "Non mobile wording"; + const mobileWidget = "MobileWordingWidget"; + const dropOffAndInShopWidget = "DropOffAndInShopWordingWidget" + const mixin = { + methods: { + getCmsContent: jest.fn().mockImplementation((widget, _) => { + if (widget == mobileWidget){ + return mobileWording; + } + if (widget == dropOffAndInShopWidget){ + return nonMobileWording; + } + return ""; + }), + setCmsContent: jest.fn() + } + }; + processIfStatements.mockImplementation((content) => content); + getStringWithCustomValues.mockImplementation((content, _) => content); + test.each([ + [AppointmentTypeStrings.MOBILE, mobileWording], + [AppointmentTypeStrings.MOBILE_NOT_ITAC_AND_NOT_NOCOMP, mobileWording], + [AppointmentTypeStrings.DROP_OFF, nonMobileWording], + [AppointmentTypeStrings.IN_SHOP, nonMobileWording], + ['unknown', null], + [null, null], + [undefined, null], + ])('appointment type %p returns wording %p', (type, wording) => { + // Arrange + var order = deepClone(sessionStorage); + order.serviceLocation.appointmentType = type; + const mockStoreActions = () => { + useMainStore().getSubmittedOrder = jest.fn().mockImplementation(() => order); + }; + const { wrapper } = getMountedComponent({}, {}, mockStoreActions, mixin); + + // Act + const testValue = wrapper.vm.appointmentWordingText; + + // Assert + expect(testValue).toEqual(wording); + }); + }); + describe('appointmentWordingText2', () => { + const mobileWording = "Mobile wording"; + const nonMobileWording = "Non mobile wording"; + const mobileWidget = "MobileWordingWidget"; + const dropOffAndInShopWidget = "DropOffAndInShopWordingWidget" + const mixin = { + methods: { + getCmsContent: jest.fn().mockImplementation((widget, _) => { + if (widget == mobileWidget){ + return mobileWording; + } + if (widget == dropOffAndInShopWidget){ + return nonMobileWording; + } + return ""; + }), + setCmsContent: jest.fn() + } + }; + processIfStatements.mockImplementation((content) => content); + getStringWithCustomValues.mockImplementation((content, _) => content); + test.each([ + [AppointmentTypeStrings.MOBILE, mobileWording], + [AppointmentTypeStrings.MOBILE_NOT_ITAC_AND_NOT_NOCOMP, mobileWording], + [AppointmentTypeStrings.DROP_OFF, nonMobileWording], + [AppointmentTypeStrings.IN_SHOP, nonMobileWording], + ['unknown', null], + [null, null], + [undefined, null], + ])('appointment type %p returns wording "%p"', (type, wording) => { + // Arrange + var order = deepClone(sessionStorage); + order.serviceLocation.appointmentType = type; + const mockStoreActions = () => { + useMainStore().getSubmittedOrder = jest.fn().mockImplementation(() => order); + }; + const { wrapper } = getMountedComponent({}, {}, mockStoreActions, mixin); + + // Act + const testValue = wrapper.vm.appointmentWordingText2; + + // Assert + expect(testValue).toEqual(wording); + }); + }); + describe('isMobileAppointment', () => { + test.each([ + [AppointmentTypeStrings.MOBILE, true], + [AppointmentTypeStrings.MOBILE_NOT_ITAC_AND_NOT_NOCOMP, true], + [AppointmentTypeStrings.IN_SHOP, false], + [AppointmentTypeStrings.DROP_OFF, false], + ['other', false], + [null, false], + [undefined, false] + ])('appointment type %p returns %p', (type, expected) => { + // Arrange + var order = deepClone(sessionStorage); + order.serviceLocation.appointmentType = type; + const mockStoreActions = () => { + useMainStore().getSubmittedOrder = jest.fn().mockImplementation(() => order); + }; + const { wrapper } = getMountedComponent({}, {}, mockStoreActions); + + // Act + const testValue = wrapper.vm.isMobileAppointment; + + // Assert + expect(testValue).toBe(expected); }); }); describe('isInShopAppointment', () => { - test('in shop appointment type returns true', () => { - - }); test.each([ - AppointmentTypeStrings.MOBILE, - AppointmentTypeStrings.MOBILE_NOT_ITAC_AND_NOT_NOCOMP, - AppointmentTypeStrings.DROP_OFF, - 'invalid type', - null, - undefined - ])('non in shop appointment type %p returns false', (type) => { - + [AppointmentTypeStrings.MOBILE, false], + [AppointmentTypeStrings.MOBILE_NOT_ITAC_AND_NOT_NOCOMP, false], + [AppointmentTypeStrings.IN_SHOP, true], + [AppointmentTypeStrings.DROP_OFF, false], + ['other', false], + [null, false], + [undefined, false] + ])('appointment type %p returns %p', (type, expected) => { + // Arrange + var order = deepClone(sessionStorage); + order.serviceLocation.appointmentType = type; + const mockStoreActions = () => { + useMainStore().getSubmittedOrder = jest.fn().mockImplementation(() => order); + }; + const { wrapper } = getMountedComponent({}, {}, mockStoreActions); + + // Act + const testValue = wrapper.vm.isInShopAppointment; + + // Assert + expect(testValue).toBe(expected); }); }); describe('isDropOffAppointment', () => { - test('drop off appointment type returns true', () => { - - }); test.each([ - AppointmentTypeStrings.MOBILE, - AppointmentTypeStrings.MOBILE_NOT_ITAC_AND_NOT_NOCOMP, - AppointmentTypeStrings.IN_SHOP, - 'invalid type', - null, - undefined - ])('non drop off appointment type %p returns false', (type) => { - - }); - }); - describe('uncategorized', () => { - // TODO make format date test - test('appointmentDateFormatted should return date in expected format', () => { + [AppointmentTypeStrings.MOBILE, false], + [AppointmentTypeStrings.MOBILE_NOT_ITAC_AND_NOT_NOCOMP, false], + [AppointmentTypeStrings.IN_SHOP, false], + [AppointmentTypeStrings.DROP_OFF, true], + ['other', false], + [null, false], + [undefined, false] + ])('appointment type %p returns %p', (type, expected) => { // Arrange - window.sessionStorage.setItem('submittedOrder', JSON.stringify(sessionStorage)); - const { wrapper } = getMountedComponent(initialStore); - - // Act - const testValue = wrapper.vm.appointmentDateFormatted; - - // Assert - expect(testValue).toEqual('Friday, March 1'); - }); - - test('appointmentWordingText should return Mobile text in expected format', () => { - // Arrange - const testSessionStorage = { - schedule: { - date: '2019-01-01', - startTime: '09:00', - endTime: '10:00' - }, - serviceLocation: { - address: '123 Test Way', - address2: '#1', - city: 'Mesa', - state: 'AZ', - zipCode: '12345', - appointmentType: 'Mobile' - }, - insuranceCoverage: { - coverageStatus: coverageStatuses.VERIFIED, - coverageType: coverageType.Deductible - }, - payment: { - isPayInAdvance: false - }, - lineItems: { - vaps: [] - }, - policy: {}, - damage: {} + var order = deepClone(sessionStorage); + order.serviceLocation.appointmentType = type; + const mockStoreActions = () => { + useMainStore().getSubmittedOrder = jest.fn().mockImplementation(() => order); }; - window.sessionStorage.setItem('submittedOrder', JSON.stringify(testSessionStorage)); - const { wrapper } = getMountedComponent(); + const { wrapper } = getMountedComponent({}, {}, mockStoreActions); // Act - const testValue = wrapper.vm.appointmentWordingText; + const testValue = wrapper.vm.isDropOffAppointment; // Assert - expect(testValue).toEqual('wording text 123 Test Way, #1,
Mesa, AZ 12345'); - }); - test('appointmentWordingText should return Drop Off text in expected format', () => { - // Arrange - const testSessionStorage = { - schedule: { - date: '2019-01-01', - startTime: '09:00', - endTime: '10:00' - }, - serviceLocation: { - provider: { - address: { - streetAddress: '123 Safelite Street', - city: 'Mesa', - state: 'AZ', - zipCode: '12345' - } - }, - appointmentType: 'Dropoff' - }, - insuranceCoverage: { - coverageStatus: coverageStatuses.VERIFIED, - coverageType: coverageType.Deductible - }, - payment: { - isPayInAdvance: false - }, - lineItems: { - vaps: [] - }, - policy: {}, - damage: {} - }; - window.sessionStorage.setItem('submittedOrder', JSON.stringify(testSessionStorage)); - const { wrapper } = getMountedComponent(); - - // Act - const testValue = wrapper.vm.appointmentWordingText; - - // Assert - expect(testValue).toEqual('wording text 123 Safelite Street,
Mesa, AZ 12345'); - }); - test('appointmentWordingText should return In Shop text in expected format', () => { - // Arrange - const testSessionStorage = { - schedule: { - date: '2019-01-01', - startTime: '09:00', - endTime: '10:00' - }, - serviceLocation: { - provider: { - address: { - streetAddress: '123 Safelite Street', - city: 'Mesa', - state: 'AZ', - zipCode: '12345' - } - }, - appointmentType: 'Inshop' - }, - insuranceCoverage: { - coverageStatus: coverageStatuses.VERIFIED, - coverageType: coverageType.Deductible - }, - payment: { - isPayInAdvance: false - }, - lineItems: { - vaps: [] - }, - policy: {}, - damage: {} - }; - window.sessionStorage.setItem('submittedOrder', JSON.stringify(testSessionStorage)); - const { wrapper } = getMountedComponent(); - - // Act - const testValue = wrapper.vm.appointmentWordingText; - - // Assert - expect(testValue).toEqual('wording text 123 Safelite Street,
Mesa, AZ 12345'); - }); - - test('appointmentWordingText2 should return Mobile text in expected format', () => { - // Arrange - const testSessionStorage = { - schedule: { - date: '2019-01-01', - startTime: '09:00', - endTime: '10:00' - }, - serviceLocation: { - address: '123 Test Way', - address2: '#1', - city: 'Mesa', - state: 'AZ', - zipCode: '12345', - appointmentType: 'Mobile' - }, - insuranceCoverage: { - coverageStatus: coverageStatuses.VERIFIED, - coverageType: coverageType.Deductible - }, - payment: { - isPayInAdvance: false - }, - lineItems: { - vaps: [] - }, - policy: {}, - damage: {} - }; - window.sessionStorage.setItem('submittedOrder', JSON.stringify(testSessionStorage)); - const { wrapper } = getMountedComponent(); - - // Act - const testValue = wrapper.vm.appointmentWordingText2; - - // Assert - expect(testValue).toEqual(wordingText); - }); - test('appointmentWordingText2 should return Drop Off and text in expected format', () => { - // Arrange - const testSessionStorage = { - schedule: { - date: '2019-01-01', - startTime: '09:00', - endTime: '10:00' - }, - serviceLocation: { - provider: { - address: { - streetAddress: '123 Safelite Street', - city: 'Mesa', - state: 'AZ', - zipCode: '12345' - } - }, - appointmentType: 'Dropoff' - }, - insuranceCoverage: { - coverageStatus: coverageStatuses.VERIFIED, - coverageType: coverageType.Deductible - }, - payment: { - isPayInAdvance: false - }, - lineItems: { - vaps: [] - }, - policy: {}, - damage: {} - }; - window.sessionStorage.setItem('submittedOrder', JSON.stringify(testSessionStorage)); - const { wrapper } = getMountedComponent(); - - // Act - const testValue = wrapper.vm.appointmentWordingText2; - const expected = wrapper.vm.getBodyText2FromCms('Test Widget'); - - // Assert - expect(testValue).toEqual(expected); - }); - test('appointmentWordingText2 should return In Shop text in expected format', () => { - // Arrange - const testSessionStorage = { - schedule: { - date: '2019-01-01', - startTime: '09:00', - endTime: '10:00' - }, - serviceLocation: { - provider: { - address: { - streetAddress: '123 Safelite Street', - city: 'Mesa', - state: 'AZ', - zipCode: '12345' - } - }, - appointmentType: 'Inshop' - }, - insuranceCoverage: { - coverageStatus: coverageStatuses.VERIFIED, - coverageType: coverageType.Deductible - }, - payment: { - isPayInAdvance: false - }, - lineItems: { - vaps: [] - }, - policy: {}, - damage: {} - }; - window.sessionStorage.setItem('submittedOrder', JSON.stringify(testSessionStorage)); - const { wrapper } = getMountedComponent(); - - // Act - const testValue = wrapper.vm.appointmentWordingText2; - const expected = wrapper.vm.getBodyText2FromCms('Test Widget'); - - // Assert - expect(testValue).toEqual(expected); + expect(testValue).toBe(expected); }); }); }); describe('Methods', () => { describe('formatDate', () => { - // TODO test cases confirm day of week test.each([ - ['', '2020-04-22'], // Monday, April 22 - ['', '2018-02-01'], // Tuesday, February 1 - ['', '2026-12-30'] // Wednesday, December 30 - ])('returns "%p" given "%p"', (expected, date) => { + ['Wednesday, April 22', '2020-04-22'], + ['Thursday, February 1', '2018-02-01'], + ['Wednesday, December 30', '2026-12-30'] + ])('returns %p given %p', (expected, date) => { + // Arrange + var order = deepClone(sessionStorage); + const mockStoreActions = () => { + useMainStore().getSubmittedOrder = jest.fn().mockImplementation(() => order); + }; + const { wrapper } = getMountedComponent({}, {}, mockStoreActions); + // Act + const result = wrapper.vm.formatDate(date); + + // Assert + expect(result).toBe(expected); }); }); }) diff --git a/src/layouts/order-confirmation/order-confirmation.vue b/src/layouts/order-confirmation/order-confirmation.vue index bdd1d5ea..60182e7a 100644 --- a/src/layouts/order-confirmation/order-confirmation.vue +++ b/src/layouts/order-confirmation/order-confirmation.vue @@ -252,7 +252,7 @@ export default { }, serviceLocationFullAddress() { var { address, address2, city, state, zipCode } = this.serviceLocation; - return `${address}, ${address2 ? `${address2},` : ''}
${city}, ${state} ${zipCode}`; + return `${address ?? ''}, ${address2 ? `${address2},` : ''}
${city ?? ''}, ${state ?? ''} ${zipCode ?? ''}`; }, providerFullAddress() { var { streetAddress, city, state, zipCode } = this.providerAddress; @@ -380,10 +380,8 @@ export default { rawText, 'custom', (v) => { return this.customValueMap[v] } - ) - const x = getStringWithCustomValues(processedIfStatements, this.customValueMap); - console.log(JSON.stringify(x)); - return x; + ); + return getStringWithCustomValues(processedIfStatements, this.customValueMap); }, formatDate(date) { // This conversion ensures we don't get get GMT induced date changes