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

View file

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

View file

@ -425,7 +425,7 @@ describe('coverageStatement.vue-working', () => {
// Assert // Assert
expect(result).toBeFalsy(); 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 // Arrange
const { wrapper } = getMountedComponent(verifiedDeductibleStoreState); const { wrapper } = getMountedComponent(verifiedDeductibleStoreState);

View file

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