1 | "use strict";
|
2 |
|
3 | function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
4 |
|
5 | var _react = _interopRequireDefault(require("react"));
|
6 |
|
7 | var _react2 = require("@testing-library/react");
|
8 |
|
9 | var _coreEvents = require("@storybook/core-events");
|
10 |
|
11 | var _theming = require("@storybook/theming");
|
12 |
|
13 | var _Panel = _interopRequireWildcard(require("./Panel"));
|
14 |
|
15 | var _shared = require("../shared");
|
16 |
|
17 | function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
18 |
|
19 | function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
20 |
|
21 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
22 |
|
23 | var createTestApi = function createTestApi() {
|
24 | return {
|
25 | on: jest.fn(function () {
|
26 | return function () {};
|
27 | }),
|
28 | off: jest.fn(),
|
29 | emit: jest.fn(),
|
30 | getQueryParam: jest.fn(function () {
|
31 | return undefined;
|
32 | }),
|
33 | setQueryParams: jest.fn()
|
34 | };
|
35 | };
|
36 |
|
37 | describe('Panel', function () {
|
38 | it('should subscribe to setKnobs event of channel', function () {
|
39 | var testApi = createTestApi();
|
40 | (0, _react2.render)( _react["default"].createElement(_theming.ThemeProvider, {
|
41 | theme: (0, _theming.convert)(_theming.themes.light)
|
42 | }, _react["default"].createElement(_Panel["default"], {
|
43 | api: testApi,
|
44 | active: true
|
45 | })));
|
46 | expect(testApi.on).toHaveBeenCalledWith(_shared.SET, expect.any(Function));
|
47 | });
|
48 | it('should subscribe to STORY_CHANGE event', function () {
|
49 | var testApi = createTestApi();
|
50 | (0, _react2.render)( _react["default"].createElement(_theming.ThemeProvider, {
|
51 | theme: (0, _theming.convert)(_theming.themes.light)
|
52 | }, _react["default"].createElement(_Panel["default"], {
|
53 | api: testApi,
|
54 | active: true
|
55 | })));
|
56 | expect(testApi.on.mock.calls).toContainEqual([_coreEvents.STORY_CHANGED, expect.any(Function)]);
|
57 | expect(testApi.on).toHaveBeenCalledWith(_shared.SET, expect.any(Function));
|
58 | });
|
59 | describe('setKnobs handler', function () {
|
60 | it('should read url params and set values for existing knobs', function () {
|
61 | var handlers = {};
|
62 | var testQueryParams = {
|
63 | 'knob-foo': 'test string',
|
64 | bar: 'some other string'
|
65 | };
|
66 | var testApi = {
|
67 | on: function on(e, handler) {
|
68 | handlers[e] = handler;
|
69 | return function () {};
|
70 | },
|
71 | off: jest.fn(),
|
72 | emit: jest.fn(),
|
73 | getQueryParam: function getQueryParam(key) {
|
74 | return testQueryParams[key];
|
75 | },
|
76 | setQueryParams: jest.fn()
|
77 | };
|
78 | (0, _react2.render)( _react["default"].createElement(_theming.ThemeProvider, {
|
79 | theme: (0, _theming.convert)(_theming.themes.light)
|
80 | }, _react["default"].createElement(_Panel["default"], {
|
81 | api: testApi,
|
82 | active: true
|
83 | })));
|
84 | var setKnobsHandler = handlers[_shared.SET];
|
85 | var knobs = {
|
86 | foo: {
|
87 | name: 'foo',
|
88 | value: 'default string',
|
89 | type: 'text'
|
90 | },
|
91 | baz: {
|
92 | name: 'baz',
|
93 | value: 'another knob value',
|
94 | type: 'text'
|
95 | }
|
96 | };
|
97 | setKnobsHandler({
|
98 | knobs: knobs,
|
99 | timestamp: +new Date()
|
100 | });
|
101 | var knobFromUrl = {
|
102 | name: 'foo',
|
103 | value: testQueryParams['knob-foo'],
|
104 | type: 'text'
|
105 | };
|
106 | var e = _shared.CHANGE;
|
107 | expect(testApi.emit).toHaveBeenCalledWith(e, knobFromUrl);
|
108 | });
|
109 | });
|
110 | describe('handleChange()', function () {
|
111 | it.skip('should set queryParams and emit knobChange event', function () {
|
112 | var testApi = {
|
113 | getQueryParam: jest.fn(),
|
114 | setQueryParams: jest.fn(function () {
|
115 | return undefined;
|
116 | }),
|
117 | on: jest.fn(function () {
|
118 | return function () {};
|
119 | }),
|
120 | off: jest.fn(),
|
121 | emit: jest.fn()
|
122 | };
|
123 | (0, _react2.render)( _react["default"].createElement(_Panel["default"], {
|
124 | api: testApi,
|
125 | active: true
|
126 | }));
|
127 | var testChangedKnob = {
|
128 | name: 'foo',
|
129 | value: 'changed text',
|
130 | type: 'text'
|
131 | };
|
132 |
|
133 |
|
134 | expect(testApi.emit).toHaveBeenCalledWith(_shared.CHANGE, testChangedKnob);
|
135 |
|
136 | });
|
137 | });
|
138 | describe('groups', function () {
|
139 | var testApi = {
|
140 | off: jest.fn(),
|
141 | emit: jest.fn(),
|
142 | getQueryParam: jest.fn(function () {
|
143 | return undefined;
|
144 | }),
|
145 | setQueryParams: jest.fn(),
|
146 | on: jest.fn(function () {
|
147 | return function () {};
|
148 | })
|
149 | };
|
150 | it.skip('should have no tabs when there are no groupIds', function () {
|
151 |
|
152 |
|
153 |
|
154 |
|
155 | var root = (0, _react2.render)( _react["default"].createElement(_theming.ThemeProvider, {
|
156 | theme: (0, _theming.convert)(_theming.themes.light)
|
157 | }, _react["default"].createElement(_Panel["default"], {
|
158 | api: testApi,
|
159 | active: true
|
160 | })));
|
161 |
|
162 |
|
163 |
|
164 |
|
165 |
|
166 |
|
167 |
|
168 |
|
169 |
|
170 |
|
171 |
|
172 |
|
173 |
|
174 |
|
175 |
|
176 |
|
177 |
|
178 |
|
179 |
|
180 |
|
181 |
|
182 | });
|
183 | it.skip('should have one tab per groupId when all are defined', function () {
|
184 | var root = (0, _react2.render)( _react["default"].createElement(_theming.ThemeProvider, {
|
185 | theme: (0, _theming.convert)(_theming.themes.light)
|
186 | }, _react["default"].createElement(_Panel["default"], {
|
187 | api: testApi,
|
188 | active: true
|
189 | })));
|
190 |
|
191 |
|
192 |
|
193 |
|
194 |
|
195 |
|
196 |
|
197 |
|
198 |
|
199 |
|
200 |
|
201 |
|
202 |
|
203 |
|
204 |
|
205 |
|
206 |
|
207 |
|
208 |
|
209 |
|
210 |
|
211 |
|
212 |
|
213 |
|
214 |
|
215 |
|
216 | });
|
217 | it.skip("the ".concat(_Panel.DEFAULT_GROUP_ID, " tab should have its own additional content when there are knobs both with and without a groupId"), function () {
|
218 | var root = (0, _react2.render)( _react["default"].createElement(_theming.ThemeProvider, {
|
219 | theme: (0, _theming.convert)(_theming.themes.light)
|
220 | }, _react["default"].createElement(_Panel["default"], {
|
221 | api: testApi,
|
222 | active: true
|
223 | })));
|
224 |
|
225 |
|
226 |
|
227 |
|
228 |
|
229 |
|
230 |
|
231 |
|
232 |
|
233 |
|
234 |
|
235 |
|
236 |
|
237 |
|
238 |
|
239 |
|
240 |
|
241 |
|
242 |
|
243 |
|
244 |
|
245 |
|
246 |
|
247 |
|
248 |
|
249 |
|
250 | });
|
251 | });
|
252 | }); |
\ | No newline at end of file |