UNPKG

react-storybook-addon-chapters

Version:

React Storybook Chapters addon allows showcasing of multiple components within a story by breaking it down into smaller categories (chapters) and subcategories (sections) for more organizational goodness.

128 lines (115 loc) 3.89 kB
"use strict"; var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard"); var _chai = require("chai"); var _index = _interopRequireWildcard(require("../index")); /* eslint-disable no-unused-expressions, import/no-extraneous-dependencies */ var _global = global, describe = _global.describe, it = _global.it; var DEFAULTS = { addonInfo: { inline: false, header: true, source: true, propTables: [], maxPropsIntoLine: 3, maxPropObjectKeys: 3, maxPropArrayLength: 3, maxPropStringLength: 50 }, sectionOptions: { showSource: true, allowSourceToggling: true, showPropTables: false, allowPropTablesToggling: true, useTheme: true, decorator: false } }; describe('Chapters Addon', function () { describe('addWithChapters method', function () { it('does not break if no arguments are passed', function () { var scope = { add: function add(name, callback) { callback(); } }; var fn = _index["default"].addWithChapters.bind(scope); (0, _chai.expect)(fn).to.not["throw"](); }); it('passes all expected params to the underlying Story component', function () { var context = {}; var content = { subtitle: 'Story subtitle', info: 'Story info', chapters: [] }; var scope = { add: function add(name, callback) { var story = callback(context); (0, _chai.expect)(story.props.title).to.equal('Story title'); (0, _chai.expect)(story.props.subtitle).to.equal(content.subtitle); (0, _chai.expect)(story.props.info).to.equal(content.info); (0, _chai.expect)(story.props.chapters).to.equal(content.chapters); (0, _chai.expect)(story.props.context).to.equal(context); } }; _index["default"].addWithChapters.call(scope, 'Story title', content); }); it('can be passed a function as a configuration argument', function () { var expected = { subtitle: 'Story subtitle', info: 'Story info', chapters: [] }; var content = function content() { return expected; }; var scope = { add: function add(name, callback) { var story = callback({}); var actual = story.props; (0, _chai.expect)(actual).to.include.all.keys(expected); } }; _index["default"].addWithChapters.call(scope, 'Story title', content); }); }); describe('default options', function () { it('are what we expect', function () { var scope = { add: function add(name, callback) { var story = callback({}); (0, _chai.expect)(story.props.addonInfo).to.deep.equal(DEFAULTS.addonInfo); (0, _chai.expect)(story.props.sectionOptions).to.deep.equal(DEFAULTS.sectionOptions); } }; _index["default"].addWithChapters.call(scope); }); it('can be overridden by setDefaults', function () { var addonInfo = { header: false, source: false }; var sectionOptions = { showSource: false, showPropTables: true }; (0, _index.setDefaults)({ addonInfo: addonInfo, sectionOptions: sectionOptions }); var scope = { add: function add(name, callback) { var story = callback({}); (0, _chai.expect)(story.props.addonInfo.header).to.be["false"]; (0, _chai.expect)(story.props.addonInfo.header).to.be["false"]; (0, _chai.expect)(story.props.sectionOptions.showSource).to.be["false"]; (0, _chai.expect)(story.props.sectionOptions.showPropTables).to.be["true"]; // reset to default values (0, _index.setDefaults)(DEFAULTS); } }; _index["default"].addWithChapters.call(scope); }); }); });