diff --git a/src/commonComponents/vehicleBanner/vehicleBanner.spec.js b/src/commonComponents/vehicleBanner/vehicleBanner.spec.js index c8bcede15..00f9bec45 100644 --- a/src/commonComponents/vehicleBanner/vehicleBanner.spec.js +++ b/src/commonComponents/vehicleBanner/vehicleBanner.spec.js @@ -1,56 +1,52 @@ -import { mount, flushPromises } from '@vue/test-utils'; +import { mount, enableAutoUnmount, flushPromises } from '@vue/test-utils'; import vehicleBanner from './vehicleBanner'; -import axios from 'axios'; +import { nextTick } from 'vue'; +import { getMountOptions } from "@/helpers/unit-test-helper.js" -jest.mock('axios', () => ({ - get: () => Promise.resolve({ data: '"imgSrc": "https://s3.amazonaws.com/safelite-lab-vehicle-images/Evox/8963_cc0320_032_UG_white_2014_Ford_Focus_18029225538399034889.jpg"' }) -})) - -describe('vehicleBanner with no props', () => { +describe('vehicleBanner', () => { // Arrange - const wrapper = mount(vehicleBanner, { - propsData: {} + const mountOptions = getMountOptions({ + actionList: [ + { + actionName: "getMockPageData", + data: { + imgData: "" + } + } + ] }); + enableAutoUnmount(afterEach) + // Act + const wrapper = mount(vehicleBanner, { + ...mountOptions + }); // Assert - it('renders the blurrycar image', () => { + it('renders the blurrycar image when no vehicleImageSrc is found', () => { expect(wrapper.find('img').attributes('class')).toContain('blurrycar'); - }) -}); - -describe('vehicleBanner with isBlurred true', () => { - // Arrange - const wrapper = mount(vehicleBanner, { - propsData: { - isBlurred: true, - carId: "00test" - } }); - // Act - // Assert - it('renders the blurrycar image', () => { - expect(wrapper.find('img').attributes('class')).toContain('blurrycar'); - }) -}); + it('renders the blurrycar image when isBlurred is true', async () => { + await wrapper.setData("test string"); + await wrapper.setProps({ isBlurred: true }); -describe('vehicleBanner with valid src image', () => { - // Arrange - const wrapper = mount(vehicleBanner, { - propsData: { - carId: "00test" - } + // timeout needed for image call to have time to return with a vehicleSrcImage + setTimeout(() => { + expect(wrapper.find('img').attributes('class')).toContain('blurrycar'); + }, 500); }); - // Act - // Assert - it('does not render the blurry image', async () => { - await flushPromises(); + it('renders an actual car image when vehicleImageSrc is found and isBlurred is false', async () => { + await wrapper.setData("test string"); + await wrapper.setProps({ isBlurred: false}); + await flushPromises(); // including this doesn't appear to matter + await nextTick(); // including this doesn't appear to matter + // timeout needed for image call to have time to return with a vehicleSrcImage setTimeout(() => { expect(wrapper.find('img').attributes('class')).not.toContain('blurrycar'); }, 500); - }) -}); + }); +}); diff --git a/src/commonComponents/vehicleBanner/vehicleBanner.vue b/src/commonComponents/vehicleBanner/vehicleBanner.vue index 461657080..6039160b7 100644 --- a/src/commonComponents/vehicleBanner/vehicleBanner.vue +++ b/src/commonComponents/vehicleBanner/vehicleBanner.vue @@ -1,10 +1,11 @@