wix-storybook-utils
Version:
Utilities for automated component documentation within Storybook
81 lines • 2.92 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var enzyme_1 = require("enzyme");
var index_1 = require("../../index");
var _1 = require(".");
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 = (0, enzyme_1.mount)((0, _1.header)(section, tslib_1.__assign(tslib_1.__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 = (0, index_1.header)({ issueUrl: 'hello' });
var driver = testkit();
driver.when.created(section);
expect(driver.get.issueUrl()).toBe('hello');
});
it('should be derived from storyConfig', function () {
var section = (0, index_1.header)({});
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 = (0, index_1.header)({ sourceUrl: 'hello' });
var driver = testkit();
driver.when.created(section);
expect(driver.get.sourceUrl()).toBe('hello');
});
});
});
//# sourceMappingURL=index.test.js.map