UNPKG

@shopgate/engage

Version:
1 lines 3.25 kB
import React from'react';import{shallow}from'enzyme';import Image from'@shopgate/pwa-common/components/Image';import appConfig from'@shopgate/pwa-common/helpers/config';import PlaceholderIcon from'@shopgate/pwa-ui-shared/icons/PlaceholderIcon';import styles from"./style";import ProductImage from"./index";jest.unmock('@shopgate/pwa-core');jest.mock("../../../core/hocs/withWidgetSettings");jest.mock('@shopgate/pwa-common/helpers/config');jest.mock("./connector",function(){return function(Component){return Component;};});jest.mock('@shopgate/engage/components',function(){return{Image:function Image(){return null;}};});describe('<ProductImage />',function(){it('should render a placeholder if no src prop is provided',function(){var wrapper=shallow(React.createElement(ProductImage,null)).dive();expect(wrapper).toMatchSnapshot();expect(wrapper.find(Image).length).toBe(0);expect(wrapper.find(PlaceholderIcon).length).toBe(1);});it('should render the image without a placeholder',function(){var wrapper=shallow(React.createElement(ProductImage,{src:"http://placehold.it/300x300"})).dive();expect(wrapper).toMatchSnapshot();expect(wrapper.find(Image).length).toBe(1);expect(wrapper.find(PlaceholderIcon).length).toBe(0);});it('should not apply an inner shadow to the placeholder if turned off via the app config',function(){jest.spyOn(appConfig,'hideProductImageShadow','get').mockReturnValue(true);var wrapper=shallow(React.createElement(ProductImage,null)).dive();expect(wrapper).toMatchSnapshot();expect(wrapper.find(".".concat(styles.innerShadow)).length).toBe(0);});it('should not apply an inner shadow to the image if turned off via the app config',function(){jest.spyOn(appConfig,'hideProductImageShadow','get').mockReturnValue(true);var wrapper=shallow(React.createElement(ProductImage,{src:"http://placehold.it/300x300"})).dive();expect(wrapper).toMatchSnapshot();expect(wrapper.find(".".concat(styles.innerShadow)).length).toBe(0);});it('should not apply an inner shadow to the placeholder if turned off via the widget settings',function(){var wrapper=shallow(React.createElement(ProductImage,{widgetSettings:{showInnerShadow:false}})).dive();expect(wrapper).toMatchSnapshot();expect(wrapper.find(".".concat(styles.innerShadow)).length).toBe(0);});it('should not apply an inner shadow to the image if turned off via the widget settings',function(){var wrapper=shallow(React.createElement(ProductImage,{src:"http://placehold.it/300x300",widgetSettings:{showInnerShadow:false}}));expect(wrapper).toMatchSnapshot();expect(wrapper.find(".".concat(styles.innerShadow)).length).toBe(0);});it('should apply an inner shadow to the placeholder if turned off via the widget settings',function(){var wrapper=shallow(React.createElement(ProductImage,{widgetSettings:{showInnerShadow:true}})).dive();expect(wrapper).toMatchSnapshot();expect(wrapper.find(".".concat(styles.innerShadow)).length).toBe(1);});it('should apply an inner shadow to the image if turned off via the widget settings',function(){var wrapper=shallow(React.createElement(ProductImage,{src:"http://placehold.it/300x300",widgetSettings:{showInnerShadow:true}})).dive();expect(wrapper).toMatchSnapshot();expect(wrapper.find(".".concat(styles.innerShadow)).length).toBe(1);});});