diff --git a/src/layouts/tpa-confirmation/tpa-confirmation.spec.js b/src/layouts/tpa-confirmation/tpa-confirmation.spec.js new file mode 100644 index 00000000..258dc420 --- /dev/null +++ b/src/layouts/tpa-confirmation/tpa-confirmation.spec.js @@ -0,0 +1,168 @@ +// Components +import tpaConfirmation from '@/layouts/tpa-confirmation/tpa-confirmation.vue'; + +// Supporting Files +// import baseMixin from '@/mixins/base-mixin'; +import { getMountOptions } from '@/helpers/unit-test-helper.js'; +// import navigationScenarios from '@/router/router-constants/navigation-scenarios.js'; +import { useMainStore } from '@/store/index.js'; +import settleAllPromises from '@/helpers/layout-helper.js'; +import { fetchCmsContentForPage } from '@/helpers/cms-content-helper'; +import { mount } from '@vue/test-utils'; +import { createTestingPinia } from '@pinia/testing'; + +jest.mock('@/helpers/layout-helper.js', () => jest.fn()); + +jest.mock('@/helpers/cms-content-helper', () => ({ + fetchCmsContentForPage: jest.fn(), + processIfStatements: jest.fn(), + doesCopyContainRouterLink: jest.fn(), + splitCopyOnCMSPlaceHolder: jest.fn().mockImplementation(() => 'test'), + getRouterLinkRouteFromCopy: jest.fn(), + getRouterLinkDisplayTextFromCopy: jest.fn(), + doesCopyContainTextLink: jest.fn() +})); + +const mockMixin = { + methods: { + getCmsContent: jest.fn().mockImplementation(() => ''), + setCmsContent: jest.fn() + } +}; + +const footerStub = { + render: () => {}, + methods: { + updateButtonText: jest.fn() + } +}; + +function getMountedComponent(mainInitialState = {}, initialData = {}, methodToRun = () => {}) { + const mountOptions = getMountOptions({ + router: { + navigate: jest.fn() + } + }); + + mountOptions.global.stubs = { + siteFooter: footerStub + }; + const testingPinia = createTestingPinia({ + initialState: { + main: mainInitialState + } + }); + useMainStore(testingPinia); + methodToRun(); + + mountOptions.global.plugins = [testingPinia]; + mountOptions.mixins = [mockMixin]; + mountOptions.data = () => ( + initialData + ); + + const apiResponses = { + supportingItems: [] + }; + const apiPromise = Promise.resolve(apiResponses); + settleAllPromises.mockImplementation(() => apiPromise); + fetchCmsContentForPage.mockImplementation(() => Promise.resolve()); + + const wrapper = mount(tpaConfirmation, mountOptions); + return { wrapper }; +} + +describe('TPAConfirmation.vue', () => { + describe('Rendering', () => { + test('Should render Site Header', () => { + // Arrange + const { wrapper } = getMountedComponent({}); + + // Act + const siteHeader = wrapper.findComponent({ ref: 'siteHeader' }); + + // Assert + expect(siteHeader.exists()).toBe(true); + }); + test('Should render Vehicle Banner', () => { + // Arrange + const { wrapper } = getMountedComponent({}); + + // Act + const vehicleBanner = wrapper.findComponent({ ref: 'vehicleBanner' }); + + // Assert + expect(vehicleBanner.exists()).toBe(true); + }); + test('Should render Confirmation Body One', () => { + // Arrange + const { wrapper } = getMountedComponent({}); + + // Act + const bodyOne = wrapper.findComponent({ ref: 'tpaConfirmationBodyOne' }); + + // Assert + expect(bodyOne.exists()).toBe(true); + }); + test('Should render Confirmation Body Two', () => { + // Arrange + const { wrapper } = getMountedComponent({}); + + // Act + const bodyTwo = wrapper.findComponent({ ref: 'tpaConfirmationBodyTwo' }); + + // Assert + expect(bodyTwo.exists()).toBe(true); + }); + test('Should render Contact Carrier text', () => { + // Arrange + const { wrapper } = getMountedComponent({}); + + // Act + const contactCarrierText = wrapper.findComponent({ ref: 'contactCarrierText' }); + + // Assert + expect(contactCarrierText.exists()).toBe(true); + }); + test('Should render Order Details title', () => { + // Arrange + const { wrapper } = getMountedComponent({}); + + // Act + const orderDetailsTitle = wrapper.findComponent({ ref: 'tpaConfirmationOrderDetailsTitle' }); + + // Assert + expect(orderDetailsTitle.exists()).toBe(true); + }); + test('Should render Order Details body', () => { + // Arrange + const { wrapper } = getMountedComponent({}); + + // Act + const orderDetailsBody = wrapper.findComponent({ ref: 'tpaConfirmationOrderDetailsBody' }); + + // Assert + expect(orderDetailsBody.exists()).toBe(true); + }); + test('Should render Deductible Box', () => { + // Arrange + const { wrapper } = getMountedComponent({}); + + // Act + const deductibleBox = wrapper.findComponent({ ref: 'deductibleBox' }); + + // Assert + expect(deductibleBox.exists()).toBe(true); + }); + test('Should render Site Footer', () => { + // Arrange + const { wrapper } = getMountedComponent({}); + + // Act + const siteFooter = wrapper.findComponent({ ref: 'siteFooter' }); + + // Assert + expect(siteFooter.exists()).toBe(true); + }); + }); +});