UNPKG

@salesforce/design-system-react

Version:

Salesforce Lightning Design System for React

164 lines (144 loc) 6.09 kB
"use strict"; var _react = require("react"); var _react2 = _interopRequireDefault(_react); var _createReactClass = require("create-react-class"); var _createReactClass2 = _interopRequireDefault(_createReactClass); var _propTypes = require("prop-types"); var _propTypes2 = _interopRequireDefault(_propTypes); var _chai = require("chai"); var _chai2 = _interopRequireDefault(_chai); var _chaiEnzyme = require("chai-enzyme"); var _chaiEnzyme2 = _interopRequireDefault(_chaiEnzyme); var _enzymeHelpers = require("../../../tests/enzyme-helpers"); var _illustration = require("../../illustration"); var _illustration2 = _interopRequireDefault(_illustration); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } /* eslint-env mocha */ /* global sinon */ /* eslint-disable prefer-arrow-callback */ /* eslint-disable no-unused-expressions */ // `this.wrapper` and `this.dom` is set in the helpers file _chai2.default.use((0, _chaiEnzyme2.default)()); var DemoIllustration = (0, _createReactClass2.default)({ displayName: 'DemoIllustration', render: function render() { return _react2.default.createElement(_illustration2.default, this.props); } }); describe('SLDSIllustration: ', function () { describe('Image with heading and message render', function () { var svg; var heading; var messageBody; beforeEach((0, _enzymeHelpers.mountComponent)(_react2.default.createElement(DemoIllustration, { className: "custom-illustration", internalIllustration: true, heading: "Lorem ipsum dolor", messageBody: "Lorem ipsum dolor sit amet, consectetur", name: "No Access", path: "/assets/images/illustrations/empty-state-no-access.svg#no-access", size: "small", style: { backgroundColor: 'rgb(218, 165, 32)' } }))); afterEach(_enzymeHelpers.unmountComponent); it('renders container class', function () { (0, _chai.expect)(this.wrapper.hasClass('slds-illustration')).to.be.true; (0, _chai.expect)(this.wrapper.hasClass('custom-illustration')).to.be.true; }); it('renders illustration size class', function () { (0, _chai.expect)(this.wrapper.hasClass('slds-illustration_small')).to.be.true; }); it('sets svg aria-hidden to true', function () { svg = this.wrapper.find('svg'); (0, _chai.expect)(svg.node.getAttribute('aria-hidden')).to.equal('true'); }); it('renders illustration svg class', function () { (0, _chai.expect)(svg.hasClass('slds-illustration__svg')).to.be.true; }); it('renders svg name attribute', function () { svg = this.wrapper.find('svg'); // also tests that all '_' and ' ' are replaced with '-' (0, _chai.expect)(svg.node.getAttribute('name')).to.equal('no-access'); }); it('renders svg custom background color', function () { svg = this.wrapper.find('svg'); (0, _chai.expect)(svg).to.have.style('backgroundColor', 'rgb(218, 165, 32)'); }); it('renders heading', function () { heading = this.wrapper.find('.slds-text-heading_medium'); (0, _chai.expect)(heading.text()).to.equal('Lorem ipsum dolor'); }); it('renders message body', function () { messageBody = this.wrapper.find('.slds-text-body_regular'); (0, _chai.expect)(messageBody.text()).to.equal('Lorem ipsum dolor sit amet, consectetur'); }); }); describe('Heading and message render', function () { var svg; var heading; var messageBody; beforeEach((0, _enzymeHelpers.mountComponent)(_react2.default.createElement(DemoIllustration, { internalIllustration: true, heading: "Lorem ipsum dolor", messageBody: "Lorem ipsum dolor sit amet, consectetur" }))); afterEach(_enzymeHelpers.unmountComponent); it('does not render svg', function () { svg = this.wrapper.find('svg'); (0, _chai.expect)(svg.node).to.be.undefined; }); it('renders heading', function () { heading = this.wrapper.find('.slds-text-heading_medium'); (0, _chai.expect)(heading.text()).to.equal('Lorem ipsum dolor'); }); it('renders message body', function () { messageBody = this.wrapper.find('.slds-text-body_regular'); (0, _chai.expect)(messageBody.text()).to.equal('Lorem ipsum dolor sit amet, consectetur'); }); }); describe('Heading only renders', function () { var svg; var heading; var messageBody; beforeEach((0, _enzymeHelpers.mountComponent)(_react2.default.createElement(DemoIllustration, { internalIllustration: true, heading: "Lorem ipsum dolor" }))); afterEach(_enzymeHelpers.unmountComponent); it('does not render svg', function () { svg = this.wrapper.find('svg'); (0, _chai.expect)(svg.node).to.be.undefined; }); it('renders heading', function () { heading = this.wrapper.find('.slds-text-heading_medium'); (0, _chai.expect)(heading.text()).to.equal('Lorem ipsum dolor'); }); it('does not render message body', function () { messageBody = this.wrapper.find('.slds-text-body_regular'); (0, _chai.expect)(messageBody.node).to.be.undefined; }); }); describe('Message only renders', function () { var svg; var heading; var messageBody; beforeEach((0, _enzymeHelpers.mountComponent)(_react2.default.createElement(DemoIllustration, { internalIllustration: true, messageBody: "Lorem ipsum dolor sit amet, consectetur" }))); afterEach(_enzymeHelpers.unmountComponent); it('does not render svg', function () { svg = this.wrapper.find('svg'); (0, _chai.expect)(svg.node).to.be.undefined; }); it('does not render heading', function () { heading = this.wrapper.find('.slds-text-heading_medium'); (0, _chai.expect)(heading.node).to.be.undefined; }); it('renders message body', function () { messageBody = this.wrapper.find('.slds-text-body_regular'); (0, _chai.expect)(messageBody.text()).to.equal('Lorem ipsum dolor sit amet, consectetur'); }); }); });