UNPKG

wix-storybook-utils

Version:

Utilities for automated component documentation within Storybook

103 lines 4.21 kB
"use strict"; /* global describe it expect */ Object.defineProperty(exports, "__esModule", { value: true }); var tslib_1 = require("tslib"); var categorize_props_1 = tslib_1.__importDefault(require("./categorize-props")); describe('categorizeProps', function () { describe('given nothing', function () { it('should return empty object', function () { expect((0, categorize_props_1.default)()).toEqual({}); }); }); describe('given props without category definitions', function () { it('should return props under `primary` property', function () { var props = { one: 'hello', two: 'world', }; expect((0, categorize_props_1.default)(props)).toEqual({ primary: expect.objectContaining({ props: props }), }); }); }); describe('given props and category definitions', function () { it('should return object with shape of matchers', function () { var props = { onClick: 'hello click', onBlur: 'hello blur', ariaRequired: 'hello required', something: 'else', }; var categories = { accessibility: { matcher: function (name) { return name.startsWith('aria'); } }, events: { matcher: function (name) { return name.startsWith('on'); } }, }; expect((0, categorize_props_1.default)(props, categories)).toEqual({ accessibility: expect.objectContaining({ props: { ariaRequired: 'hello required', }, }), events: expect.objectContaining({ props: { onClick: 'hello click', onBlur: 'hello blur', }, }), primary: expect.objectContaining({ props: { something: 'else', }, }), }); }); it('should return object including only existing categories', function () { var props = { // 1. this do not include any aria nor event properties something: 'else', }; var categories = { accessibility: { matcher: function (name) { return name.startsWith('aria'); } }, events: { matcher: function (name) { return name.startsWith('on'); } }, }; expect((0, categorize_props_1.default)(props, categories)).toEqual({ // 2. this should not include events nor accessibility properties primary: { props: { something: 'else' }, }, }); }); it('should add props property and keep original category definition structure', function () { var props = { hello: 'world', }; var categories = { whatever: { matcher: function () { return true; }, hello: 'here too', i: 'should remain', }, }; expect((0, categorize_props_1.default)(props, categories)).toEqual({ whatever: tslib_1.__assign(tslib_1.__assign({}, categories.whatever), { props: { hello: 'world' } }), }); }); it('should categorize props in given order', function () { var props = { hello: 'is it me', you: 'are looking for', }; var matcher = function () { return true; }; var categories = { first: { order: 1, matcher: matcher }, realFirst: { order: 0, matcher: matcher }, }; expect((0, categorize_props_1.default)(props, categories)).toEqual({ realFirst: expect.objectContaining({ props: { hello: 'is it me', you: 'are looking for' }, }), }); }); }); }); //# sourceMappingURL=categorize-props.test.js.map