UNPKG

@shopgate/engage

Version:
5 lines 1.49 kB
import React from'react';import{mount}from'enzyme';import configureStore from'redux-mock-store';import{Provider}from'react-redux';import{useWidgetSettings}from'@shopgate/engage/core/hooks/useWidgetSettings';import{mockedProduct1,mockedStateWithDiscount,mockedStateWithoutDiscount}from"./mock";import ProductDiscountBadge from"./index";jest.mock('@shopgate/engage/components');jest.mock('@shopgate/engage/core/hooks/useWidgetSettings',function(){return{useWidgetSettings:jest.fn()};});describe('<ProductDiscountBadge />',function(){var mockedStore=configureStore();beforeEach(function(){useWidgetSettings.mockReturnValue({pdp:{show:true,style:{color:'blue'}}});});/** * createComponent * @param {Object} mockedState mockedState * @return {*} */var createComponent=function createComponent(mockedState){var store=mockedStore(mockedState);return mount(React.createElement(Provider,{store:store},React.createElement(ProductDiscountBadge,{productId:mockedProduct1.productId})));};it('should render without discount',function(){var wrapper=createComponent(mockedStateWithoutDiscount);expect(wrapper).toMatchSnapshot();});it('should render with discount',function(){var wrapper=createComponent(mockedStateWithDiscount);expect(wrapper).toMatchSnapshot();});it('should not render with discount if widgetSetting is false',function(){useWidgetSettings.mockReturnValue({pdp:{show:false,style:{}}});var wrapper=createComponent(mockedStateWithDiscount);expect(wrapper).toMatchSnapshot();});});