@salesforce/design-system-react
Version:
Salesforce Lightning Design System for React
187 lines (160 loc) • 8.16 kB
JavaScript
;
var _react = require("react");
var _react2 = _interopRequireDefault(_react);
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 }; }
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
_chai2.default.use((0, _chaiEnzyme2.default)());
var DemoIllustration =
/*#__PURE__*/
function (_React$Component) {
_inherits(DemoIllustration, _React$Component);
function DemoIllustration() {
_classCallCheck(this, DemoIllustration);
return _possibleConstructorReturn(this, (DemoIllustration.__proto__ || Object.getPrototypeOf(DemoIllustration)).apply(this, arguments));
}
_createClass(DemoIllustration, [{
key: "render",
value: function render() {
return _react2.default.createElement(_illustration2.default, this.props);
}
}]);
return DemoIllustration;
}(_react2.default.Component);
Object.defineProperty(DemoIllustration, "displayName", {
configurable: true,
enumerable: true,
writable: true,
value: 'DemoIllustration'
});
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).to.have.className('slds-illustration');
(0, _chai.expect)(this.wrapper).to.have.className('custom-illustration');
});
it('renders illustration size class', function () {
(0, _chai.expect)(this.wrapper).to.have.className('slds-illustration_small');
});
it('sets svg aria-hidden to true', function () {
svg = this.wrapper.find('svg');
(0, _chai.expect)(svg).to.have.attr('aria-hidden', 'true');
});
it('renders illustration svg class', function () {
svg = this.wrapper.find('svg');
(0, _chai.expect)(svg.hasClass('slds-illustration__svg')).to.be.true; // chai-enzyme is buggy with an svg
});
it('renders svg name attribute', function () {
svg = this.wrapper.find('svg'); // also tests that all '_' and ' ' are replaced with '-'
(0, _chai.expect)(svg).to.have.attr('name', '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).not.to.be.present();
});
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).not.to.be.present();
});
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 () {
(0, _chai.expect)(this.wrapper.find('.slds-text-body_regular')).not.to.be.present();
});
});
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).not.to.be.present();
});
it('does not render heading', function () {
heading = this.wrapper.find('.slds-text-heading_medium');
(0, _chai.expect)(heading).not.to.be.present();
});
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');
});
});
});