wix-storybook-utils
Version:
Utilities for automated component documentation within Storybook
133 lines • 4.44 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var components_hints_builder_1 = require("./components-hints-builder");
describe('getComponentsHints', function () {
it('should return null if components scope is not provided', function () {
expect((0, components_hints_builder_1.getComponentsHints)()).toBe(null);
});
it("should return empty hints object if provided components don't have propTypes", function () {
var componentsScope = {
Box: {},
Text: {},
};
expect((0, components_hints_builder_1.getComponentsHints)(componentsScope)).toEqual({});
});
it('sort components', function () {
var componentsScope = {
Text: {
propTypes: {
color: {},
},
},
Box: {
propTypes: {
color: {},
},
},
};
expect(Object.keys((0, components_hints_builder_1.getComponentsHints)(componentsScope))).toEqual([
'Box',
'Text',
]);
});
it('sort attributes', function () {
var componentsScope = {
Box: {
propTypes: {
verticalAlign: {
type: {
name: 'oneOf',
value: ['top', 'middle', 'bottom', 'space-between'],
},
},
color: {
type: { name: 'string' },
},
size: {
type: { name: 'oneOf', value: ['medium', 'large'] },
},
},
},
};
var hints = (0, components_hints_builder_1.getComponentsHints)(componentsScope);
expect(Object.keys(hints.Box.attrs)).toEqual([
'color',
'size',
'verticalAlign',
]);
});
it('should parse oneOf type props, but omit className and children props', function () {
var componentsScope = {
Box: {
propTypes: {
children: {
type: { name: 'node' },
},
className: {
type: { name: 'string' },
},
verticalAlign: {
type: {
name: 'oneOf',
value: ['top', 'middle', 'bottom', 'space-between'],
},
},
color: {
type: { name: 'string' },
},
},
},
};
expect((0, components_hints_builder_1.getComponentsHints)(componentsScope)).toEqual({
Box: {
attrs: {
color: null,
verticalAlign: ['top', 'middle', 'bottom', 'space-between'],
},
},
});
});
it('should parse compound components props', function () {
var componentsScope = {
Card: {
propTypes: {
hideOverflow: {
type: { name: 'bool' },
},
dataHook: { type: { name: 'string' } },
},
Content: {
propTypes: {
size: {
type: {
name: 'oneOf',
value: ['medium', 'large'],
},
},
},
},
Divider: {
displayName: 'Divider',
},
displayName: 'Card',
},
};
expect((0, components_hints_builder_1.getComponentsHints)(componentsScope)).toEqual({
Card: {
attrs: {
hideOverflow: null,
dataHook: null,
},
},
'Card.Content': {
attrs: {
size: ['medium', 'large'],
},
},
'Card.Divider': {
attrs: {},
},
});
});
});
//# sourceMappingURL=components-hints-builder.spec.js.map