UNPKG

lucid-ui

Version:

A UI component library from AppNexus.

73 lines (71 loc) 3.03 kB
import _has from "lodash/has"; import _forEach from "lodash/forEach"; import _noop from "lodash/noop"; import assert from 'assert'; import React from 'react'; import { shallow } from 'enzyme'; import { common } from '../../util/generic-tests'; import RadioButtonLabeled from './RadioButtonLabeled'; import RadioButton from '../RadioButton/RadioButton'; describe('RadioButtonLabeled', function () { common(RadioButtonLabeled); describe('render', function () { it('should allow multiple Label children', function () { var wrapper = shallow( /*#__PURE__*/React.createElement(RadioButtonLabeled, null, /*#__PURE__*/React.createElement(RadioButtonLabeled.Label, null, /*#__PURE__*/React.createElement("span", null, "one"), /*#__PURE__*/React.createElement("span", null, "two")))); assert.equal(wrapper.find(RadioButtonLabeled.Label).children().at(0).text(), 'one', 'wrong or missing first Label child'); assert.equal(wrapper.find(RadioButtonLabeled.Label).children().at(1).text(), 'two', 'wrong or missing second Label child'); }); }); describe('props', function () { describe('isDisabled', function () { it('passes the value through to its `RadioButton` instance.', function () { var wrapper = shallow( /*#__PURE__*/React.createElement(RadioButtonLabeled, { isDisabled: true })); assert.equal(wrapper.find(RadioButton).prop('isDisabled'), true); }); }); describe('isSelected', function () { it('passes the value through to its `RadioButton` instance.', function () { var wrapper = shallow( /*#__PURE__*/React.createElement(RadioButtonLabeled, { isSelected: true })); assert.equal(wrapper.find(RadioButton).prop('isSelected'), true); }); }); describe('onSelect', function () { it('passes the value through to its `RadioButton` instance.', function () { var foo = function foo() { return null; }; var wrapper = shallow( /*#__PURE__*/React.createElement(RadioButtonLabeled, { onSelect: foo })); assert.equal(wrapper.find(RadioButton).prop('onSelect'), foo); }); }); describe('pass throughs', function () { it('passes through all props not defined in `propTypes` to its `RadioButton` instance.', function () { var wrapper = shallow( /*#__PURE__*/React.createElement(RadioButtonLabeled, { className: "wut", isDisabled: true, isSelected: true, style: { fontWeight: 'bold' }, onSelect: _noop, foo: 1, bar: 2, baz: 3, qux: 4, quux: 5 })); var radioButtonProps = wrapper.find(RadioButton).props(); // It should pass `foo`, `bar`, `baz`, `qux`, and `quux` through // to the `RadioButton` instance. _forEach(['foo', 'bar', 'baz', 'qux', 'quux'], function (prop) { assert(_has(radioButtonProps, prop)); }); }); }); }); });