wix-storybook-utils
Version:
Utilities for automated component documentation within Storybook
43 lines • 1.99 kB
JavaScript
;
/* global expect describe it */
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var react_1 = tslib_1.__importDefault(require("react"));
var enzyme_1 = require("enzyme");
var _1 = tslib_1.__importDefault(require("."));
var getTabbedViewDriver = function () {
var wrapper;
return {
mount: function (activeTabId, tabs) {
wrapper = (0, enzyme_1.mount)(react_1.default.createElement(_1.default, { showTabs: true, activeTabId: activeTabId, tabs: tabs }, tabs.map(function (tab, i) { return (react_1.default.createElement("div", { key: i, "data-hook": "child-".concat(tab) })); })));
},
getChildById: function (tabId) { return wrapper.find("[data-hook=\"child-".concat(tabId, "\"]")); },
clickOnTab: function (tabId) {
return wrapper.find("[data-hook=\"".concat(tabId, "\"]")).simulate('click');
},
cleanup: function () { return wrapper.unmount(); },
};
};
describe('TabbedView', function () {
var driver;
afterEach(function () { return driver.cleanup(); });
it('should show correct children based on activeTabId', function () {
var firstTabId = 'tab1';
var activeTabId = 'tab2';
var tabs = [firstTabId, activeTabId];
driver = getTabbedViewDriver();
driver.mount(activeTabId, tabs);
expect(driver.getChildById(firstTabId).exists()).toBe(false);
expect(driver.getChildById(activeTabId).exists()).toBe(true);
});
it('should be case insensitive for activeTabId', function () {
var firstTabId = 'tab1';
var activeTabId = 'tab2';
var tabs = [firstTabId, activeTabId];
driver = getTabbedViewDriver();
driver.mount(activeTabId.toUpperCase(), tabs);
expect(driver.getChildById(firstTabId).exists()).toBe(false);
expect(driver.getChildById(activeTabId).exists()).toBe(true);
});
});
//# sourceMappingURL=index.spec.js.map