@shopgate/engage
Version:
Shopgate's ENGAGE library.
5 lines • 2 kB
JavaScript
import React from'react';import{Provider}from'react-redux';import configureStore from'redux-mock-store';import{mount}from'enzyme';import mockRenderOptions from'@shopgate/pwa-common/helpers/mocks/mockRenderOptions';import{setMocks,mockedStateWithTwoReviews,mockedStateWithoutReview}from'@shopgate/pwa-common-commerce/reviews/mock';import Rating from"./index";import{getElementById}from"./mock";setMocks();jest.mock('@shopgate/engage/components');describe('Rating (product header)',function(){var mockedStore=configureStore();/**
* Makes component.
* @param {Object} state State
* @returns {Object}
*/var getComponent=function getComponent(state){return mount(React.createElement(Provider,{store:mockedStore(state)},React.createElement(Rating,{productId:"foo"})),mockRenderOptions);};describe('Rendering',function(){it('should render rating when data is available',function(){var component=getComponent(mockedStateWithTwoReviews);expect(component).toMatchSnapshot();});it('should render nothing when data is not available',function(){var component=getComponent(mockedStateWithoutReview);expect(component.isEmptyRender()).toBe(true);});});describe('Scroll on click',function(){var scrollSpy=jest.fn();it('should scroll to reviews when clicked',function(){jest.spyOn(document,'getElementById').mockImplementation(getElementById(scrollSpy));var component=getComponent(mockedStateWithTwoReviews);component.simulate('click');expect(scrollSpy.mock.calls[0][0]).toBe(0);expect(scrollSpy.mock.calls[0][1]).toBe(70);expect(scrollSpy).toHaveBeenCalled();document.getElementById.mockReset();document.getElementById.mockRestore();});it('should do nothing when clicked but no reviews excerpt element',function(){jest.spyOn(document,'getElementById').mockImplementation(function(){return null;});var component=getComponent(mockedStateWithTwoReviews);component.simulate('click');expect(scrollSpy.mock.calls.length).toBe(1);document.getElementById.mockReset();document.getElementById.mockRestore();});});});