From 66e5996834397e68579ac6ac06f249d95abedaa3 Mon Sep 17 00:00:00 2001 From: Michaela Brydon Date: Wed, 27 Mar 2024 14:09:09 -0400 Subject: [PATCH] Finishing tests --- src/helpers/price-calculator.spec.js | 2 +- .../cart-dropdown/cart-dropdown.spec.js | 340 ++++++++++++++++-- .../cart-dropdown/cart-dropdown.vue | 23 +- .../coverage-statement.spec.js | 2 +- .../coverage-statement/coverage-statement.vue | 2 +- 5 files changed, 331 insertions(+), 38 deletions(-) diff --git a/src/helpers/price-calculator.spec.js b/src/helpers/price-calculator.spec.js index 4d09128b..5ef5669d 100644 --- a/src/helpers/price-calculator.spec.js +++ b/src/helpers/price-calculator.spec.js @@ -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', () => { diff --git a/src/iss-components/cart-dropdown/cart-dropdown.spec.js b/src/iss-components/cart-dropdown/cart-dropdown.spec.js index 6515d11b..ac28476e 100644 --- a/src/iss-components/cart-dropdown/cart-dropdown.spec.js +++ b/src/iss-components/cart-dropdown/cart-dropdown.spec.js @@ -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 diff --git a/src/iss-components/cart-dropdown/cart-dropdown.vue b/src/iss-components/cart-dropdown/cart-dropdown.vue index c714da37..e50d73e7 100644 --- a/src/iss-components/cart-dropdown/cart-dropdown.vue +++ b/src/iss-components/cart-dropdown/cart-dropdown.vue @@ -58,7 +58,7 @@ :key="i" class="packaged-cart-item">
- {{ item.name }} + {{ item?.name ?? '' }}
@@ -85,8 +85,8 @@
- {{ mobileFeeCartItem.name }} - {{ getDisplayed(mobileFeeCartItem.subTotal) }} + {{ mobileFeeCartItem?.name ?? '' }} + {{ getDisplayed(mobileFeeCartItem?.subTotal ?? 0) }}
@@ -100,7 +100,7 @@ @@ -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 diff --git a/src/layouts/coverage-statement/coverage-statement.spec.js b/src/layouts/coverage-statement/coverage-statement.spec.js index 760d8f5b..91ac7ab7 100644 --- a/src/layouts/coverage-statement/coverage-statement.spec.js +++ b/src/layouts/coverage-statement/coverage-statement.spec.js @@ -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); diff --git a/src/layouts/coverage-statement/coverage-statement.vue b/src/layouts/coverage-statement/coverage-statement.vue index 014e11a2..1da5f638 100644 --- a/src/layouts/coverage-statement/coverage-statement.vue +++ b/src/layouts/coverage-statement/coverage-statement.vue @@ -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';