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">