DigitalConsumer.ISS/src/layouts/tpa-confirmation/tpa-confirmation.spec.js
2024-02-07 15:05:46 -05:00

389 lines
14 KiB
JavaScript

// Components
import tpaConfirmation from '@/layouts/tpa-confirmation/tpa-confirmation.vue';
// Supporting Files
import { getMountOptions } from '@/helpers/unit-test-helper.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';
import bailoutMessage from '@/constants/bailoutMessage';
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(),
navigateToExternalUrl: 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('If Advanced flow, should display Site Footer', () => {
// Arrange
const carrierReturnUrl = 'testURL';
const initialStore = {
issConfig: {
successReturnURL: carrierReturnUrl
}
};
const { wrapper } = getMountedComponent(initialStore);
// Act
const siteFooter = wrapper.findComponent({ ref: 'siteFooter' });
// Assert
expect(siteFooter.exists()).toBe(true);
});
test('If Essential flow, should not display Site Footer', () => {
// Arrange
const { wrapper } = getMountedComponent();
// Act
const siteFooter = wrapper.findComponent({ ref: 'siteFooter' });
// Assert
expect(siteFooter.isVisible()).toBe(false);
});
});
describe('Computed properties', () => {
describe('Deductible Box value', () => {
test('Should return "Verifying coverage" when isVerified false', () => {
// Arrange
const initialStore = {
order: {
payment: {
insuranceCoverage: { isVerified: false }
}
}
};
const { wrapper } = getMountedComponent(initialStore);
const expected = 'Verifying coverage';
// Assert
expect(wrapper.vm.deductibleBoxValue).toBe(expected);
});
test('Should return deductible value when isVerified true', () => {
// Arrange
const currentDeductible = '500';
const initialStore = {
order: {
payment: {
insuranceCoverage: { isVerified: true }
},
currentDeductible
}
};
const { wrapper } = getMountedComponent(initialStore);
const notExpected = 'Verifying coverage';
// Assert
expect(wrapper.vm.deductibleBoxValue).not.toBe(notExpected);
});
});
});
describe('Methods', () => {
describe('getCustomValueFromString', () => {
describe('with argument deductibleAboveZero', () => {
test.each([
[false],
[true]
])(
'returns false when isVerified %p and currentDeductible is zero',
(isVerified) => {
// Arrange
const initialStore = {
order: {
payment: {
insuranceCoverage: { isVerified }
},
currentDeductible: 0
}
};
const { wrapper } = getMountedComponent(initialStore);
const argument = 'deductibleAboveZero';
// Act
const result = wrapper.vm.getCustomValueFromString(argument);
// Assert
expect(result).toBe(false);
}
);
test.each([
[true, true],
[false, false]
])(
'returns %p when isVerified %p and currentDeductible is not zero',
(expected, isVerified) => {
// Arrange
const initialStore = {
order: {
payment: {
insuranceCoverage: { isVerified }
},
currentDeductible: 500
}
};
const { wrapper } = getMountedComponent(initialStore);
const argument = 'deductibleAboveZero';
// Act
const result = wrapper.vm.getCustomValueFromString(argument);
// Assert
expect(result).toBe(expected);
}
);
});
describe('with argument zeroDeductible', () => {
test.each([
[true, true],
[false, false]
])(
'returns %p when isVerified is %p currentDeductible is zero',
(expected, isVerified) => {
// Arrange
const initialStore = {
order: {
payment: {
insuranceCoverage: { isVerified }
},
currentDeductible: 0
}
};
const { wrapper } = getMountedComponent(initialStore);
const argument = 'zeroDeductible';
// Act
const result = wrapper.vm.getCustomValueFromString(argument);
// Assert
expect(result).toBe(expected);
}
);
test.each([
[false],
[true]
])(
'returns false when isVerified is %p currentDeductible is not zero',
(isVerified) => {
// Arrange
const initialStore = {
order: {
payment: {
insuranceCoverage: { isVerified }
},
currentDeductible: 250
}
};
const { wrapper } = getMountedComponent(initialStore);
const argument = 'zeroDeductible';
// Act
const result = wrapper.vm.getCustomValueFromString(argument);
// Assert
expect(result).toBe(false);
}
);
});
describe('with argument verifyingCoverage', () => {
test.each([
[true, false],
[false, true]
])(
'with argument verifyingCoverage returns %p when isVerified %p',
(expected, isVerified) => {
// Arrange
const initialStore = {
order: {
payment: {
insuranceCoverage: { isVerified }
},
currentDeductible: 26
}
};
const { wrapper } = getMountedComponent(initialStore);
const argument = 'verifyingCoverage';
// Act
const result = wrapper.vm.getCustomValueFromString(argument);
// Assert
expect(result).toBe(expected);
}
);
});
});
describe('setBailoutInfo', () => {
test('setBailout method is called when routerLink clicked', async () => {
// Arrange
const { wrapper } = getMountedComponent({});
const contactCarrierText = wrapper.get('#contactCarrierText');
// Act
await contactCarrierText.trigger('click');
// Assert
expect(wrapper.vm.mainStore.setBailout).toHaveBeenCalledWith(
wrapper.vm.$router.currentRoute,
bailoutMessage.RequestCallback
);
});
});
describe('Navigation', () => {
test('If Advanced flow, forward button action navigates to carrier URL', () => {
// Arrange
const carrierReturnUrl = 'testURL';
const initialStore = {
issConfig: {
successReturnURL: carrierReturnUrl
}
};
const { wrapper } = getMountedComponent(initialStore);
// Act
wrapper.vm.forwardButtonAction();
// Assert
expect(wrapper.vm.$router.navigateToExternalUrl).toHaveBeenCalledWith(carrierReturnUrl);
});
});
});
});