@shopgate/pwa-common 6.19.4 → 6.19.5-rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,7 @@
1
1
  import{logger}from'@shopgate/pwa-core/helpers';import{historyPush,historyReset}from"../router";import{INDEX_PATH_DEEPLINK,INDEX_PATH}from"../../constants/RoutePaths";/**
2
2
  * @param {Object} payload The link payload.
3
- * @param {boolean} allowExternalLinks Wether the function should open external links or should try to convert them to internal links
3
+ * @param {boolean} allowExternalLinks Wether the function should open external links or should try
4
+ * to convert them to internal links
4
5
  * @return {Function}
5
6
  */export default function handleLink(payload){var allowExternalLinks=arguments.length>1&&arguments[1]!==undefined?arguments[1]:false;return function(dispatch){var link=payload.link;if(!link){return;}// cast to string
6
7
  link=String(link);var pathname;if(link.startsWith('http')){// Link is common URL schema.
@@ -1 +1 @@
1
- import{historyPush,historyReset}from"../router";import{INDEX_PATH_DEEPLINK}from"../../constants/RoutePaths";import handleLink from"./handleLink";jest.mock("../../actions/router",function(){return{historyPush:jest.fn(),historyReset:jest.fn()};});describe('handleLink()',function(){var dispatch=jest.fn();beforeEach(function(){jest.clearAllMocks();});it('should return a redux thunk',function(){expect(handleLink()).toBeInstanceOf(Function);});it('should do nothing when the link is empty',function(){handleLink({})(dispatch);expect(dispatch).not.toHaveBeenCalled();});describe('handle deep link',function(){it('should dispatch historyReset() when the link is a deeplink to the index page',function(){handleLink({link:"shopgate-10006:/".concat(INDEX_PATH_DEEPLINK)})(dispatch);expect(dispatch).toHaveBeenCalledTimes(1);expect(historyReset).toHaveBeenCalledTimes(1);});it('should dispatch historyPush for common deeplinks',function(){var link='/some/page';var deeplink="shopgate-10006:/".concat(link);handleLink({link:deeplink})(dispatch);expect(dispatch).toHaveBeenCalledTimes(1);expect(historyPush).toHaveBeenCalledTimes(1);expect(historyPush).toHaveBeenCalledWith({pathname:link});});});describe('handle universal link',function(){it('should dispatch historyPush for universal link',function(){var link='/page/test';var universalLink="https://example.com".concat(link);handleLink({link:universalLink})(dispatch);expect(dispatch).toHaveBeenCalledTimes(1);expect(historyPush).toHaveBeenCalledTimes(1);expect(historyPush).toHaveBeenCalledWith({pathname:link});});it('should dispatch historyReset() when the link is an universal link to the index page',function(){handleLink({link:'https://example.com/'})(dispatch);expect(dispatch).toHaveBeenCalledTimes(1);expect(historyReset).toHaveBeenCalledTimes(1);});it('should dispatch historyReset() when the link is invalid URL',function(){handleLink({link:'http !@@##%$^&^*&* s://example.com/'})(dispatch);expect(dispatch).toHaveBeenCalledTimes(1);expect(historyReset).toHaveBeenCalledTimes(1);});});describe('handle external push message links',function(){it('should dispatch historyPush for the external link',function(){var link='http://www.google.de';handleLink({link:link},true)(dispatch);expect(dispatch).toHaveBeenCalledTimes(1);expect(historyPush).toHaveBeenCalledTimes(1);expect(historyPush).toHaveBeenCalledWith({pathname:link});});it('should dispatch historyPush with only the pathname for the external links which are no push messages',function(){var link='http://www.google.de/path/test';handleLink({link:link})(dispatch);expect(dispatch).toHaveBeenCalledTimes(1);expect(historyPush).toHaveBeenCalledTimes(1);expect(historyPush).toHaveBeenCalledWith({pathname:'/path/test'});});});});
1
+ import{historyPush,historyReset}from"../router";import{INDEX_PATH_DEEPLINK}from"../../constants/RoutePaths";import handleLink from"./handleLink";jest.mock("../../actions/router",function(){return{historyPush:jest.fn(),historyReset:jest.fn()};});var mockedError=jest.fn();jest.mock('@shopgate/pwa-core/helpers',function(){return{logger:{error:function error(){return mockedError.apply(void 0,arguments);}}};});describe('handleLink()',function(){var dispatch=jest.fn();beforeEach(function(){jest.clearAllMocks();});it('should return a redux thunk',function(){expect(handleLink()).toBeInstanceOf(Function);});it('should do nothing when the link is empty',function(){handleLink({})(dispatch);expect(dispatch).not.toHaveBeenCalled();});describe('handle deep link',function(){it('should dispatch historyReset() when the link is a deeplink to the index page',function(){handleLink({link:"shopgate-10006:/".concat(INDEX_PATH_DEEPLINK)})(dispatch);expect(dispatch).toHaveBeenCalledTimes(1);expect(historyReset).toHaveBeenCalledTimes(1);});it('should dispatch historyPush for common deeplinks',function(){var link='/some/page';var deeplink="shopgate-10006:/".concat(link);handleLink({link:deeplink})(dispatch);expect(dispatch).toHaveBeenCalledTimes(1);expect(historyPush).toHaveBeenCalledTimes(1);expect(historyPush).toHaveBeenCalledWith({pathname:link});});});describe('handle universal link',function(){it('should dispatch historyPush for universal link',function(){var link='/page/test';var universalLink="https://example.com".concat(link);handleLink({link:universalLink})(dispatch);expect(dispatch).toHaveBeenCalledTimes(1);expect(historyPush).toHaveBeenCalledTimes(1);expect(historyPush).toHaveBeenCalledWith({pathname:link});});it('should dispatch historyReset() when the link is an universal link to the index page',function(){handleLink({link:'https://example.com/'})(dispatch);expect(dispatch).toHaveBeenCalledTimes(1);expect(historyReset).toHaveBeenCalledTimes(1);});it('should dispatch historyReset() when the link is invalid URL',function(){handleLink({link:'http !@@##%$^&^*&* s://example.com/'})(dispatch);expect(dispatch).toHaveBeenCalledTimes(1);expect(historyReset).toHaveBeenCalledTimes(1);expect(mockedError).toHaveBeenCalledTimes(1);});});describe('handle external push message links',function(){it('should dispatch historyPush for the external link',function(){var link='http://www.google.de';handleLink({link:link},true)(dispatch);expect(dispatch).toHaveBeenCalledTimes(1);expect(historyPush).toHaveBeenCalledTimes(1);expect(historyPush).toHaveBeenCalledWith({pathname:link});});it('should dispatch historyPush with only the pathname for the external links which are no push messages',function(){var link='http://www.google.de/path/test';handleLink({link:link})(dispatch);expect(dispatch).toHaveBeenCalledTimes(1);expect(historyPush).toHaveBeenCalledTimes(1);expect(historyPush).toHaveBeenCalledWith({pathname:'/path/test'});});});});
@@ -1,8 +1,8 @@
1
- import React from'react';import{mount}from'enzyme';import{JSDOM}from'jsdom';import{embeddedMedia}from'@shopgate/pwa-common/collections';import HtmlSanitizer from"./index";jest.mock('@shopgate/pwa-common/collections/EmbeddedMedia',function(){return{add:jest.fn(),remove:jest.fn()};});jest.mock("../EmbeddedMedia",function(){return function(_ref){var children=_ref.children;return children;};});jest.mock("./connector",function(){return function(Cmp){return Cmp;};});/**
1
+ function _extends(){_extends=Object.assign||function(target){for(var i=1;i<arguments.length;i++){var source=arguments[i];for(var key in source){if(Object.prototype.hasOwnProperty.call(source,key)){target[key]=source[key];}}}return target;};return _extends.apply(this,arguments);}import React from'react';import{mount}from'enzyme';import{JSDOM}from'jsdom';import{embeddedMedia}from'@shopgate/pwa-common/collections';import HtmlSanitizer from"./index";jest.mock('@shopgate/pwa-common/collections/EmbeddedMedia',function(){return{add:jest.fn(),remove:jest.fn()};});jest.mock("../EmbeddedMedia",function(){return function(_ref){var children=_ref.children;return children;};});jest.mock("./connector",function(){return function(Cmp){return Cmp;};});/**
2
2
  * @param {string} html HTML markup.
3
3
  * @param {Object} props Component props.
4
4
  * @returns {JSX}
5
- */var createWrapper=function createWrapper(html){var props=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};return mount(React.createElement(HtmlSanitizer,props,html));};describe('<HtmlSanitizer />',function(){beforeEach(function(){jest.clearAllMocks();});it('should render the HtmlSanitizer',function(){/**
5
+ */var createWrapper=function createWrapper(html){var props=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};return mount(React.createElement(HtmlSanitizer,_extends({navigate:function navigate(){}},props),html));};describe('<HtmlSanitizer />',function(){beforeEach(function(){jest.clearAllMocks();});it('should render the HtmlSanitizer',function(){/**
6
6
  * The value for html is the HTML-escaped equivalent of the following:
7
7
  * <h1>Hello World!</h1>
8
8
  * @type {string}
@@ -15,4 +15,4 @@ expect(wrapper.html()).toEqual('<div class=" common__html-sanitizer"><h1>Hello W
15
15
  * <script>var y = 23;</script>
16
16
  * @type {string}
17
17
  */var html='&lt;script src=&quot;https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.js&quot;&gt;&lt;/script&gt; &lt;script type=&quot;text/javascript&quot;&gt;var x = 42;&lt;/script&gt; &lt;p&gt;Foo Bar&lt;/p&gt; &lt;script&gt;var y = 23;&lt;/script&gt;';var wrapper=createWrapper(html,{decode:true});// Test result of dangerouslySetInnerHTML.
18
- expect(wrapper.html()).toEqual('<div class=" common__html-sanitizer"> <p>Foo Bar</p> </div>');expect(wrapper).toMatchSnapshot();});describe('Link handling',function(){var mockedHandleClick=jest.fn();beforeEach(function(){mockedHandleClick.mockClear();});it('follows a link from a plain <a>',function(){var doc=new JSDOM('<!doctype html><html><body><div>/<div></body></html>').window.document;var html='&lt;a id=&quot;link&quot; href=&quot;#follow-me-and-everything-is-alright&quot;&gt;Plain Link&lt;/a&gt;';var wrapper=mount(React.createElement(HtmlSanitizer,{decode:true,settings:{handleClick:mockedHandleClick}},html),{attachTo:doc.getElementsByTagName('div')[0]});var aTag=doc.getElementsByTagName('a')[0];aTag.closest=function(){return aTag;};var event={target:aTag,preventDefault:function preventDefault(){}};wrapper.instance().handleTap(event);expect(mockedHandleClick).toHaveBeenCalledTimes(1);expect(mockedHandleClick).toHaveBeenCalledWith('#follow-me-and-everything-is-alright','');});it('follows a link from a <a> with other HTML inside',function(){var doc=new JSDOM('<!doctype html><html><body><div>/<div></body></html>').window.document;var html='&lt;a id=&quot;link&quot; target=&quot;_blank&quot; href=&quot;#I-ll-be-the-one-to-tuck-you-in-at-night&quot;&gt;&lt;span&gt;Span Link&lt;/span&gt;&lt;/a&gt;';var wrapper=mount(React.createElement(HtmlSanitizer,{decode:true,settings:{handleClick:mockedHandleClick}},html),{attachTo:doc.getElementsByTagName('div')[0]});var aTag=doc.getElementsByTagName('a')[0];var spanTag=doc.getElementsByTagName('span')[0];spanTag.closest=function(){return aTag;};var event={target:spanTag,preventDefault:function preventDefault(){}};wrapper.instance().handleTap(event);expect(mockedHandleClick).toHaveBeenCalledTimes(1);expect(mockedHandleClick).toHaveBeenCalledWith('#I-ll-be-the-one-to-tuck-you-in-at-night','_blank');});});});
18
+ expect(wrapper.html()).toEqual('<div class=" common__html-sanitizer"> <p>Foo Bar</p> </div>');expect(wrapper).toMatchSnapshot();});describe('Link handling',function(){var mockedHandleClick=jest.fn();beforeEach(function(){mockedHandleClick.mockClear();});it('follows a link from a plain <a>',function(){var doc=new JSDOM('<!doctype html><html><body><div>/<div></body></html>').window.document;var html='&lt;a id=&quot;link&quot; href=&quot;#follow-me-and-everything-is-alright&quot;&gt;Plain Link&lt;/a&gt;';var wrapper=mount(React.createElement(HtmlSanitizer,{decode:true,settings:{handleClick:mockedHandleClick},navigate:function navigate(){}},html),{attachTo:doc.getElementsByTagName('div')[0]});var aTag=doc.getElementsByTagName('a')[0];aTag.closest=function(){return aTag;};var event={target:aTag,preventDefault:function preventDefault(){}};wrapper.instance().handleTap(event);expect(mockedHandleClick).toHaveBeenCalledTimes(1);expect(mockedHandleClick).toHaveBeenCalledWith('#follow-me-and-everything-is-alright','');});it('follows a link from a <a> with other HTML inside',function(){var doc=new JSDOM('<!doctype html><html><body><div>/<div></body></html>').window.document;var html='&lt;a id=&quot;link&quot; target=&quot;_blank&quot; href=&quot;#I-ll-be-the-one-to-tuck-you-in-at-night&quot;&gt;&lt;span&gt;Span Link&lt;/span&gt;&lt;/a&gt;';var wrapper=mount(React.createElement(HtmlSanitizer,{decode:true,settings:{handleClick:mockedHandleClick},navigate:function navigate(){}},html),{attachTo:doc.getElementsByTagName('div')[0]});var aTag=doc.getElementsByTagName('a')[0];var spanTag=doc.getElementsByTagName('span')[0];spanTag.closest=function(){return aTag;};var event={target:spanTag,preventDefault:function preventDefault(){}};wrapper.instance().handleTap(event);expect(mockedHandleClick).toHaveBeenCalledTimes(1);expect(mockedHandleClick).toHaveBeenCalledWith('#I-ll-be-the-one-to-tuck-you-in-at-night','_blank');});});});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shopgate/pwa-common",
3
- "version": "6.19.4",
3
+ "version": "6.19.5-rc.1",
4
4
  "description": "Common library for the Shopgate Connect PWA.",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Shopgate <support@shopgate.com>",
@@ -16,7 +16,7 @@
16
16
  ],
