INSR-10489: Add tests related to benefit recal modal to schedule page
This commit is contained in:
parent
ca8d77d2c2
commit
1f7e5f10ec
1 changed files with 113 additions and 2 deletions
|
|
@ -13,6 +13,7 @@ jest.mock('@/helpers/cms-content-helper', () => ({
|
|||
}));
|
||||
|
||||
const RECAL_ACK_MODAL_REF_NAME = 'recalAckModal';
|
||||
const BENEFIT_RECAL_MODAL_REF_NAME = 'benefitRecalModal';
|
||||
|
||||
const mockMixin = {
|
||||
methods: {
|
||||
|
|
@ -74,6 +75,18 @@ const recalAckModalStub = {
|
|||
}
|
||||
};
|
||||
|
||||
const benefitRecalModalStub = {
|
||||
template: '<div></div>',
|
||||
methods: {
|
||||
openModal: jest.fn(),
|
||||
footerButtonClick: jest.fn()
|
||||
}
|
||||
};
|
||||
|
||||
const mockBenefitRecalModalContent = {
|
||||
HeaderText: 'Benefit Recalibration Modal Header'
|
||||
}
|
||||
|
||||
function getShallowMountedComponent(initialData = {}, methodToRun = () => {}) {
|
||||
const mountOptions = getMountOptions({
|
||||
router: {
|
||||
|
|
@ -85,7 +98,8 @@ function getShallowMountedComponent(initialData = {}, methodToRun = () => {}) {
|
|||
siteFooter: footerStub,
|
||||
loadingModal: loadingModalStub,
|
||||
serviceLocation: serviceLocationStub,
|
||||
recalAckModal: recalAckModalStub
|
||||
recalAckModal: recalAckModalStub,
|
||||
benefitRecalModal: benefitRecalModalStub
|
||||
};
|
||||
|
||||
methodToRun();
|
||||
|
|
@ -107,6 +121,16 @@ function getShallowMountedComponent(initialData = {}, methodToRun = () => {}) {
|
|||
configurable: true
|
||||
});
|
||||
|
||||
// Manually create the ref for benefitRecalModal since shallowMount doesn't populate it
|
||||
Object.defineProperty(wrapper.vm.$refs, BENEFIT_RECAL_MODAL_REF_NAME, {
|
||||
value: {
|
||||
openModal: jest.fn(),
|
||||
footerButtonClick: jest.fn()
|
||||
},
|
||||
writable: false,
|
||||
configurable: true
|
||||
});
|
||||
|
||||
// Manually create the ref for serviceLocation since shallowMount doesn't populate it
|
||||
Object.defineProperty(wrapper.vm.$refs, 'serviceLocation', {
|
||||
value: {
|
||||
|
|
@ -158,6 +182,9 @@ beforeEach(() => {
|
|||
lineItems: {
|
||||
glassParts: [],
|
||||
supportingItems: []
|
||||
},
|
||||
issConfig: {
|
||||
clientName: 'TestClient'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -390,4 +417,88 @@ describe('schedule page methods...', () => {
|
|||
// Assert
|
||||
expect(wrapper.vm.$router.navigate).toHaveBeenCalled();
|
||||
});
|
||||
test('backButtonAction opens benefitRecalModal when hasBenefitRecalModal returns true and benefitRecalModalAcknowledged is false', () => {
|
||||
// Arrange
|
||||
const { wrapper } = getShallowMountedComponent();
|
||||
wrapper.vm.getCmsContent = jest.fn().mockReturnValue('Benefit Recalibration Modal Header');
|
||||
wrapper.vm.benefitRecalModalAcknowledged = false;
|
||||
|
||||
// Act
|
||||
wrapper.vm.backButtonAction();
|
||||
|
||||
// Assert
|
||||
expect(wrapper.vm.$refs[BENEFIT_RECAL_MODAL_REF_NAME].openModal).toHaveBeenCalled();
|
||||
});
|
||||
test('backButtonAction pushes non-recalibration_version event when opening benefitRecalModal and hasRecalibrationPart is false', () => {
|
||||
// Arrange
|
||||
const { wrapper } = getShallowMountedComponent();
|
||||
wrapper.vm.getCmsContent = jest.fn().mockReturnValue('Benefit Recalibration Modal Header');
|
||||
wrapper.vm.benefitRecalModalAcknowledged = false;
|
||||
wrapper.vm.mainStore.lineItems.glassParts = [
|
||||
{
|
||||
partNumber: 'TEST123',
|
||||
requiresRecalibration: false
|
||||
}
|
||||
];
|
||||
wrapper.vm.pushEventToGA = jest.fn();
|
||||
|
||||
// Act
|
||||
wrapper.vm.backButtonAction();
|
||||
|
||||
// Assert
|
||||
expect(wrapper.vm.pushEventToGA).toHaveBeenCalledWith(
|
||||
'safelite_benefit_modal_displayed',
|
||||
wrapper.vm.mainStore.accountNameForEvents,
|
||||
'non-recalibration_version',
|
||||
true
|
||||
);
|
||||
});
|
||||
test('backButtonAction pushes recalibration_version event when opening benefitRecalModal and hasRecalibrationPart is true', () => {
|
||||
// Arrange
|
||||
const { wrapper } = getShallowMountedComponent();
|
||||
wrapper.vm.getCmsContent = jest.fn().mockReturnValue('Benefit Recalibration Modal Header');
|
||||
wrapper.vm.benefitRecalModalAcknowledged = false;
|
||||
wrapper.vm.mainStore.lineItems.glassParts = [
|
||||
{
|
||||
partNumber: 'TEST123',
|
||||
requiresRecalibration: true
|
||||
}
|
||||
];
|
||||
wrapper.vm.pushEventToGA = jest.fn();
|
||||
|
||||
// Act
|
||||
wrapper.vm.backButtonAction();
|
||||
|
||||
// Assert
|
||||
expect(wrapper.vm.pushEventToGA).toHaveBeenCalledWith(
|
||||
'safelite_benefit_modal_displayed',
|
||||
wrapper.vm.mainStore.accountNameForEvents,
|
||||
'recalibration_version',
|
||||
true
|
||||
);
|
||||
});
|
||||
test('backButtonAction navigates back when hasBenefitRecalModal is true and benefitRecalModalAcknowledged is true', () => {
|
||||
// Arrange
|
||||
const { wrapper } = getShallowMountedComponent();
|
||||
wrapper.vm.getCmsContent = jest.fn().mockReturnValue('Benefit Recalibration Modal Header');
|
||||
wrapper.vm.benefitRecalModalAcknowledged = true;
|
||||
wrapper.vm.navigateBack = jest.fn();
|
||||
|
||||
// Act
|
||||
wrapper.vm.backButtonAction();
|
||||
|
||||
// Assert
|
||||
expect(wrapper.vm.navigateBack).toHaveBeenCalled();
|
||||
});
|
||||
test('backButtonAction navigates back when hasBenefitRecalModal is false', () => {
|
||||
// Arrange
|
||||
const { wrapper } = getShallowMountedComponent();
|
||||
wrapper.vm.navigateBack = jest.fn();
|
||||
|
||||
// Act
|
||||
wrapper.vm.backButtonAction();
|
||||
|
||||
// Assert
|
||||
expect(wrapper.vm.navigateBack).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
Loading…
Reference in a new issue