wix-storybook-utils
Version:
Utilities for automated component documentation within Storybook
79 lines • 2.81 kB
JavaScript
import { __assign } from "tslib";
import { mount } from 'enzyme';
import { header as headerBuilder } from '../../index';
import { header } from '.';
var testkit = function () {
var component;
var storyConfigMock = {
metadata: {
displayName: 'test',
props: {},
},
config: {
importFormat: '',
moduleName: '',
repoBaseURL: '',
},
component: {},
};
var issueUrlHook = 'section-header-issueUrl';
var sourceUrlHook = 'section-header-sourceUrl';
return {
when: {
created: function (section, config) {
if (config === void 0) { config = {}; }
component = mount(header(section, __assign(__assign({}, storyConfigMock), config)));
return component;
},
},
get: {
issueUrl: function () {
return component.find("[data-hook=\"".concat(issueUrlHook, "\"] a")).prop('href');
},
sourceUrl: function () {
return component.find("[data-hook=\"".concat(sourceUrlHook, "\"] a")).prop('href');
},
issueUrlExists: function () {
return !!component.find("[data-hook=\"".concat(issueUrlHook, "\"]")).length;
},
sourceUrlExists: function () {
return !!component.find("[data-hook=\"".concat(sourceUrlHook, "\"]")).length;
},
},
};
};
describe('header section view', function () {
describe('issueUrl', function () {
it('should be rendered from issueUrl section config', function () {
var section = headerBuilder({ issueUrl: 'hello' });
var driver = testkit();
driver.when.created(section);
expect(driver.get.issueUrl()).toBe('hello');
});
it('should be derived from storyConfig', function () {
var section = headerBuilder({});
var driver = testkit();
driver.when.created(section, {
config: {
issueURL: 'hello',
},
});
expect(driver.get.issueUrl()).toBe('hello');
driver.when.created(section, {
config: {
issueURL: '',
},
});
expect(driver.get.issueUrlExists()).toBe(false);
});
});
describe('sourceUrl', function () {
it('should be rendered from sourceUrl section config', function () {
var section = headerBuilder({ sourceUrl: 'hello' });
var driver = testkit();
driver.when.created(section);
expect(driver.get.sourceUrl()).toBe('hello');
});
});
});
//# sourceMappingURL=index.test.js.map