17
17
  "dependencies": {
18
18
  "@sentry/browser": "^4.6.3",
19
- "@shopgate/pwa-benchmark": "6.19.4",
19
+ "@shopgate/pwa-benchmark": "6.19.5-rc.1",
20
20
  "@virtuous/conductor": "~2.4.0",
21
21
  "@virtuous/react-conductor": "~2.4.0",
22
22
  "@virtuous/redux-persister": "1.1.0-beta.7",
@@ -44,7 +44,7 @@
44
44
  "url-search-params": "^0.10.0"
45
45
  },
46
46
  "devDependencies": {
47
- "@shopgate/pwa-core": "6.19.4",
47
+ "@shopgate/pwa-core": "6.19.5-rc.1",
48
48
  "lodash": "^4.17.4",
49
49
  "prop-types": "~15.7.2",
50
50
  "react": "~16.12.0",
@@ -4,4 +4,4 @@ import _regeneratorRuntime from"@babel/runtime/regenerator";function asyncGenera
4
4
  */var MockComponent=function MockComponent(_ref){var isLoading=_ref.isLoading,path=_ref.path;return isLoading(path)?React.createElement("div",null):null;};/**
5
5
  * @param {string} path A mocked path.
6
6
  * @return {JSX}
7
- */var createWrapper=function createWrapper(){var path=arguments.length>0&&arguments[0]!==undefined?arguments[0]:'/';var wrapper=mount(React.createElement(LoadingProvider,null,React.createElement(LoadingContext.Consumer,null,function(props){return React.createElement(MockComponent,_extends({},props,{path:path}));})));return wrapper;};describe('LoadingProvider',function(){beforeAll(function(){jest.resetAllMocks();jest.spyOn(UIEvents,'addListener');jest.spyOn(UIEvents,'removeListener');jest.spyOn(UIEvents,'emit');});beforeEach(function(){jest.clearAllMocks();});it('should not render the child component when the current path is not loading',function(){var wrapper=createWrapper();expect(wrapper).toMatchSnapshot();expect(wrapper.state('loading')).toEqual(new Map());expect(wrapper.find('MockComponent > div').exists()).toBe(false);});it('should render the child component when the current path is loading',/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(){var wrapper;return _regeneratorRuntime.wrap(function _callee$(_context){while(1){switch(_context.prev=_context.next){case 0:wrapper=createWrapper(MOCKED_PATH);expect(wrapper).toMatchSnapshot();wrapper.instance().setLoading(MOCKED_PATH);wrapper.update();expect(wrapper.find('MockComponent > div').exists()).toBe(true);wrapper.instance().unsetLoading(MOCKED_PATH);wrapper.update();expect(wrapper.find('MockComponent > div').exists()).toBe(false);case 8:case"end":return _context.stop();}}},_callee);})));it('should populate internal methods its children',function(){var wrapper=createWrapper();expect(wrapper).toMatchSnapshot();var child=wrapper.find('MockComponent');expect(child.prop('setLoading')).toEqual(wrapper.instance().setLoading);expect(child.prop('unsetLoading')).toEqual(wrapper.instance().unsetLoading);expect(child.prop('isLoading')).toEqual(wrapper.instance().isLoading);expect(child.prop('loading')).toEqual(wrapper.state('loading'));});it('should register event listeners within the constructor',function(){var wrapper=createWrapper();expect(UIEvents.addListener).toHaveBeenCalledTimes(3);expect(UIEvents.addListener).toHaveBeenCalledWith(LoadingProvider.SET,wrapper.instance().setLoading);expect(UIEvents.addListener).toHaveBeenCalledWith(LoadingProvider.RESET,wrapper.instance().resetLoading);expect(UIEvents.addListener).toHaveBeenCalledWith(LoadingProvider.UNSET,wrapper.instance().unsetLoading);});it('should remove event listeners within componentWillUnmount',function(){var wrapper=createWrapper();wrapper.unmount();expect(UIEvents.removeListener).toHaveBeenCalledTimes(3);expect(UIEvents.removeListener).toHaveBeenCalledWith(LoadingProvider.SET,expect.any(Function));expect(UIEvents.removeListener).toHaveBeenCalledWith(LoadingProvider.RESET,expect.any(Function));expect(UIEvents.removeListener).toHaveBeenCalledWith(LoadingProvider.UNSET,expect.any(Function));});describe('LoadingProvider.setLoading()',function(){it('should emit the SET event',function(){LoadingProvider.setLoading(MOCKED_PATH);expect(UIEvents.emit).toHaveBeenCalledTimes(1);expect(UIEvents.emit).toHaveBeenCalledWith(LoadingProvider.SET,MOCKED_PATH);});});describe('LoadingProvider.resetLoading()',function(){it('should emit the RESET event',function(){LoadingProvider.resetLoading(MOCKED_PATH);expect(UIEvents.emit).toHaveBeenCalledTimes(1);expect(UIEvents.emit).toHaveBeenCalledWith(LoadingProvider.RESET,MOCKED_PATH);});});describe('LoadingProvider.unsetLoading()',function(){it('should emit the UNSET event',function(){LoadingProvider.unsetLoading(MOCKED_PATH);expect(UIEvents.emit).toHaveBeenCalledTimes(1);expect(UIEvents.emit).toHaveBeenCalledWith(LoadingProvider.UNSET,MOCKED_PATH);});});describe('.setLoading()',function(){it('should increase the loading counter for a path',function(){var instance=createWrapper().instance();var loading=instance.state.loading;expect(loading.has(MOCKED_PATH)).toBe(false);instance.setLoading(MOCKED_PATH);expect(loading.has(MOCKED_PATH)).toBe(true);expect(loading.get(MOCKED_PATH)).toBe(1);instance.setLoading(MOCKED_PATH);expect(loading.has(MOCKED_PATH)).toBe(true);expect(loading.get(MOCKED_PATH)).toBe(2);});});describe('.resetLoading()',function(){it('should resets the loading counter for a path',function(){var instance=createWrapper().instance();var loading=instance.state.loading;expect(loading.has(MOCKED_PATH)).toBe(false);instance.resetLoading(MOCKED_PATH);expect(loading.has(MOCKED_PATH)).toBe(false);instance.setLoading(MOCKED_PATH);instance.setLoading(MOCKED_PATH);expect(loading.has(MOCKED_PATH)).toBe(true);expect(loading.get(MOCKED_PATH)).toBe(2);instance.resetLoading(MOCKED_PATH);expect(loading.has(MOCKED_PATH)).toBe(false);});});describe('.unsetLoading()',function(){it('should decrease the loading counter for a path',function(){var instance=createWrapper().instance();var loading=instance.state.loading;instance.setLoading(MOCKED_PATH);instance.setLoading(MOCKED_PATH);instance.unsetLoading(MOCKED_PATH);expect(loading.get(MOCKED_PATH)).toBe(1);instance.unsetLoading(MOCKED_PATH);expect(loading.has(MOCKED_PATH)).toBe(false);instance.unsetLoading(MOCKED_PATH);expect(loading.has(MOCKED_PATH)).toBe(false);});});describe('.isLoading()',function(){it('should work as expected',function(){var ANOTHER_PATH='/some/other/path';var instance=createWrapper().instance();expect(instance.isLoading(MOCKED_PATH)).toBe(false);expect(instance.isLoading(ANOTHER_PATH)).toBe(false);instance.setLoading(MOCKED_PATH);expect(instance.isLoading(MOCKED_PATH)).toBe(true);expect(instance.isLoading(ANOTHER_PATH)).toBe(false);instance.setLoading(ANOTHER_PATH);expect(instance.isLoading(MOCKED_PATH)).toBe(true);expect(instance.isLoading(ANOTHER_PATH)).toBe(true);instance.unsetLoading(MOCKED_PATH);instance.unsetLoading(MOCKED_PATH);instance.unsetLoading(ANOTHER_PATH);instance.unsetLoading(ANOTHER_PATH);expect(instance.isLoading(MOCKED_PATH)).toBe(false);expect(instance.isLoading(ANOTHER_PATH)).toBe(false);});});});
7
+ */var createWrapper=function createWrapper(){var path=arguments.length>0&&arguments[0]!==undefined?arguments[0]:'/';var wrapper=mount(React.createElement(LoadingProvider,null,React.createElement(LoadingContext.Consumer,null,function(props){return React.createElement(MockComponent,_extends({},props,{path:path}));})));return wrapper;};describe('LoadingProvider',function(){beforeAll(function(){jest.resetAllMocks();jest.spyOn(UIEvents,'addListener');jest.spyOn(UIEvents,'removeListener');jest.spyOn(UIEvents,'emit');});beforeEach(function(){jest.clearAllMocks();});it('should not render the child component when the current path is not loading',function(){var wrapper=createWrapper();expect(wrapper).toMatchSnapshot();expect(wrapper.state('loading')).toEqual(new Map());expect(wrapper.find('MockComponent > div').exists()).toBe(false);});it('should render the child component when the current path is loading',/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(){var wrapper;return _regeneratorRuntime.wrap(function _callee$(_context){while(1){switch(_context.prev=_context.next){case 0:wrapper=createWrapper(MOCKED_PATH);expect(wrapper).toMatchSnapshot();wrapper.instance().setLoading(MOCKED_PATH);wrapper.update();setTimeout(function(){expect(wrapper.find('MockComponent > div').exists()).toBe(true);wrapper.instance().unsetLoading(MOCKED_PATH);wrapper.update();expect(wrapper.find('MockComponent > div').exists()).toBe(false);},0);case 5:case"end":return _context.stop();}}},_callee);})));it('should populate internal methods its children',function(){var wrapper=createWrapper();expect(wrapper).toMatchSnapshot();var child=wrapper.find('MockComponent');expect(child.prop('setLoading')).toEqual(wrapper.instance().setLoading);expect(child.prop('unsetLoading')).toEqual(wrapper.instance().unsetLoading);expect(child.prop('isLoading')).toEqual(wrapper.instance().isLoading);expect(child.prop('loading')).toEqual(wrapper.state('loading'));});it('should register event listeners within the constructor',function(){var wrapper=createWrapper();expect(UIEvents.addListener).toHaveBeenCalledTimes(3);expect(UIEvents.addListener).toHaveBeenCalledWith(LoadingProvider.SET,wrapper.instance().setLoading);expect(UIEvents.addListener).toHaveBeenCalledWith(LoadingProvider.RESET,wrapper.instance().resetLoading);expect(UIEvents.addListener).toHaveBeenCalledWith(LoadingProvider.UNSET,wrapper.instance().unsetLoading);});it('should remove event listeners within componentWillUnmount',function(){var wrapper=createWrapper();wrapper.unmount();expect(UIEvents.removeListener).toHaveBeenCalledTimes(3);expect(UIEvents.removeListener).toHaveBeenCalledWith(LoadingProvider.SET,expect.any(Function));expect(UIEvents.removeListener).toHaveBeenCalledWith(LoadingProvider.RESET,expect.any(Function));expect(UIEvents.removeListener).toHaveBeenCalledWith(LoadingProvider.UNSET,expect.any(Function));});describe('LoadingProvider.setLoading()',function(){it('should emit the SET event',function(){LoadingProvider.setLoading(MOCKED_PATH);expect(UIEvents.emit).toHaveBeenCalledTimes(1);expect(UIEvents.emit).toHaveBeenCalledWith(LoadingProvider.SET,MOCKED_PATH);});});describe('LoadingProvider.resetLoading()',function(){it('should emit the RESET event',function(){LoadingProvider.resetLoading(MOCKED_PATH);expect(UIEvents.emit).toHaveBeenCalledTimes(1);expect(UIEvents.emit).toHaveBeenCalledWith(LoadingProvider.RESET,MOCKED_PATH);});});describe('LoadingProvider.unsetLoading()',function(){it('should emit the UNSET event',function(){LoadingProvider.unsetLoading(MOCKED_PATH);expect(UIEvents.emit).toHaveBeenCalledTimes(1);expect(UIEvents.emit).toHaveBeenCalledWith(LoadingProvider.UNSET,MOCKED_PATH);});});describe('.setLoading()',function(){it('should increase the loading counter for a path',function(){var instance=createWrapper().instance();var loading=instance.state.loading;expect(loading.has(MOCKED_PATH)).toBe(false);instance.setLoading(MOCKED_PATH);expect(loading.has(MOCKED_PATH)).toBe(true);expect(loading.get(MOCKED_PATH)).toBe(1);instance.setLoading(MOCKED_PATH);expect(loading.has(MOCKED_PATH)).toBe(true);expect(loading.get(MOCKED_PATH)).toBe(2);});});describe('.resetLoading()',function(){it('should resets the loading counter for a path',function(){var instance=createWrapper().instance();var loading=instance.state.loading;expect(loading.has(MOCKED_PATH)).toBe(false);instance.resetLoading(MOCKED_PATH);expect(loading.has(MOCKED_PATH)).toBe(false);instance.setLoading(MOCKED_PATH);instance.setLoading(MOCKED_PATH);expect(loading.has(MOCKED_PATH)).toBe(true);expect(loading.get(MOCKED_PATH)).toBe(2);instance.resetLoading(MOCKED_PATH);expect(loading.has(MOCKED_PATH)).toBe(false);});});describe('.unsetLoading()',function(){it('should decrease the loading counter for a path',function(){var instance=createWrapper().instance();var loading=instance.state.loading;instance.setLoading(MOCKED_PATH);instance.setLoading(MOCKED_PATH);instance.unsetLoading(MOCKED_PATH);expect(loading.get(MOCKED_PATH)).toBe(1);instance.unsetLoading(MOCKED_PATH);expect(loading.has(MOCKED_PATH)).toBe(false);instance.unsetLoading(MOCKED_PATH);expect(loading.has(MOCKED_PATH)).toBe(false);});});describe('.isLoading()',function(){it('should work as expected',function(){var ANOTHER_PATH='/some/other/path';var instance=createWrapper().instance();expect(instance.isLoading(MOCKED_PATH)).toBe(false);expect(instance.isLoading(ANOTHER_PATH)).toBe(false);instance.setLoading(MOCKED_PATH);expect(instance.isLoading(MOCKED_PATH)).toBe(true);expect(instance.isLoading(ANOTHER_PATH)).toBe(false);instance.setLoading(ANOTHER_PATH);expect(instance.isLoading(MOCKED_PATH)).toBe(true);expect(instance.isLoading(ANOTHER_PATH)).toBe(true);instance.unsetLoading(MOCKED_PATH);instance.unsetLoading(MOCKED_PATH);instance.unsetLoading(ANOTHER_PATH);instance.unsetLoading(ANOTHER_PATH);expect(instance.isLoading(MOCKED_PATH)).toBe(false);expect(instance.isLoading(ANOTHER_PATH)).toBe(false);});});});