UNPKG

wix-style-react

Version:
60 lines (48 loc) 2.1 kB
var _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; }; import React from 'react'; import { stub } from 'sinon'; import { mount } from 'enzyme'; import * as Utils from '../utils'; import withItemMaxWidth from './index'; describe('withItemMaxWidth hoc', function () { stub(Utils, 'getWidth'); afterEach(function () { Utils.getWidth.reset(); Utils.getWidth.resetBehavior(); }); afterAll(function () { Utils.getWidth.restore(); }); var Component = function Component() { return React.createElement('div', null); }; // eslint-disable-line react/prop-types var aComponent = function aComponent() { var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; return mount(React.createElement(withItemMaxWidth(Component), props)); }; var anItem = function anItem(id) { var title = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'Any'; return { id: id, title: title }; }; it('sets itemMaxWidth for compactSide type', function () { var items = [anItem(0), anItem(1)]; var containerSize = 100; Utils.getWidth.returns(containerSize); var comp = aComponent({ items: items, type: 'compactSide' }); var actualWidth = comp.find(Component).prop('itemMaxWidth'); var expectedWidth = containerSize / items.length - 18 * (items.length - 1); expect(actualWidth).toEqual(expectedWidth); }); it('does not set itemMaxWidth for other types', function () { var comp = aComponent({ items: [anItem('a'), anItem('b')], type: 'uniformFull' }); expect(comp.find(Component).prop('itemMaxWidth')).toBe(undefined); }); it('passes props to the wrapped component', function () { var props = { a: '1', b: true, c: 3 }; var comp = aComponent(_extends({ items: [anItem(0)] }, props)); expect(comp.find(Component).props()).toMatchObject(props); }); });