Finishing tests

This commit is contained in:
Michaela Brydon 2024-03-27 14:09:09 -04:00
parent ef55856d02
commit 66e5996834
5 changed files with 331 additions and 38 deletions

View file

@ -1,4 +1,4 @@
import getPriceOfLineItems from "@/helpers/price-calculator.js";
import getPriceOfLineItems from '@/helpers/price-calculator.js';
describe('getPriceOfLineItems', () => {
test('Returns zero when no line items', () => {

View file

@ -9,19 +9,21 @@ import coverageStatuses from '@/constants/coverage-statuses';
import { formatAmountInDollars } from '@/helpers/text-helper.js';
import partTypeStrings from '@/constants/part-type-strings';
import { getHighestFullySatisfiedTier, getPackageContents } from '@/helpers/service-package-helper.js';
import getPriceOfLineItems from '@/helpers/price-calculator.js';
const VERIFYING_COVERAGE = 'Verifying coverage';
jest.mock('@/helpers/text-helper', () => ({
formatAmountInDollars: jest.fn()
}));
jest.mock('@/helpers/price-calculator.js', () => jest.fn());
jest.mock('@/helpers/service-package-helper', () => ({
getHighestFullySatisfiedTier: jest.fn(),
getPackageContents: jest.fn()
}));
function getMountedComponent(mainInitialState = {}, initialData = {}, propsData = {}, mockMixin = {}) {
function getMountedComponent(mainInitialState = {}, initialData = {}, propsData = {}) {
const mountOptions = getMountOptions({
router: {
navigate: jest.fn()
@ -185,7 +187,7 @@ describe('cart-dropdown component', () => {
order: {
lineItems: {
supportingItems: [{
partType: partTypeStrings.REPLACE_FEE
partType: partTypeStrings.RECYCLE_FEE
}]
}
}
@ -621,8 +623,9 @@ describe('cart-dropdown component', () => {
});
test('returns front wiper when front wiper included in types', () => {
// Arrange
const packageContents = [partTypeStrings.FRONT_WIPER];
getPackageContents.mockImplementationOnce(() => packageContents);
const frontWiperPartType = partTypeStrings.FRONT_WIPER;
const packageContents = [frontWiperPartType];
getPackageContents.mockImplementation(() => packageContents);
const mountOptions = getMountOptions({
router: { navigate: jest.fn() }
@ -630,16 +633,32 @@ describe('cart-dropdown component', () => {
const expectedName = 'some name';
const vapsItemDescriptions = [
{
Name: partTypeStrings.FRONT_WIPER,
Name: frontWiperPartType,
Text: expectedName
}
];
const widgetName = 'VapsItemDescriptions';
const mockMixin = {
methods: {
getCmsContent: jest.fn(() => vapsItemDescriptions)
getCmsContent: jest.fn((widget, _) => (widget === widgetName ? vapsItemDescriptions : []))
}
};
mountOptions.mixins = [mockMixin];
const storeData = {
order: {
lineItems: {
vaps: [{ partType: frontWiperPartType }]
}
}
};
const testingPinia = createTestingPinia({
initialState: {
main: storeData
}
});
useMainStore(testingPinia);
mountOptions.global.plugins = [testingPinia];
const wrapper = shallowMount(cartDropdown, mountOptions);
// Act
@ -651,7 +670,8 @@ describe('cart-dropdown component', () => {
});
test('returns rear wiper when rear wiper included in types', () => {
// Arrange
const packageContents = [partTypeStrings.REAR_WIPER];
const rearWiperPartType = partTypeStrings.REAR_WIPER;
const packageContents = [rearWiperPartType];
getPackageContents.mockImplementationOnce(() => packageContents);
const mountOptions = getMountOptions({
@ -660,7 +680,7 @@ describe('cart-dropdown component', () => {
const expectedName = 'some other name';
const vapsItemDescriptions = [
{
Name: partTypeStrings.REAR_WIPER,
Name: rearWiperPartType,
Text: expectedName
}
];
@ -670,6 +690,21 @@ describe('cart-dropdown component', () => {
}
};
mountOptions.mixins = [mockMixin];
const storeData = {
order: {
lineItems: {
vaps: [{ partType: rearWiperPartType }]
}
}
};
const testingPinia = createTestingPinia({
initialState: {
main: storeData
}
});
useMainStore(testingPinia);
mountOptions.global.plugins = [testingPinia];
const wrapper = shallowMount(cartDropdown, mountOptions);
// Act
@ -681,7 +716,8 @@ describe('cart-dropdown component', () => {
});
test('returns rain defense when rain defense included in types', () => {
// Arrange
const packageContents = [partTypeStrings.RAIN_DEFENSE];
const rainDefensePartType = partTypeStrings.RAIN_DEFENSE;
const packageContents = [rainDefensePartType];
getPackageContents.mockImplementationOnce(() => packageContents);
const mountOptions = getMountOptions({
@ -690,7 +726,7 @@ describe('cart-dropdown component', () => {
const expectedName = 'different name';
const vapsItemDescriptions = [
{
Name: partTypeStrings.RAIN_DEFENSE,
Name: rainDefensePartType,
Text: expectedName
}
];
@ -700,6 +736,21 @@ describe('cart-dropdown component', () => {
}
};
mountOptions.mixins = [mockMixin];
const storeData = {
order: {
lineItems: {
vaps: [{ partType: rainDefensePartType }]
}
}
};
const testingPinia = createTestingPinia({
initialState: {
main: storeData
}
});
useMainStore(testingPinia);
mountOptions.global.plugins = [testingPinia];
const wrapper = shallowMount(cartDropdown, mountOptions);
// Act
@ -711,7 +762,10 @@ describe('cart-dropdown component', () => {
});
test('returns expected when all included in types', () => {
// Arrange
const packageContents = [partTypeStrings.FRONT_WIPER, partTypeStrings.REAR_WIPER, partTypeStrings.RAIN_DEFENSE];
const frontWiperPartType = partTypeStrings.FRONT_WIPER;
const rearWiperPartType = partTypeStrings.REAR_WIPER;
const rainDefensePartType = partTypeStrings.RAIN_DEFENSE;
const packageContents = [frontWiperPartType, rearWiperPartType, rainDefensePartType];
getPackageContents.mockImplementationOnce(() => packageContents);
const mountOptions = getMountOptions({
@ -722,15 +776,15 @@ describe('cart-dropdown component', () => {
const expectedRainDefenseName = 'rain defense';
const vapsItemDescriptions = [
{
Name: partTypeStrings.FRONT_WIPER,
Name: frontWiperPartType,
Text: expectedFrontWiperName
},
{
Name: partTypeStrings.REAR_WIPER,
Name: rearWiperPartType,
Text: expectedRearWiperName
},
{
Name: partTypeStrings.RAIN_DEFENSE,
Name: rainDefensePartType,
Text: expectedRainDefenseName
}
];
@ -740,6 +794,25 @@ describe('cart-dropdown component', () => {
}
};
mountOptions.mixins = [mockMixin];
const storeData = {
order: {
lineItems: {
vaps: [
{ partType: frontWiperPartType },
{ partType: rearWiperPartType },
{ partType: rainDefensePartType }
]
}
}
};
const testingPinia = createTestingPinia({
initialState: {
main: storeData
}
});
useMainStore(testingPinia);
mountOptions.global.plugins = [testingPinia];
const wrapper = shallowMount(cartDropdown, mountOptions);
// Act
@ -852,7 +925,7 @@ describe('cart-dropdown component', () => {
expect(result).toBe(expected);
});
});
describe.only('recycleFeeCartItem', () => {
describe('recycleFeeCartItem', () => {
test.each([
[null], [undefined], [[]]
])('returns null when supporting items %p', (supportingItems) => {
@ -926,7 +999,7 @@ describe('cart-dropdown component', () => {
expect(result.name).toBe(expectedName);
});
});
describe.only('mobileFeeCartItem', () => {
describe('mobileFeeCartItem', () => {
test.each([[null], [undefined]])('returns null when mobile fee %p', (mobileFee) => {
// Arrange
const storeData = {
@ -1106,14 +1179,235 @@ describe('cart-dropdown component', () => {
expect(result).toBe(dollarAmount);
});
});
// TODO
describe('getCartItemForVapsPart', () => {
test('returns item with no label when no descriptions returned', () => {});
test('returns item with no label when type not in descriptions', () => {});
test('returns item with no label when description text not defined', () => {});
test('returns expected label when vaps description text set', () => {});
test.each([[undefined], [null], []])('returns item with no line items when vapsInOrder %p', (vapsInOrder) => {});
test('returns item with expected lineItems when part type found in vapsInOrder', () => {});
test('returns item with no label when no descriptions returned', () => {
// Arrange
const mountOptions = getMountOptions({
router: { navigate: jest.fn() }
});
const descriptions = [];
const widgetName = 'VapsItemDescriptions';
const mockMixin = {
methods: {
getCmsContent: jest.fn((widget, _) => (widget === widgetName ? descriptions : []))
}
};
mountOptions.mixins = [mockMixin];
const part = 'some part';
const storeData = {
order: {
lineItems: {
vaps: [{ partType: part }]
}
}
};
const testingPinia = createTestingPinia({
initialState: {
main: storeData
}
});
useMainStore(testingPinia);
mountOptions.global.plugins = [testingPinia];
const wrapper = shallowMount(cartDropdown, mountOptions);
const expectedName = '';
// Act
const result = wrapper.vm.getCartItemForVapsPart(part);
// Assert
expect(result.name).toBe(expectedName);
});
test('returns item with no label when type not in descriptions', () => {
// Arrange
const mountOptions = getMountOptions({
router: { navigate: jest.fn() }
});
const descriptions = [{
Name: 'not part name'
}];
const widgetName = 'VapsItemDescriptions';
const mockMixin = {
methods: {
getCmsContent: jest.fn((widget, _) => (widget === widgetName ? descriptions : []))
}
};
mountOptions.mixins = [mockMixin];
const part = 'some part';
const storeData = {
order: {
lineItems: {
vaps: [{ partType: part }]
}
}
};
const testingPinia = createTestingPinia({
initialState: {
main: storeData
}
});
useMainStore(testingPinia);
mountOptions.global.plugins = [testingPinia];
const wrapper = shallowMount(cartDropdown, mountOptions);
const expectedName = '';
// Act
const result = wrapper.vm.getCartItemForVapsPart(part);
// Assert
expect(result.name).toBe(expectedName);
});
test('returns item with no label when description text not defined', () => {
// Arrange
const mountOptions = getMountOptions({
router: { navigate: jest.fn() }
});
const part = 'some part';
const descriptions = [{
Name: part
}];
const widgetName = 'VapsItemDescriptions';
const mockMixin = {
methods: {
getCmsContent: jest.fn((widget, _) => (widget === widgetName ? descriptions : []))
}
};
mountOptions.mixins = [mockMixin];
const storeData = {
order: {
lineItems: {
vaps: [{ partType: part }]
}
}
};
const testingPinia = createTestingPinia({
initialState: {
main: storeData
}
});
useMainStore(testingPinia);
mountOptions.global.plugins = [testingPinia];
const wrapper = shallowMount(cartDropdown, mountOptions);
const expectedName = '';
// Act
const result = wrapper.vm.getCartItemForVapsPart(part);
// Assert
expect(result.name).toBe(expectedName);
});
test('returns expected label when vaps description text set', () => {
// Arrange
const mountOptions = getMountOptions({
router: { navigate: jest.fn() }
});
const part = 'some part';
const expectedName = 'name to show up';
const descriptions = [{
Name: part,
Text: expectedName
}];
const widgetName = 'VapsItemDescriptions';
const mockMixin = {
methods: {
getCmsContent: jest.fn((widget, _) => (widget === widgetName ? descriptions : []))
}
};
mountOptions.mixins = [mockMixin];
const storeData = {
order: {
lineItems: {
vaps: [{ partType: part }]
}
}
};
const testingPinia = createTestingPinia({
initialState: {
main: storeData
}
});
useMainStore(testingPinia);
mountOptions.global.plugins = [testingPinia];
const wrapper = shallowMount(cartDropdown, mountOptions);
// Act
const result = wrapper.vm.getCartItemForVapsPart(part);
// Assert
expect(result.name).toBe(expectedName);
});
test.each([
[undefined], [null]
])('returns null when vapsInOrder %p', async (vapsInOrder) => {
// Arrange
const mountOptions = getMountOptions({
router: { navigate: jest.fn() }
});
const part = 'some part';
const expectedName = 'name to show up';
const descriptions = [{
Name: part,
Text: expectedName
}];
const widgetName = 'VapsItemDescriptions';
const mockMixin = {
methods: {
getCmsContent: jest.fn((widget, _) => (widget === widgetName ? descriptions : []))
}
};
mountOptions.mixins = [mockMixin];
const storeData = {
order: {
lineItems: {
vaps: vapsInOrder
}
}
};
const testingPinia = createTestingPinia({
initialState: {
main: storeData
}
});
useMainStore(testingPinia);
mountOptions.global.plugins = [testingPinia];
const wrapper = shallowMount(cartDropdown, mountOptions);
// Act
const result = wrapper.vm.getCartItemForVapsPart(part);
// Assert
expect(result).toBe(null);
});
test('returns item with expected price when part type found in vapsInOrder', () => {
// Arrange
const mountOptions = getMountOptions({
router: { navigate: jest.fn() }
});
const part = 'some part';
const vaps = [{ partType: part }];
const storeData = {
order: {
lineItems: { vaps }
}
};
const testingPinia = createTestingPinia({
initialState: {
main: storeData
}
});
useMainStore(testingPinia);
mountOptions.global.plugins = [testingPinia];
const expectedSubtotal = 93;
getPriceOfLineItems.mockImplementation(() => expectedSubtotal);
const wrapper = shallowMount(cartDropdown, mountOptions);
// Act
const result = wrapper.vm.getCartItemForVapsPart(part);
// Assert
expect(result.subTotal).toBe(expectedSubtotal);
});
});
describe('removeItem', () => {
// TODO when written

View file

@ -58,7 +58,7 @@
:key="i"
class="packaged-cart-item">
<div class="py-1 d-flex justify-content-between align-items-center">
<span>{{ item.name }}</span>
<span>{{ item?.name ?? '' }}</span>
<textLink
v-if="!readOnly || !showAsPaid"
ref="removeLink"
@ -67,7 +67,7 @@
href="javascript:void(0)"
@clickEvent="removeItem">
<template #after-text>
<span class="sr-only">{{ item.name }}</span>
<span class="sr-only">{{ item?.name ?? '' }}</span>
</template>
</textLink>
</div>
@ -85,8 +85,8 @@
<div
id="mobile-fee-item"
class="d-flex justify-content-between align-items-center">
<span id="mobile-fee-label">{{ mobileFeeCartItem.name }}</span>
<span id="mobile-fee-value">{{ getDisplayed(mobileFeeCartItem.subTotal) }}</span>
<span id="mobile-fee-label">{{ mobileFeeCartItem?.name ?? '' }}</span>
<span id="mobile-fee-value">{{ getDisplayed(mobileFeeCartItem?.subTotal ?? 0) }}</span>
</div>
</div>
@ -100,7 +100,7 @@
<span id="recycle-fee-label">
<textLink
linkType="text"
:text="recycleFeeCartItem.name"
:text="recycleFeeCartItem?.name ?? ''"
href="javascript:void(0)"
@clickEvent="openModal(recyclingModalCmsWidgetName)" />
</span>
@ -250,13 +250,13 @@ export default {
this.servicePackageTier
) ?? [];
const items = [];
if (packageContentTypes.includes(partTypeStrings.FRONT_WIPER)) {
if (packageContentTypes.includes(partTypeStrings.FRONT_WIPER) ?? this.frontWipersCartItem) {
items.push(this.frontWipersCartItem);
}
if (packageContentTypes.includes(partTypeStrings.REAR_WIPER)) {
if (packageContentTypes.includes(partTypeStrings.REAR_WIPER) ?? this.rearWipersCartItem) {
items.push(this.rearWipersCartItem);
}
if (packageContentTypes.includes(partTypeStrings.RAIN_DEFENSE)) {
if (packageContentTypes.includes(partTypeStrings.RAIN_DEFENSE) ?? this.rainDefenseCartItem) {
items.push(this.rainDefenseCartItem);
}
return items;
@ -299,14 +299,13 @@ export default {
return '';
}
const currentPackage = this.servicePackageNames
?.find((entry) => entry.Name === this.servicePackageTier);
?.find((entry) => entry?.Name === this.servicePackageTier);
return currentPackage?.SubWidgetName ?? '';
},
recycleFeeCartItem() {
const recycleFeeLineItem = useMainStore().lineItems.supportingItems
?.find((lineItem) => lineItem.partType === partTypeStrings.RECYCLE_FEE);
console.log(`line item: ${JSON.stringify(recycleFeeLineItem)}`);
return recycleFeeLineItem
? this.getCartItem(
this.getCmsContent(this.widget.recycleFee, widgetFields.TEXT_BLOCK_WIDGET.TEXT),
@ -339,7 +338,7 @@ export default {
getCartItem(label, lineItems) {
let cartItem = null;
if (lineItems) {
if (lineItems && lineItems.length > 0) {
cartItem = {
name: label,
subTotal: getPriceOfLineItems(lineItems),
@ -368,7 +367,7 @@ export default {
return '';
}
const vapsTypeDescription = vapsItemDescriptions?.find((entry) => entry.Name === vapsType);
const vapsTypeDescription = vapsItemDescriptions?.find((entry) => entry?.Name === vapsType);
return vapsTypeDescription?.Text ?? '';
},
formatAmountInDollars

View file

@ -425,7 +425,7 @@ describe('coverageStatement.vue-working', () => {
// Assert
expect(result).toBeFalsy();
});
test('returns true when policyLookupSuccessful, isNoComp false, and deductible over service price', () => {
test('returns true when policyLookupSuccessful, isNoComp false, and deductible over service price', () => {
// Arrange
const { wrapper } = getMountedComponent(verifiedDeductibleStoreState);

View file

@ -130,7 +130,7 @@ import issPageValues from '@/router/router-constants/issPage-values';
import bailoutMessage from '@/constants/bailoutMessage';
import coverageStatuses from '@/constants/coverage-statuses';
import widgetFields from '@/constants/cms-widget-fields.js';
import getPriceOfLineItems from '@/helpers/price-calculator.js';
import { getPriceOfLineItems } from '@/helpers/price-calculator.js';
import { formatAmountInDollars } from '@/helpers/text-helper.js';
const SAFELITE_PROVIDER = 'Safelite';