wix-storybook-utils
Version:
Utilities for automated component documentation within Storybook
40 lines • 1.79 kB
JavaScript
/* global expect describe it */
import React from 'react';
import { mount } from 'enzyme';
import TabbedView from '.';
var getTabbedViewDriver = function () {
var wrapper;
return {
mount: function (activeTabId, tabs) {
wrapper = mount(React.createElement(TabbedView, { showTabs: true, activeTabId: activeTabId, tabs: tabs }, tabs.map(function (tab, i) { return (React.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