From 58a0f3a64a354268adf5a2fbcf1a54b23024e1bf Mon Sep 17 00:00:00 2001 From: Adam Caouette Date: Tue, 23 Nov 2021 15:22:24 -0500 Subject: [PATCH] CSR-120: expand test coverage --- .../vehicle-banner/vehicle-banner.spec.js | 122 +++++++++++++++--- 1 file changed, 104 insertions(+), 18 deletions(-) diff --git a/src/common-components/vehicle-banner/vehicle-banner.spec.js b/src/common-components/vehicle-banner/vehicle-banner.spec.js index f002793a5..296f62e11 100644 --- a/src/common-components/vehicle-banner/vehicle-banner.spec.js +++ b/src/common-components/vehicle-banner/vehicle-banner.spec.js @@ -1,11 +1,23 @@ -import { shallowMount, enableAutoUnmount } from '@vue/test-utils'; +import { shallowMount } from '@vue/test-utils'; import vehicleBanner from './vehicle-banner'; import { getMountOptions } from "@/helpers/unit-test-helper.js"; import { storeActions } from "@/constants/store-actions"; describe('vehicleBanner', () => { - // Arrange - const mountOptions = getMountOptions({ + const $store = { + state: { + order: { + vehicle: { + vin: null, + year: null, + make: null, + model: null, + style: null + } + } + } + }; + const actionList = { actionList: [ { actionName: storeActions.LOOKUP_VEHICLE_BY_YMMS, @@ -30,33 +42,107 @@ describe('vehicleBanner', () => { } } ] - }); - enableAutoUnmount(afterEach) + }; - // Act - const wrapper = shallowMount(vehicleBanner, { - ...mountOptions - }); - - // Assert - it('renders the blurrycar image when vehicleImageSrc is not present', () => { + test('renders the blurrycar image when vehicleImageSrc is not present', async () => { + // Arrange + const mountOptions = getMountOptions(actionList); + mountOptions.global.mocks = { + ...mountOptions.global.mocks, + $store + } + // Act + const wrapper = shallowMount(vehicleBanner, { + ...mountOptions + }); + // Assert expect(wrapper.find('img').attributes('class')).toContain('blurrycar'); + wrapper.unmount(); }); - // Assert - it('does not render the blurrycar image when vehicleImageSrc exists', async () => { - await wrapper.setData({ 'vehicleImageSrc': 'https://s3.amazonaws.com/safelite-lab-vehicle-images/Evox/8963_cc0320_032_UG_white_2014_Ford_Focus_18029225538399034889.jpg' }); + test('does not render the blurrycar image when vehicleImageSrc exists', async () => { + // Arrange + const mountOptions = getMountOptions(actionList); + mountOptions.global.mocks = { + ...mountOptions.global.mocks, + $store + } + // Act + const wrapper = shallowMount(vehicleBanner, { + ...mountOptions, + data() { + return { + vehicleImageSrc: "https://s3.amazonaws.com/safelite-lab-vehicle-images/Evox/8963_cc0320_032_UG_white_2014_Ford_Focus_18029225538399034889.jpg" + } + } + }); + // Assert setTimeout(() => { expect(wrapper.find('img').attributes('class')).not.toContain('blurrycar'); }, 500); + wrapper.unmount(); }); - // Assert - it('does not render the blurrycar image when passedCarId is set', async () => { - await wrapper.setProps({ 'passedCarId': 'CR00068434' }); + test('does not render the blurrycar image when passedCarId is set', async () => { + // Arrange + const mountOptions = getMountOptions(actionList); + mountOptions.global.mocks = { + ...mountOptions.global.mocks, + $store, + } + // Act + const wrapper = shallowMount(vehicleBanner, { + ...mountOptions, + props: { + passedCarId: "CR00068434" + } + }); + // Assert setTimeout(() => { expect(wrapper.find('img').attributes('class')).not.toContain('blurrycar'); }, 500); + wrapper.unmount(); }); + test('does not render the blurrycar image when a YMMS object is found', async () => { + // Arrange + $store.state.order.vehicle.year = "2019" + $store.state.order.vehicle.make = "acura" + $store.state.order.vehicle.model = "rdx" + $store.state.order.vehicle.style = "4 door utility" + const mountOptions = getMountOptions(actionList); + mountOptions.global.mocks = { + ...mountOptions.global.mocks, + $store + } + // Act + const wrapper = shallowMount(vehicleBanner, { + ...mountOptions + }); + // Assert + setTimeout(() => { + expect(wrapper.find('img').attributes('class')).not.toContain('blurrycar'); + }, 500); + wrapper.unmount(); + + }); + + test('does not render the blurrycar image when a VIN is found', async () => { + // Arrange + $store.state.order.vehicle.vin = "1J4GW58S4XC541166"; + const mountOptions = getMountOptions(actionList); + mountOptions.global.mocks = { + ...mountOptions.global.mocks, + $store + } + // Act + const wrapper = shallowMount(vehicleBanner, { + ...mountOptions + }); + // Assert + setTimeout(() => { + expect(wrapper.find('img').attributes('class')).not.toContain('blurrycar'); + }, 500); + wrapper.unmount(); + }); });