UNPKG

lucid-ui

Version:

A UI component library from AppNexus.

59 lines 2.27 kB
import React from 'react'; import assert from 'assert'; import { common } from '../../util/generic-tests'; import { shallow } from 'enzyme'; import Validation from './Validation'; describe('Validation', function () { common(Validation, { getDefaultProps: function getDefaultProps() { return { children: /*#__PURE__*/React.createElement("span", null, "foo") }; } }); describe('render', function () { it('should render children', function () { var content = /*#__PURE__*/React.createElement("div", null, "foo"); var wrapper = shallow( /*#__PURE__*/React.createElement(Validation, null, content)); assert(wrapper.children().first().equals(content)); }); }); describe('props', function () { describe('Error', function () { var wrapper; beforeEach(function () { return wrapper = shallow( /*#__PURE__*/React.createElement(Validation, { Error: "error" }, /*#__PURE__*/React.createElement("div", null, "foo"))); }); it('should add error class', function () { assert(wrapper.hasClass('lucid-Validation-is-error')); }); it('should add error content', function () { assert.equal(wrapper.find('.lucid-Validation-error-content').text(), 'error'); }); }); describe('null Error', function () { var wrapper; beforeEach(function () { return wrapper = shallow( /*#__PURE__*/React.createElement(Validation, { Error: null }, /*#__PURE__*/React.createElement("div", null, "foo"))); }); it('should not add error class', function () { assert(!wrapper.hasClass('lucid-Validation-is-error')); }); it('should not add error content', function () { assert.equal(wrapper.find('.lucid-Validation-error-content').length, 0); }); }); describe('child components', function () { describe('Error', function () { it('should render an error', function () { var wrapper = shallow( /*#__PURE__*/React.createElement(Validation, null, /*#__PURE__*/React.createElement(Validation.Error, null, "foo"), "Content")); assert.equal(wrapper.find('.lucid-Validation-error-content').text(), 'foo'); }); }); }); }); });