orc-scripts 1.2.0-pre.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +19 -0
- package/README.md +76 -0
- package/babel.js +1 -0
- package/eslint.js +1 -0
- package/jest.js +1 -0
- package/package.json +164 -0
- package/prettier.js +1 -0
- package/src/__mocks__/fileMock.js +1 -0
- package/src/config/babel-preset.js +4 -0
- package/src/config/babel-transform.js +4 -0
- package/src/config/babel-whitelist.json +1 -0
- package/src/config/babelrc.js +38 -0
- package/src/config/eslintrc.js +15 -0
- package/src/config/jest-resolver.js +35 -0
- package/src/config/jest.config.js +45 -0
- package/src/config/jestSetupFiles.js +4 -0
- package/src/config/prettier.config.js +9 -0
- package/src/config/setAssetPath.js +1 -0
- package/src/config/unexpected-form.js +317 -0
- package/src/config/unexpected-form.test.js +2397 -0
- package/src/config/unexpected-module.js +112 -0
- package/src/config/unexpected-module.test.js +1106 -0
- package/src/config/unexpected-styles.js +44 -0
- package/src/config/unexpected-styles.test.js +118 -0
- package/src/config/unexpected.js +117 -0
- package/src/config/unexpected.test.js +393 -0
- package/src/config/webpack.config.js +103 -0
- package/src/index.js +19 -0
- package/src/run-script.js +99 -0
- package/src/scripts/build/cli.js +43 -0
- package/src/scripts/build/index.js +9 -0
- package/src/scripts/build/web.js +24 -0
- package/src/scripts/buildDep.js +122 -0
- package/src/scripts/buildIconsSheet.js +50 -0
- package/src/scripts/clean.js +8 -0
- package/src/scripts/extract-messages.js +22 -0
- package/src/scripts/generateApi.js +152 -0
- package/src/scripts/getDist.js +20 -0
- package/src/scripts/mergeTranslations.js +32 -0
- package/src/scripts/prep.js +28 -0
- package/src/scripts/start.js +45 -0
- package/src/scripts/tag.js +76 -0
- package/src/scripts/test.js +26 -0
- package/src/scripts/validateTranslations.js +72 -0
- package/src/utils.js +95 -0
- package/src/utils.test.js +93 -0
- package/webpack.js +1 -0
|
@@ -0,0 +1,2397 @@
|
|
|
1
|
+
expect.output.preferredWidth = 80;
|
|
2
|
+
|
|
3
|
+
describe("<array-like> to be a form definition", () => {
|
|
4
|
+
describe("<object> to be a form field", () => {
|
|
5
|
+
it("passes with a name only", () =>
|
|
6
|
+
expect(() => expect({ name: "field1", type: "CheckboxInput" }, "to be a form field"), "not to throw"));
|
|
7
|
+
|
|
8
|
+
it("passes with a name and string label", () =>
|
|
9
|
+
expect(
|
|
10
|
+
() => expect({ name: "field1", type: "CheckboxInput", label: "A field" }, "to be a form field"),
|
|
11
|
+
"not to throw",
|
|
12
|
+
));
|
|
13
|
+
|
|
14
|
+
it("passes with a name and object label", () =>
|
|
15
|
+
expect(
|
|
16
|
+
() =>
|
|
17
|
+
expect(
|
|
18
|
+
{
|
|
19
|
+
name: "Field1",
|
|
20
|
+
type: "CheckboxInput",
|
|
21
|
+
label: { id: "test.field1", defaultMessage: "A field" },
|
|
22
|
+
},
|
|
23
|
+
"to be a form field",
|
|
24
|
+
),
|
|
25
|
+
"not to throw",
|
|
26
|
+
));
|
|
27
|
+
|
|
28
|
+
it("fails if name not a string", () =>
|
|
29
|
+
expect(
|
|
30
|
+
() => expect({ name: ["field1"], type: "CheckboxInput" }, "to be a form field"),
|
|
31
|
+
"to throw",
|
|
32
|
+
"expected { name: [ 'field1' ], type: 'CheckboxInput' } to be a form field\n" +
|
|
33
|
+
"\n" +
|
|
34
|
+
"{\n" +
|
|
35
|
+
" name: [ 'field1' ], // should be a string\n" +
|
|
36
|
+
" type: 'CheckboxInput'\n" +
|
|
37
|
+
"}",
|
|
38
|
+
));
|
|
39
|
+
|
|
40
|
+
it("fails if type not a string", () =>
|
|
41
|
+
expect(
|
|
42
|
+
() => expect({ name: "field1", type: ["InvalidType"] }, "to be a form field"),
|
|
43
|
+
"to throw",
|
|
44
|
+
"expected { name: 'field1', type: [ 'InvalidType' ] } to be a form field\n" +
|
|
45
|
+
" Invalid type [ 'InvalidType' ]",
|
|
46
|
+
));
|
|
47
|
+
|
|
48
|
+
it("fails if type not valid", () =>
|
|
49
|
+
expect(
|
|
50
|
+
() => expect({ name: "field1", type: "InvalidType" }, "to be a form field"),
|
|
51
|
+
"to throw",
|
|
52
|
+
"expected { name: 'field1', type: 'InvalidType' } to be a form field\n Invalid type 'InvalidType'",
|
|
53
|
+
));
|
|
54
|
+
|
|
55
|
+
describe("type 'Button'", () => {
|
|
56
|
+
it("passes with a name and button attributes", () =>
|
|
57
|
+
expect(
|
|
58
|
+
() =>
|
|
59
|
+
expect(
|
|
60
|
+
{
|
|
61
|
+
name: "Field1",
|
|
62
|
+
type: "Button",
|
|
63
|
+
primary: true,
|
|
64
|
+
active: true,
|
|
65
|
+
buttonText: {
|
|
66
|
+
id: "test.button.label",
|
|
67
|
+
defaultMessage: "Label",
|
|
68
|
+
},
|
|
69
|
+
icon: "an-icon",
|
|
70
|
+
autofocus: true,
|
|
71
|
+
disabled: true,
|
|
72
|
+
},
|
|
73
|
+
"to be a form field",
|
|
74
|
+
),
|
|
75
|
+
"not to throw",
|
|
76
|
+
));
|
|
77
|
+
|
|
78
|
+
it("fails if button attributes invalid", () =>
|
|
79
|
+
expect(
|
|
80
|
+
() =>
|
|
81
|
+
expect(
|
|
82
|
+
{
|
|
83
|
+
name: "Field1",
|
|
84
|
+
type: "Button",
|
|
85
|
+
primary: "foo",
|
|
86
|
+
active: 0,
|
|
87
|
+
buttonText: { defaultMessage: "A label" },
|
|
88
|
+
icon: [],
|
|
89
|
+
autofocus: {},
|
|
90
|
+
disabled: "!true",
|
|
91
|
+
},
|
|
92
|
+
"to be a form field",
|
|
93
|
+
),
|
|
94
|
+
"to throw",
|
|
95
|
+
"expected\n" +
|
|
96
|
+
"{\n" +
|
|
97
|
+
" name: 'Field1', type: 'Button', primary: 'foo', active: 0,\n" +
|
|
98
|
+
" buttonText: { defaultMessage: 'A label' }, icon: [], autofocus: {},\n" +
|
|
99
|
+
" disabled: '!true'\n" +
|
|
100
|
+
"}\n" +
|
|
101
|
+
"to be a form field\n" +
|
|
102
|
+
"\n" +
|
|
103
|
+
"{\n" +
|
|
104
|
+
" name: 'Field1',\n" +
|
|
105
|
+
" type: 'Button',\n" +
|
|
106
|
+
" primary: 'foo', // should be a boolean\n" +
|
|
107
|
+
" active: 0, // should be a boolean\n" +
|
|
108
|
+
" buttonText:\n" +
|
|
109
|
+
" { defaultMessage: 'A label' }, // should be a label\n" +
|
|
110
|
+
" // should satisfy\n" +
|
|
111
|
+
" // {\n" +
|
|
112
|
+
" // id: expect.it('to be a string'),\n" +
|
|
113
|
+
" // defaultMessage: expect.it('to be a string')\n" +
|
|
114
|
+
" // }\n" +
|
|
115
|
+
" //\n" +
|
|
116
|
+
" // {\n" +
|
|
117
|
+
" // defaultMessage: 'A label'\n" +
|
|
118
|
+
" // // missing: id: should be a string\n" +
|
|
119
|
+
" // }\n" +
|
|
120
|
+
" icon: [], // should be a string\n" +
|
|
121
|
+
" autofocus: {}, // should be a boolean\n" +
|
|
122
|
+
" disabled: '!true' // should be a boolean\n" +
|
|
123
|
+
"}",
|
|
124
|
+
));
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
describe("type 'CheckboxInput'", () => {
|
|
128
|
+
it("passes with a name and non-textual input attributes", () =>
|
|
129
|
+
expect(
|
|
130
|
+
() =>
|
|
131
|
+
expect(
|
|
132
|
+
{
|
|
133
|
+
name: "Field1",
|
|
134
|
+
type: "CheckboxInput",
|
|
135
|
+
autofocus: true,
|
|
136
|
+
disabled: true,
|
|
137
|
+
required: {
|
|
138
|
+
id: "test.required",
|
|
139
|
+
defaultMessage: "Field is Required",
|
|
140
|
+
},
|
|
141
|
+
tabindex: 12,
|
|
142
|
+
},
|
|
143
|
+
"to be a form field",
|
|
144
|
+
),
|
|
145
|
+
"not to throw",
|
|
146
|
+
));
|
|
147
|
+
|
|
148
|
+
it("fails if non-textual input attributes invalid", () =>
|
|
149
|
+
expect(
|
|
150
|
+
() =>
|
|
151
|
+
expect(
|
|
152
|
+
{
|
|
153
|
+
name: "Field1",
|
|
154
|
+
type: "CheckboxInput",
|
|
155
|
+
autofocus: "true",
|
|
156
|
+
disabled: 1,
|
|
157
|
+
required: [],
|
|
158
|
+
tabindex: "",
|
|
159
|
+
},
|
|
160
|
+
"to be a form field",
|
|
161
|
+
),
|
|
162
|
+
"to throw",
|
|
163
|
+
"expected\n" +
|
|
164
|
+
"{\n" +
|
|
165
|
+
" name: 'Field1', type: 'CheckboxInput', autofocus: 'true', disabled: 1,\n" +
|
|
166
|
+
" required: [], tabindex: ''\n" +
|
|
167
|
+
"}\n" +
|
|
168
|
+
"to be a form field\n" +
|
|
169
|
+
"\n" +
|
|
170
|
+
"{\n" +
|
|
171
|
+
" name: 'Field1',\n" +
|
|
172
|
+
" type: 'CheckboxInput',\n" +
|
|
173
|
+
" autofocus: 'true', // should be a boolean\n" +
|
|
174
|
+
" disabled: 1, // should be a boolean\n" +
|
|
175
|
+
" required:\n" +
|
|
176
|
+
" [], // should be a label\n" +
|
|
177
|
+
" // should satisfy\n" +
|
|
178
|
+
" // {\n" +
|
|
179
|
+
" // id: expect.it('to be a string'),\n" +
|
|
180
|
+
" // defaultMessage: expect.it('to be a string')\n" +
|
|
181
|
+
" // }\n" +
|
|
182
|
+
" //\n" +
|
|
183
|
+
" // [\n" +
|
|
184
|
+
" // // missing: id: should be a string\n" +
|
|
185
|
+
" // // missing: defaultMessage: should be a string\n" +
|
|
186
|
+
" // ]\n" +
|
|
187
|
+
" tabindex: '' // should be a number\n" +
|
|
188
|
+
"}",
|
|
189
|
+
));
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
describe("type 'DateInput'", () => {
|
|
193
|
+
it("passes with a name and general input attributes", () =>
|
|
194
|
+
expect(
|
|
195
|
+
() =>
|
|
196
|
+
expect(
|
|
197
|
+
{
|
|
198
|
+
name: "Field1",
|
|
199
|
+
type: "DateInput",
|
|
200
|
+
autocomplete: "on",
|
|
201
|
+
autofocus: true,
|
|
202
|
+
disabled: true,
|
|
203
|
+
readOnly: true,
|
|
204
|
+
required: {
|
|
205
|
+
id: "test.required",
|
|
206
|
+
defaultMessage: "Field is Required",
|
|
207
|
+
},
|
|
208
|
+
tabindex: 12,
|
|
209
|
+
},
|
|
210
|
+
"to be a form field",
|
|
211
|
+
),
|
|
212
|
+
"not to throw",
|
|
213
|
+
));
|
|
214
|
+
|
|
215
|
+
it("fails if general input attributes invalid", () =>
|
|
216
|
+
expect(
|
|
217
|
+
() =>
|
|
218
|
+
expect(
|
|
219
|
+
{
|
|
220
|
+
name: "Field1",
|
|
221
|
+
type: "DateInput",
|
|
222
|
+
autocomplete: "on",
|
|
223
|
+
autofocus: "true",
|
|
224
|
+
disabled: 0,
|
|
225
|
+
readOnly: { t: true },
|
|
226
|
+
required: [],
|
|
227
|
+
tabindex: "foo",
|
|
228
|
+
},
|
|
229
|
+
"to be a form field",
|
|
230
|
+
),
|
|
231
|
+
"to throw",
|
|
232
|
+
"expected\n" +
|
|
233
|
+
"{\n" +
|
|
234
|
+
" name: 'Field1', type: 'DateInput', autocomplete: 'on',\n" +
|
|
235
|
+
" autofocus: 'true', disabled: 0, readOnly: { t: true }, required: [],\n" +
|
|
236
|
+
" tabindex: 'foo'\n" +
|
|
237
|
+
"}\n" +
|
|
238
|
+
"to be a form field\n" +
|
|
239
|
+
"\n" +
|
|
240
|
+
"{\n" +
|
|
241
|
+
" name: 'Field1',\n" +
|
|
242
|
+
" type: 'DateInput',\n" +
|
|
243
|
+
" autocomplete: 'on',\n" +
|
|
244
|
+
" autofocus: 'true', // should be a boolean\n" +
|
|
245
|
+
" disabled: 0, // should be a boolean\n" +
|
|
246
|
+
" readOnly: { t: true }, // should be a boolean\n" +
|
|
247
|
+
" required:\n" +
|
|
248
|
+
" [], // should be a label\n" +
|
|
249
|
+
" // should satisfy\n" +
|
|
250
|
+
" // {\n" +
|
|
251
|
+
" // id: expect.it('to be a string'),\n" +
|
|
252
|
+
" // defaultMessage: expect.it('to be a string')\n" +
|
|
253
|
+
" // }\n" +
|
|
254
|
+
" //\n" +
|
|
255
|
+
" // [\n" +
|
|
256
|
+
" // // missing: id: should be a string\n" +
|
|
257
|
+
" // // missing: defaultMessage: should be a string\n" +
|
|
258
|
+
" // ]\n" +
|
|
259
|
+
" tabindex: 'foo' // should be a number\n" +
|
|
260
|
+
"}",
|
|
261
|
+
));
|
|
262
|
+
|
|
263
|
+
it("passes with a name and date input attributes", () =>
|
|
264
|
+
expect(
|
|
265
|
+
() =>
|
|
266
|
+
expect(
|
|
267
|
+
{
|
|
268
|
+
name: "Field1",
|
|
269
|
+
type: "DateInput",
|
|
270
|
+
max: "2012-04-15",
|
|
271
|
+
min: "2010-02-12",
|
|
272
|
+
step: 2,
|
|
273
|
+
},
|
|
274
|
+
"to be a form field",
|
|
275
|
+
),
|
|
276
|
+
"not to throw",
|
|
277
|
+
));
|
|
278
|
+
|
|
279
|
+
it("fails if date input attributes invalid", () =>
|
|
280
|
+
expect(
|
|
281
|
+
() =>
|
|
282
|
+
expect(
|
|
283
|
+
{
|
|
284
|
+
name: "Field1",
|
|
285
|
+
type: "DateInput",
|
|
286
|
+
max: "4th of July",
|
|
287
|
+
min: 2010,
|
|
288
|
+
step: "1 minute",
|
|
289
|
+
},
|
|
290
|
+
"to be a form field",
|
|
291
|
+
),
|
|
292
|
+
"to throw",
|
|
293
|
+
"expected\n" +
|
|
294
|
+
"{\n" +
|
|
295
|
+
" name: 'Field1',\n" +
|
|
296
|
+
" type: 'DateInput',\n" +
|
|
297
|
+
" max: '4th of July',\n" +
|
|
298
|
+
" min: 2010,\n" +
|
|
299
|
+
" step: '1 minute'\n" +
|
|
300
|
+
"}\n" +
|
|
301
|
+
"to be a form field\n" +
|
|
302
|
+
"\n" +
|
|
303
|
+
"{\n" +
|
|
304
|
+
" name: 'Field1',\n" +
|
|
305
|
+
" type: 'DateInput',\n" +
|
|
306
|
+
" max: '4th of July', // ✓ should be a string and\n" +
|
|
307
|
+
" // ⨯ should match /^\\d{4}-\\d{2}-\\d{2}$/\n" +
|
|
308
|
+
" min: 2010, // ⨯ should be a string and\n" +
|
|
309
|
+
" // ⨯ should match /^\\d{4}-\\d{2}-\\d{2}$/\n" +
|
|
310
|
+
" step: '1 minute' // should be a number\n" +
|
|
311
|
+
"}",
|
|
312
|
+
));
|
|
313
|
+
});
|
|
314
|
+
|
|
315
|
+
describe("type 'EmailInput'", () => {
|
|
316
|
+
it("passes with a name and general input attributes", () =>
|
|
317
|
+
expect(
|
|
318
|
+
() =>
|
|
319
|
+
expect(
|
|
320
|
+
{
|
|
321
|
+
name: "Field1",
|
|
322
|
+
type: "EmailInput",
|
|
323
|
+
autocomplete: "on",
|
|
324
|
+
autofocus: true,
|
|
325
|
+
disabled: true,
|
|
326
|
+
readOnly: true,
|
|
327
|
+
required: {
|
|
328
|
+
id: "test.required",
|
|
329
|
+
defaultMessage: "Field is Required",
|
|
330
|
+
},
|
|
331
|
+
tabindex: 12,
|
|
332
|
+
},
|
|
333
|
+
"to be a form field",
|
|
334
|
+
),
|
|
335
|
+
"not to throw",
|
|
336
|
+
));
|
|
337
|
+
|
|
338
|
+
it("fails if general input attributes invalid", () =>
|
|
339
|
+
expect(
|
|
340
|
+
() =>
|
|
341
|
+
expect(
|
|
342
|
+
{
|
|
343
|
+
name: "Field1",
|
|
344
|
+
type: "EmailInput",
|
|
345
|
+
autocomplete: "on",
|
|
346
|
+
autofocus: "true",
|
|
347
|
+
disabled: 0,
|
|
348
|
+
readOnly: { t: true },
|
|
349
|
+
required: [],
|
|
350
|
+
tabindex: "foo",
|
|
351
|
+
},
|
|
352
|
+
"to be a form field",
|
|
353
|
+
),
|
|
354
|
+
"to throw",
|
|
355
|
+
"expected\n" +
|
|
356
|
+
"{\n" +
|
|
357
|
+
" name: 'Field1', type: 'EmailInput', autocomplete: 'on',\n" +
|
|
358
|
+
" autofocus: 'true', disabled: 0, readOnly: { t: true }, required: [],\n" +
|
|
359
|
+
" tabindex: 'foo'\n" +
|
|
360
|
+
"}\n" +
|
|
361
|
+
"to be a form field\n" +
|
|
362
|
+
"\n" +
|
|
363
|
+
"{\n" +
|
|
364
|
+
" name: 'Field1',\n" +
|
|
365
|
+
" type: 'EmailInput',\n" +
|
|
366
|
+
" autocomplete: 'on',\n" +
|
|
367
|
+
" autofocus: 'true', // should be a boolean\n" +
|
|
368
|
+
" disabled: 0, // should be a boolean\n" +
|
|
369
|
+
" readOnly: { t: true }, // should be a boolean\n" +
|
|
370
|
+
" required:\n" +
|
|
371
|
+
" [], // should be a label\n" +
|
|
372
|
+
" // should satisfy\n" +
|
|
373
|
+
" // {\n" +
|
|
374
|
+
" // id: expect.it('to be a string'),\n" +
|
|
375
|
+
" // defaultMessage: expect.it('to be a string')\n" +
|
|
376
|
+
" // }\n" +
|
|
377
|
+
" //\n" +
|
|
378
|
+
" // [\n" +
|
|
379
|
+
" // // missing: id: should be a string\n" +
|
|
380
|
+
" // // missing: defaultMessage: should be a string\n" +
|
|
381
|
+
" // ]\n" +
|
|
382
|
+
" tabindex: 'foo' // should be a number\n" +
|
|
383
|
+
"}",
|
|
384
|
+
));
|
|
385
|
+
|
|
386
|
+
it("passes with a name and email input attributes", () =>
|
|
387
|
+
expect(
|
|
388
|
+
() =>
|
|
389
|
+
expect(
|
|
390
|
+
{
|
|
391
|
+
name: "Field1",
|
|
392
|
+
type: "EmailInput",
|
|
393
|
+
maxlength: 15,
|
|
394
|
+
minlength: 3,
|
|
395
|
+
multiple: true,
|
|
396
|
+
pattern: /olo/,
|
|
397
|
+
placeholder: {
|
|
398
|
+
id: "test.placeholder",
|
|
399
|
+
defaultMessage: "Placeholder here",
|
|
400
|
+
},
|
|
401
|
+
size: 18,
|
|
402
|
+
spellcheck: "",
|
|
403
|
+
},
|
|
404
|
+
"to be a form field",
|
|
405
|
+
),
|
|
406
|
+
"not to throw",
|
|
407
|
+
));
|
|
408
|
+
|
|
409
|
+
it("fails if email input attributes invalid", () =>
|
|
410
|
+
expect(
|
|
411
|
+
() =>
|
|
412
|
+
expect(
|
|
413
|
+
{
|
|
414
|
+
name: "Field1",
|
|
415
|
+
type: "EmailInput",
|
|
416
|
+
maxlength: "15",
|
|
417
|
+
minlength: -4,
|
|
418
|
+
multiple: "no",
|
|
419
|
+
pattern: 33,
|
|
420
|
+
placeholder: { foo: "Placeholder here" },
|
|
421
|
+
size: 0,
|
|
422
|
+
spellcheck: "wut",
|
|
423
|
+
},
|
|
424
|
+
"to be a form field",
|
|
425
|
+
),
|
|
426
|
+
"to throw",
|
|
427
|
+
"expected\n" +
|
|
428
|
+
"{\n" +
|
|
429
|
+
" name: 'Field1', type: 'EmailInput', maxlength: '15', minlength: -4,\n" +
|
|
430
|
+
" multiple: 'no', pattern: 33, placeholder: { foo: 'Placeholder here' },\n" +
|
|
431
|
+
" size: 0, spellcheck: 'wut'\n" +
|
|
432
|
+
"}\n" +
|
|
433
|
+
"to be a form field\n" +
|
|
434
|
+
"\n" +
|
|
435
|
+
"{\n" +
|
|
436
|
+
" name: 'Field1',\n" +
|
|
437
|
+
" type: 'EmailInput',\n" +
|
|
438
|
+
" maxlength:\n" +
|
|
439
|
+
" '15', // ⨯ should be a number and\n" +
|
|
440
|
+
" // ⨯ should be greater than 0\n" +
|
|
441
|
+
" minlength:\n" +
|
|
442
|
+
" -4, // ✓ should be a number and\n" +
|
|
443
|
+
" // ⨯ should be greater than 0\n" +
|
|
444
|
+
" multiple: 'no', // should be a boolean\n" +
|
|
445
|
+
" pattern: 33, // should be a regular expression\n" +
|
|
446
|
+
" placeholder:\n" +
|
|
447
|
+
" { foo: 'Placeholder here' }, // should be a label\n" +
|
|
448
|
+
" // should satisfy\n" +
|
|
449
|
+
" // {\n" +
|
|
450
|
+
" // id: expect.it('to be a string'),\n" +
|
|
451
|
+
" // defaultMessage: expect.it('to be a string')\n" +
|
|
452
|
+
" // }\n" +
|
|
453
|
+
" //\n" +
|
|
454
|
+
" // {\n" +
|
|
455
|
+
" // foo: 'Placeholder here'\n" +
|
|
456
|
+
" // // missing: id: should be a string\n" +
|
|
457
|
+
" // // missing: defaultMessage: should be a string\n" +
|
|
458
|
+
" // }\n" +
|
|
459
|
+
" size: 0, // ✓ should be a number and\n" +
|
|
460
|
+
" // ⨯ should be greater than 0\n" +
|
|
461
|
+
" spellcheck:\n" +
|
|
462
|
+
" 'wut' // ⨯ should be a boolean or\n" +
|
|
463
|
+
" // ⨯ should be ''\n" +
|
|
464
|
+
" //\n" +
|
|
465
|
+
" // -wut\n" +
|
|
466
|
+
"}",
|
|
467
|
+
));
|
|
468
|
+
});
|
|
469
|
+
|
|
470
|
+
describe("type 'MultiSelector'", () => {
|
|
471
|
+
it("passes with a name and empty options only", () =>
|
|
472
|
+
expect(
|
|
473
|
+
() =>
|
|
474
|
+
expect(
|
|
475
|
+
{
|
|
476
|
+
name: "field1",
|
|
477
|
+
type: "MultiSelector",
|
|
478
|
+
options: [],
|
|
479
|
+
},
|
|
480
|
+
"to be a form field",
|
|
481
|
+
),
|
|
482
|
+
"not to throw",
|
|
483
|
+
));
|
|
484
|
+
|
|
485
|
+
it("passes with a name and string label, string options", () =>
|
|
486
|
+
expect(
|
|
487
|
+
() =>
|
|
488
|
+
expect(
|
|
489
|
+
{
|
|
490
|
+
name: "field1",
|
|
491
|
+
type: "MultiSelector",
|
|
492
|
+
label: "A field",
|
|
493
|
+
options: [{ label: "Foo", value: "foo" }],
|
|
494
|
+
},
|
|
495
|
+
"to be a form field",
|
|
496
|
+
),
|
|
497
|
+
"not to throw",
|
|
498
|
+
));
|
|
499
|
+
|
|
500
|
+
it("passes with a name and object label, object options", () =>
|
|
501
|
+
expect(
|
|
502
|
+
() =>
|
|
503
|
+
expect(
|
|
504
|
+
{
|
|
505
|
+
name: "Field1",
|
|
506
|
+
type: "MultiSelector",
|
|
507
|
+
label: { id: "test.field1", defaultMessage: "A field" },
|
|
508
|
+
options: [
|
|
509
|
+
{
|
|
510
|
+
label: { id: "test.option", defaultMessage: "Foo" },
|
|
511
|
+
value: "foo",
|
|
512
|
+
},
|
|
513
|
+
],
|
|
514
|
+
},
|
|
515
|
+
"to be a form field",
|
|
516
|
+
),
|
|
517
|
+
"not to throw",
|
|
518
|
+
));
|
|
519
|
+
|
|
520
|
+
it("passes with a name and general input attributes", () =>
|
|
521
|
+
expect(
|
|
522
|
+
() =>
|
|
523
|
+
expect(
|
|
524
|
+
{
|
|
525
|
+
name: "Field1",
|
|
526
|
+
type: "MultiSelector",
|
|
527
|
+
options: [{ label: "Foo", value: "foo" }],
|
|
528
|
+
autocomplete: "on",
|
|
529
|
+
autofocus: true,
|
|
530
|
+
disabled: true,
|
|
531
|
+
readOnly: true,
|
|
532
|
+
required: {
|
|
533
|
+
id: "test.required",
|
|
534
|
+
defaultMessage: "Field is Required",
|
|
535
|
+
},
|
|
536
|
+
tabindex: 12,
|
|
537
|
+
},
|
|
538
|
+
"to be a form field",
|
|
539
|
+
),
|
|
540
|
+
"not to throw",
|
|
541
|
+
));
|
|
542
|
+
|
|
543
|
+
it("fails if general input attributes invalid", () =>
|
|
544
|
+
expect(
|
|
545
|
+
() =>
|
|
546
|
+
expect(
|
|
547
|
+
{
|
|
548
|
+
name: "Field1",
|
|
549
|
+
type: "MultiSelector",
|
|
550
|
+
options: [{ label: "Foo", value: "foo" }],
|
|
551
|
+
autocomplete: "on",
|
|
552
|
+
autofocus: "true",
|
|
553
|
+
disabled: 0,
|
|
554
|
+
readOnly: { t: true },
|
|
555
|
+
required: [],
|
|
556
|
+
tabindex: "foo",
|
|
557
|
+
},
|
|
558
|
+
"to be a form field",
|
|
559
|
+
),
|
|
560
|
+
"to throw",
|
|
561
|
+
"expected\n" +
|
|
562
|
+
"{\n" +
|
|
563
|
+
" name: 'Field1', type: 'MultiSelector',\n" +
|
|
564
|
+
" options: [ { label: 'Foo', value: 'foo' } ], autocomplete: 'on',\n" +
|
|
565
|
+
" autofocus: 'true', disabled: 0, readOnly: { t: true }, required: [],\n" +
|
|
566
|
+
" tabindex: 'foo'\n" +
|
|
567
|
+
"}\n" +
|
|
568
|
+
"to be a form field\n" +
|
|
569
|
+
"\n" +
|
|
570
|
+
"{\n" +
|
|
571
|
+
" name: 'Field1',\n" +
|
|
572
|
+
" type: 'MultiSelector',\n" +
|
|
573
|
+
" options: [ { label: 'Foo', value: 'foo' } ],\n" +
|
|
574
|
+
" autocomplete: 'on',\n" +
|
|
575
|
+
" autofocus: 'true', // should be a boolean\n" +
|
|
576
|
+
" disabled: 0, // should be a boolean\n" +
|
|
577
|
+
" readOnly: { t: true }, // should be a boolean\n" +
|
|
578
|
+
" required:\n" +
|
|
579
|
+
" [], // should be a label\n" +
|
|
580
|
+
" // should satisfy\n" +
|
|
581
|
+
" // {\n" +
|
|
582
|
+
" // id: expect.it('to be a string'),\n" +
|
|
583
|
+
" // defaultMessage: expect.it('to be a string')\n" +
|
|
584
|
+
" // }\n" +
|
|
585
|
+
" //\n" +
|
|
586
|
+
" // [\n" +
|
|
587
|
+
" // // missing: id: should be a string\n" +
|
|
588
|
+
" // // missing: defaultMessage: should be a string\n" +
|
|
589
|
+
" // ]\n" +
|
|
590
|
+
" tabindex: 'foo' // should be a number\n" +
|
|
591
|
+
"}",
|
|
592
|
+
));
|
|
593
|
+
|
|
594
|
+
it("fails if options missing", () =>
|
|
595
|
+
expect(
|
|
596
|
+
() =>
|
|
597
|
+
expect(
|
|
598
|
+
{
|
|
599
|
+
name: "field1",
|
|
600
|
+
type: "MultiSelector",
|
|
601
|
+
},
|
|
602
|
+
"to be a form field",
|
|
603
|
+
),
|
|
604
|
+
"to throw",
|
|
605
|
+
"expected { name: 'field1', type: 'MultiSelector' } to be a form field\n" +
|
|
606
|
+
"\n" +
|
|
607
|
+
"{\n" +
|
|
608
|
+
" name: 'field1',\n" +
|
|
609
|
+
" type: 'MultiSelector'\n" +
|
|
610
|
+
" // missing: options: ⨯ should be an array and\n" +
|
|
611
|
+
" ⨯ should have items satisfying { label: expect.it('to be a label'), value: expect.it('to be defined') }\n" +
|
|
612
|
+
" or\n" +
|
|
613
|
+
" ⨯ should equal []\n" +
|
|
614
|
+
"}",
|
|
615
|
+
));
|
|
616
|
+
});
|
|
617
|
+
|
|
618
|
+
describe("type 'LineLabel'", () => {
|
|
619
|
+
it("passes with a name only", () =>
|
|
620
|
+
expect(() => expect({ name: "field1", type: "LineLabel" }, "to be a form field"), "not to throw"));
|
|
621
|
+
});
|
|
622
|
+
|
|
623
|
+
describe("type 'NumberInput'", () => {
|
|
624
|
+
it("passes with a name and general input attributes", () =>
|
|
625
|
+
expect(
|
|
626
|
+
() =>
|
|
627
|
+
expect(
|
|
628
|
+
{
|
|
629
|
+
name: "Field1",
|
|
630
|
+
type: "NumberInput",
|
|
631
|
+
autocomplete: "on",
|
|
632
|
+
autofocus: true,
|
|
633
|
+
disabled: true,
|
|
634
|
+
readOnly: true,
|
|
635
|
+
required: {
|
|
636
|
+
id: "test.required",
|
|
637
|
+
defaultMessage: "Field is Required",
|
|
638
|
+
},
|
|
639
|
+
tabindex: 12,
|
|
640
|
+
},
|
|
641
|
+
"to be a form field",
|
|
642
|
+
),
|
|
643
|
+
"not to throw",
|
|
644
|
+
));
|
|
645
|
+
|
|
646
|
+
it("fails if general input attributes invalid", () =>
|
|
647
|
+
expect(
|
|
648
|
+
() =>
|
|
649
|
+
expect(
|
|
650
|
+
{
|
|
651
|
+
name: "Field1",
|
|
652
|
+
type: "NumberInput",
|
|
653
|
+
autocomplete: "on",
|
|
654
|
+
autofocus: "true",
|
|
655
|
+
disabled: 0,
|
|
656
|
+
readOnly: { t: true },
|
|
657
|
+
required: [],
|
|
658
|
+
tabindex: "foo",
|
|
659
|
+
},
|
|
660
|
+
"to be a form field",
|
|
661
|
+
),
|
|
662
|
+
"to throw",
|
|
663
|
+
"expected\n" +
|
|
664
|
+
"{\n" +
|
|
665
|
+
" name: 'Field1', type: 'NumberInput', autocomplete: 'on',\n" +
|
|
666
|
+
" autofocus: 'true', disabled: 0, readOnly: { t: true }, required: [],\n" +
|
|
667
|
+
" tabindex: 'foo'\n" +
|
|
668
|
+
"}\n" +
|
|
669
|
+
"to be a form field\n" +
|
|
670
|
+
"\n" +
|
|
671
|
+
"{\n" +
|
|
672
|
+
" name: 'Field1',\n" +
|
|
673
|
+
" type: 'NumberInput',\n" +
|
|
674
|
+
" autocomplete: 'on',\n" +
|
|
675
|
+
" autofocus: 'true', // should be a boolean\n" +
|
|
676
|
+
" disabled: 0, // should be a boolean\n" +
|
|
677
|
+
" readOnly: { t: true }, // should be a boolean\n" +
|
|
678
|
+
" required:\n" +
|
|
679
|
+
" [], // should be a label\n" +
|
|
680
|
+
" // should satisfy\n" +
|
|
681
|
+
" // {\n" +
|
|
682
|
+
" // id: expect.it('to be a string'),\n" +
|
|
683
|
+
" // defaultMessage: expect.it('to be a string')\n" +
|
|
684
|
+
" // }\n" +
|
|
685
|
+
" //\n" +
|
|
686
|
+
" // [\n" +
|
|
687
|
+
" // // missing: id: should be a string\n" +
|
|
688
|
+
" // // missing: defaultMessage: should be a string\n" +
|
|
689
|
+
" // ]\n" +
|
|
690
|
+
" tabindex: 'foo' // should be a number\n" +
|
|
691
|
+
"}",
|
|
692
|
+
));
|
|
693
|
+
|
|
694
|
+
it("passes with a name and number input attributes", () =>
|
|
695
|
+
expect(
|
|
696
|
+
() =>
|
|
697
|
+
expect(
|
|
698
|
+
{
|
|
699
|
+
name: "Field1",
|
|
700
|
+
type: "NumberInput",
|
|
701
|
+
max: 200,
|
|
702
|
+
min: 2,
|
|
703
|
+
placeholder: {
|
|
704
|
+
id: "test.placeholder",
|
|
705
|
+
defaultMessage: "Placeholder here",
|
|
706
|
+
},
|
|
707
|
+
step: 2,
|
|
708
|
+
},
|
|
709
|
+
"to be a form field",
|
|
710
|
+
),
|
|
711
|
+
"not to throw",
|
|
712
|
+
));
|
|
713
|
+
|
|
714
|
+
it("fails if number input attributes invalid", () =>
|
|
715
|
+
expect(
|
|
716
|
+
() =>
|
|
717
|
+
expect(
|
|
718
|
+
{
|
|
719
|
+
name: "Field1",
|
|
720
|
+
type: "NumberInput",
|
|
721
|
+
max: "200",
|
|
722
|
+
min: [2],
|
|
723
|
+
placeholder: null,
|
|
724
|
+
step: NaN,
|
|
725
|
+
},
|
|
726
|
+
"to be a form field",
|
|
727
|
+
),
|
|
728
|
+
"to throw",
|
|
729
|
+
"expected\n" +
|
|
730
|
+
"{\n" +
|
|
731
|
+
" name: 'Field1', type: 'NumberInput', max: '200', min: [ 2 ],\n" +
|
|
732
|
+
" placeholder: null, step: NaN\n" +
|
|
733
|
+
"}\n" +
|
|
734
|
+
"to be a form field\n" +
|
|
735
|
+
"\n" +
|
|
736
|
+
"{\n" +
|
|
737
|
+
" name: 'Field1',\n" +
|
|
738
|
+
" type: 'NumberInput',\n" +
|
|
739
|
+
" max: '200', // should be a number\n" +
|
|
740
|
+
" min: [ 2 ], // should be a number\n" +
|
|
741
|
+
" placeholder:\n" +
|
|
742
|
+
" null, // should be a label\n" +
|
|
743
|
+
" // should equal\n" +
|
|
744
|
+
" // {\n" +
|
|
745
|
+
" // id: expect.it('to be a string'),\n" +
|
|
746
|
+
" // defaultMessage: expect.it('to be a string')\n" +
|
|
747
|
+
" // }\n" +
|
|
748
|
+
" step: NaN // expected NaN to be a number\n" +
|
|
749
|
+
"}",
|
|
750
|
+
));
|
|
751
|
+
});
|
|
752
|
+
|
|
753
|
+
describe("type 'ReadOnly'", () => {
|
|
754
|
+
it("passes with a name only", () =>
|
|
755
|
+
expect(() => expect({ name: "field1", type: "ReadOnly" }, "to be a form field"), "not to throw"));
|
|
756
|
+
});
|
|
757
|
+
|
|
758
|
+
describe("type 'Selector'", () => {
|
|
759
|
+
it("passes with a name and empty options only", () =>
|
|
760
|
+
expect(
|
|
761
|
+
() =>
|
|
762
|
+
expect(
|
|
763
|
+
{
|
|
764
|
+
name: "field1",
|
|
765
|
+
type: "Selector",
|
|
766
|
+
options: [],
|
|
767
|
+
},
|
|
768
|
+
"to be a form field",
|
|
769
|
+
),
|
|
770
|
+
"not to throw",
|
|
771
|
+
));
|
|
772
|
+
|
|
773
|
+
it("passes with a name and string label, string options", () =>
|
|
774
|
+
expect(
|
|
775
|
+
() =>
|
|
776
|
+
expect(
|
|
777
|
+
{
|
|
778
|
+
name: "field1",
|
|
779
|
+
type: "Selector",
|
|
780
|
+
label: "A field",
|
|
781
|
+
options: [{ label: "Foo", value: "foo" }],
|
|
782
|
+
},
|
|
783
|
+
"to be a form field",
|
|
784
|
+
),
|
|
785
|
+
"not to throw",
|
|
786
|
+
));
|
|
787
|
+
|
|
788
|
+
it("passes with a name and object label, object options", () =>
|
|
789
|
+
expect(
|
|
790
|
+
() =>
|
|
791
|
+
expect(
|
|
792
|
+
{
|
|
793
|
+
name: "Field1",
|
|
794
|
+
type: "Selector",
|
|
795
|
+
label: { id: "test.field1", defaultMessage: "A field" },
|
|
796
|
+
options: [
|
|
797
|
+
{
|
|
798
|
+
label: { id: "test.option", defaultMessage: "Foo" },
|
|
799
|
+
value: "foo",
|
|
800
|
+
},
|
|
801
|
+
],
|
|
802
|
+
},
|
|
803
|
+
"to be a form field",
|
|
804
|
+
),
|
|
805
|
+
"not to throw",
|
|
806
|
+
));
|
|
807
|
+
|
|
808
|
+
it("passes with a name and general input attributes", () =>
|
|
809
|
+
expect(
|
|
810
|
+
() =>
|
|
811
|
+
expect(
|
|
812
|
+
{
|
|
813
|
+
name: "Field1",
|
|
814
|
+
type: "Selector",
|
|
815
|
+
options: [{ label: "Foo", value: "foo" }],
|
|
816
|
+
autocomplete: "on",
|
|
817
|
+
autofocus: true,
|
|
818
|
+
disabled: true,
|
|
819
|
+
readOnly: true,
|
|
820
|
+
required: {
|
|
821
|
+
id: "test.required",
|
|
822
|
+
defaultMessage: "Field is Required",
|
|
823
|
+
},
|
|
824
|
+
tabindex: 12,
|
|
825
|
+
},
|
|
826
|
+
"to be a form field",
|
|
827
|
+
),
|
|
828
|
+
"not to throw",
|
|
829
|
+
));
|
|
830
|
+
|
|
831
|
+
it("fails if general input attributes invalid", () =>
|
|
832
|
+
expect(
|
|
833
|
+
() =>
|
|
834
|
+
expect(
|
|
835
|
+
{
|
|
836
|
+
name: "Field1",
|
|
837
|
+
type: "Selector",
|
|
838
|
+
options: [{ label: "Foo", value: "foo" }],
|
|
839
|
+
autocomplete: "on",
|
|
840
|
+
autofocus: "true",
|
|
841
|
+
disabled: 0,
|
|
842
|
+
readOnly: { t: true },
|
|
843
|
+
required: [],
|
|
844
|
+
tabindex: "foo",
|
|
845
|
+
},
|
|
846
|
+
"to be a form field",
|
|
847
|
+
),
|
|
848
|
+
"to throw",
|
|
849
|
+
"expected\n" +
|
|
850
|
+
"{\n" +
|
|
851
|
+
" name: 'Field1', type: 'Selector',\n" +
|
|
852
|
+
" options: [ { label: 'Foo', value: 'foo' } ], autocomplete: 'on',\n" +
|
|
853
|
+
" autofocus: 'true', disabled: 0, readOnly: { t: true }, required: [],\n" +
|
|
854
|
+
" tabindex: 'foo'\n" +
|
|
855
|
+
"}\n" +
|
|
856
|
+
"to be a form field\n" +
|
|
857
|
+
"\n" +
|
|
858
|
+
"{\n" +
|
|
859
|
+
" name: 'Field1',\n" +
|
|
860
|
+
" type: 'Selector',\n" +
|
|
861
|
+
" options: [ { label: 'Foo', value: 'foo' } ],\n" +
|
|
862
|
+
" autocomplete: 'on',\n" +
|
|
863
|
+
" autofocus: 'true', // should be a boolean\n" +
|
|
864
|
+
" disabled: 0, // should be a boolean\n" +
|
|
865
|
+
" readOnly: { t: true }, // should be a boolean\n" +
|
|
866
|
+
" required:\n" +
|
|
867
|
+
" [], // should be a label\n" +
|
|
868
|
+
" // should satisfy\n" +
|
|
869
|
+
" // {\n" +
|
|
870
|
+
" // id: expect.it('to be a string'),\n" +
|
|
871
|
+
" // defaultMessage: expect.it('to be a string')\n" +
|
|
872
|
+
" // }\n" +
|
|
873
|
+
" //\n" +
|
|
874
|
+
" // [\n" +
|
|
875
|
+
" // // missing: id: should be a string\n" +
|
|
876
|
+
" // // missing: defaultMessage: should be a string\n" +
|
|
877
|
+
" // ]\n" +
|
|
878
|
+
" tabindex: 'foo' // should be a number\n" +
|
|
879
|
+
"}",
|
|
880
|
+
));
|
|
881
|
+
|
|
882
|
+
it("fails if options missing", () =>
|
|
883
|
+
expect(
|
|
884
|
+
() =>
|
|
885
|
+
expect(
|
|
886
|
+
{
|
|
887
|
+
name: "field1",
|
|
888
|
+
type: "Selector",
|
|
889
|
+
},
|
|
890
|
+
"to be a form field",
|
|
891
|
+
),
|
|
892
|
+
"to throw",
|
|
893
|
+
"expected { name: 'field1', type: 'Selector' } to be a form field\n" +
|
|
894
|
+
"\n" +
|
|
895
|
+
"{\n" +
|
|
896
|
+
" name: 'field1',\n" +
|
|
897
|
+
" type: 'Selector'\n" +
|
|
898
|
+
" // missing: options: ⨯ should be an array and\n" +
|
|
899
|
+
" ⨯ should have items satisfying { label: expect.it('to be a label'), value: expect.it('to be defined') }\n" +
|
|
900
|
+
" or\n" +
|
|
901
|
+
" ⨯ should equal []\n" +
|
|
902
|
+
"}",
|
|
903
|
+
));
|
|
904
|
+
});
|
|
905
|
+
|
|
906
|
+
describe("type 'SmallButton'", () => {
|
|
907
|
+
it("passes with a name and button attributes", () =>
|
|
908
|
+
expect(
|
|
909
|
+
() =>
|
|
910
|
+
expect(
|
|
911
|
+
{
|
|
912
|
+
name: "Field1",
|
|
913
|
+
type: "SmallButton",
|
|
914
|
+
primary: true,
|
|
915
|
+
active: true,
|
|
916
|
+
altText: {
|
|
917
|
+
id: "test.button.label",
|
|
918
|
+
defaultMessage: "Label",
|
|
919
|
+
},
|
|
920
|
+
icon: "an-icon",
|
|
921
|
+
autofocus: true,
|
|
922
|
+
disabled: true,
|
|
923
|
+
},
|
|
924
|
+
"to be a form field",
|
|
925
|
+
),
|
|
926
|
+
"not to throw",
|
|
927
|
+
));
|
|
928
|
+
|
|
929
|
+
it("fails if missing icon or altText", () =>
|
|
930
|
+
expect(
|
|
931
|
+
() =>
|
|
932
|
+
expect(
|
|
933
|
+
{
|
|
934
|
+
name: "Field1",
|
|
935
|
+
type: "SmallButton",
|
|
936
|
+
},
|
|
937
|
+
"to be a form field",
|
|
938
|
+
),
|
|
939
|
+
"to throw",
|
|
940
|
+
"expected { name: 'Field1', type: 'SmallButton' } to be a form field\n" +
|
|
941
|
+
"\n" +
|
|
942
|
+
"{\n" +
|
|
943
|
+
" name: 'Field1',\n" +
|
|
944
|
+
" type: 'SmallButton'\n" +
|
|
945
|
+
" // missing: altText:\n" +
|
|
946
|
+
" should be a label\n" +
|
|
947
|
+
" should be a string\n" +
|
|
948
|
+
" // missing: icon: should be a string\n" +
|
|
949
|
+
"}",
|
|
950
|
+
));
|
|
951
|
+
|
|
952
|
+
it("fails if button attributes invalid", () =>
|
|
953
|
+
expect(
|
|
954
|
+
() =>
|
|
955
|
+
expect(
|
|
956
|
+
{
|
|
957
|
+
name: "Field1",
|
|
958
|
+
type: "SmallButton",
|
|
959
|
+
primary: "foo",
|
|
960
|
+
active: 0,
|
|
961
|
+
altText: { defaultMessage: "A label" },
|
|
962
|
+
icon: [],
|
|
963
|
+
autofocus: {},
|
|
964
|
+
disabled: "!true",
|
|
965
|
+
},
|
|
966
|
+
"to be a form field",
|
|
967
|
+
),
|
|
968
|
+
"to throw",
|
|
969
|
+
"expected\n" +
|
|
970
|
+
"{\n" +
|
|
971
|
+
" name: 'Field1', type: 'SmallButton', primary: 'foo', active: 0,\n" +
|
|
972
|
+
" altText: { defaultMessage: 'A label' }, icon: [], autofocus: {},\n" +
|
|
973
|
+
" disabled: '!true'\n" +
|
|
974
|
+
"}\n" +
|
|
975
|
+
"to be a form field\n" +
|
|
976
|
+
"\n" +
|
|
977
|
+
"{\n" +
|
|
978
|
+
" name: 'Field1',\n" +
|
|
979
|
+
" type: 'SmallButton',\n" +
|
|
980
|
+
" primary: 'foo', // should be a boolean\n" +
|
|
981
|
+
" active: 0, // should be a boolean\n" +
|
|
982
|
+
" altText:\n" +
|
|
983
|
+
" { defaultMessage: 'A label' }, // should be a label\n" +
|
|
984
|
+
" // should satisfy\n" +
|
|
985
|
+
" // {\n" +
|
|
986
|
+
" // id: expect.it('to be a string'),\n" +
|
|
987
|
+
" // defaultMessage: expect.it('to be a string')\n" +
|
|
988
|
+
" // }\n" +
|
|
989
|
+
" //\n" +
|
|
990
|
+
" // {\n" +
|
|
991
|
+
" // defaultMessage: 'A label'\n" +
|
|
992
|
+
" // // missing: id: should be a string\n" +
|
|
993
|
+
" // }\n" +
|
|
994
|
+
" icon: [], // should be a string\n" +
|
|
995
|
+
" autofocus: {}, // should be a boolean\n" +
|
|
996
|
+
" disabled: '!true' // should be a boolean\n" +
|
|
997
|
+
"}",
|
|
998
|
+
));
|
|
999
|
+
});
|
|
1000
|
+
|
|
1001
|
+
describe("type 'SwitchInput'", () => {
|
|
1002
|
+
it("passes with a name and non-textual input attributes", () =>
|
|
1003
|
+
expect(
|
|
1004
|
+
() =>
|
|
1005
|
+
expect(
|
|
1006
|
+
{
|
|
1007
|
+
name: "Field1",
|
|
1008
|
+
type: "SwitchInput",
|
|
1009
|
+
autofocus: true,
|
|
1010
|
+
disabled: true,
|
|
1011
|
+
required: {
|
|
1012
|
+
id: "test.required",
|
|
1013
|
+
defaultMessage: "Field is Required",
|
|
1014
|
+
},
|
|
1015
|
+
tabindex: 12,
|
|
1016
|
+
},
|
|
1017
|
+
"to be a form field",
|
|
1018
|
+
),
|
|
1019
|
+
"not to throw",
|
|
1020
|
+
));
|
|
1021
|
+
|
|
1022
|
+
it("fails if non-textual input attributes invalid", () =>
|
|
1023
|
+
expect(
|
|
1024
|
+
() =>
|
|
1025
|
+
expect(
|
|
1026
|
+
{
|
|
1027
|
+
name: "Field1",
|
|
1028
|
+
type: "SwitchInput",
|
|
1029
|
+
autofocus: "true",
|
|
1030
|
+
disabled: 1,
|
|
1031
|
+
required: [],
|
|
1032
|
+
tabindex: "",
|
|
1033
|
+
},
|
|
1034
|
+
"to be a form field",
|
|
1035
|
+
),
|
|
1036
|
+
"to throw",
|
|
1037
|
+
"expected\n" +
|
|
1038
|
+
"{\n" +
|
|
1039
|
+
" name: 'Field1', type: 'SwitchInput', autofocus: 'true', disabled: 1,\n" +
|
|
1040
|
+
" required: [], tabindex: ''\n" +
|
|
1041
|
+
"}\n" +
|
|
1042
|
+
"to be a form field\n" +
|
|
1043
|
+
"\n" +
|
|
1044
|
+
"{\n" +
|
|
1045
|
+
" name: 'Field1',\n" +
|
|
1046
|
+
" type: 'SwitchInput',\n" +
|
|
1047
|
+
" autofocus: 'true', // should be a boolean\n" +
|
|
1048
|
+
" disabled: 1, // should be a boolean\n" +
|
|
1049
|
+
" required:\n" +
|
|
1050
|
+
" [], // should be a label\n" +
|
|
1051
|
+
" // should satisfy\n" +
|
|
1052
|
+
" // {\n" +
|
|
1053
|
+
" // id: expect.it('to be a string'),\n" +
|
|
1054
|
+
" // defaultMessage: expect.it('to be a string')\n" +
|
|
1055
|
+
" // }\n" +
|
|
1056
|
+
" //\n" +
|
|
1057
|
+
" // [\n" +
|
|
1058
|
+
" // // missing: id: should be a string\n" +
|
|
1059
|
+
" // // missing: defaultMessage: should be a string\n" +
|
|
1060
|
+
" // ]\n" +
|
|
1061
|
+
" tabindex: '' // should be a number\n" +
|
|
1062
|
+
"}",
|
|
1063
|
+
));
|
|
1064
|
+
|
|
1065
|
+
it("passes with a name and switch input attributes", () =>
|
|
1066
|
+
expect(
|
|
1067
|
+
() =>
|
|
1068
|
+
expect(
|
|
1069
|
+
{
|
|
1070
|
+
name: "Field1",
|
|
1071
|
+
type: "SwitchInput",
|
|
1072
|
+
onCaption: "On",
|
|
1073
|
+
offCaption: "Off",
|
|
1074
|
+
onColor: "#00FF00",
|
|
1075
|
+
offColor: "#FF0000",
|
|
1076
|
+
},
|
|
1077
|
+
"to be a form field",
|
|
1078
|
+
),
|
|
1079
|
+
"not to throw",
|
|
1080
|
+
));
|
|
1081
|
+
|
|
1082
|
+
it("fails if switch input attributes invalid", () =>
|
|
1083
|
+
expect(
|
|
1084
|
+
() =>
|
|
1085
|
+
expect(
|
|
1086
|
+
{
|
|
1087
|
+
name: "Field1",
|
|
1088
|
+
type: "SwitchInput",
|
|
1089
|
+
onCaption: 1,
|
|
1090
|
+
offCaption: {},
|
|
1091
|
+
onColor: ["red"],
|
|
1092
|
+
offColor: 0,
|
|
1093
|
+
},
|
|
1094
|
+
"to be a form field",
|
|
1095
|
+
),
|
|
1096
|
+
"to throw",
|
|
1097
|
+
"expected\n" +
|
|
1098
|
+
"{\n" +
|
|
1099
|
+
" name: 'Field1', type: 'SwitchInput', onCaption: 1, offCaption: {},\n" +
|
|
1100
|
+
" onColor: [ 'red' ], offColor: 0\n" +
|
|
1101
|
+
"}\n" +
|
|
1102
|
+
"to be a form field\n" +
|
|
1103
|
+
"\n" +
|
|
1104
|
+
"{\n" +
|
|
1105
|
+
" name: 'Field1',\n" +
|
|
1106
|
+
" type: 'SwitchInput',\n" +
|
|
1107
|
+
" onCaption:\n" +
|
|
1108
|
+
" 1, // should be a label\n" +
|
|
1109
|
+
" // should be a string\n" +
|
|
1110
|
+
" offCaption:\n" +
|
|
1111
|
+
" {}, // should be a label\n" +
|
|
1112
|
+
" // should satisfy\n" +
|
|
1113
|
+
" // {\n" +
|
|
1114
|
+
" // id: expect.it('to be a string'),\n" +
|
|
1115
|
+
" // defaultMessage: expect.it('to be a string')\n" +
|
|
1116
|
+
" // }\n" +
|
|
1117
|
+
" //\n" +
|
|
1118
|
+
" // {\n" +
|
|
1119
|
+
" // // missing: id: should be a string\n" +
|
|
1120
|
+
" // // missing: defaultMessage: should be a string\n" +
|
|
1121
|
+
" // }\n" +
|
|
1122
|
+
" onColor: [ 'red' ], // should be a string\n" +
|
|
1123
|
+
" offColor: 0 // should be a string\n" +
|
|
1124
|
+
"}",
|
|
1125
|
+
));
|
|
1126
|
+
});
|
|
1127
|
+
|
|
1128
|
+
describe("type 'TextInput'", () => {
|
|
1129
|
+
it("passes with a name and general input attributes", () =>
|
|
1130
|
+
expect(
|
|
1131
|
+
() =>
|
|
1132
|
+
expect(
|
|
1133
|
+
{
|
|
1134
|
+
name: "Field1",
|
|
1135
|
+
type: "TextInput",
|
|
1136
|
+
autocomplete: "on",
|
|
1137
|
+
autofocus: true,
|
|
1138
|
+
disabled: true,
|
|
1139
|
+
readOnly: true,
|
|
1140
|
+
required: {
|
|
1141
|
+
id: "test.required",
|
|
1142
|
+
defaultMessage: "Field is Required",
|
|
1143
|
+
},
|
|
1144
|
+
tabindex: 12,
|
|
1145
|
+
},
|
|
1146
|
+
"to be a form field",
|
|
1147
|
+
),
|
|
1148
|
+
"not to throw",
|
|
1149
|
+
));
|
|
1150
|
+
|
|
1151
|
+
it("fails if general input attributes invalid", () =>
|
|
1152
|
+
expect(
|
|
1153
|
+
() =>
|
|
1154
|
+
expect(
|
|
1155
|
+
{
|
|
1156
|
+
name: "Field1",
|
|
1157
|
+
type: "TextInput",
|
|
1158
|
+
autocomplete: "on",
|
|
1159
|
+
autofocus: "true",
|
|
1160
|
+
disabled: 0,
|
|
1161
|
+
readOnly: { t: true },
|
|
1162
|
+
required: [],
|
|
1163
|
+
tabindex: "foo",
|
|
1164
|
+
},
|
|
1165
|
+
"to be a form field",
|
|
1166
|
+
),
|
|
1167
|
+
"to throw",
|
|
1168
|
+
"expected\n" +
|
|
1169
|
+
"{\n" +
|
|
1170
|
+
" name: 'Field1', type: 'TextInput', autocomplete: 'on',\n" +
|
|
1171
|
+
" autofocus: 'true', disabled: 0, readOnly: { t: true }, required: [],\n" +
|
|
1172
|
+
" tabindex: 'foo'\n" +
|
|
1173
|
+
"}\n" +
|
|
1174
|
+
"to be a form field\n" +
|
|
1175
|
+
"\n" +
|
|
1176
|
+
"{\n" +
|
|
1177
|
+
" name: 'Field1',\n" +
|
|
1178
|
+
" type: 'TextInput',\n" +
|
|
1179
|
+
" autocomplete: 'on',\n" +
|
|
1180
|
+
" autofocus: 'true', // should be a boolean\n" +
|
|
1181
|
+
" disabled: 0, // should be a boolean\n" +
|
|
1182
|
+
" readOnly: { t: true }, // should be a boolean\n" +
|
|
1183
|
+
" required:\n" +
|
|
1184
|
+
" [], // should be a label\n" +
|
|
1185
|
+
" // should satisfy\n" +
|
|
1186
|
+
" // {\n" +
|
|
1187
|
+
" // id: expect.it('to be a string'),\n" +
|
|
1188
|
+
" // defaultMessage: expect.it('to be a string')\n" +
|
|
1189
|
+
" // }\n" +
|
|
1190
|
+
" //\n" +
|
|
1191
|
+
" // [\n" +
|
|
1192
|
+
" // // missing: id: should be a string\n" +
|
|
1193
|
+
" // // missing: defaultMessage: should be a string\n" +
|
|
1194
|
+
" // ]\n" +
|
|
1195
|
+
" tabindex: 'foo' // should be a number\n" +
|
|
1196
|
+
"}",
|
|
1197
|
+
));
|
|
1198
|
+
|
|
1199
|
+
it("passes with a name and text input attributes", () =>
|
|
1200
|
+
expect(
|
|
1201
|
+
() =>
|
|
1202
|
+
expect(
|
|
1203
|
+
{
|
|
1204
|
+
name: "Field1",
|
|
1205
|
+
type: "TextInput",
|
|
1206
|
+
maxlength: 15,
|
|
1207
|
+
minlength: 3,
|
|
1208
|
+
pattern: /olo/,
|
|
1209
|
+
placeholder: "Placeholder here",
|
|
1210
|
+
size: 18,
|
|
1211
|
+
spellcheck: "",
|
|
1212
|
+
},
|
|
1213
|
+
"to be a form field",
|
|
1214
|
+
),
|
|
1215
|
+
"not to throw",
|
|
1216
|
+
));
|
|
1217
|
+
|
|
1218
|
+
it("fails if text input attributes invalid", () =>
|
|
1219
|
+
expect(
|
|
1220
|
+
() =>
|
|
1221
|
+
expect(
|
|
1222
|
+
{
|
|
1223
|
+
name: "Field1",
|
|
1224
|
+
type: "TextInput",
|
|
1225
|
+
maxlength: 0,
|
|
1226
|
+
minlength: "three",
|
|
1227
|
+
pattern: {},
|
|
1228
|
+
placeholder: ["Placeholder here"],
|
|
1229
|
+
size: -15,
|
|
1230
|
+
spellcheck: null,
|
|
1231
|
+
},
|
|
1232
|
+
"to be a form field",
|
|
1233
|
+
),
|
|
1234
|
+
"to throw",
|
|
1235
|
+
"expected\n" +
|
|
1236
|
+
"{\n" +
|
|
1237
|
+
" name: 'Field1', type: 'TextInput', maxlength: 0, minlength: 'three',\n" +
|
|
1238
|
+
" pattern: {}, placeholder: [ 'Placeholder here' ], size: -15,\n" +
|
|
1239
|
+
" spellcheck: null\n" +
|
|
1240
|
+
"}\n" +
|
|
1241
|
+
"to be a form field\n" +
|
|
1242
|
+
"\n" +
|
|
1243
|
+
"{\n" +
|
|
1244
|
+
" name: 'Field1',\n" +
|
|
1245
|
+
" type: 'TextInput',\n" +
|
|
1246
|
+
" maxlength:\n" +
|
|
1247
|
+
" 0, // ✓ should be a number and\n" +
|
|
1248
|
+
" // ⨯ should be greater than 0\n" +
|
|
1249
|
+
" minlength:\n" +
|
|
1250
|
+
" 'three', // ⨯ should be a number and\n" +
|
|
1251
|
+
" // ⨯ should be greater than 0\n" +
|
|
1252
|
+
" pattern: {}, // should be a regular expression\n" +
|
|
1253
|
+
" placeholder:\n" +
|
|
1254
|
+
" [ 'Placeholder here' ], // should be a label\n" +
|
|
1255
|
+
" // should satisfy\n" +
|
|
1256
|
+
" // {\n" +
|
|
1257
|
+
" // id: expect.it('to be a string'),\n" +
|
|
1258
|
+
" // defaultMessage: expect.it('to be a string')\n" +
|
|
1259
|
+
" // }\n" +
|
|
1260
|
+
" //\n" +
|
|
1261
|
+
" // [\n" +
|
|
1262
|
+
" // 'Placeholder here'\n" +
|
|
1263
|
+
" // // missing: id: should be a string\n" +
|
|
1264
|
+
" // // missing: defaultMessage: should be a string\n" +
|
|
1265
|
+
" // ]\n" +
|
|
1266
|
+
" size: -15, // ✓ should be a number and\n" +
|
|
1267
|
+
" // ⨯ should be greater than 0\n" +
|
|
1268
|
+
" spellcheck:\n" +
|
|
1269
|
+
" null // ⨯ should be a boolean or\n" +
|
|
1270
|
+
" // ⨯ should be ''\n" +
|
|
1271
|
+
"}",
|
|
1272
|
+
));
|
|
1273
|
+
});
|
|
1274
|
+
|
|
1275
|
+
describe("type 'TimeInput'", () => {
|
|
1276
|
+
it("passes with a name and general input attributes", () =>
|
|
1277
|
+
expect(
|
|
1278
|
+
() =>
|
|
1279
|
+
expect(
|
|
1280
|
+
{
|
|
1281
|
+
name: "Field1",
|
|
1282
|
+
type: "TimeInput",
|
|
1283
|
+
autocomplete: "on",
|
|
1284
|
+
autofocus: true,
|
|
1285
|
+
disabled: true,
|
|
1286
|
+
readOnly: true,
|
|
1287
|
+
required: {
|
|
1288
|
+
id: "test.required",
|
|
1289
|
+
defaultMessage: "Field is Required",
|
|
1290
|
+
},
|
|
1291
|
+
tabindex: 12,
|
|
1292
|
+
},
|
|
1293
|
+
"to be a form field",
|
|
1294
|
+
),
|
|
1295
|
+
"not to throw",
|
|
1296
|
+
));
|
|
1297
|
+
|
|
1298
|
+
it("fails if general input attributes invalid", () =>
|
|
1299
|
+
expect(
|
|
1300
|
+
() =>
|
|
1301
|
+
expect(
|
|
1302
|
+
{
|
|
1303
|
+
name: "Field1",
|
|
1304
|
+
type: "TimeInput",
|
|
1305
|
+
autocomplete: "on",
|
|
1306
|
+
autofocus: "true",
|
|
1307
|
+
disabled: 0,
|
|
1308
|
+
readOnly: { t: true },
|
|
1309
|
+
required: [],
|
|
1310
|
+
tabindex: "foo",
|
|
1311
|
+
},
|
|
1312
|
+
"to be a form field",
|
|
1313
|
+
),
|
|
1314
|
+
"to throw",
|
|
1315
|
+
"expected\n" +
|
|
1316
|
+
"{\n" +
|
|
1317
|
+
" name: 'Field1', type: 'TimeInput', autocomplete: 'on',\n" +
|
|
1318
|
+
" autofocus: 'true', disabled: 0, readOnly: { t: true }, required: [],\n" +
|
|
1319
|
+
" tabindex: 'foo'\n" +
|
|
1320
|
+
"}\n" +
|
|
1321
|
+
"to be a form field\n" +
|
|
1322
|
+
"\n" +
|
|
1323
|
+
"{\n" +
|
|
1324
|
+
" name: 'Field1',\n" +
|
|
1325
|
+
" type: 'TimeInput',\n" +
|
|
1326
|
+
" autocomplete: 'on',\n" +
|
|
1327
|
+
" autofocus: 'true', // should be a boolean\n" +
|
|
1328
|
+
" disabled: 0, // should be a boolean\n" +
|
|
1329
|
+
" readOnly: { t: true }, // should be a boolean\n" +
|
|
1330
|
+
" required:\n" +
|
|
1331
|
+
" [], // should be a label\n" +
|
|
1332
|
+
" // should satisfy\n" +
|
|
1333
|
+
" // {\n" +
|
|
1334
|
+
" // id: expect.it('to be a string'),\n" +
|
|
1335
|
+
" // defaultMessage: expect.it('to be a string')\n" +
|
|
1336
|
+
" // }\n" +
|
|
1337
|
+
" //\n" +
|
|
1338
|
+
" // [\n" +
|
|
1339
|
+
" // // missing: id: should be a string\n" +
|
|
1340
|
+
" // // missing: defaultMessage: should be a string\n" +
|
|
1341
|
+
" // ]\n" +
|
|
1342
|
+
" tabindex: 'foo' // should be a number\n" +
|
|
1343
|
+
"}",
|
|
1344
|
+
));
|
|
1345
|
+
|
|
1346
|
+
it("passes with a name and time input attributes", () =>
|
|
1347
|
+
expect(
|
|
1348
|
+
() =>
|
|
1349
|
+
expect(
|
|
1350
|
+
{
|
|
1351
|
+
name: "Field1",
|
|
1352
|
+
type: "TimeInput",
|
|
1353
|
+
max: "15:35",
|
|
1354
|
+
min: "22:21:05",
|
|
1355
|
+
step: "any",
|
|
1356
|
+
},
|
|
1357
|
+
"to be a form field",
|
|
1358
|
+
),
|
|
1359
|
+
"not to throw",
|
|
1360
|
+
));
|
|
1361
|
+
|
|
1362
|
+
it("fails if time input attributes invalid", () =>
|
|
1363
|
+
expect(
|
|
1364
|
+
() =>
|
|
1365
|
+
expect(
|
|
1366
|
+
{
|
|
1367
|
+
name: "Field1",
|
|
1368
|
+
type: "TimeInput",
|
|
1369
|
+
max: "15-35",
|
|
1370
|
+
min: "aaaa:21:05",
|
|
1371
|
+
step: "none",
|
|
1372
|
+
},
|
|
1373
|
+
"to be a form field",
|
|
1374
|
+
),
|
|
1375
|
+
"to throw",
|
|
1376
|
+
"expected\n" +
|
|
1377
|
+
"{\n" +
|
|
1378
|
+
" name: 'Field1',\n" +
|
|
1379
|
+
" type: 'TimeInput',\n" +
|
|
1380
|
+
" max: '15-35',\n" +
|
|
1381
|
+
" min: 'aaaa:21:05',\n" +
|
|
1382
|
+
" step: 'none'\n" +
|
|
1383
|
+
"}\n" +
|
|
1384
|
+
"to be a form field\n" +
|
|
1385
|
+
"\n" +
|
|
1386
|
+
"{\n" +
|
|
1387
|
+
" name: 'Field1',\n" +
|
|
1388
|
+
" type: 'TimeInput',\n" +
|
|
1389
|
+
" max: '15-35', // ✓ should be a string and\n" +
|
|
1390
|
+
" // ⨯ should match /^\\d{2}:\\d{2}(?::\\d{2})?$/\n" +
|
|
1391
|
+
" min: 'aaaa:21:05', // ✓ should be a string and\n" +
|
|
1392
|
+
" // ⨯ should match /^\\d{2}:\\d{2}(?::\\d{2})?$/\n" +
|
|
1393
|
+
" step: 'none' // ⨯ should be a number or\n" +
|
|
1394
|
+
" // ⨯ should be 'any'\n" +
|
|
1395
|
+
" //\n" +
|
|
1396
|
+
" // -none\n" +
|
|
1397
|
+
" // +any\n" +
|
|
1398
|
+
"}",
|
|
1399
|
+
));
|
|
1400
|
+
});
|
|
1401
|
+
|
|
1402
|
+
describe("type 'TranslationInput'", () => {
|
|
1403
|
+
it("passes with a name and 'more' label", () =>
|
|
1404
|
+
expect(
|
|
1405
|
+
() =>
|
|
1406
|
+
expect(
|
|
1407
|
+
{
|
|
1408
|
+
name: "Field1",
|
|
1409
|
+
type: "TranslationInput",
|
|
1410
|
+
moreLabel: "More",
|
|
1411
|
+
},
|
|
1412
|
+
"to be a form field",
|
|
1413
|
+
),
|
|
1414
|
+
"not to throw",
|
|
1415
|
+
));
|
|
1416
|
+
|
|
1417
|
+
it("fails if missing 'more' label", () =>
|
|
1418
|
+
expect(
|
|
1419
|
+
() =>
|
|
1420
|
+
expect(
|
|
1421
|
+
{
|
|
1422
|
+
name: "Field1",
|
|
1423
|
+
type: "TranslationInput",
|
|
1424
|
+
},
|
|
1425
|
+
"to be a form field",
|
|
1426
|
+
),
|
|
1427
|
+
"to throw",
|
|
1428
|
+
"expected { name: 'Field1', type: 'TranslationInput' } to be a form field\n" +
|
|
1429
|
+
"\n" +
|
|
1430
|
+
"{\n" +
|
|
1431
|
+
" name: 'Field1',\n" +
|
|
1432
|
+
" type: 'TranslationInput'\n" +
|
|
1433
|
+
" // missing: moreLabel:\n" +
|
|
1434
|
+
" should be a label\n" +
|
|
1435
|
+
" should be a string\n" +
|
|
1436
|
+
"}",
|
|
1437
|
+
));
|
|
1438
|
+
|
|
1439
|
+
it("passes with a name and general input attributes", () =>
|
|
1440
|
+
expect(
|
|
1441
|
+
() =>
|
|
1442
|
+
expect(
|
|
1443
|
+
{
|
|
1444
|
+
name: "Field1",
|
|
1445
|
+
type: "TranslationInput",
|
|
1446
|
+
moreLabel: "More",
|
|
1447
|
+
autocomplete: "on",
|
|
1448
|
+
autofocus: true,
|
|
1449
|
+
disabled: true,
|
|
1450
|
+
readOnly: true,
|
|
1451
|
+
required: {
|
|
1452
|
+
id: "test.required",
|
|
1453
|
+
defaultMessage: "Field is Required",
|
|
1454
|
+
},
|
|
1455
|
+
tabindex: 12,
|
|
1456
|
+
},
|
|
1457
|
+
"to be a form field",
|
|
1458
|
+
),
|
|
1459
|
+
"not to throw",
|
|
1460
|
+
));
|
|
1461
|
+
|
|
1462
|
+
it("fails if general input attributes invalid", () =>
|
|
1463
|
+
expect(
|
|
1464
|
+
() =>
|
|
1465
|
+
expect(
|
|
1466
|
+
{
|
|
1467
|
+
name: "Field1",
|
|
1468
|
+
type: "TranslationInput",
|
|
1469
|
+
moreLabel: "More",
|
|
1470
|
+
autocomplete: "on",
|
|
1471
|
+
autofocus: "true",
|
|
1472
|
+
disabled: 0,
|
|
1473
|
+
readOnly: { t: true },
|
|
1474
|
+
required: [],
|
|
1475
|
+
tabindex: "foo",
|
|
1476
|
+
},
|
|
1477
|
+
"to be a form field",
|
|
1478
|
+
),
|
|
1479
|
+
"to throw",
|
|
1480
|
+
"expected\n" +
|
|
1481
|
+
"{\n" +
|
|
1482
|
+
" name: 'Field1', type: 'TranslationInput', moreLabel: 'More',\n" +
|
|
1483
|
+
" autocomplete: 'on', autofocus: 'true', disabled: 0,\n" +
|
|
1484
|
+
" readOnly: { t: true }, required: [], tabindex: 'foo'\n" +
|
|
1485
|
+
"}\n" +
|
|
1486
|
+
"to be a form field\n" +
|
|
1487
|
+
"\n" +
|
|
1488
|
+
"{\n" +
|
|
1489
|
+
" name: 'Field1',\n" +
|
|
1490
|
+
" type: 'TranslationInput',\n" +
|
|
1491
|
+
" moreLabel: 'More',\n" +
|
|
1492
|
+
" autocomplete: 'on',\n" +
|
|
1493
|
+
" autofocus: 'true', // should be a boolean\n" +
|
|
1494
|
+
" disabled: 0, // should be a boolean\n" +
|
|
1495
|
+
" readOnly: { t: true }, // should be a boolean\n" +
|
|
1496
|
+
" required:\n" +
|
|
1497
|
+
" [], // should be a label\n" +
|
|
1498
|
+
" // should satisfy\n" +
|
|
1499
|
+
" // {\n" +
|
|
1500
|
+
" // id: expect.it('to be a string'),\n" +
|
|
1501
|
+
" // defaultMessage: expect.it('to be a string')\n" +
|
|
1502
|
+
" // }\n" +
|
|
1503
|
+
" //\n" +
|
|
1504
|
+
" // [\n" +
|
|
1505
|
+
" // // missing: id: should be a string\n" +
|
|
1506
|
+
" // // missing: defaultMessage: should be a string\n" +
|
|
1507
|
+
" // ]\n" +
|
|
1508
|
+
" tabindex: 'foo' // should be a number\n" +
|
|
1509
|
+
"}",
|
|
1510
|
+
));
|
|
1511
|
+
|
|
1512
|
+
it("passes with a name and text input attributes", () =>
|
|
1513
|
+
expect(
|
|
1514
|
+
() =>
|
|
1515
|
+
expect(
|
|
1516
|
+
{
|
|
1517
|
+
name: "Field1",
|
|
1518
|
+
type: "TranslationInput",
|
|
1519
|
+
moreLabel: "More",
|
|
1520
|
+
maxlength: 15,
|
|
1521
|
+
minlength: 3,
|
|
1522
|
+
pattern: /olo/,
|
|
1523
|
+
placeholder: "Placeholder here",
|
|
1524
|
+
size: 18,
|
|
1525
|
+
spellcheck: "",
|
|
1526
|
+
},
|
|
1527
|
+
"to be a form field",
|
|
1528
|
+
),
|
|
1529
|
+
"not to throw",
|
|
1530
|
+
));
|
|
1531
|
+
|
|
1532
|
+
it("fails if text input attributes invalid", () =>
|
|
1533
|
+
expect(
|
|
1534
|
+
() =>
|
|
1535
|
+
expect(
|
|
1536
|
+
{
|
|
1537
|
+
name: "Field1",
|
|
1538
|
+
type: "TranslationInput",
|
|
1539
|
+
moreLabel: "More",
|
|
1540
|
+
maxlength: 0,
|
|
1541
|
+
minlength: "three",
|
|
1542
|
+
pattern: {},
|
|
1543
|
+
placeholder: ["Placeholder here"],
|
|
1544
|
+
size: -15,
|
|
1545
|
+
spellcheck: null,
|
|
1546
|
+
},
|
|
1547
|
+
"to be a form field",
|
|
1548
|
+
),
|
|
1549
|
+
"to throw",
|
|
1550
|
+
"expected\n" +
|
|
1551
|
+
"{\n" +
|
|
1552
|
+
" name: 'Field1', type: 'TranslationInput', moreLabel: 'More',\n" +
|
|
1553
|
+
" maxlength: 0, minlength: 'three', pattern: {},\n" +
|
|
1554
|
+
" placeholder: [ 'Placeholder here' ], size: -15, spellcheck: null\n" +
|
|
1555
|
+
"}\n" +
|
|
1556
|
+
"to be a form field\n" +
|
|
1557
|
+
"\n" +
|
|
1558
|
+
"{\n" +
|
|
1559
|
+
" name: 'Field1',\n" +
|
|
1560
|
+
" type: 'TranslationInput',\n" +
|
|
1561
|
+
" moreLabel: 'More',\n" +
|
|
1562
|
+
" maxlength:\n" +
|
|
1563
|
+
" 0, // ✓ should be a number and\n" +
|
|
1564
|
+
" // ⨯ should be greater than 0\n" +
|
|
1565
|
+
" minlength:\n" +
|
|
1566
|
+
" 'three', // ⨯ should be a number and\n" +
|
|
1567
|
+
" // ⨯ should be greater than 0\n" +
|
|
1568
|
+
" pattern: {}, // should be a regular expression\n" +
|
|
1569
|
+
" placeholder:\n" +
|
|
1570
|
+
" [ 'Placeholder here' ], // should be a label\n" +
|
|
1571
|
+
" // should satisfy\n" +
|
|
1572
|
+
" // {\n" +
|
|
1573
|
+
" // id: expect.it('to be a string'),\n" +
|
|
1574
|
+
" // defaultMessage: expect.it('to be a string')\n" +
|
|
1575
|
+
" // }\n" +
|
|
1576
|
+
" //\n" +
|
|
1577
|
+
" // [\n" +
|
|
1578
|
+
" // 'Placeholder here'\n" +
|
|
1579
|
+
" // // missing: id: should be a string\n" +
|
|
1580
|
+
" // // missing: defaultMessage: should be a string\n" +
|
|
1581
|
+
" // ]\n" +
|
|
1582
|
+
" size: -15, // ✓ should be a number and\n" +
|
|
1583
|
+
" // ⨯ should be greater than 0\n" +
|
|
1584
|
+
" spellcheck:\n" +
|
|
1585
|
+
" null // ⨯ should be a boolean or\n" +
|
|
1586
|
+
" // ⨯ should be ''\n" +
|
|
1587
|
+
"}",
|
|
1588
|
+
));
|
|
1589
|
+
});
|
|
1590
|
+
});
|
|
1591
|
+
|
|
1592
|
+
describe("<object> to be a form combination field", () => {
|
|
1593
|
+
it("passes with a array of fields", () =>
|
|
1594
|
+
expect(
|
|
1595
|
+
() =>
|
|
1596
|
+
expect(
|
|
1597
|
+
{
|
|
1598
|
+
type: "Combination",
|
|
1599
|
+
fields: [
|
|
1600
|
+
{
|
|
1601
|
+
name: "labelA",
|
|
1602
|
+
type: "LineLabel",
|
|
1603
|
+
},
|
|
1604
|
+
{
|
|
1605
|
+
name: "fieldA",
|
|
1606
|
+
type: "TextInput",
|
|
1607
|
+
},
|
|
1608
|
+
],
|
|
1609
|
+
},
|
|
1610
|
+
"to be a form combination field",
|
|
1611
|
+
),
|
|
1612
|
+
"not to throw",
|
|
1613
|
+
));
|
|
1614
|
+
|
|
1615
|
+
it("fails if missing type", () =>
|
|
1616
|
+
expect(
|
|
1617
|
+
() =>
|
|
1618
|
+
expect(
|
|
1619
|
+
{
|
|
1620
|
+
fields: [
|
|
1621
|
+
{
|
|
1622
|
+
name: "labelA",
|
|
1623
|
+
type: "LineLabel",
|
|
1624
|
+
},
|
|
1625
|
+
{
|
|
1626
|
+
name: "fieldA",
|
|
1627
|
+
type: "TextInput",
|
|
1628
|
+
},
|
|
1629
|
+
],
|
|
1630
|
+
},
|
|
1631
|
+
"to be a form combination field",
|
|
1632
|
+
),
|
|
1633
|
+
"to throw",
|
|
1634
|
+
"expected\n" +
|
|
1635
|
+
"{\n" +
|
|
1636
|
+
" fields: [\n" +
|
|
1637
|
+
" { name: 'labelA', type: 'LineLabel' },\n" +
|
|
1638
|
+
" { name: 'fieldA', type: 'TextInput' }\n" +
|
|
1639
|
+
" ]\n" +
|
|
1640
|
+
"}\n" +
|
|
1641
|
+
"to be a form combination field",
|
|
1642
|
+
));
|
|
1643
|
+
|
|
1644
|
+
it("fails if field array missing", () =>
|
|
1645
|
+
expect(
|
|
1646
|
+
() => expect({ type: "Combination" }, "to be a form combination field"),
|
|
1647
|
+
"to throw",
|
|
1648
|
+
"expected { type: 'Combination' } to be a form combination field\n" +
|
|
1649
|
+
"\n" +
|
|
1650
|
+
"{\n" +
|
|
1651
|
+
" type: 'Combination'\n" +
|
|
1652
|
+
" // missing: fields: ⨯ should be an array and\n" +
|
|
1653
|
+
" ⨯ should have items satisfying 'to be a form field'\n" +
|
|
1654
|
+
"}",
|
|
1655
|
+
));
|
|
1656
|
+
|
|
1657
|
+
it("fails if field array empty", () =>
|
|
1658
|
+
expect(
|
|
1659
|
+
() => expect({ type: "Combination", fields: [] }, "to be a form combination field"),
|
|
1660
|
+
"to throw",
|
|
1661
|
+
"expected { type: 'Combination', fields: [] } to be a form combination field\n" +
|
|
1662
|
+
"\n" +
|
|
1663
|
+
"{\n" +
|
|
1664
|
+
" type: 'Combination',\n" +
|
|
1665
|
+
" fields:\n" +
|
|
1666
|
+
" [] // ✓ should be an array and\n" +
|
|
1667
|
+
" // ⨯ should have items satisfying to be a form field\n" +
|
|
1668
|
+
" // should not be empty\n" +
|
|
1669
|
+
"}",
|
|
1670
|
+
));
|
|
1671
|
+
|
|
1672
|
+
it("passes with equal-length arrays of fields and proportions", () =>
|
|
1673
|
+
expect(
|
|
1674
|
+
() =>
|
|
1675
|
+
expect(
|
|
1676
|
+
{
|
|
1677
|
+
type: "Combination",
|
|
1678
|
+
fields: [
|
|
1679
|
+
{
|
|
1680
|
+
name: "labelA",
|
|
1681
|
+
type: "LineLabel",
|
|
1682
|
+
},
|
|
1683
|
+
{
|
|
1684
|
+
name: "fieldA",
|
|
1685
|
+
type: "TextInput",
|
|
1686
|
+
},
|
|
1687
|
+
],
|
|
1688
|
+
proportions: ["50px", 90],
|
|
1689
|
+
},
|
|
1690
|
+
"to be a form combination field",
|
|
1691
|
+
),
|
|
1692
|
+
"not to throw",
|
|
1693
|
+
));
|
|
1694
|
+
|
|
1695
|
+
it("passes if proportions shorter than fields", () =>
|
|
1696
|
+
expect(
|
|
1697
|
+
() =>
|
|
1698
|
+
expect(
|
|
1699
|
+
{
|
|
1700
|
+
type: "Combination",
|
|
1701
|
+
fields: [
|
|
1702
|
+
{
|
|
1703
|
+
name: "labelA",
|
|
1704
|
+
type: "LineLabel",
|
|
1705
|
+
},
|
|
1706
|
+
{
|
|
1707
|
+
name: "fieldA",
|
|
1708
|
+
type: "TextInput",
|
|
1709
|
+
},
|
|
1710
|
+
],
|
|
1711
|
+
proportions: ["50px"],
|
|
1712
|
+
},
|
|
1713
|
+
"to be a form combination field",
|
|
1714
|
+
),
|
|
1715
|
+
"not to throw",
|
|
1716
|
+
));
|
|
1717
|
+
|
|
1718
|
+
it("fails if proportions longer than fields", () =>
|
|
1719
|
+
expect(
|
|
1720
|
+
() =>
|
|
1721
|
+
expect(
|
|
1722
|
+
{
|
|
1723
|
+
type: "Combination",
|
|
1724
|
+
fields: [
|
|
1725
|
+
{
|
|
1726
|
+
name: "labelA",
|
|
1727
|
+
type: "LineLabel",
|
|
1728
|
+
},
|
|
1729
|
+
{
|
|
1730
|
+
name: "fieldA",
|
|
1731
|
+
type: "TextInput",
|
|
1732
|
+
},
|
|
1733
|
+
],
|
|
1734
|
+
proportions: ["50px", 90, 10],
|
|
1735
|
+
},
|
|
1736
|
+
"to be a form combination field",
|
|
1737
|
+
),
|
|
1738
|
+
"to throw",
|
|
1739
|
+
"expected\n" +
|
|
1740
|
+
"{\n" +
|
|
1741
|
+
" type: 'Combination',\n" +
|
|
1742
|
+
" fields: [\n" +
|
|
1743
|
+
" { name: 'labelA', type: 'LineLabel' },\n" +
|
|
1744
|
+
" { name: 'fieldA', type: 'TextInput' }\n" +
|
|
1745
|
+
" ],\n" +
|
|
1746
|
+
" proportions: [ '50px', 90, 10 ]\n" +
|
|
1747
|
+
"}\n" +
|
|
1748
|
+
"to be a form combination field\n" +
|
|
1749
|
+
"\n" +
|
|
1750
|
+
"{\n" +
|
|
1751
|
+
" type: 'Combination',\n" +
|
|
1752
|
+
" fields: [\n" +
|
|
1753
|
+
" { name: 'labelA', type: 'LineLabel' },\n" +
|
|
1754
|
+
" { name: 'fieldA', type: 'TextInput' }\n" +
|
|
1755
|
+
" ],\n" +
|
|
1756
|
+
" proportions:\n" +
|
|
1757
|
+
" [ '50px', 90, 10 ] // ✓ should be an array and\n" +
|
|
1758
|
+
" // ✓ should have items satisfying and\n" +
|
|
1759
|
+
" // expect.it('to be a string')\n" +
|
|
1760
|
+
" // .or('to be a number')\n" +
|
|
1761
|
+
" // ⨯ should be shorter than or same length as\n" +
|
|
1762
|
+
" // [\n" +
|
|
1763
|
+
" // { name: 'labelA', type: 'LineLabel' },\n" +
|
|
1764
|
+
" // { name: 'fieldA', type: 'TextInput' }\n" +
|
|
1765
|
+
" // ]\n" +
|
|
1766
|
+
"}",
|
|
1767
|
+
));
|
|
1768
|
+
|
|
1769
|
+
it("fails if proportion contents not string or number", () =>
|
|
1770
|
+
expect(
|
|
1771
|
+
() =>
|
|
1772
|
+
expect(
|
|
1773
|
+
{
|
|
1774
|
+
type: "Combination",
|
|
1775
|
+
fields: [
|
|
1776
|
+
{
|
|
1777
|
+
name: "label",
|
|
1778
|
+
type: "LineLabel",
|
|
1779
|
+
},
|
|
1780
|
+
{
|
|
1781
|
+
name: "fieldA",
|
|
1782
|
+
type: "TextInput",
|
|
1783
|
+
},
|
|
1784
|
+
{
|
|
1785
|
+
name: "fieldB",
|
|
1786
|
+
type: "TextInput",
|
|
1787
|
+
},
|
|
1788
|
+
{
|
|
1789
|
+
name: "fieldC",
|
|
1790
|
+
type: "TextInput",
|
|
1791
|
+
},
|
|
1792
|
+
],
|
|
1793
|
+
proportions: [null, {}, [90], true],
|
|
1794
|
+
},
|
|
1795
|
+
"to be a form combination field",
|
|
1796
|
+
),
|
|
1797
|
+
"to throw",
|
|
1798
|
+
"expected\n" +
|
|
1799
|
+
"{\n" +
|
|
1800
|
+
" type: 'Combination',\n" +
|
|
1801
|
+
" fields: [\n" +
|
|
1802
|
+
" { name: 'label', type: 'LineLabel' },\n" +
|
|
1803
|
+
" { name: 'fieldA', type: 'TextInput' },\n" +
|
|
1804
|
+
" { name: 'fieldB', type: 'TextInput' },\n" +
|
|
1805
|
+
" { name: 'fieldC', type: 'TextInput' }\n" +
|
|
1806
|
+
" ],\n" +
|
|
1807
|
+
" proportions: [ null, {}, [ 90 ], true ]\n" +
|
|
1808
|
+
"}\n" +
|
|
1809
|
+
"to be a form combination field\n" +
|
|
1810
|
+
"\n" +
|
|
1811
|
+
"{\n" +
|
|
1812
|
+
" type: 'Combination',\n" +
|
|
1813
|
+
" fields: [\n" +
|
|
1814
|
+
" { name: 'label', type: 'LineLabel' },\n" +
|
|
1815
|
+
" { name: 'fieldA', type: 'TextInput' },\n" +
|
|
1816
|
+
" { name: 'fieldB', type: 'TextInput' },\n" +
|
|
1817
|
+
" { name: 'fieldC', type: 'TextInput' }\n" +
|
|
1818
|
+
" ],\n" +
|
|
1819
|
+
" proportions:\n" +
|
|
1820
|
+
" [ null, {}, [ 90 ], true ] // ✓ should be an array and\n" +
|
|
1821
|
+
" // ⨯ should have items satisfying and\n" +
|
|
1822
|
+
" // expect.it('to be a string')\n" +
|
|
1823
|
+
" // .or('to be a number')\n" +
|
|
1824
|
+
" //\n" +
|
|
1825
|
+
" // [\n" +
|
|
1826
|
+
" // null, // ⨯ should be a string or\n" +
|
|
1827
|
+
" // // ⨯ should be a number\n" +
|
|
1828
|
+
" // {}, // ⨯ should be a string or\n" +
|
|
1829
|
+
" // // ⨯ should be a number\n" +
|
|
1830
|
+
" // [ 90 ], // ⨯ should be a string or\n" +
|
|
1831
|
+
" // // ⨯ should be a number\n" +
|
|
1832
|
+
" // true // ⨯ should be a string or\n" +
|
|
1833
|
+
" // // ⨯ should be a number\n" +
|
|
1834
|
+
" // ]\n" +
|
|
1835
|
+
" // ✓ should be shorter than or same length as\n" +
|
|
1836
|
+
" // [\n" +
|
|
1837
|
+
" // { name: 'label', type: 'LineLabel' },\n" +
|
|
1838
|
+
" // { name: 'fieldA', type: 'TextInput' },\n" +
|
|
1839
|
+
" // { name: 'fieldB', type: 'TextInput' },\n" +
|
|
1840
|
+
" // { name: 'fieldC', type: 'TextInput' }\n" +
|
|
1841
|
+
" // ]\n" +
|
|
1842
|
+
"}",
|
|
1843
|
+
));
|
|
1844
|
+
});
|
|
1845
|
+
|
|
1846
|
+
describe("<object> to be a form list", () => {
|
|
1847
|
+
it("passes with a name and single field definition", () =>
|
|
1848
|
+
expect(
|
|
1849
|
+
() =>
|
|
1850
|
+
expect(
|
|
1851
|
+
{
|
|
1852
|
+
type: "List",
|
|
1853
|
+
name: "ListA",
|
|
1854
|
+
rowField: {
|
|
1855
|
+
name: "fieldA",
|
|
1856
|
+
type: "TextInput",
|
|
1857
|
+
},
|
|
1858
|
+
},
|
|
1859
|
+
"to be a form list",
|
|
1860
|
+
),
|
|
1861
|
+
"not to throw",
|
|
1862
|
+
));
|
|
1863
|
+
|
|
1864
|
+
it("passes with a name and combination field definition", () =>
|
|
1865
|
+
expect(
|
|
1866
|
+
() =>
|
|
1867
|
+
expect(
|
|
1868
|
+
{
|
|
1869
|
+
type: "List",
|
|
1870
|
+
name: "ListA",
|
|
1871
|
+
rowField: {
|
|
1872
|
+
type: "Combination",
|
|
1873
|
+
fields: [
|
|
1874
|
+
{
|
|
1875
|
+
name: "labelA",
|
|
1876
|
+
type: "LineLabel",
|
|
1877
|
+
},
|
|
1878
|
+
{
|
|
1879
|
+
name: "fieldA",
|
|
1880
|
+
type: "TextInput",
|
|
1881
|
+
},
|
|
1882
|
+
],
|
|
1883
|
+
},
|
|
1884
|
+
},
|
|
1885
|
+
"to be a form list",
|
|
1886
|
+
),
|
|
1887
|
+
"not to throw",
|
|
1888
|
+
));
|
|
1889
|
+
|
|
1890
|
+
it("passes with a name, rowCount and field definition", () =>
|
|
1891
|
+
expect(
|
|
1892
|
+
() =>
|
|
1893
|
+
expect(
|
|
1894
|
+
{
|
|
1895
|
+
type: "List",
|
|
1896
|
+
name: "ListA",
|
|
1897
|
+
rowCount: 1,
|
|
1898
|
+
rowField: {
|
|
1899
|
+
name: "fieldA",
|
|
1900
|
+
type: "TextInput",
|
|
1901
|
+
},
|
|
1902
|
+
},
|
|
1903
|
+
"to be a form list",
|
|
1904
|
+
),
|
|
1905
|
+
"not to throw",
|
|
1906
|
+
));
|
|
1907
|
+
|
|
1908
|
+
it("fails if rowCount not numeric", () =>
|
|
1909
|
+
expect(
|
|
1910
|
+
() =>
|
|
1911
|
+
expect(
|
|
1912
|
+
{
|
|
1913
|
+
type: "List",
|
|
1914
|
+
name: "ListA",
|
|
1915
|
+
rowCount: "1",
|
|
1916
|
+
rowField: {
|
|
1917
|
+
name: "fieldA",
|
|
1918
|
+
type: "TextInput",
|
|
1919
|
+
},
|
|
1920
|
+
},
|
|
1921
|
+
"to be a form list",
|
|
1922
|
+
),
|
|
1923
|
+
"to throw",
|
|
1924
|
+
"expected\n" +
|
|
1925
|
+
"{\n" +
|
|
1926
|
+
" type: 'List',\n" +
|
|
1927
|
+
" name: 'ListA',\n" +
|
|
1928
|
+
" rowCount: '1',\n" +
|
|
1929
|
+
" rowField: { name: 'fieldA', type: 'TextInput' }\n" +
|
|
1930
|
+
"}\n" +
|
|
1931
|
+
"to be a form list\n" +
|
|
1932
|
+
"\n" +
|
|
1933
|
+
"{\n" +
|
|
1934
|
+
" type: 'List',\n" +
|
|
1935
|
+
" name: 'ListA',\n" +
|
|
1936
|
+
" rowCount: '1', // should be a number\n" +
|
|
1937
|
+
" rowField: { name: 'fieldA', type: 'TextInput' }\n" +
|
|
1938
|
+
"}",
|
|
1939
|
+
));
|
|
1940
|
+
|
|
1941
|
+
it("passes with a name, rowCount, static values and field definition", () =>
|
|
1942
|
+
expect(
|
|
1943
|
+
() =>
|
|
1944
|
+
expect(
|
|
1945
|
+
{
|
|
1946
|
+
type: "List",
|
|
1947
|
+
name: "ListA",
|
|
1948
|
+
rowCount: 1,
|
|
1949
|
+
staticValues: ["Foo"],
|
|
1950
|
+
rowField: {
|
|
1951
|
+
name: "fieldA",
|
|
1952
|
+
type: "TextInput",
|
|
1953
|
+
},
|
|
1954
|
+
},
|
|
1955
|
+
"to be a form list",
|
|
1956
|
+
),
|
|
1957
|
+
"not to throw",
|
|
1958
|
+
));
|
|
1959
|
+
|
|
1960
|
+
it("fails with static values but no row count", () =>
|
|
1961
|
+
expect(
|
|
1962
|
+
() =>
|
|
1963
|
+
expect(
|
|
1964
|
+
{
|
|
1965
|
+
type: "List",
|
|
1966
|
+
name: "ListA",
|
|
1967
|
+
staticValues: ["Foo"],
|
|
1968
|
+
rowField: {
|
|
1969
|
+
name: "fieldA",
|
|
1970
|
+
type: "TextInput",
|
|
1971
|
+
},
|
|
1972
|
+
},
|
|
1973
|
+
"to be a form list",
|
|
1974
|
+
),
|
|
1975
|
+
"to throw",
|
|
1976
|
+
"expected\n" +
|
|
1977
|
+
"{\n" +
|
|
1978
|
+
" type: 'List',\n" +
|
|
1979
|
+
" name: 'ListA',\n" +
|
|
1980
|
+
" staticValues: [ 'Foo' ],\n" +
|
|
1981
|
+
" rowField: { name: 'fieldA', type: 'TextInput' }\n" +
|
|
1982
|
+
"}\n" +
|
|
1983
|
+
"to be a form list\n" +
|
|
1984
|
+
" Form list without row count cannot have static values",
|
|
1985
|
+
));
|
|
1986
|
+
|
|
1987
|
+
it("passes with a name, single field definition and string add button label", () =>
|
|
1988
|
+
expect(
|
|
1989
|
+
() =>
|
|
1990
|
+
expect(
|
|
1991
|
+
{
|
|
1992
|
+
type: "List",
|
|
1993
|
+
name: "ListA",
|
|
1994
|
+
rowField: {
|
|
1995
|
+
name: "fieldA",
|
|
1996
|
+
type: "TextInput",
|
|
1997
|
+
},
|
|
1998
|
+
add: "Add Thing",
|
|
1999
|
+
},
|
|
2000
|
+
"to be a form list",
|
|
2001
|
+
),
|
|
2002
|
+
"not to throw",
|
|
2003
|
+
));
|
|
2004
|
+
|
|
2005
|
+
it("passes with a name, single field definition and object add button label", () =>
|
|
2006
|
+
expect(
|
|
2007
|
+
() =>
|
|
2008
|
+
expect(
|
|
2009
|
+
{
|
|
2010
|
+
type: "List",
|
|
2011
|
+
name: "ListA",
|
|
2012
|
+
rowField: {
|
|
2013
|
+
name: "fieldA",
|
|
2014
|
+
type: "TextInput",
|
|
2015
|
+
},
|
|
2016
|
+
add: { id: "test.add", defaultMessage: "Add Thing" },
|
|
2017
|
+
},
|
|
2018
|
+
"to be a form list",
|
|
2019
|
+
),
|
|
2020
|
+
"not to throw",
|
|
2021
|
+
));
|
|
2022
|
+
|
|
2023
|
+
it("fails with row count and add button text", () =>
|
|
2024
|
+
expect(
|
|
2025
|
+
() =>
|
|
2026
|
+
expect(
|
|
2027
|
+
{
|
|
2028
|
+
type: "List",
|
|
2029
|
+
name: "ListA",
|
|
2030
|
+
rowCount: 2,
|
|
2031
|
+
rowField: {
|
|
2032
|
+
name: "fieldA",
|
|
2033
|
+
type: "TextInput",
|
|
2034
|
+
},
|
|
2035
|
+
add: "Add Thing",
|
|
2036
|
+
},
|
|
2037
|
+
"to be a form list",
|
|
2038
|
+
),
|
|
2039
|
+
"to throw",
|
|
2040
|
+
"expected\n" +
|
|
2041
|
+
"{\n" +
|
|
2042
|
+
" type: 'List',\n" +
|
|
2043
|
+
" name: 'ListA',\n" +
|
|
2044
|
+
" rowCount: 2,\n" +
|
|
2045
|
+
" rowField: { name: 'fieldA', type: 'TextInput' },\n" +
|
|
2046
|
+
" add: 'Add Thing'\n" +
|
|
2047
|
+
"}\n" +
|
|
2048
|
+
"to be a form list\n" +
|
|
2049
|
+
" Form list with row count cannot have 'add' label",
|
|
2050
|
+
));
|
|
2051
|
+
});
|
|
2052
|
+
|
|
2053
|
+
describe("<object> to be a form fieldset", () => {
|
|
2054
|
+
it("passes with a string label and fields array", () =>
|
|
2055
|
+
expect(
|
|
2056
|
+
() =>
|
|
2057
|
+
expect(
|
|
2058
|
+
{
|
|
2059
|
+
type: "Fieldset",
|
|
2060
|
+
label: "A field set",
|
|
2061
|
+
fields: [
|
|
2062
|
+
{ name: "field1", type: "CheckboxInput" },
|
|
2063
|
+
{
|
|
2064
|
+
type: "Combination",
|
|
2065
|
+
fields: [
|
|
2066
|
+
{
|
|
2067
|
+
name: "labelA",
|
|
2068
|
+
type: "LineLabel",
|
|
2069
|
+
},
|
|
2070
|
+
{
|
|
2071
|
+
name: "fieldA",
|
|
2072
|
+
type: "TextInput",
|
|
2073
|
+
},
|
|
2074
|
+
],
|
|
2075
|
+
},
|
|
2076
|
+
{
|
|
2077
|
+
type: "List",
|
|
2078
|
+
name: "ListA",
|
|
2079
|
+
rowField: {
|
|
2080
|
+
name: "fieldA",
|
|
2081
|
+
type: "TextInput",
|
|
2082
|
+
},
|
|
2083
|
+
},
|
|
2084
|
+
],
|
|
2085
|
+
},
|
|
2086
|
+
"to be a form fieldset",
|
|
2087
|
+
),
|
|
2088
|
+
"not to throw",
|
|
2089
|
+
));
|
|
2090
|
+
|
|
2091
|
+
it("fails if missing label or fields", () =>
|
|
2092
|
+
expect(
|
|
2093
|
+
() =>
|
|
2094
|
+
expect(
|
|
2095
|
+
{
|
|
2096
|
+
type: "Fieldset",
|
|
2097
|
+
},
|
|
2098
|
+
"to be a form fieldset",
|
|
2099
|
+
),
|
|
2100
|
+
"to throw",
|
|
2101
|
+
"expected { type: 'Fieldset' } to be a form fieldset\n" +
|
|
2102
|
+
"\n" +
|
|
2103
|
+
"{\n" +
|
|
2104
|
+
" type: 'Fieldset'\n" +
|
|
2105
|
+
" // missing: label: should be a label\n" +
|
|
2106
|
+
" should be a string\n" +
|
|
2107
|
+
" // missing: fields: ⨯ should be an array and\n" +
|
|
2108
|
+
" ⨯ should have items satisfying\n" +
|
|
2109
|
+
" expect.it('to be a form field')\n" +
|
|
2110
|
+
" .or('to be a form combination field')\n" +
|
|
2111
|
+
" .or('to be a form list')\n" +
|
|
2112
|
+
"}",
|
|
2113
|
+
));
|
|
2114
|
+
|
|
2115
|
+
it("fails if fields malformed", () =>
|
|
2116
|
+
expect(
|
|
2117
|
+
() =>
|
|
2118
|
+
expect(
|
|
2119
|
+
{
|
|
2120
|
+
type: "Fieldset",
|
|
2121
|
+
label: "A field set",
|
|
2122
|
+
fields: [
|
|
2123
|
+
{ name: "field1", type: "ChockboxInput" },
|
|
2124
|
+
{
|
|
2125
|
+
type: "Combination",
|
|
2126
|
+
proportions: [30, 50, 30],
|
|
2127
|
+
fields: [
|
|
2128
|
+
{
|
|
2129
|
+
name: "labelA",
|
|
2130
|
+
type: "LineLabel",
|
|
2131
|
+
},
|
|
2132
|
+
{
|
|
2133
|
+
name: "fieldA",
|
|
2134
|
+
type: "TextInput",
|
|
2135
|
+
},
|
|
2136
|
+
],
|
|
2137
|
+
},
|
|
2138
|
+
{
|
|
2139
|
+
type: "List",
|
|
2140
|
+
name: "ListA",
|
|
2141
|
+
rowField: {
|
|
2142
|
+
name: "fieldA",
|
|
2143
|
+
type: "TextInput",
|
|
2144
|
+
},
|
|
2145
|
+
add: "Foo",
|
|
2146
|
+
rowCount: 13,
|
|
2147
|
+
},
|
|
2148
|
+
],
|
|
2149
|
+
},
|
|
2150
|
+
"to be a form fieldset",
|
|
2151
|
+
),
|
|
2152
|
+
"to throw",
|
|
2153
|
+
"expected\n" +
|
|
2154
|
+
"{\n" +
|
|
2155
|
+
" type: 'Fieldset',\n" +
|
|
2156
|
+
" label: 'A field set',\n" +
|
|
2157
|
+
" fields: [\n" +
|
|
2158
|
+
" { name: 'field1', type: 'ChockboxInput' },\n" +
|
|
2159
|
+
" { type: 'Combination', proportions: ..., fields: ... },\n" +
|
|
2160
|
+
" { type: 'List', name: 'ListA', rowField: ..., add: 'Foo', rowCount: 13 }\n" +
|
|
2161
|
+
" ]\n" +
|
|
2162
|
+
"}\n" +
|
|
2163
|
+
"to be a form fieldset\n" +
|
|
2164
|
+
"\n" +
|
|
2165
|
+
"{\n" +
|
|
2166
|
+
" type: 'Fieldset',\n" +
|
|
2167
|
+
" label: 'A field set',\n" +
|
|
2168
|
+
" fields:\n" +
|
|
2169
|
+
" [\n" +
|
|
2170
|
+
" { name: 'field1', type: 'ChockboxInput' },\n" +
|
|
2171
|
+
" { type: 'Combination', proportions: ..., fields: ... },\n" +
|
|
2172
|
+
" { type: 'List', name: 'ListA', rowField: ..., add: 'Foo', rowCount: 13 }\n" +
|
|
2173
|
+
" ]\n" +
|
|
2174
|
+
" // ✓ should be an array and\n" +
|
|
2175
|
+
" // ⨯ should have items satisfying\n" +
|
|
2176
|
+
" // expect.it('to be a form field')\n" +
|
|
2177
|
+
" // .or('to be a form combination field')\n" +
|
|
2178
|
+
" // .or('to be a form list')\n" +
|
|
2179
|
+
" //\n" +
|
|
2180
|
+
" // [\n" +
|
|
2181
|
+
" // { name: 'field1', type: 'ChockboxInput' },\n" +
|
|
2182
|
+
" // // ⨯ should be a form field or\n" +
|
|
2183
|
+
" // // Invalid type 'ChockboxInput'\n" +
|
|
2184
|
+
" // // ⨯ should be a form combination field or\n" +
|
|
2185
|
+
" // // ⨯ should be a form list\n" +
|
|
2186
|
+
" // { type: 'Combination', proportions: [ 30, 50, 30 ], fields: [ ..., ... ] },\n" +
|
|
2187
|
+
" // // ⨯ should be a form field or\n" +
|
|
2188
|
+
" // // ⨯ should be a form combination field or\n" +
|
|
2189
|
+
" // //\n" +
|
|
2190
|
+
" // // {\n" +
|
|
2191
|
+
" // // type: 'Combination',\n" +
|
|
2192
|
+
" // // proportions:\n" +
|
|
2193
|
+
" // // [ 30, 50, 30 ], // ✓ should be an array and\n" +
|
|
2194
|
+
" // // // ✓ should have items satisfying and\n" +
|
|
2195
|
+
" // // // expect.it('to be a string')\n" +
|
|
2196
|
+
" // // // .or('to be a number')\n" +
|
|
2197
|
+
" // // // ⨯ should be shorter than or same length as\n" +
|
|
2198
|
+
" // // // [\n" +
|
|
2199
|
+
" // // // { name: 'labelA', type: 'LineLabel' },\n" +
|
|
2200
|
+
" // // // { name: 'fieldA', type: 'TextInput' }\n" +
|
|
2201
|
+
" // // // ]\n" +
|
|
2202
|
+
" // // fields: [\n" +
|
|
2203
|
+
" // // { name: 'labelA', type: 'LineLabel' },\n" +
|
|
2204
|
+
" // // { name: 'fieldA', type: 'TextInput' }\n" +
|
|
2205
|
+
" // // ]\n" +
|
|
2206
|
+
" // // }\n" +
|
|
2207
|
+
" // // ⨯ should be a form list\n" +
|
|
2208
|
+
" // {\n" +
|
|
2209
|
+
" // type: 'List',\n" +
|
|
2210
|
+
" // name: 'ListA',\n" +
|
|
2211
|
+
" // rowField: { name: 'fieldA', type: 'TextInput' },\n" +
|
|
2212
|
+
" // add: 'Foo',\n" +
|
|
2213
|
+
" // rowCount: 13\n" +
|
|
2214
|
+
" // }\n" +
|
|
2215
|
+
" // // ⨯ should be a form field or\n" +
|
|
2216
|
+
" // // ⨯ should be a form combination field or\n" +
|
|
2217
|
+
" // // ⨯ should be a form list\n" +
|
|
2218
|
+
" // // Form list with row count cannot have 'add' label\n" +
|
|
2219
|
+
" // ]\n" +
|
|
2220
|
+
"}",
|
|
2221
|
+
));
|
|
2222
|
+
});
|
|
2223
|
+
|
|
2224
|
+
it("passes if field definition is valid", () =>
|
|
2225
|
+
expect(
|
|
2226
|
+
() =>
|
|
2227
|
+
expect(
|
|
2228
|
+
[
|
|
2229
|
+
{ name: "field1", type: "CheckboxInput" },
|
|
2230
|
+
{
|
|
2231
|
+
type: "Combination",
|
|
2232
|
+
fields: [
|
|
2233
|
+
{
|
|
2234
|
+
name: "labelA",
|
|
2235
|
+
type: "LineLabel",
|
|
2236
|
+
},
|
|
2237
|
+
{
|
|
2238
|
+
name: "fieldA",
|
|
2239
|
+
type: "TextInput",
|
|
2240
|
+
},
|
|
2241
|
+
],
|
|
2242
|
+
},
|
|
2243
|
+
{
|
|
2244
|
+
type: "List",
|
|
2245
|
+
name: "ListA",
|
|
2246
|
+
rowField: {
|
|
2247
|
+
name: "fieldB",
|
|
2248
|
+
type: "TextInput",
|
|
2249
|
+
},
|
|
2250
|
+
},
|
|
2251
|
+
{
|
|
2252
|
+
type: "Fieldset",
|
|
2253
|
+
label: "A field set",
|
|
2254
|
+
fields: [
|
|
2255
|
+
{ name: "field2", type: "CheckboxInput" },
|
|
2256
|
+
{
|
|
2257
|
+
type: "Combination",
|
|
2258
|
+
fields: [
|
|
2259
|
+
{
|
|
2260
|
+
name: "labelC",
|
|
2261
|
+
type: "LineLabel",
|
|
2262
|
+
},
|
|
2263
|
+
{
|
|
2264
|
+
name: "fieldC",
|
|
2265
|
+
type: "TextInput",
|
|
2266
|
+
},
|
|
2267
|
+
],
|
|
2268
|
+
},
|
|
2269
|
+
{
|
|
2270
|
+
type: "List",
|
|
2271
|
+
name: "ListB",
|
|
2272
|
+
rowField: {
|
|
2273
|
+
name: "fieldD",
|
|
2274
|
+
type: "TextInput",
|
|
2275
|
+
},
|
|
2276
|
+
},
|
|
2277
|
+
],
|
|
2278
|
+
},
|
|
2279
|
+
],
|
|
2280
|
+
"to be a form definition",
|
|
2281
|
+
),
|
|
2282
|
+
"not to throw",
|
|
2283
|
+
));
|
|
2284
|
+
|
|
2285
|
+
it("fails if field definition is valid", () =>
|
|
2286
|
+
expect(
|
|
2287
|
+
() =>
|
|
2288
|
+
expect(
|
|
2289
|
+
[
|
|
2290
|
+
{ type: "CheckboxInput" },
|
|
2291
|
+
{
|
|
2292
|
+
type: "Combination",
|
|
2293
|
+
fields: [],
|
|
2294
|
+
},
|
|
2295
|
+
{
|
|
2296
|
+
type: "List",
|
|
2297
|
+
name: "ListA",
|
|
2298
|
+
rowField: {
|
|
2299
|
+
name: "fieldB",
|
|
2300
|
+
},
|
|
2301
|
+
},
|
|
2302
|
+
{
|
|
2303
|
+
type: "Fieldset",
|
|
2304
|
+
fields: [
|
|
2305
|
+
{ name: "field2", type: "CheckboxInput" },
|
|
2306
|
+
{
|
|
2307
|
+
type: "Combination",
|
|
2308
|
+
fields: [
|
|
2309
|
+
{
|
|
2310
|
+
name: "labelC",
|
|
2311
|
+
type: "LineLabel",
|
|
2312
|
+
},
|
|
2313
|
+
{
|
|
2314
|
+
name: "fieldC",
|
|
2315
|
+
type: "TextInput",
|
|
2316
|
+
},
|
|
2317
|
+
],
|
|
2318
|
+
},
|
|
2319
|
+
{
|
|
2320
|
+
type: "List",
|
|
2321
|
+
name: "ListB",
|
|
2322
|
+
rowField: {
|
|
2323
|
+
name: "fieldD",
|
|
2324
|
+
type: "TextInput",
|
|
2325
|
+
},
|
|
2326
|
+
},
|
|
2327
|
+
],
|
|
2328
|
+
},
|
|
2329
|
+
],
|
|
2330
|
+
"to be a form definition",
|
|
2331
|
+
),
|
|
2332
|
+
"to throw",
|
|
2333
|
+
"expected\n" +
|
|
2334
|
+
"[\n" +
|
|
2335
|
+
" { type: 'CheckboxInput' },\n" +
|
|
2336
|
+
" { type: 'Combination', fields: [] },\n" +
|
|
2337
|
+
" { type: 'List', name: 'ListA', rowField: { name: 'fieldB' } },\n" +
|
|
2338
|
+
" { type: 'Fieldset', fields: [ ..., ..., ... ] }\n" +
|
|
2339
|
+
"]\n" +
|
|
2340
|
+
"to be a form definition\n" +
|
|
2341
|
+
"\n" +
|
|
2342
|
+
"[\n" +
|
|
2343
|
+
" { type: 'CheckboxInput' }, // ⨯ should be a form field or\n" +
|
|
2344
|
+
" //\n" +
|
|
2345
|
+
" // {\n" +
|
|
2346
|
+
" // type: 'CheckboxInput'\n" +
|
|
2347
|
+
" // // missing: name: should be a string\n" +
|
|
2348
|
+
" // }\n" +
|
|
2349
|
+
" // ⨯ should be a form combination field or\n" +
|
|
2350
|
+
" // ⨯ should be a form list or\n" +
|
|
2351
|
+
" // ⨯ should be a form fieldset\n" +
|
|
2352
|
+
" { type: 'Combination', fields: [] },\n" +
|
|
2353
|
+
" // ⨯ should be a form field or\n" +
|
|
2354
|
+
" // ⨯ should be a form combination field or\n" +
|
|
2355
|
+
" //\n" +
|
|
2356
|
+
" // {\n" +
|
|
2357
|
+
" // type: 'Combination',\n" +
|
|
2358
|
+
" // fields:\n" +
|
|
2359
|
+
" // [] // ✓ should be an array and\n" +
|
|
2360
|
+
" // // ⨯ should have items satisfying to be a form field\n" +
|
|
2361
|
+
" // // should not be empty\n" +
|
|
2362
|
+
" // }\n" +
|
|
2363
|
+
" // ⨯ should be a form list or\n" +
|
|
2364
|
+
" // ⨯ should be a form fieldset\n" +
|
|
2365
|
+
" { type: 'List', name: 'ListA', rowField: { name: 'fieldB' } },\n" +
|
|
2366
|
+
" // ⨯ should be a form field or\n" +
|
|
2367
|
+
" // ⨯ should be a form combination field or\n" +
|
|
2368
|
+
" // ⨯ should be a form list or\n" +
|
|
2369
|
+
" //\n" +
|
|
2370
|
+
" // {\n" +
|
|
2371
|
+
" // type: 'List',\n" +
|
|
2372
|
+
" // name: 'ListA',\n" +
|
|
2373
|
+
" // rowField:\n" +
|
|
2374
|
+
" // { name: 'fieldB' } // ⨯ should be a form field or\n" +
|
|
2375
|
+
" // // Invalid type undefined\n" +
|
|
2376
|
+
" // // ⨯ should be a form combination field\n" +
|
|
2377
|
+
" // }\n" +
|
|
2378
|
+
" // ⨯ should be a form fieldset\n" +
|
|
2379
|
+
" { type: 'Fieldset', fields: [ ..., ..., ... ] }\n" +
|
|
2380
|
+
" // ⨯ should be a form field or\n" +
|
|
2381
|
+
" // ⨯ should be a form combination field or\n" +
|
|
2382
|
+
" // ⨯ should be a form list or\n" +
|
|
2383
|
+
" // ⨯ should be a form fieldset\n" +
|
|
2384
|
+
" //\n" +
|
|
2385
|
+
" // {\n" +
|
|
2386
|
+
" // type: 'Fieldset',\n" +
|
|
2387
|
+
" // fields: [\n" +
|
|
2388
|
+
" // { name: 'field2', type: 'CheckboxInput' },\n" +
|
|
2389
|
+
" // { type: 'Combination', fields: ... },\n" +
|
|
2390
|
+
" // { type: 'List', name: 'ListB', rowField: ... }\n" +
|
|
2391
|
+
" // ]\n" +
|
|
2392
|
+
" // // missing: label: should be a label\n" +
|
|
2393
|
+
" // should be a string\n" +
|
|
2394
|
+
" // }\n" +
|
|
2395
|
+
"]",
|
|
2396
|
+
));
|
|
2397
|
+
});
|