@shopgate/pwa-ui-shared 6.22.0-beta.3 → 6.22.0-beta.5

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.
@@ -0,0 +1,34 @@
1
+ ActionButton Component
2
+ ---
3
+
4
+ The ActionButton serves as a clickable Button and can also show a loading indicator based on the loading prop.
5
+
6
+ ## Getting Started
7
+
8
+ ```jsx
9
+ import ActionButton from '../ActionButton';
10
+
11
+ <ActionButton onClick={handleClick} />
12
+ ```
13
+
14
+ ## Props
15
+
16
+ ### onClick (required)
17
+
18
+ _Type_: `Function`
19
+
20
+ Accepts a callback function for the components click event.
21
+
22
+ ### loading
23
+
24
+ _Type_: `boolean`
25
+ _Default_: `false`
26
+
27
+ Shows a loading indicator if set to true.
28
+
29
+ ###### Usage:
30
+
31
+ ```jsx
32
+ <ActionButton loading={true} ... />
33
+ ```
34
+ ---
package/package.json CHANGED
@@ -1,16 +1,16 @@
1
1
  {
2
2
  "name": "@shopgate/pwa-ui-shared",
3
- "version": "6.22.0-beta.3",
3
+ "version": "6.22.0-beta.5",
4
4
  "description": "Shopgate's shared UI components.",
5
5
  "main": "index.js",
6
6
  "license": "Apache-2.0",
7
7
  "dependencies": {
8
- "@shopgate/pwa-ui-ios": "6.22.0-beta.3",
9
- "@shopgate/pwa-ui-material": "6.22.0-beta.3"
8
+ "@shopgate/pwa-ui-ios": "6.22.0-beta.5",
9
+ "@shopgate/pwa-ui-material": "6.22.0-beta.5"
10
10
  },
11
11
  "devDependencies": {
12
- "@shopgate/pwa-common": "6.22.0-beta.3",
13
- "@shopgate/pwa-common-commerce": "6.22.0-beta.3",
12
+ "@shopgate/pwa-common": "6.22.0-beta.5",
13
+ "@shopgate/pwa-common-commerce": "6.22.0-beta.5",
14
14
  "classnames": "^2.2.5",
15
15
  "react": "~16.12.0"
16
16
  },
@@ -1,8 +0,0 @@
1
- function _slicedToArray(arr,i){return _arrayWithHoles(arr)||_iterableToArrayLimit(arr,i)||_unsupportedIterableToArray(arr,i)||_nonIterableRest();}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");}function _unsupportedIterableToArray(o,minLen){if(!o)return;if(typeof o==="string")return _arrayLikeToArray(o,minLen);var n=Object.prototype.toString.call(o).slice(8,-1);if(n==="Object"&&o.constructor)n=o.constructor.name;if(n==="Map"||n==="Set")return Array.from(o);if(n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return _arrayLikeToArray(o,minLen);}function _arrayLikeToArray(arr,len){if(len==null||len>arr.length)len=arr.length;for(var i=0,arr2=new Array(len);i<len;i++){arr2[i]=arr[i];}return arr2;}function _iterableToArrayLimit(arr,i){var _i=arr==null?null:typeof Symbol!=="undefined"&&arr[Symbol.iterator]||arr["@@iterator"];if(_i==null)return;var _arr=[];var _n=true;var _d=false;var _s,_e;try{for(_i=_i.call(arr);!(_n=(_s=_i.next()).done);_n=true){_arr.push(_s.value);if(i&&_arr.length===i)break;}}catch(err){_d=true;_e=err;}finally{try{if(!_n&&_i["return"]!=null)_i["return"]();}finally{if(_d)throw _e;}}return _arr;}function _arrayWithHoles(arr){if(Array.isArray(arr))return arr;}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);}function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function");}}function _defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if("value"in descriptor)descriptor.writable=true;Object.defineProperty(target,descriptor.key,descriptor);}}function _createClass(Constructor,protoProps,staticProps){if(protoProps)_defineProperties(Constructor.prototype,protoProps);if(staticProps)_defineProperties(Constructor,staticProps);Object.defineProperty(Constructor,"prototype",{writable:false});return Constructor;}import React from'react';import{mount}from'enzyme';import{getAbsoluteHeight}from'@shopgate/pwa-common/helpers/dom';import UIEvents from'@shopgate/pwa-core/emitters/ui';import{SHEET_EVENTS}from"../Sheet";import{updateInsetBackgroundColor,updateFooterHeight}from"./style";import Footer from"./index";var mutationConstructorSpy=jest.fn();var mutationObserveSpy=jest.fn();/* eslint-disable require-jsdoc, extra-rules/potential-point-free, class-methods-use-this */global.MutationObserver=/*#__PURE__*/function(){function _class(callback){_classCallCheck(this,_class);mutationConstructorSpy(callback);}_createClass(_class,[{key:"observe",value:function observe(element,initObject){mutationObserveSpy(element,initObject);}}]);return _class;}();/* eslint-enable require-jsdoc, extra-rules/potential-point-free, class-methods-use-this */var mockedPortalContent;jest.mock("./style",function(){var actual=require.requireActual("./style");return _extends({},actual,{updateInsetBackgroundColor:jest.fn(),updateFooterHeight:jest.fn()});});jest.mock('@shopgate/pwa-core/emitters/ui',function(){return{addListener:jest.fn(),removeListener:jest.fn()};});jest.mock('@shopgate/pwa-common/helpers/dom',function(){var actual=require.requireActual('@shopgate/pwa-common/helpers/dom');return _extends({},actual,{getAbsoluteHeight:jest.fn()});});jest.mock('@shopgate/pwa-common/components/Portal',function(){// eslint-disable-next-line require-jsdoc
2
- function Portal(){return mockedPortalContent||null;}return Portal;});var mockedWarn=jest.fn();jest.mock('@shopgate/pwa-core/helpers',function(){return{logger:{warn:function warn(){return mockedWarn.apply(void 0,arguments);}}};});var FOOTER_CHILD_ID='footer-child';var PORTAL_CONTENT_ID='portal-content';var insetBackgroundUpdateSpy=jest.spyOn(Footer.prototype,'performFooterUpdate');var defaultBackgroundColor='red';var defaultChildren=/*#__PURE__*/React.createElement("div",{id:FOOTER_CHILD_ID,style:{backgroundColor:defaultBackgroundColor}});/**
3
- * @param {NodeList} children Children for the footer.
4
- * @returns {JSX}
5
- */var createComponent=function createComponent(){var children=arguments.length>0&&arguments[0]!==undefined?arguments[0]:defaultChildren;var wrapper=mount(/*#__PURE__*/React.createElement("div",null,/*#__PURE__*/React.createElement(Footer,null,children)));return wrapper.find(Footer);};/**
6
- * @param {Object} wrapper A wrapper.
7
- * @param {string} id Id of the element to change.
8
- */var addHeightToWrapperElement=function addHeightToWrapperElement(wrapper,id){var elements=wrapper.instance().ref.current.querySelectorAll("#".concat(id));if(elements){Array.from(elements).forEach(function(element){Object.defineProperty(element,'clientHeight',{get:function get(){return 30;}});});}};describe('<Footer />',function(){beforeEach(function(){jest.clearAllMocks();mockedPortalContent=null;});it('should render the component',function(){var wrapper=createComponent();expect(wrapper).toMatchSnapshot();expect(wrapper.find('Portal')).toHaveLength(2);expect(wrapper.find("div#AppFooter > #".concat(FOOTER_CHILD_ID))).toExist();expect(mutationConstructorSpy).toHaveBeenCalledWith(expect.any(Function));expect(insetBackgroundUpdateSpy).toHaveBeenCalledTimes(1);expect(mockedWarn).toHaveBeenCalledTimes(1);});describe('.hasVisibleContent()',function(){it('should return FALSE when footer has no visible content',function(){var wrapper=createComponent();expect(wrapper.instance().hasVisibleContent()).toBe(false);});it('should return FALSE when there are components, but they are not visible',function(){mockedPortalContent=/*#__PURE__*/React.createElement("div",{id:PORTAL_CONTENT_ID});var wrapper=createComponent();expect(wrapper.instance().hasVisibleContent()).toBe(false);});it('should return FALSE when there are components, but they are supposed to be ignored',function(){mockedPortalContent=/*#__PURE__*/React.createElement("div",{id:PORTAL_CONTENT_ID,"data-footer-inset-update-ignore":true});var wrapper=createComponent(null);addHeightToWrapperElement(wrapper,PORTAL_CONTENT_ID);expect(wrapper.instance().hasVisibleContent()).toBe(false);});it('should return TRUE when the core portal has visible content',function(){var wrapper=createComponent();addHeightToWrapperElement(wrapper,FOOTER_CHILD_ID);expect(wrapper.instance().hasVisibleContent()).toBe(true);});it('should return TRUE when the an extension portal has visible content',function(){mockedPortalContent=/*#__PURE__*/React.createElement("div",{id:PORTAL_CONTENT_ID});var wrapper=createComponent(null);addHeightToWrapperElement(wrapper,PORTAL_CONTENT_ID);expect(wrapper.instance().hasVisibleContent()).toBe(true);});});describe('.getInsetBackgroundColor()',function(){it('should return null when there is no visible content',function(){var wrapper=createComponent(null);addHeightToWrapperElement(wrapper,FOOTER_CHILD_ID);var elements=wrapper.instance().ref.current.children;expect(wrapper.instance().getInsetBackgroundColor(elements)).toBe(null);});it('should return "red" when there is visible content within the core portal',function(){var wrapper=createComponent();addHeightToWrapperElement(wrapper,FOOTER_CHILD_ID);var elements=wrapper.instance().ref.current.children;expect(wrapper.instance().getInsetBackgroundColor(elements)).toBe(defaultBackgroundColor);});it('should return "blue" when there is visible content within the core portal',function(){var backgroundColor='blue';mockedPortalContent=/*#__PURE__*/React.createElement("div",{id:FOOTER_CHILD_ID,style:{backgroundColor:backgroundColor}});var wrapper=createComponent();addHeightToWrapperElement(wrapper,PORTAL_CONTENT_ID);addHeightToWrapperElement(wrapper,FOOTER_CHILD_ID);var elements=wrapper.instance().ref.current.children;expect(wrapper.instance().getInsetBackgroundColor(elements)).toBe(backgroundColor);});it('should return "red" when there is visible content within the core portal',function(){var backgroundColor='blue';mockedPortalContent=/*#__PURE__*/React.createElement("div",{id:FOOTER_CHILD_ID,style:{backgroundColor:backgroundColor},"data-footer-inset-update-ignore":true});var wrapper=createComponent();addHeightToWrapperElement(wrapper,PORTAL_CONTENT_ID);addHeightToWrapperElement(wrapper,FOOTER_CHILD_ID);var elements=wrapper.instance().ref.current.children;expect(wrapper.instance().getInsetBackgroundColor(elements)).toBe(defaultBackgroundColor);});it('should return null when the last visible content in invisible by the background color',function(){var backgroundColor='rgba(0, 0, 0, 0)';mockedPortalContent=/*#__PURE__*/React.createElement("div",{id:FOOTER_CHILD_ID,style:{backgroundColor:backgroundColor}});var wrapper=createComponent();addHeightToWrapperElement(wrapper,PORTAL_CONTENT_ID);addHeightToWrapperElement(wrapper,FOOTER_CHILD_ID);var elements=wrapper.instance().ref.current.children;expect(wrapper.instance().getInsetBackgroundColor(elements)).toBe(null);});});describe('.performFooterUpdate()',function(){it('should do nothing when the ref is empty',function(){var wrapper=createComponent();wrapper.instance().ref.current=null;updateInsetBackgroundColor.mockClear();wrapper.instance().performFooterUpdate();expect(updateInsetBackgroundColor).not.toHaveBeenCalled();});it('should update the inset background color',function(){var wrapper=createComponent();updateInsetBackgroundColor.mockClear();var instance=wrapper.instance();instance.performFooterUpdate();var backgroundColor=instance.getInsetBackgroundColor(instance.ref.current.children);expect(updateInsetBackgroundColor).toHaveBeenCalledTimes(1);expect(updateInsetBackgroundColor).toHaveBeenCalledWith(backgroundColor);});});describe('MutationObserver',function(){var callback;var instance;beforeEach(function(){var wrapper=createComponent();instance=wrapper.instance();insetBackgroundUpdateSpy.mockClear();var _mutationConstructorS=_slicedToArray(mutationConstructorSpy.mock.calls,1);var _mutationConstructorS2=_slicedToArray(_mutationConstructorS[0],1);callback=_mutationConstructorS2[0];});it('should observer with the correct initialization',function(){expect(mutationObserveSpy).toHaveBeenCalledWith(instance.ref.current,{attributes:true,childList:true,subtree:true});});it('should perform an inset update when the updated DOM element is not ignored',function(){var element=document.createElement('div');callback([{target:element}]);expect(insetBackgroundUpdateSpy).toHaveBeenCalledTimes(1);});it('should not perform an inset update when the updated DOM element is ignored',function(){var element=document.createElement('div');element.setAttribute('data-footer-inset-update-ignore','true');callback([{target:element}]);expect(insetBackgroundUpdateSpy).not.toHaveBeenCalled();});});describe('UI events subscriptions',function(){it('should subscribe / unsubscribe UI events',function(){var wrapper=mount(/*#__PURE__*/React.createElement(Footer,null,/*#__PURE__*/React.createElement("div",null,"Footer")));var instance=wrapper.instance();expect(UIEvents.addListener).toBeCalledTimes(2);expect(UIEvents.addListener).nthCalledWith(1,SHEET_EVENTS.OPEN,instance.hide);expect(UIEvents.addListener).nthCalledWith(2,SHEET_EVENTS.CLOSE,instance.show);wrapper.unmount();expect(UIEvents.removeListener).toBeCalledTimes(2);expect(UIEvents.removeListener).nthCalledWith(1,SHEET_EVENTS.OPEN,instance.hide);expect(UIEvents.removeListener).nthCalledWith(2,SHEET_EVENTS.CLOSE,instance.show);});});describe('updateFooterHeight',function(){var instance;beforeEach(function(){var wrapper=createComponent();instance=wrapper.instance();});it('should set footer height to zero',function(){instance.hide();expect(updateFooterHeight).toHaveBeenCalledWith(0);});it('should set footer height',function(){getAbsoluteHeight.mockReturnValueOnce('48px');instance.show();expect(updateFooterHeight).toHaveBeenCalledWith('48px');});});});
@@ -1 +0,0 @@
1
- import buildCountryList from"./buildCountryList";jest.mock('@shopgate/pwa-core/helpers',function(){return{logger:{error:function error(){}}};});var countryElement={countries:['DE','US']};describe('buildCountryList',function(){it('should return empty list when config is wrong',function(){expect(buildCountryList({countries:''})).toEqual({});});it('should return list with 2 countries',function(){var expected={DE:'Germany',US:'United States'};expect(buildCountryList(countryElement)).toEqual(expected);});it('should return list with 2 countries and optional on top',function(){var expected={'':'',DE:'Germany',US:'United States'};expect(buildCountryList(countryElement,{'':''})).toEqual(expected);});it('should ignore unknown countries',function(){var expected={DE:'Germany'};expect(buildCountryList({countries:['DE','XX']})).toEqual(expected);});});
@@ -1 +0,0 @@
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);}/* eslint-disable extra-rules/no-single-line-objects */import{ELEMENT_TYPE_SELECT}from"../elementTypes";import buildFormDefaults from"./buildFormDefaults";var formElement={id:'field',"default":'foo',custom:false};var defaults={field:'baz',customAttributes:{}};describe('buildFormDefaults',function(){it('should build defaults from element defaults',function(){var expected={field:'foo'};expect(buildFormDefaults([formElement],{})).toEqual(expected);});it('should build defaults from object defaults ',function(){var expected={field:'baz'};expect(buildFormDefaults([formElement],defaults)).toEqual(expected);});it('should build defaults for custom from element defaults',function(){var expected={field:'foo'};var el=_extends({},formElement,{custom:true});expect(buildFormDefaults([el],defaults)).toEqual(expected);});it('should build defaults for custom from object defaults',function(){var expected={field:'baz'};var el=_extends({},formElement,{custom:true});var def=_extends({},defaults,{customAttributes:{field:'baz'}});expect(buildFormDefaults([el],def)).toEqual(expected);});describe('ELEMENT_TYPE_SELECT',function(){var options={mr:'Mr.',mrs:'Mrs.'};it('should set default value',function(){var el=_extends({},formElement,{type:ELEMENT_TYPE_SELECT,options:options});expect(buildFormDefaults([el])).toEqual({field:'foo'});});it('should set first option',function(){var el=_extends({},formElement,{type:ELEMENT_TYPE_SELECT,options:options,"default":null});expect(buildFormDefaults([el])).toEqual({field:'mr'});});});});/* eslint-enable extra-rules/no-single-line-objects */
@@ -1,2 +0,0 @@
1
- var _excluded=["handleChange"],_excluded2=["handleChange"],_excluded3=["handleChange"];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);}function _objectWithoutProperties(source,excluded){if(source==null)return{};var target=_objectWithoutPropertiesLoose(source,excluded);var key,i;if(Object.getOwnPropertySymbols){var sourceSymbolKeys=Object.getOwnPropertySymbols(source);for(i=0;i<sourceSymbolKeys.length;i++){key=sourceSymbolKeys[i];if(excluded.indexOf(key)>=0)continue;if(!Object.prototype.propertyIsEnumerable.call(source,key))continue;target[key]=source[key];}}return target;}function _objectWithoutPropertiesLoose(source,excluded){if(source==null)return{};var target={};var sourceKeys=Object.keys(source);var key,i;for(i=0;i<sourceKeys.length;i++){key=sourceKeys[i];if(excluded.indexOf(key)>=0)continue;target[key]=source[key];}return target;}import{ELEMENT_TYPE_COUNTRY}from"../elementTypes";import buildFormElements from"./buildFormElements";jest.mock('@shopgate/pwa-core/helpers',function(){return{logger:{error:function error(){}}};});var formElementConfig={sortOrder:1,label:'Label',type:'text',"default":'default',placeholder:'locales',required:true,visible:true};var formElement={id:'field',sortOrder:1,label:'Label',type:'text',"default":'default',placeholder:'locales',required:true,visible:true,custom:false};describe('buildFormElements',function(){it('should not build custom field',function(){var config={fields:{custom:formElementConfig}};expect(buildFormElements(config)).toEqual([]);});it('should not build empty config',function(){var config={fields:{}};expect(buildFormElements(config)).toEqual([]);});it('should build text element',function(){var config={fields:{field:formElementConfig}};var _buildFormElements$=buildFormElements(config)[0],ignore=_buildFormElements$.handleChange,restElement=_objectWithoutProperties(_buildFormElements$,_excluded);expect(restElement).toEqual(formElement);});it('should build 1 country element',function(){var config={fields:{country:_extends({},formElementConfig,{type:ELEMENT_TYPE_COUNTRY}),country_2:_extends({},formElementConfig,{type:ELEMENT_TYPE_COUNTRY})}};var expected=_extends({},formElement,{id:'country',type:ELEMENT_TYPE_COUNTRY});var _buildFormElements$2=buildFormElements(config)[0],ignore=_buildFormElements$2.handleChange,restElement=_objectWithoutProperties(_buildFormElements$2,_excluded2);expect(restElement).toEqual(expected);});it('should build custom text element',function(){var config={fields:{custom:{field:formElementConfig}}};var expected=_extends({},formElement,{custom:true});var _buildFormElements$3=buildFormElements(config)[0],ignore=_buildFormElements$3.handleChange,restElement=_objectWithoutProperties(_buildFormElements$3,_excluded3);expect(restElement).toEqual(expected);});it('should build correct change handler for text field',function(){var config={fields:{field:formElementConfig}};var mockHandler=jest.fn();var handleChange=buildFormElements(config,mockHandler)[0].handleChange;// Invoke handler with field value
2
- handleChange('bar');expect(mockHandler).toBeCalledWith('field','bar');});});
@@ -1 +0,0 @@
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 iso3166 from"../iso-3166-2";import buildProvinceList from"./buildProvinceList";describe('buildProvinceList',function(){it('should return empty list when country is unknown',function(){expect(buildProvinceList('SOME')).toEqual({});});it('should return a list with US provinces',function(){var expected=iso3166.US.divisions;expect(buildProvinceList('US')).toEqual(expected);});it('should return a list with US provinces and optional',function(){var expected=_extends({'':''},iso3166.US.divisions);expect(buildProvinceList('US',{'':''})).toEqual(expected);});});
@@ -1 +0,0 @@
1
- import React from'react';import{mount}from'enzyme';import Ellipsis from'@shopgate/pwa-common/components/Ellipsis';import ProductProperties from"./index";var properties=[{label:'Label One',value:'Value One'},{label:'Label Two',value:'Value Two'}];describe('<ProductProperties />',function(){it('should not render when no properties are passed',function(){var wrapper=mount(/*#__PURE__*/React.createElement(ProductProperties,null));expect(wrapper).toMatchSnapshot();expect(wrapper).toBeEmptyRender();});it('should not render when an empty list of properties is passed',function(){var wrapper=mount(/*#__PURE__*/React.createElement(ProductProperties,{properties:[]}));expect(wrapper).toMatchSnapshot();expect(wrapper).toBeEmptyRender();});it('should render as expected when properties are passed',function(){expect.assertions(5);var wrapper=mount(/*#__PURE__*/React.createElement(ProductProperties,{properties:properties}));expect(wrapper).toMatchSnapshot();expect(wrapper.find(Ellipsis).exists()).toBe(false);var listElements=wrapper.find('li');expect(listElements.length).toBe(2);listElements.forEach(function(el,index){expect(listElements.at(index).text()).toBe("".concat(properties[index].label,": ").concat(properties[index].value));});});it('should use the ellipsis component when the lineClamp prop is passed ',function(){expect.assertions(6);var lineClamp=2;var wrapper=mount(/*#__PURE__*/React.createElement(ProductProperties,{properties:properties,lineClamp:lineClamp}));expect(wrapper).toMatchSnapshot();var listElements=wrapper.find(Ellipsis);expect(listElements.length).toBe(2);listElements.forEach(function(el,index){expect(el.prop('rows')).toBe(lineClamp);expect(listElements.at(index).text()).toBe("".concat(properties[index].label,": ").concat(properties[index].value));});});});
@@ -1,3 +0,0 @@
1
- /* eslint-disable no-console */import React from'react';import{mount}from'enzyme';import RatingNumber from"./index";jest.mock('@shopgate/pwa-common/components/I18n',function(){return{// eslint-disable-next-line react/prop-types
2
- Number:function Number(_ref){var rating=_ref.rating;return/*#__PURE__*/React.createElement("div",null,rating);}};});// One of the tests deliberately produces a react warning. The console is mocked to avoid ugly logs.
3
- console.error=jest.fn();describe('RatingNumber',function(){it('should render a number',function(){var component=mount(/*#__PURE__*/React.createElement(RatingNumber,{rating:100,className:"class-test"}));expect(component).toMatchSnapshot();expect(component.find('Number').props().number).toBe(5);expect(component.find('Number').props().fractions).toBe(2);expect(component.find('Number').props().className).toBe('class-test ui-shared__rating-number');expect(console.error).not.toHaveBeenCalled();});it('should return when rating is null',function(){var component=mount(/*#__PURE__*/React.createElement(RatingNumber,{rating:null}));expect(component.html()).toBe(null);expect(console.error).not.toHaveBeenCalled();});it('should return Number when rating is zero',function(){var component=mount(/*#__PURE__*/React.createElement(RatingNumber,{rating:0}));expect(component.html()).not.toBe(null);expect(console.error).not.toHaveBeenCalled();});it('should return number when division result is NaN',function(){var component=mount(/*#__PURE__*/React.createElement(RatingNumber,{rating:{}}));expect(component.html()).toBe(null);expect(console.error).toHaveBeenCalledTimes(1);});});/* eslint-enable no-console */
@@ -1 +0,0 @@
1
- import _regeneratorRuntime from"@babel/runtime/regenerator";function asyncGeneratorStep(gen,resolve,reject,_next,_throw,key,arg){try{var info=gen[key](arg);var value=info.value;}catch(error){reject(error);return;}if(info.done){resolve(value);}else{Promise.resolve(value).then(_next,_throw);}}function _asyncToGenerator(fn){return function(){var self=this,args=arguments;return new Promise(function(resolve,reject){var gen=fn.apply(self,args);function _next(value){asyncGeneratorStep(gen,resolve,reject,_next,_throw,"next",value);}function _throw(err){asyncGeneratorStep(gen,resolve,reject,_next,_throw,"throw",err);}_next(undefined);});};}import React from'react';import{mount}from'enzyme';import{defaultClientInformation}from'@shopgate/pwa-core/helpers/version';import AppScanner from'@shopgate/pwa-core/classes/Scanner';import{SCANNER_SCOPE_DEFAULT,SCANNER_TYPE_BARCODE,SCANNER_MIN_APP_LIB_VERSION}from'@shopgate/pwa-core/constants/Scanner';import CameraOverlay from"./components/CameraOverlay";import FlashlightButton from"./components/ScannerBar/components/FlashlightButton";import ScannerOverlay from"./index";jest.mock('@shopgate/pwa-core/classes/AppCommand');jest.mock('react-dom',function(){return{createPortal:function createPortal(element){return/*#__PURE__*/React.createElement("div",{id:"portal-content"},element);}};});defaultClientInformation.libVersion=SCANNER_MIN_APP_LIB_VERSION;describe('<ScannerOverlay />',function(){var toggleFlashlightSpy=jest.spyOn(AppScanner,'toggleFlashlight');it('should render the component',function(){var wrapper=mount(/*#__PURE__*/React.createElement(ScannerOverlay,null));expect(wrapper).toMatchSnapshot();expect(wrapper.find(CameraOverlay)).not.toBeEmptyRender();expect(wrapper.find(CameraOverlay)).not.toBeEmptyRender();expect(wrapper.state('flashlight')).toBe(false);});it('should toggle the flashlight when the button is pressed',/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(){var wrapper,button;return _regeneratorRuntime.wrap(function _callee$(_context){while(1){switch(_context.prev=_context.next){case 0:_context.next=2;return AppScanner.open(SCANNER_SCOPE_DEFAULT,SCANNER_TYPE_BARCODE);case 2:wrapper=mount(/*#__PURE__*/React.createElement(ScannerOverlay,null));button=wrapper.find(FlashlightButton).find('ToggleIcon');button.simulate('click');expect(wrapper.state('flashlight')).toBe(true);expect(toggleFlashlightSpy).toHaveBeenCalledTimes(1);button.simulate('click');expect(wrapper.state('flashlight')).toBe(false);expect(toggleFlashlightSpy).toHaveBeenCalledTimes(2);case 10:case"end":return _context.stop();}}},_callee);})));});