UNPKG

7.18 kBJavaScriptView Raw
1"use strict";
2
3var _index = require("../index");
4
5// Note: this is a helper to batch test return types and avoid "declared but never read" errors
6function expectKnobOfType() {}
7
8var groupId = 'GROUP-ID1';
9/** Text knob */
10
11expectKnobOfType((0, _index.text)('text simple', 'Batman'), (0, _index.text)('text with group', 'default', groupId));
12/** Date knob */
13
14expectKnobOfType((0, _index.date)('date simple', new Date('January 20 1887')), (0, _index.date)('date with group', new Date(), groupId));
15/** Boolean knob */
16
17expectKnobOfType((0, _index["boolean"])('boolean simple', false), (0, _index["boolean"])('boolean with group', true, groupId));
18/** Color knob */
19
20expectKnobOfType((0, _index.color)('color simple', 'black'), (0, _index.color)('color with group', '#ffffff', groupId));
21/** Number knob */
22
23expectKnobOfType((0, _index.number)('number basic', 42), (0, _index.number)('number with options', 72, {
24 range: true,
25 min: 60,
26 max: 90,
27 step: 1
28}), (0, _index.number)('number with group', 1, {}, groupId));
29/** Radios knob */
30
31expectKnobOfType((0, _index.radios)('radio with string values', {
32 1100: '1100',
33 2200: '2200',
34 3300: '3300'
35}, '2200'));
36expectKnobOfType((0, _index.radios)('radio with number values', {
37 3: 3,
38 7: 7,
39 23: 23
40}, 3));
41expectKnobOfType((0, _index.radios)('radio with mixed value', {
42 1100: '1100',
43 2200: 2200,
44 3300: '3300'
45}, null, groupId));
46/** Select knob */
47
48var SomeEnum;
49
50(function (SomeEnum) {
51 SomeEnum[SomeEnum["Type1"] = 1] = "Type1";
52 SomeEnum[SomeEnum["Type2"] = 2] = "Type2";
53})(SomeEnum || (SomeEnum = {}));
54
55var ButtonVariant;
56
57(function (ButtonVariant) {
58 ButtonVariant["primary"] = "primary";
59 ButtonVariant["secondary"] = "secondary";
60})(ButtonVariant || (ButtonVariant = {}));
61
62var stringLiteralArray = ['Apple', 'Banana', 'Grapes'];
63expectKnobOfType((0, _index.select)('select with string options', {
64 None: 'none',
65 Underline: 'underline',
66 'Line-through': 'line-through'
67}, 'none'), (0, _index.select)('select with string array', ['yes', 'no'], 'yes'), (0, _index.select)('select with string literal array', stringLiteralArray, stringLiteralArray[0]), (0, _index.select)('select with readonly array', ['red', 'blue'], 'red'), (0, _index.select)('select with string enum options', ButtonVariant, ButtonVariant.primary));
68expectKnobOfType((0, _index.select)('select with an undefined in array', ['Apple', 'Banana', 'Grapes', undefined, null, false], undefined));
69expectKnobOfType((0, _index.select)('select with null option', {
70 a: 'Option',
71 b: null
72}, null, groupId));
73expectKnobOfType((0, _index.select)('select with number options', {
74 'type a': 1,
75 'type b': 2
76}, 1), (0, _index.select)('select with numeric enum options', {
77 'type a': SomeEnum.Type1,
78 'type b': SomeEnum.Type2
79}, SomeEnum.Type2), (0, _index.select)('select with number array', [1, 2, 3, 4], 1), (0, _index.select)('select with readonly number array', [1, 2], 1));
80expectKnobOfType((0, _index.select)('select with null option', {
81 a: 1,
82 b: null
83}, null, groupId));
84expectKnobOfType((0, _index.select)('select with string and string array options', {
85 Red: 'red',
86 Blue: 'blue',
87 Yellow: 'yellow',
88 Rainbow: ['red', 'orange', 'etc'],
89 None: 'transparent'
90}, 'red'));
91expectKnobOfType((0, _index.select)('select with number and number array options', {
92 Red: 1,
93 Blue: 2,
94 Yellow: 3,
95 Rainbow: [4, 5, 6],
96 None: 7
97}, 7));
98expectKnobOfType((0, _index.select)('select with string, string array, and null options', {
99 Red: 'red',
100 Blue: 'blue',
101 Yellow: 'yellow',
102 Rainbow: ['red', 'orange', 'etc'],
103 None: null
104}, null));
105expectKnobOfType((0, _index.select)('select with number array options', {
106 ones: [1],
107 twos: [2, 2],
108 threes: [3, 3, 3]
109}, [1]));
110expectKnobOfType((0, _index.select)('select with object options', {
111 foo: {
112 foo: 'bar'
113 },
114 bar: {
115 bar: 'foo'
116 },
117 foobar: {
118 foobar: 'barfoo'
119 }
120}, {
121 foo: 'bar'
122}));
123expectKnobOfType((0, _index.select)('select with object, array, and string options', {
124 foo: {
125 foo: 'bar'
126 },
127 bar: 'bar',
128 foobar: ['foo', 'bar']
129}, {
130 foo: 'bar'
131}));
132/** Object knob */
133
134expectKnobOfType((0, _index.object)('object simple', {
135 fontFamily: 'Arial',
136 padding: 20
137}), (0, _index.object)('object with group', {}, groupId));
138/** Options knob */
139
140var visibleToolOptions = {
141 hammer: 'hammer',
142 saw: 'saw',
143 drill: 'drill'
144};
145expectKnobOfType((0, _index.optionsKnob)('options with single selection', visibleToolOptions, 'hammer', {
146 display: 'check'
147}), (0, _index.optionsKnob)('options with multi selection', visibleToolOptions, ['hammer', 'saw'], {
148 display: 'inline-check'
149}), (0, _index.optionsKnob)('options with readonly multi selection', visibleToolOptions, ['hammer'], {
150 display: 'radio'
151}), (0, _index.optionsKnob)('options with group', {}, '', {
152 display: 'check'
153}));
154expectKnobOfType((0, _index.optionsKnob)('select with null option', {
155 a: 1,
156 b: null
157}, null, {
158 display: 'check'
159}));
160expectKnobOfType((0, _index.optionsKnob)('options with string and string array options', {
161 Red: 'red',
162 Blue: 'blue',
163 Yellow: 'yellow',
164 Rainbow: ['red', 'orange', 'etc'],
165 None: 'transparent'
166}, 'red', {
167 display: 'check'
168}));
169expectKnobOfType((0, _index.optionsKnob)('select with number and number array options', {
170 Red: 1,
171 Blue: 2,
172 Yellow: 3,
173 Rainbow: [4, 5, 6],
174 None: 7
175}, 7, {
176 display: 'check'
177}));
178expectKnobOfType((0, _index.optionsKnob)('select with string, string array, and null options', {
179 Red: 'red',
180 Blue: 'blue',
181 Yellow: 'yellow',
182 Rainbow: ['red', 'orange', 'etc'],
183 None: null
184}, null, {
185 display: 'check'
186}));
187expectKnobOfType((0, _index.optionsKnob)('select with number array options', {
188 ones: [1],
189 twos: [2, 2],
190 threes: [3, 3, 3]
191}, [1], {
192 display: 'check'
193}));
194/** Array knob */
195
196var arrayReadonly = (0, _index.array)('array as readonly', ['hi', 'there']);
197expectKnobOfType((0, _index.array)('array simple', ['red', 'green', 'blue']), arrayReadonly, (0, _index.array)('array with group', [], ',', groupId)); // Should return a mutable array despite the readonly input
198
199arrayReadonly.push('Make sure that the output is still mutable although the input need not be!');
200/** Button knob */
201
202expectKnobOfType((0, _index.button)('button simple', function () {}), (0, _index.button)('button with group', function () {
203 return undefined;
204}, groupId));
205/** Files knob */
206
207expectKnobOfType((0, _index.files)('files simple', 'image/*', []), (0, _index.files)('files with group', 'image/*', ['img.jpg'], groupId));
208/** Generic knob */
209
210expectKnobOfType((0, _index.knob)('generic knob as text', {
211 type: 'text',
212 value: 'a'
213}), (0, _index.knob)('generic knob as color', {
214 type: 'color',
215 value: 'black'
216}), (0, _index.knob)('generic knob as string select', {
217 type: 'select',
218 value: 'yes',
219 options: ['yes', 'no'],
220 selectV2: true
221}));
222expectKnobOfType((0, _index.knob)('generic knob as number', {
223 type: 'number',
224 value: 42
225}), (0, _index.knob)('generic knob as select', {
226 type: 'radios',
227 value: 3,
228 options: {
229 3: 3,
230 7: 7,
231 23: 23
232 }
233}), (0, _index.knob)('generic knob as number select', {
234 type: 'select',
235 value: 1,
236 options: [1, 2],
237 selectV2: true
238}));
\No newline at end of file