@shopgate/pwa-common
Version:
Common library for the Shopgate Connect PWA.
1 lines • 1.85 kB
JavaScript
import React from'react';import{mount,shallow}from'enzyme';import Drawer from"./index";jest.mock('@shopgate/engage/a11y/components');describe('<Drawer />',function(){var onOpen=jest.fn();var onClose=jest.fn();var onDidOpen=jest.fn();var onDidClose=jest.fn();beforeEach(function(){jest.clearAllMocks();});it('should render',function(){var wrapper=shallow(React.createElement(Drawer,null));expect(wrapper).toMatchSnapshot();});it('should execute callback when drawer is opened',function(){var wrapper=mount(React.createElement(Drawer,{onOpen:onOpen}));wrapper.setProps({isOpen:true});expect(onOpen).toBeCalled();});it('should execute callback when drawer is closed',function(){var wrapper=mount(React.createElement(Drawer,{isOpen:true,onClose:onClose}));wrapper.setProps({isOpen:false});expect(onClose).toBeCalled();});it('should add custom classes',function(){var wrapper=mount(React.createElement(Drawer,{className:"custom-class-name",isOpen:true}));expect(wrapper).toMatchSnapshot();expect(wrapper.hasClass('custom-class-name')).toEqual(true);});it('should execute callback when drawer open animation did end',function(){var wrapper=mount(React.createElement(Drawer,{className:"custom-class-name",isOpen:false,onOpen:onOpen,onDidOpen:onDidOpen}));expect(wrapper).toMatchSnapshot();wrapper.setProps({isOpen:true});expect(onOpen).toBeCalled();expect(onDidOpen).not.toBeCalled();wrapper.simulate('animationEnd');expect(onDidOpen).toBeCalled();});it('should execute callback when drawer close animation did end',function(){var wrapper=mount(React.createElement(Drawer,{className:"custom-class-name",isOpen:true,onClose:onClose,onDidClose:onDidClose}));expect(wrapper).toMatchSnapshot();wrapper.setProps({isOpen:false});expect(onClose).toBeCalled();expect(onDidClose).not.toBeCalled();wrapper.simulate('animationEnd');expect(onDidClose).toBeCalled();});});