UNPKG

lucid-ui

Version:

A UI component library from AppNexus.

98 lines (94 loc) 4.1 kB
import _has from "lodash/has"; import _forEach from "lodash/forEach"; import _noop from "lodash/noop"; 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 assert from 'assert'; import React from 'react'; import { CSSTransition } from 'react-transition-group'; import { mount, shallow } from 'enzyme'; import { common } from '../../util/generic-tests'; import SwitchLabeled from './SwitchLabeled'; import Switch from '../Switch/Switch'; describe('SwitchLabeled', function () { common(SwitchLabeled); describe('props', function () { describe('isDisabled', function () { it('passes the value through to its `Switch` instance.', function () { var wrapper = shallow( /*#__PURE__*/React.createElement(SwitchLabeled, { isDisabled: true })); assert.equal(wrapper.find(Switch).prop('isDisabled'), true); }); it('defaults to `false`.', function () { var wrapper = mount( /*#__PURE__*/React.createElement(SwitchLabeled, null)); assert.equal(wrapper.prop('isDisabled'), false); }); }); describe('isSelected', function () { it('passes the value through to its `Switch` instance.', function () { var wrapper = shallow( /*#__PURE__*/React.createElement(SwitchLabeled, { isSelected: true })); assert.equal(wrapper.find(Switch).prop('isSelected'), true); }); it('defaults to `false`.', function () { var wrapper = mount( /*#__PURE__*/React.createElement(SwitchLabeled, null)); assert.equal(wrapper.prop('isSelected'), false); }); }); describe('onSelect', function () { it('passes the value through to its `Switch` instance.', function () { var foo = function foo() { return null; }; var wrapper = shallow( /*#__PURE__*/React.createElement(SwitchLabeled, { onSelect: foo })); assert.equal(wrapper.find(Switch).prop('onSelect'), foo); }); it('defaults to the Lodash `noop` method.', function () { var wrapper = mount( /*#__PURE__*/React.createElement(SwitchLabeled, null)); assert.equal(wrapper.prop('onSelect'), _noop); }); }); describe('Label (as a prop)', function () { it('renders the value in a `span` neighboring its `Switch` instance.', function () { var wrapper = shallow( /*#__PURE__*/React.createElement(SwitchLabeled, { Label: 'foo' })); assert.equal(wrapper.find(CSSTransition).find('span').prop('children'), 'foo'); }); }); describe('Label (as a child)', function () { it('renders the value in a `span` neighboring its `Switch` instance.', function () { var wrapper = shallow( /*#__PURE__*/React.createElement(SwitchLabeled, null, /*#__PURE__*/React.createElement(SwitchLabeled.Label, null, "foo"))); assert.equal(wrapper.find(CSSTransition).find('span').prop('children'), 'foo'); }); }); describe('pass throughs', function () { it('passes through all props not defined in `propTypes` to its `Switch` instance.', function () { var extraProps = { foo: 1, bar: 2, baz: 3, qux: 4, quux: 5 }; var wrapper = shallow( /*#__PURE__*/React.createElement(SwitchLabeled, _extends({ className: "wut", isDisabled: true, isSelected: true, style: { fontWeight: 'bold' }, onSelect: _noop }, extraProps))); var switchProps = wrapper.find(Switch).props(); // It should pass `foo`, `bar`, `baz`, `qux`, and `quux` through // to the `Switch` instance. _forEach(['foo', 'bar', 'baz', 'qux', 'quux'], function (prop) { assert(_has(switchProps, prop)); }); }); }); }); });