DigitalConsumer.ISS/src/layouts/payment-method/payment-method.spec.js
Michaela Brydon 4ac5b788c8 Fixing tests
2024-04-17 12:39:18 -04:00

254 lines
8.5 KiB
JavaScript

// Components
import paymentMethod from '@/layouts/payment-method/payment-method.vue';
// Supporting Files
import { shallowMount } from '@vue/test-utils';
import { createTestingPinia } from '@pinia/testing';
import { getMountOptions } from '@/helpers/unit-test-helper.js';
import { useMainStore, getDefaultState } from '@/store';
import issPageValues from '@/router/router-constants/issPage-values';
import { paymentMethods } from '@/constants/payment-method-constants';
import queryStrings from '@/constants/query-strings';
import { experimentSettings } from '@/constants/experiments';
function setupMocks({ customMountOptions = {}, queryString }, mainInitialState = {}, customMixin = null) {
const mountOptions = getMountOptions({
...customMountOptions,
route: { query: { issPage: issPageValues.PAYMENT_METHOD, ...queryString }, params: {} }
});
const testingPinia = createTestingPinia({
initialState: {
main: mainInitialState
}
});
useMainStore(testingPinia);
const mockMixin = customMixin ?? {
methods: {
getSettingValue: jest.fn((settingName) => {
if (settingName === experimentSettings.ISS_DISPLAY_PAY_IN_ADVANCE) {
return 'true';
}
return 'false';
})
}
};
mountOptions.global.plugins = [testingPinia];
mountOptions.global.mixins = [mockMixin];
const wrapper = shallowMount(paymentMethod, mountOptions);
return wrapper;
}
beforeEach(() => {
const store = useMainStore();
const defaultState = getDefaultState();
Object.keys(defaultState).forEach((key) => {
store[key] = defaultState[key];
});
});
describe('payment-method.vue', () => {
describe('Payment Method Type', () => {
test('getting payment method when method is pay later', async () => {
// Arrange
const payLaterMethod = paymentMethods.PAY_AT_TIME_OF_SERVICE;
const store = {
order: {
payment: {
isPayInAdvance: false,
payInAdvanceType: null
}
}
};
const wrapper = setupMocks({}, store);
// Act
const paymethod = wrapper.vm.getPaymentMethodFromStore();
// Assert
expect(paymethod).toBe(payLaterMethod);
});
test('getting payment method when method is pay in advance', async () => {
// Arrange
const payInAdvanceMethod = paymentMethods.CREDIT_CARD;
const store = {
order: {
payment: {
isPayInAdvance: true,
payInAdvanceType: payInAdvanceMethod
}
}
};
const wrapper = setupMocks({}, store);
// Act
const paymethod = wrapper.vm.getPaymentMethodFromStore();
// Assert
expect(paymethod).toBe(payInAdvanceMethod);
});
});
describe('Pay In Advance Error Alert', () => {
test('show pay in advance error alert when contained in querystring', () => {
// Arrange
const queryString = {
[queryStrings.DISPLAY_PAY_IN_ADVANCE_ALERT]: paymentMethods.AFTERPAY
};
const wrapper = setupMocks({ queryString });
// Assert
const payInAdvanceErrorAlert = wrapper.find('[name="payInAdvanceErrorAlert"]');
expect(payInAdvanceErrorAlert.exists()).toBeTruthy();
expect(payInAdvanceErrorAlert.isVisible()).toBeTruthy();
});
test('hide pay in advance error alert when not contained in querystring', () => {
// Arrange
const wrapper = setupMocks({});
// Assert
const payInAdvanceErrorAlert = wrapper.find('[name="payInAdvanceErrorAlert"]');
expect(payInAdvanceErrorAlert.exists()).toBeFalsy();
});
});
describe('isPayInAdvanceDisabled', () => {
let store = {};
let mixin = {
methods: {
getSettingValue: jest.fn((settingName) => {
if (settingName === experimentSettings.ISS_DISPLAY_PAY_IN_ADVANCE) {
return 'true';
}
return 'false';
})
}
};
beforeEach(() => {
store = {
order: {
policy: {
isITAC: false,
noCoverage: false,
policyLookupSuccessful: true
},
payment: {
insuranceCoverage: {
isVerified: true
}
},
currentDeductible: 123
},
issConfig: {
isClaimRegistrationRequired: true,
enableNoCompQuote: true
},
applicationUser: {
experiments: [
{
settings: {
ISSDisplayPIAInsurance_ISS: 'true'
}
}
]
}
};
});
test('returns true when policyLookupSuccessful false', () => {
// Arrange
store.order.policy.policyLookupSuccessful = false;
const wrapper = setupMocks({}, store, mixin);
// Act
const result = wrapper.vm.isPayInAdvanceDisabled;
// Assert
expect(result).toBeTruthy();
});
test('returns true when no comp and enableNoCompQuote false', () => {
// Arrange
store.order.policy.noCoverage = true;
store.issConfig.enableNoCompQuote = false;
const wrapper = setupMocks({}, store, mixin);
// Act
const result = wrapper.vm.isPayInAdvanceDisabled;
// Assert
expect(result).toBeTruthy();
});
test('returns true when not no comp and currentDeductible null', () => {
// Arrange
store.order.policy.noCoverage = false;
store.order.currentDeductible = null;
const wrapper = setupMocks({}, store, mixin);
// Act
const result = wrapper.vm.isPayInAdvanceDisabled;
// Assert
expect(result).toBeTruthy();
});
test('returns true when isClaimRegistrationRequired true and insurance coverage not verified', () => {
// Arrange
store.order.payment.insuranceCoverage.isVerified = false;
store.issConfig.isClaimRegistrationRequired = true;
const wrapper = setupMocks({}, store, mixin);
// Act
const result = wrapper.vm.isPayInAdvanceDisabled;
// Assert
expect(result).toBeTruthy();
});
test('returns false when no comp, enableNoCompQuote true, and currentDeductible null and pia enabled', () => {
// Arrange
store.order.policy.noCoverage = true;
store.issConfig.enableNoCompQuote = true;
store.order.currentDeductible = null;
const wrapper = setupMocks({}, store, mixin);
// Act
const result = wrapper.vm.isPayInAdvanceDisabled;
// Assert
expect(result).toBeFalsy();
});
test('returns false when not no comp, currentDeductible not null and pia enabled', () => {
// Arrange
const wrapper = setupMocks({}, store, mixin);
// Act
const result = wrapper.vm.isPayInAdvanceDisabled;
// Assert
expect(result).toBeFalsy();
});
test('returns true when pia not enabled', () => {
// Arrange
mixin = {
methods: {
getSettingValue: jest.fn((settingName) => {
if (settingName === experimentSettings.ISS_DISPLAY_PAY_IN_ADVANCE) {
return 'false';
}
return 'true';
})
}
};
const wrapper = setupMocks({}, store, mixin);
// Act
const result = wrapper.vm.isPayInAdvanceDisabled;
// Assert
expect(result).toBeTruthy();
});
});
});