@shopgate/pwa-common
Version:
Common library for the Shopgate Connect PWA.
11 lines • 3.01 kB
JavaScript
/* eslint-disable no-unused-vars */import React from'react';import{mount}from'enzyme';import{Provider}from'react-redux';import{configureStore}from"../../store";import modalReducer from"../../reducers/modal";import showModal from"../../actions/modal/showModal";import ModalContainer from"./index";// const store = configureStore({ modal: modalReducer });
// Replacement for commented out configureStore()
var store={};jest.mock('redux-logger',function(){return{createLogger:function createLogger(){return function(){return function(next){return function(action){return next(action);};};};}};});global.requestAnimationFrame=function(fn){return fn();};/**
* Some mock modal component.
* @param {func} onConfirm Confirm callback
* @param {func} onDismiss Dismiss callback
* @constructor
*/var MockModal=function MockModal(_ref){var onConfirm=_ref.onConfirm,onDismiss=_ref.onDismiss;return React.createElement("div",{className:"modal"},React.createElement("button",{className:"confirmBtn",onClick:onConfirm,type:"button"}),React.createElement("button",{className:"dismissBtn",onClick:onDismiss,type:"button"}));};describe.skip('<ModalContainer />',function(){var renderedElement;var dispatch=store.dispatch,getState=store.getState;/**
* The rendered component.
*/var renderComponent=function renderComponent(){renderedElement=mount(React.createElement(Provider,{store:store},React.createElement("div",{id:"container"},React.createElement(ModalContainer,{component:MockModal}))));};beforeEach(function(){// Reset the modals state before each test.
getState().modal=[];renderComponent();});describe('Given the component was mounted to the DOM',function(){it('should match snapshot',function(){expect(renderedElement).toMatchSnapshot();});it('should show no modal',function(){expect(renderedElement.find('.modal').length).toBe(0);});describe('Given a modal gets dispatched',function(){var modalPromise;beforeEach(function(){modalPromise=dispatch(showModal({title:'Title',message:'Message'}));renderedElement.update();});it('should contain a modal item in the state',function(){expect(getState().modal.length).toBe(1);});it('should show the modal',function(){expect(renderedElement.find('.modal').length).toBe(1);});describe('Given the modal gets confirmed',function(){beforeEach(function(){renderedElement.find('.confirmBtn').simulate('click');});it('should resolve the promise as confirmed',function(){modalPromise.then(function(confirmed){return expect(confirmed).toBe(true);});});it('should contain no modal item in the state',function(){expect(getState().modal.length).toBe(0);});it('should not show the modal anymore',function(){expect(renderedElement.find('.modal').length).toBe(0);});});describe('Given the modal gets dismissed',function(){beforeEach(function(){renderedElement.find('.dismissBtn').simulate('click');});it('should resolve the promise as dismissed',function(){modalPromise.then(function(confirmed){return expect(confirmed).toBe(false);});});});});});});/* eslint-enable no-unused-vars */