UNPKG

@salesforce/design-system-react

Version:

Salesforce Lightning Design System for React

126 lines (111 loc) 4.66 kB
"use strict"; var _react = _interopRequireDefault(require("react")); var _enzyme = require("enzyme"); var _chai = _interopRequireDefault(require("chai")); var _lodash = _interopRequireDefault(require("lodash.assign")); var _iconSettings = _interopRequireDefault(require("../../icon-settings")); var _link = _interopRequireDefault(require("../../app-launcher/link")); var _tile = _interopRequireDefault(require("../../app-launcher/tile")); var _expandableSection = _interopRequireDefault(require("../../app-launcher/expandable-section")); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } var expect = _chai.default.expect; var should = _chai.default.should(); describe('SLDS APP LAUNCHER EXPANDABLE SECTION *******************************************', function () { var handles = { section: null }; var defaultSectionProps = { title: 'All Items' }; var defaultChildren = [_react.default.createElement(_tile.default, { key: "asdf", title: "Marketing Cloud" }), _react.default.createElement(_tile.default, { key: "qwer", title: "Support Cloud" })]; var linkChildren = [_react.default.createElement(_link.default, { key: "asdf" }, "Accounts"), _react.default.createElement(_link.default, { key: "qwer" }, "Ammnouncements")]; var createSection = function createSection(props, children) { return _react.default.createElement(_expandableSection.default, (0, _lodash.default)({}, defaultSectionProps, props), children); }; function mountSection(props) { var children = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : defaultChildren; handles.section = (0, _enzyme.mount)(_react.default.createElement(_iconSettings.default, { iconPath: "/assets/icons" }, createSection(props, children))); } describe('App Launcher Expandable Section', function () { var onToggleOpen; beforeEach(function () { onToggleOpen = sinon.spy(); mountSection({ assistiveText: { toggleSection: 'Collapse Section' }, onToggleOpen: onToggleOpen, title: 'ALL THE ITEMS!' }); }); it('section exists', function () { should.exist(handles.section); }); it('section has "slds-is-open" class when open', function () { expect(handles.section.find('.slds-section')).to.have.className('slds-is-open'); }); it('section has a title', function () { should.exist(handles.section.find('.slds-section__title')); }); it('ul has proper classes', function () { should.exist(handles.section.find('ul.slds-grid.slds-grid_pull-padded.slds-wrap')); }); it('li exists', function () { expect(handles.section.find('li').length).to.equal(2); }); it('renders li with proper classes', function () { var li = handles.section.find('li').at(0); expect(li).to.have.className('slds-p-horizontal_small'); expect(li).to.have.className('slds-size_1-of-1'); expect(li).to.have.className('slds-medium-size_1-of-3'); }); it('renders custom section title', function () { expect(handles.section.find('h3 .slds-truncate').text()).to.equal('ALL THE ITEMS!'); }); it('renders custom toggle assistve text', function () { expect(handles.section.find('h3 span.slds-assistive-text').text()).to.equal('Collapse Section'); }); it('toggling section fires callback', function () { handles.section.find('h3 button.slds-button').simulate('click'); expect(onToggleOpen.calledOnce).to.be.true; // eslint-disable-line no-unused-expressions }); }); describe('App Launcher Expandable Section (non-collapsible) with links', function () { beforeEach(function () { mountSection({ nonCollapsible: true }, linkChildren); }); it('does not render toggle if non-collapsible is true', function () { should.not.exist(handles.section.find('.slds-button .slds-button_icon .slds-m-right_small')); }); it('renders li with proper classes', function () { var li = handles.section.find('li').at(0); expect(li).to.have.className('slds-col_padded'); expect(li).to.have.className('slds-p-vertical_xx-small'); expect(li).to.have.className('slds-size_1-of-5'); }); }); describe('App Launcher Expandable Section (closed)', function () { beforeEach(function () { mountSection({ isOpen: false }); }); it('section does not have "slds-is-open" class when closed', function () { expect(handles.section.find('.slds-section.slds-is-open').length).to.eql(0); }); }); });