Adding tests

This commit is contained in:
Michaela Brydon 2024-04-12 13:20:49 -04:00
parent e3852f2b7b
commit 1e80a0b486
4 changed files with 387 additions and 204 deletions

View file

@ -313,115 +313,6 @@ describe('cart-dropdown component', () => {
}); });
}); });
describe('computed', () => { describe('computed', () => {
describe('isUnverified', () => {
test('returns false when no comp', () => {
// Arrange
const storeData = {
order: {
policy: {
isITAC: false,
noCoverage: true
},
currentDeductible: null
}
};
const { wrapper } = getMountedComponent(storeData);
// Act
const result = wrapper.vm.isUnverified;
// Assert
expect(result).toBeFalsy();
});
test('returns false when itac', () => {
// Arrange
const storeData = {
order: {
payment: {
insuranceCoverage: {
coverageStatus: coverageStatuses.PENDING
}
},
policy: {
isITAC: true
},
currentDeductible: null
}
};
const { wrapper } = getMountedComponent(storeData);
// Act
const result = wrapper.vm.isUnverified;
// Assert
expect(result).toBeFalsy();
});
test('returns false when deductible not null and verified coverage status', () => {
// Arrange
const storeData = {
order: {
payment: {
insuranceCoverage: {
coverageStatus: coverageStatuses.VERIFIED
}
},
policy: {
isITAC: false
},
currentDeductible: 23
}
};
const { wrapper } = getMountedComponent(storeData);
// Act
const result = wrapper.vm.isUnverified;
// Assert
expect(result).toBeFalsy();
});
test('returns true when not no comp, not itac, and deductible is null', () => {
// Arrange
const storeData = {
order: {
policy: {
isITAC: false,
noCoverage: false
},
currentDeductible: null
}
};
const { wrapper } = getMountedComponent(storeData);
// Act
const result = wrapper.vm.isUnverified;
// Assert
expect(result).toBeTruthy();
});
test('returns true when not no comp, not itac, and coverage status is not verified', () => {
// Arrange
const storeData = {
order: {
payment: {
insuranceCoverage: {
coverageStatus: coverageStatuses.PENDING
}
},
policy: {
isITAC: false
},
currentDeductible: 12
}
};
const { wrapper } = getMountedComponent(storeData);
// Act
const result = wrapper.vm.isUnverified;
// Assert
expect(result).toBeTruthy();
});
});
describe('amountDue', () => { describe('amountDue', () => {
test('returns 0 when showAsPaid is true', () => { test('returns 0 when showAsPaid is true', () => {
// Arrange // Arrange
@ -556,15 +447,22 @@ describe('cart-dropdown component', () => {
// Arrange // Arrange
const storeData = { const storeData = {
order: { order: {
policyLookupSuccessful: true,
currentDeductible: 250,
lineItems: { lineItems: {
glassParts: null, glassParts: null,
otherParts: null, otherParts: null,
supportingItems: null, supportingItems: null,
vaps: null vaps: null
},
payment: {
insuranceCoverage: { isVerified: true }
} }
},
issConfig: {
isClaimRegistrationRequired: true
} }
}; };
const { wrapper } = getMountedComponent(storeData); const { wrapper } = getMountedComponent(storeData);
// Act // Act
@ -578,6 +476,8 @@ describe('cart-dropdown component', () => {
// Arrange // Arrange
const storeData = { const storeData = {
order: { order: {
policyLookupSuccessful: true,
currentDeductible: 250,
lineItems: { lineItems: {
glassParts: [ glassParts: [
{ partType: 'mock', salesTax: null }, { partType: 'mock', salesTax: null },
@ -591,7 +491,13 @@ describe('cart-dropdown component', () => {
{ partType: 'mock', salesTax: null }, { partType: 'mock', salesTax: null },
{ partType: 'mock', salesTax: undefined } { partType: 'mock', salesTax: undefined }
] ]
},
payment: {
insuranceCoverage: { isVerified: true }
} }
},
issConfig: {
isClaimRegistrationRequired: true
} }
}; };
const { wrapper } = getMountedComponent(storeData); const { wrapper } = getMountedComponent(storeData);
@ -606,6 +512,8 @@ describe('cart-dropdown component', () => {
// Arrange // Arrange
const storeData = { const storeData = {
order: { order: {
policyLookupSuccessful: true,
currentDeductible: 250,
lineItems: { lineItems: {
glassParts: [{ partType: 'mock', salesTax: 10 }], glassParts: [{ partType: 'mock', salesTax: 10 }],
supportingItems: [ supportingItems: [
@ -619,10 +527,11 @@ describe('cart-dropdown component', () => {
vaps: [] vaps: []
}, },
payment: { payment: {
insuranceCoverage: { insuranceCoverage: { isVerified: false }
isVerified: false
}
} }
},
issConfig: {
isClaimRegistrationRequired: true
} }
}; };
const { wrapper } = getMountedComponent(storeData); const { wrapper } = getMountedComponent(storeData);
@ -636,15 +545,25 @@ describe('cart-dropdown component', () => {
test('Returns sum of vaps sales tax when coverage is unverified and order has vaps.', () => { test('Returns sum of vaps sales tax when coverage is unverified and order has vaps.', () => {
// Arrange // Arrange
const storeData = useMainStore().$state; const storeData = {
storeData.order.lineItems.glassParts = [ order: {
{ partType: 'mock', salesTax: 10 } policyLookupSuccessful: true,
]; currentDeductible: 250,
storeData.order.lineItems.vaps = [ lineItems: {
{ partType: 'mock', salesTax: 1 }, glassParts: [{ partType: 'mock', salesTax: 10 }],
{ partType: 'mock', salesTax: 2 } vaps: [
]; { partType: 'mock', salesTax: 1 },
storeData.order.payment.insuranceCoverage.isVerified = false; { partType: 'mock', salesTax: 2 }
]
},
payment: {
insuranceCoverage: { isVerified: false }
}
},
issConfig: {
isClaimRegistrationRequired: true
}
};
const { wrapper } = getMountedComponent(storeData); const { wrapper } = getMountedComponent(storeData);
@ -657,16 +576,30 @@ describe('cart-dropdown component', () => {
test('Returns Recycle Fee tax when coverage is Verified-Deductible, replace service, and no vaps.', () => { test('Returns Recycle Fee tax when coverage is Verified-Deductible, replace service, and no vaps.', () => {
// Arrange // Arrange
const storeData = useMainStore().$state; const storeData = {
storeData.order.currentDeductible = 250; order: {
storeData.order.lineItems.glassParts = [ policyLookupSuccessful: true,
{ partType: 'mock', salesTax: 10, sellingPrice: 150 } currentDeductible: 250,
]; lineItems: {
storeData.order.lineItems.supportingItems = [ glassParts: [{ partType: 'mock', salesTax: 10, sellingPrice: 150 }],
{ partNumber: partNumberStrings.RECYCLE_FEE, partType: 'mock', salesTax: 10, sellingPrice: 39.99 } supportingItems: [
]; {
storeData.order.lineItems.vaps = null; partNumber: partNumberStrings.RECYCLE_FEE,
storeData.order.payment.insuranceCoverage.isVerified = true; partType: 'mock',
salesTax: 10,
sellingPrice: 39.99
}
],
vaps: null
},
payment: {
insuranceCoverage: { isVerified: true }
}
},
issConfig: {
isClaimRegistrationRequired: true
}
};
const { wrapper } = getMountedComponent(storeData); const { wrapper } = getMountedComponent(storeData);
@ -679,24 +612,30 @@ describe('cart-dropdown component', () => {
test('Returns sum of vaps + recycle fee sales tax when Verified-Deductible, replace service, and has vaps.', () => { test('Returns sum of vaps + recycle fee sales tax when Verified-Deductible, replace service, and has vaps.', () => {
// Arrange // Arrange
const storeData = useMainStore().$state; const storeData = {
storeData.order.currentDeductible = 250; order: {
storeData.order.lineItems.glassParts = [ policyLookupSuccessful: true,
{ partType: 'mock', salesTax: 10, sellingPrice: 100 } currentDeductible: 250,
]; lineItems: {
storeData.order.lineItems.otherParts = [ glassParts: [{ partType: 'mock', salesTax: 10, sellingPrice: 100 }],
{ partType: 'mock', salesTax: 10, kitPrice: 100 } otherParts: [{ partType: 'mock', salesTax: 10, kitPrice: 100 }],
]; supportingItems: [
storeData.order.lineItems.supportingItems = [ { partNumber: partNumberStrings.RECYCLE_FEE, partType: 'mock', salesTax: 10, sellingPrice: 39.99 },
{ partNumber: partNumberStrings.RECYCLE_FEE, partType: 'mock', salesTax: 10, sellingPrice: 39.99 }, { partType: 'mock', salesTax: 10, kitPrice: 100 }
{ partType: 'mock', salesTax: 10, kitPrice: 100 } ],
]; vaps: [
storeData.order.lineItems.vaps = [ { partType: 'mock', salesTax: 2 },
{ partType: 'mock', salesTax: 2 }, { partType: 'mock', salesTax: 3 }
{ partType: 'mock', salesTax: 3 } ]
]; },
storeData.order.payment.insuranceCoverage.isVerified = true; payment: {
insuranceCoverage: { isVerified: true }
}
},
issConfig: {
isClaimRegistrationRequired: true
}
};
const { wrapper } = getMountedComponent(storeData); const { wrapper } = getMountedComponent(storeData);
// Act // Act
@ -708,23 +647,27 @@ describe('cart-dropdown component', () => {
test('Returns sum of sales tax when Verified-ITAC.', () => { test('Returns sum of sales tax when Verified-ITAC.', () => {
// Arrange // Arrange
const storeData = useMainStore().$state; const storeData = {
storeData.order.currentDeductible = 0; order: {
storeData.order.lineItems.glassParts = [ policyLookupSuccessful: true,
{ partType: 'mock', salesTax: 10, sellingPrice: 100 } currentDeductible: 0,
]; lineItems: {
storeData.order.lineItems.otherParts = [ glassParts: [{ partType: 'mock', salesTax: 10, sellingPrice: 100 }],
{ partType: 'mock', salesTax: 10, kitPrice: 100 } otherParts: [{ partType: 'mock', salesTax: 10, kitPrice: 100 }],
]; supportingItems: [{ partType: 'mock', salesTax: 10, kitPrice: 100 }],
storeData.order.lineItems.supportingItems = [ vaps: [{ partType: 'mock', salesTax: 5 }]
{ partType: 'mock', salesTax: 10, kitPrice: 100 } },
]; payment: {
storeData.order.lineItems.vaps = [ insuranceCoverage: { isVerified: true }
{ partType: 'mock', salesTax: 5 } },
]; policy: {
storeData.order.payment.insuranceCoverage.isVerified = true; isITAC: true
storeData.order.policy.isITAC = true; }
},
issConfig: {
isClaimRegistrationRequired: true
}
};
const { wrapper } = getMountedComponent(storeData); const { wrapper } = getMountedComponent(storeData);
// Act // Act
@ -736,23 +679,28 @@ describe('cart-dropdown component', () => {
test('Returns sum of sales tax when Verified-NoComp.', () => { test('Returns sum of sales tax when Verified-NoComp.', () => {
// Arrange // Arrange
const storeData = useMainStore().$state; const storeData = {
storeData.order.currentDeductible = 0; order: {
storeData.order.lineItems.glassParts = [ policyLookupSuccessful: true,
{ partType: 'mock', salesTax: 10, sellingPrice: 100 } currentDeductible: 0,
]; lineItems: {
storeData.order.lineItems.otherParts = [ glassParts: [{ partType: 'mock', salesTax: 10, sellingPrice: 100 }],
{ partType: 'mock', salesTax: 10, kitPrice: 100 } otherParts: [{ partType: 'mock', salesTax: 10, kitPrice: 100 }],
]; supportingItems: [{ partType: 'mock', salesTax: 10, kitPrice: 100 }],
storeData.order.lineItems.supportingItems = [ vaps: [{ partType: 'mock', salesTax: 5 }]
{ partType: 'mock', salesTax: 10, kitPrice: 100 } },
]; payment: {
storeData.order.lineItems.vaps = [ insuranceCoverage: { isVerified: true }
{ partType: 'mock', salesTax: 5 } },
]; policy: {
storeData.order.payment.insuranceCoverage.isVerified = true; noCoverage: true
storeData.order.policy.noCoverage = true; }
},
issConfig: {
isClaimRegistrationRequired: true,
enableNoCompQuote: true
}
};
const { wrapper } = getMountedComponent(storeData); const { wrapper } = getMountedComponent(storeData);
// Act // Act
@ -1791,21 +1739,19 @@ describe('cart-dropdown component', () => {
// Arrange // Arrange
const storeData = { const storeData = {
order: { order: {
payment: {
insuranceCoverage: {
coverageStatus: coverageStatuses.VERIFIED
}
},
policy: { policy: {
isITAC: false isITAC: false,
isNoComp: false
}, },
currentDeductible: 321 currentDeductible: 321,
policyLookupSuccessful: true
} }
}; };
const { wrapper } = getMountedComponent(storeData); const { wrapper } = getMountedComponent(storeData);
const amount = 123; const amount = 123;
const dollarAmount = '$84.00'; const dollarAmount = '$84.00';
formatAmountInDollars.mockImplementationOnce(() => dollarAmount); formatAmountInDollars
.mockImplementationOnce((value) => (value === amount ? dollarAmount : 1));
// Act // Act
const result = wrapper.vm.getDisplayed(amount); const result = wrapper.vm.getDisplayed(amount);

View file

@ -3,20 +3,28 @@ import paymentMethod from '@/layouts/payment-method/payment-method.vue';
// Supporting Files // Supporting Files
import { shallowMount } from '@vue/test-utils'; import { shallowMount } from '@vue/test-utils';
import { createTestingPinia } from '@pinia/testing';
import { getMountOptions } from '@/helpers/unit-test-helper.js'; import { getMountOptions } from '@/helpers/unit-test-helper.js';
import { useMainStore } from '@/store'; import { useMainStore, getDefaultState } from '@/store';
import issPageValues from '@/router/router-constants/issPage-values'; import issPageValues from '@/router/router-constants/issPage-values';
import { paymentMethods } from '@/constants/payment-method-constants'; import { paymentMethods } from '@/constants/payment-method-constants';
import queryStrings from '@/constants/query-strings'; import queryStrings from '@/constants/query-strings';
import { experimentSettings } from '@/constants/experiments'; import { experimentSettings } from '@/constants/experiments';
function setupMocks({ customMountOptions = {}, queryString }) { function setupMocks({ customMountOptions = {}, queryString }, mainInitialState = {}, customMixin = null) {
const mountOptions = getMountOptions({ const mountOptions = getMountOptions({
...customMountOptions, ...customMountOptions,
route: { query: { issPage: issPageValues.PAYMENT_METHOD, ...queryString }, params: {} } route: { query: { issPage: issPageValues.PAYMENT_METHOD, ...queryString }, params: {} }
}); });
const mockMixin = { const testingPinia = createTestingPinia({
initialState: {
main: mainInitialState
}
});
useMainStore(testingPinia);
const mockMixin = customMixin ?? {
methods: { methods: {
getSettingValue: jest.fn((settingName) => { getSettingValue: jest.fn((settingName) => {
if (settingName === experimentSettings.ISS_DISPLAY_PAY_IN_ADVANCE) { if (settingName === experimentSettings.ISS_DISPLAY_PAY_IN_ADVANCE) {
@ -28,6 +36,7 @@ function setupMocks({ customMountOptions = {}, queryString }) {
} }
}; };
mountOptions.global.plugins = [testingPinia];
mountOptions.global.mixins = [mockMixin]; mountOptions.global.mixins = [mockMixin];
const wrapper = shallowMount(paymentMethod, mountOptions); const wrapper = shallowMount(paymentMethod, mountOptions);
@ -35,13 +44,28 @@ function setupMocks({ customMountOptions = {}, queryString }) {
return wrapper; 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.vue', () => {
describe('Payment Method Type', () => { describe('Payment Method Type', () => {
test('getting payment method when method is pay later', async () => { test('getting payment method when method is pay later', async () => {
// Arrange // Arrange
const wrapper = setupMocks({});
const payLaterPaymentMethod = paymentMethods.PAY_AT_TIME_OF_SERVICE; const payLaterPaymentMethod = paymentMethods.PAY_AT_TIME_OF_SERVICE;
useMainStore().savePaymentMethodChoice(payLaterPaymentMethod); const store = {
order: {
payment: {
isPayInAdvance: true,
payInAdvanceType: payLaterPaymentMethod
}
}
};
const wrapper = setupMocks({}, store);
// Act // Act
const paymethod = wrapper.vm.getPaymentMethodFromStore(); const paymethod = wrapper.vm.getPaymentMethodFromStore();
@ -50,16 +74,22 @@ describe('payment-method.vue', () => {
expect(paymethod).toBe(payLaterPaymentMethod); expect(paymethod).toBe(payLaterPaymentMethod);
}); });
test('getting payment method when method is pay in advance', async () => { test('getting payment method when method is pay in advance', async () => {
// Arrange // Arrange
const wrapper = setupMocks({}); const store = {
const payInAdvancePaymentMethod = paymentMethods.CREDIT_CARD; order: {
useMainStore().savePaymentMethodChoice(payInAdvancePaymentMethod); payment: {
isPayInAdvance: false,
payInAdvanceType: null
}
}
};
const wrapper = setupMocks({}, store);
// Act // Act
const paymethod = wrapper.vm.getPaymentMethodFromStore(); const paymethod = wrapper.vm.getPaymentMethodFromStore();
// Assert // Assert
expect(paymethod).not.toBe(payInAdvancePaymentMethod); expect(paymethod).toBeNull();
}); });
}); });
@ -86,4 +116,138 @@ describe('payment-method.vue', () => {
expect(payInAdvanceErrorAlert.exists()).toBeFalsy(); 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
},
payment: {
insuranceCoverage: {
isVerified: true
}
},
currentDeductible: 123,
policyLookupSuccessful: true
},
issConfig: {
isClaimRegistrationRequired: true,
enableNoCompQuote: true
},
applicationUser: {
experiments: [
{
settings: {
ISSDisplayPIAInsurance_ISS: 'true'
}
}
]
}
};
});
test('returns true when policyLookupSuccessful false', () => {
// Arrange
store.order.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();
});
});
}); });

View file

@ -270,7 +270,7 @@ export const useMainStore = defineStore({
isITAC: (state) => !!state.order.policy.isITAC, isITAC: (state) => !!state.order.policy.isITAC,
isUnverified: (s) => { isUnverified: (s) => {
const { policyLookupSuccessful, payment, currentDeductible } = s.order; const { policyLookupSuccessful, payment, currentDeductible } = s.order;
const registerClaimSuccessful = payment.insuranceCoverage.isVerified; const registerClaimSuccessful = !!payment.insuranceCoverage.isVerified;
if (!policyLookupSuccessful) { if (!policyLookupSuccessful) {
return true; return true;
} }

View file

@ -1438,6 +1438,79 @@ describe('Store', () => {
}); });
}); });
describe('isUnverified', () => {
beforeEach(() => {
store.order.policy.isITAC = false;
store.order.policy.noCoverage = false;
store.order.payment.insuranceCoverage.isVerified = true;
store.order.currentDeductible = 123;
store.order.policyLookupSuccessful = true;
store.issConfig.isClaimRegistrationRequired = true;
store.issConfig.enableNoCompQuote = true;
});
it('returns true when policyLookupSuccessful false', () => {
// Arrange
store.order.policyLookupSuccessful = false;
// Act
const result = store.isUnverified;
// Assert
expect(result).toBeTruthy();
});
it('returns true when no comp and enableNoCompQuote false', () => {
// Arrange
store.order.policy.noCoverage = true;
store.issConfig.enableNoCompQuote = false;
// Act
const result = store.isUnverified;
// Assert
expect(result).toBeTruthy();
});
it('returns true when not no comp and currentDeductible null', () => {
// Arrange
store.order.policy.noCoverage = false;
store.order.currentDeductible = null;
// Act
const result = store.isUnverified;
// Assert
expect(result).toBeTruthy();
});
it('returns true when isClaimRegistrationRequired true and insurance coverage not verified', () => {
// Arrange
store.order.payment.insuranceCoverage.isVerified = false;
// Act
const result = store.isUnverified;
// Assert
expect(result).toBeTruthy();
});
it('returns false when no comp, enableNoCompQuote true, and currentDeductible null', () => {
// Arrange
store.order.policy.noCoverage = true;
store.order.currentDeductible = null;
store.issConfig.enableNoCompQuote = true;
// Act
const result = store.isUnverified;
// Assert
expect(result).toBeFalsy();
});
it('returns false when not no comp, currentDeductible not null', () => {
// Act
const result = store.isUnverified;
// Assert
expect(result).toBeFalsy();
});
});
describe('isMobileAppointment', () => { describe('isMobileAppointment', () => {
it('Should return true for mobile appointments', () => { it('Should return true for mobile appointments', () => {
// Arrange // Arrange