UNPKG

@shopgate/pwa-common

Version:

Common library for the Shopgate Connect PWA.

9 lines 1.64 kB
import React from'react';import PropTypes from'prop-types';import{mount}from'enzyme';import SelectBox from"./index";/** * Mock Icon component. * @returns {JSX} */var MockIconComponent=function MockIconComponent(){return React.createElement("span",{id:"icon"});};/** * Mock Item component. * @param {Object} props The components props. * @param {JSX} props.children The components children. * @returns {JSX} */var MockItemComponent=function MockItemComponent(_ref){var children=_ref.children;return React.createElement("div",null,children);};describe('<SelectBox>',function(){var dummyItems=[{label:'My item #1',value:'item_1'},{label:'My item #2',value:'item_2'},{label:'My item #3',value:'item_3'}];it('should render the selectbox with given mock components',function(){var wrapper=mount(React.createElement(SelectBox,{icon:MockIconComponent,item:MockItemComponent,items:dummyItems}));expect(wrapper).toMatchSnapshot();expect(wrapper.find(MockIconComponent).length).toEqual(1);expect(wrapper.find(MockItemComponent).length).toEqual(3);});it('should render with a default text',function(){var wrapper=mount(React.createElement(SelectBox,{icon:MockIconComponent,item:MockItemComponent,items:dummyItems,defaultText:"Foo"}));expect(wrapper).toMatchSnapshot();expect(wrapper.find('span').at(0).text()).toEqual('Foo');});it('should render with a preselected selection',function(){var wrapper=mount(React.createElement(SelectBox,{icon:MockIconComponent,item:MockItemComponent,items:dummyItems,defaultText:"Foo",initialValue:"item_2"}));expect(wrapper).toMatchSnapshot();expect(wrapper.find('span').at(0).text()).toEqual('My item #2');});});