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.
Files changed (47) hide show
  1. package/LICENSE +19 -0
  2. package/README.md +76 -0
  3. package/babel.js +1 -0
  4. package/eslint.js +1 -0
  5. package/jest.js +1 -0
  6. package/package.json +164 -0
  7. package/prettier.js +1 -0
  8. package/src/__mocks__/fileMock.js +1 -0
  9. package/src/config/babel-preset.js +4 -0
  10. package/src/config/babel-transform.js +4 -0
  11. package/src/config/babel-whitelist.json +1 -0
  12. package/src/config/babelrc.js +38 -0
  13. package/src/config/eslintrc.js +15 -0
  14. package/src/config/jest-resolver.js +35 -0
  15. package/src/config/jest.config.js +45 -0
  16. package/src/config/jestSetupFiles.js +4 -0
  17. package/src/config/prettier.config.js +9 -0
  18. package/src/config/setAssetPath.js +1 -0
  19. package/src/config/unexpected-form.js +317 -0
  20. package/src/config/unexpected-form.test.js +2397 -0
  21. package/src/config/unexpected-module.js +112 -0
  22. package/src/config/unexpected-module.test.js +1106 -0
  23. package/src/config/unexpected-styles.js +44 -0
  24. package/src/config/unexpected-styles.test.js +118 -0
  25. package/src/config/unexpected.js +117 -0
  26. package/src/config/unexpected.test.js +393 -0
  27. package/src/config/webpack.config.js +103 -0
  28. package/src/index.js +19 -0
  29. package/src/run-script.js +99 -0
  30. package/src/scripts/build/cli.js +43 -0
  31. package/src/scripts/build/index.js +9 -0
  32. package/src/scripts/build/web.js +24 -0
  33. package/src/scripts/buildDep.js +122 -0
  34. package/src/scripts/buildIconsSheet.js +50 -0
  35. package/src/scripts/clean.js +8 -0
  36. package/src/scripts/extract-messages.js +22 -0
  37. package/src/scripts/generateApi.js +152 -0
  38. package/src/scripts/getDist.js +20 -0
  39. package/src/scripts/mergeTranslations.js +32 -0
  40. package/src/scripts/prep.js +28 -0
  41. package/src/scripts/start.js +45 -0
  42. package/src/scripts/tag.js +76 -0
  43. package/src/scripts/test.js +26 -0
  44. package/src/scripts/validateTranslations.js +72 -0
  45. package/src/utils.js +95 -0
  46. package/src/utils.test.js +93 -0
  47. package/webpack.js +1 -0
@@ -0,0 +1,1106 @@
1
+ import React from "react";
2
+
3
+ const FakeComponent = () => null;
4
+
5
+ class ClassComponent extends React.Component {
6
+ render() {
7
+ return <div />;
8
+ }
9
+ }
10
+
11
+ const fakeSelector = () => {};
12
+
13
+ describe("Module structure plugin for Unexpected", () => {
14
+ describe("<object> to be a component", () => {
15
+ it("accepts function components", () => expect(FakeComponent, "to be a component"));
16
+
17
+ it("accepts class components", () => expect(ClassComponent, "to be a component"));
18
+
19
+ it("accepts memoized components", () => expect(React.memo(FakeComponent), "to be a component"));
20
+
21
+ it("fails with undefined", () =>
22
+ expect(() => expect(undefined, "to be a component"), "to throw", "expected undefined to be a component"));
23
+
24
+ it("fails with null", () =>
25
+ expect(() => expect(null, "to be a component"), "to throw", "expected null to be a component"));
26
+
27
+ it("fails with string", () =>
28
+ expect(
29
+ () => expect("FakeComponent", "to be a component"),
30
+ "to throw",
31
+ "expected 'FakeComponent' to be a component",
32
+ ));
33
+ });
34
+
35
+ describe("<object> to be a subpage", () => {
36
+ it("handles a minimal subpage", () =>
37
+ expect(() => expect({ component: FakeComponent }, "to be a subpage"), "not to throw"));
38
+
39
+ it("does not accept subpages with pages", () =>
40
+ expect(
41
+ () =>
42
+ expect(
43
+ {
44
+ component: FakeComponent,
45
+ pages: { "/foo": { component: FakeComponent, label: "A label" } },
46
+ },
47
+ "to be a subpage",
48
+ ),
49
+ "to throw",
50
+ "expected\n" +
51
+ "{\n" +
52
+ " component: () => null,\n" +
53
+ " pages: { '/foo': { component: ..., label: 'A label' } }\n" +
54
+ "}\n" +
55
+ "to be a subpage\n" +
56
+ "\n" +
57
+ "{\n" +
58
+ " component: () => null,\n" +
59
+ " pages: { '/foo': { component: ..., label: 'A label' } } // should be removed\n" +
60
+ "}",
61
+ ));
62
+
63
+ it("does not accept subpages with segments", () =>
64
+ expect(
65
+ () =>
66
+ expect(
67
+ {
68
+ component: FakeComponent,
69
+ segments: {
70
+ "/foo": { component: FakeComponent, label: "A label" },
71
+ },
72
+ },
73
+ "to be a subpage",
74
+ ),
75
+ "to throw",
76
+ "expected\n" +
77
+ "{\n" +
78
+ " component: () => null,\n" +
79
+ " segments: { '/foo': { component: ..., label: 'A label' } }\n" +
80
+ "}\n" +
81
+ "to be a subpage\n" +
82
+ "\n" +
83
+ "{\n" +
84
+ " component: () => null,\n" +
85
+ " segments: { '/foo': { component: ..., label: 'A label' } } // should be removed\n" +
86
+ "}",
87
+ ));
88
+
89
+ it("does not accept subpages with subpages", () =>
90
+ expect(
91
+ () =>
92
+ expect(
93
+ {
94
+ component: FakeComponent,
95
+ subpages: { "/foo": { component: FakeComponent } },
96
+ },
97
+ "to be a subpage",
98
+ ),
99
+ "to throw",
100
+ "expected { component: () => null, subpages: { '/foo': { component: ... } } }\n" +
101
+ "to be a subpage\n" +
102
+ "\n" +
103
+ "{\n" +
104
+ " component: () => null,\n" +
105
+ " subpages: { '/foo': { component: ... } } // should be removed\n" +
106
+ "}",
107
+ ));
108
+
109
+ it("throws error if no component", () =>
110
+ expect(
111
+ () => expect({ wrong_component: FakeComponent }, "to be a subpage"),
112
+ "to throw",
113
+ "expected { wrong_component: () => null } to be a subpage\n" +
114
+ "\n" +
115
+ "{\n" +
116
+ " wrong_component: () => null // should be removed\n" +
117
+ " // missing: component: should be a component\n" +
118
+ "}",
119
+ ));
120
+
121
+ it("handles a subpage with toolbar", () =>
122
+ expect(
123
+ () => expect({ component: FakeComponent, toolStateSelector: fakeSelector }, "to be a subpage"),
124
+ "not to throw",
125
+ ));
126
+
127
+ it("throws if toolbar state selector not function", () =>
128
+ expect(
129
+ () => expect({ component: FakeComponent, toolStateSelector: "fakeSelector" }, "to be a subpage"),
130
+ "to throw",
131
+ "expected { component: () => null, toolStateSelector: 'fakeSelector' }\n" +
132
+ "to be a subpage\n" +
133
+ "\n" +
134
+ "{\n" +
135
+ " component: () => null,\n" +
136
+ " toolStateSelector: 'fakeSelector' // should be a function\n" +
137
+ "}",
138
+ ));
139
+
140
+ it("handles a subpage with toolbar functions", () =>
141
+ expect(
142
+ () => expect({ component: FakeComponent, toolFuncSelector: fakeSelector }, "to be a subpage"),
143
+ "not to throw",
144
+ ));
145
+
146
+ it("throws if toolbar function selector not function", () =>
147
+ expect(
148
+ () => expect({ component: FakeComponent, toolFuncSelector: "fakeSelector" }, "to be a subpage"),
149
+ "to throw",
150
+ "expected { component: () => null, toolFuncSelector: 'fakeSelector' }\n" +
151
+ "to be a subpage\n" +
152
+ "\n" +
153
+ "{\n" +
154
+ " component: () => null,\n" +
155
+ " toolFuncSelector: 'fakeSelector' // should be a function\n" +
156
+ "}",
157
+ ));
158
+ });
159
+
160
+ describe("<object> to be a subpage list", () => {
161
+ it("passes when subject is an index of only subpages", () =>
162
+ expect(
163
+ () =>
164
+ expect(
165
+ {
166
+ "/foo": { component: FakeComponent },
167
+ "/bar": {
168
+ component: FakeComponent,
169
+ toolStateSelector: fakeSelector,
170
+ },
171
+ },
172
+ "to be a subpage list",
173
+ ),
174
+ "not to throw",
175
+ ));
176
+
177
+ it("fails when subject has keys not starting with /", () =>
178
+ expect(
179
+ () =>
180
+ expect(
181
+ {
182
+ foo: { component: FakeComponent },
183
+ "/bar": {
184
+ component: FakeComponent,
185
+ toolStateSelector: fakeSelector,
186
+ },
187
+ },
188
+ "to be a subpage list",
189
+ ),
190
+ "to throw",
191
+ "expected\n" +
192
+ "{\n" +
193
+ " foo: { component: () => null },\n" +
194
+ " '/bar': { component: () => null, toolStateSelector: () => {} }\n" +
195
+ "}\n" +
196
+ "to be a subpage list\n" +
197
+ "\n" +
198
+ "[\n" +
199
+ " 'foo', // should start with '/'\n" +
200
+ " '/bar'\n" +
201
+ "]",
202
+ ));
203
+
204
+ it("fails when subject is an empty object", () =>
205
+ expect(() => expect({}, "to be a subpage list"), "to throw", "expected {} to be a subpage list"));
206
+
207
+ it("fails when subject contains something not a subpage", () =>
208
+ expect(
209
+ () =>
210
+ expect(
211
+ {
212
+ "/foo": { component: FakeComponent },
213
+ "/bar": {
214
+ component: FakeComponent,
215
+ toolStateSelector: "fakeSelector",
216
+ },
217
+ },
218
+ "to be a subpage list",
219
+ ),
220
+ "to throw",
221
+ "expected\n" +
222
+ "{\n" +
223
+ " '/foo': { component: () => null },\n" +
224
+ " '/bar': { component: () => null, toolStateSelector: 'fakeSelector' }\n" +
225
+ "}\n" +
226
+ "to be a subpage list\n" +
227
+ "\n" +
228
+ "{\n" +
229
+ " '/foo': { component: () => null },\n" +
230
+ " '/bar': {\n" +
231
+ " component: () => null,\n" +
232
+ " toolStateSelector: 'fakeSelector' // should be a function\n" +
233
+ " }\n" +
234
+ "}",
235
+ ));
236
+ });
237
+
238
+ describe("<object> to be a segment", () => {
239
+ it("passes with a string label and component", () =>
240
+ expect(() => expect({ component: FakeComponent, label: "A label" }, "to be a segment"), "not to throw"));
241
+
242
+ it("passes with an object label, component and subpage list", () =>
243
+ expect(
244
+ () =>
245
+ expect(
246
+ {
247
+ component: FakeComponent,
248
+ label: { id: "test.msg", defaultMessage: "A label" },
249
+ subpages: {
250
+ "/foo": { component: FakeComponent },
251
+ },
252
+ },
253
+ "to be a segment",
254
+ ),
255
+ "not to throw",
256
+ ));
257
+
258
+ it("passes with an object label, data path, component and page list", () =>
259
+ expect(
260
+ () =>
261
+ expect(
262
+ {
263
+ component: FakeComponent,
264
+ label: { id: "test.msg", defaultMessage: "A label" },
265
+ dataPath: ["support", "index"],
266
+ pages: {
267
+ "/foo": { component: FakeComponent, label: "A label" },
268
+ "/bar": {
269
+ component: FakeComponent,
270
+ label: { id: "test.msg", defaultMessage: "A label" },
271
+ subpages: {
272
+ "/foo": { component: FakeComponent },
273
+ },
274
+ },
275
+ },
276
+ },
277
+ "to be a segment",
278
+ ),
279
+ "not to throw",
280
+ ));
281
+
282
+ it("passes with an object label, data path, data ID, and component", () =>
283
+ expect(
284
+ () =>
285
+ expect(
286
+ {
287
+ component: FakeComponent,
288
+ label: { id: "test.msg", defaultMessage: "A label" },
289
+ dataPath: ["support", 2],
290
+ dataIdParam: "identity",
291
+ },
292
+ "to be a segment",
293
+ ),
294
+ "not to throw",
295
+ ));
296
+
297
+ it("fails if data path is not an array", () =>
298
+ expect(
299
+ () =>
300
+ expect(
301
+ {
302
+ component: FakeComponent,
303
+ label: { id: "test.msg", defaultMessage: "A label" },
304
+ dataPath: "support",
305
+ dataIdParam: "identity",
306
+ },
307
+ "to be a segment",
308
+ ),
309
+ "to throw",
310
+ "expected\n" +
311
+ "{\n" +
312
+ " component: () => null,\n" +
313
+ " label: { id: 'test.msg', defaultMessage: 'A label' },\n" +
314
+ " dataPath: 'support',\n" +
315
+ " dataIdParam: 'identity'\n" +
316
+ "}\n" +
317
+ "to be a segment\n" +
318
+ "\n" +
319
+ "{\n" +
320
+ " component: () => null,\n" +
321
+ " label: { id: 'test.msg', defaultMessage: 'A label' },\n" +
322
+ " dataPath:\n" +
323
+ " 'support', // ⨯ should be an array and\n" +
324
+ " // ⨯ should have items satisfying\n" +
325
+ " // expect.it('to be a string')\n" +
326
+ " // .or('to be a number')\n" +
327
+ " dataIdParam: 'identity'\n" +
328
+ "}",
329
+ ));
330
+
331
+ it("fails if data path contains non-strings/numbers", () =>
332
+ expect(
333
+ () =>
334
+ expect(
335
+ {
336
+ component: FakeComponent,
337
+ label: { id: "test.msg", defaultMessage: "A label" },
338
+ dataPath: ["support", { foo: "foo" }],
339
+ dataIdParam: "identity",
340
+ },
341
+ "to be a segment",
342
+ ),
343
+ "to throw",
344
+ "expected\n" +
345
+ "{\n" +
346
+ " component: () => null,\n" +
347
+ " label: { id: 'test.msg', defaultMessage: 'A label' },\n" +
348
+ " dataPath: [ 'support', { foo: 'foo' } ],\n" +
349
+ " dataIdParam: 'identity'\n" +
350
+ "}\n" +
351
+ "to be a segment\n" +
352
+ "\n" +
353
+ "{\n" +
354
+ " component: () => null,\n" +
355
+ " label: { id: 'test.msg', defaultMessage: 'A label' },\n" +
356
+ " dataPath:\n" +
357
+ " [ 'support', { foo: 'foo' } ], // ✓ should be an array and\n" +
358
+ " // ⨯ should have items satisfying\n" +
359
+ " // expect.it('to be a string')\n" +
360
+ " // .or('to be a number')\n" +
361
+ " //\n" +
362
+ " // [\n" +
363
+ " // 'support',\n" +
364
+ " // { foo: 'foo' } // ⨯ should be a string or\n" +
365
+ " // // ⨯ should be a number\n" +
366
+ " // ]\n" +
367
+ " dataIdParam: 'identity'\n" +
368
+ "}",
369
+ ));
370
+
371
+ it("fails if data ID is invalid", () =>
372
+ expect(
373
+ () =>
374
+ expect(
375
+ {
376
+ component: FakeComponent,
377
+ label: { id: "test.msg", defaultMessage: "A label" },
378
+ dataPath: ["support", 2],
379
+ dataIdParam: "ident!ity",
380
+ },
381
+ "to be a segment",
382
+ ),
383
+ "to throw",
384
+ "expected\n" +
385
+ "{\n" +
386
+ " component: () => null,\n" +
387
+ " label: { id: 'test.msg', defaultMessage: 'A label' },\n" +
388
+ " dataPath: [ 'support', 2 ],\n" +
389
+ " dataIdParam: 'ident!ity'\n" +
390
+ "}\n" +
391
+ "to be a segment\n" +
392
+ "\n" +
393
+ "{\n" +
394
+ " component: () => null,\n" +
395
+ " label: { id: 'test.msg', defaultMessage: 'A label' },\n" +
396
+ " dataPath: [ 'support', 2 ],\n" +
397
+ " dataIdParam: 'ident!ity' // should match /^\\w+$/\n" +
398
+ "}",
399
+ ));
400
+
401
+ it("fails with a string label and data path", () =>
402
+ expect(
403
+ () =>
404
+ expect(
405
+ {
406
+ component: FakeComponent,
407
+ label: "A label",
408
+ dataPath: ["support", "index"],
409
+ },
410
+ "to be a segment",
411
+ ),
412
+ "to throw",
413
+ "expected\n" +
414
+ "{\n" +
415
+ " component: () => null, label: 'A label',\n" +
416
+ " dataPath: [ 'support', 'index' ]\n" +
417
+ "}\n" +
418
+ "to be a segment\n" +
419
+ "\n" +
420
+ "{\n" +
421
+ " component: () => null,\n" +
422
+ " label: 'A label', // ⨯ should be an object and\n" +
423
+ " // ✓ should be a label\n" +
424
+ " dataPath: [ 'support', 'index' ]\n" +
425
+ "}",
426
+ ));
427
+
428
+ it("fails with a segment list", () =>
429
+ expect(
430
+ () =>
431
+ expect(
432
+ {
433
+ component: FakeComponent,
434
+ label: "A label",
435
+ segments: {
436
+ "/foo": { component: FakeComponent, label: "A label" },
437
+ "/bar": {
438
+ component: FakeComponent,
439
+ label: "A label",
440
+ },
441
+ },
442
+ },
443
+ "to be a segment",
444
+ ),
445
+ "to throw",
446
+ "expected\n" +
447
+ "{\n" +
448
+ " component: () => null,\n" +
449
+ " label: 'A label',\n" +
450
+ " segments: {\n" +
451
+ " '/foo': { component: ..., label: 'A label' },\n" +
452
+ " '/bar': { component: ..., label: 'A label' }\n" +
453
+ " }\n" +
454
+ "}\n" +
455
+ "to be a segment\n" +
456
+ "\n" +
457
+ "{\n" +
458
+ " component: () => null,\n" +
459
+ " label: 'A label',\n" +
460
+ " segments: {\n" +
461
+ " '/foo': { component: ..., label: 'A label' },\n" +
462
+ " '/bar': { component: ..., label: 'A label' }\n" +
463
+ " } // should be removed\n" +
464
+ "}",
465
+ ));
466
+
467
+ it("fails if missing component", () =>
468
+ expect(
469
+ () =>
470
+ expect(
471
+ {
472
+ label: { id: "test.msg", defaultMessage: "A label" },
473
+ subpages: {
474
+ "/foo": { component: FakeComponent },
475
+ },
476
+ },
477
+ "to be a segment",
478
+ ),
479
+ "to throw",
480
+ "expected\n" +
481
+ "{\n" +
482
+ " label: { id: 'test.msg', defaultMessage: 'A label' },\n" +
483
+ " subpages: { '/foo': { component: ... } }\n" +
484
+ "}\n" +
485
+ "to be a segment\n" +
486
+ "\n" +
487
+ "{\n" +
488
+ " label: { id: 'test.msg', defaultMessage: 'A label' },\n" +
489
+ " subpages: { '/foo': { component: ... } }\n" +
490
+ " // missing: component: should be a component\n" +
491
+ "}",
492
+ ));
493
+
494
+ it("fails if missing label", () =>
495
+ expect(
496
+ () =>
497
+ expect(
498
+ {
499
+ component: FakeComponent,
500
+ subpages: {
501
+ "/foo": { component: FakeComponent },
502
+ },
503
+ },
504
+ "to be a segment",
505
+ ),
506
+ "to throw",
507
+ "expected { component: () => null, subpages: { '/foo': { component: ... } } }\n" +
508
+ "to be a segment\n" +
509
+ "\n" +
510
+ "{\n" +
511
+ " component: () => null,\n" +
512
+ " subpages: { '/foo': { component: ... } }\n" +
513
+ " // missing: label: should be a label\n" +
514
+ " should be a string\n" +
515
+ "}",
516
+ ));
517
+
518
+ it("fails if label not correct", () =>
519
+ expect(
520
+ () =>
521
+ expect(
522
+ {
523
+ component: FakeComponent,
524
+ label: 3,
525
+ subpages: {
526
+ "/foo": { component: FakeComponent },
527
+ },
528
+ },
529
+ "to be a segment",
530
+ ),
531
+ "to throw",
532
+ "expected\n" +
533
+ "{\n" +
534
+ " component: () => null, label: 3,\n" +
535
+ " subpages: { '/foo': { component: ... } }\n" +
536
+ "}\n" +
537
+ "to be a segment\n" +
538
+ "\n" +
539
+ "{\n" +
540
+ " component: () => null,\n" +
541
+ " label: 3, // should be a label\n" +
542
+ " // should be a string\n" +
543
+ " subpages: { '/foo': { component: ... } }\n" +
544
+ "}",
545
+ ));
546
+
547
+ it("fails if subpages not a subpage list", () =>
548
+ expect(
549
+ () =>
550
+ expect(
551
+ {
552
+ component: FakeComponent,
553
+ label: { id: "test.msg", defaultMessage: "A label" },
554
+ subpages: {
555
+ "/foo": { component: "FakeComponent" },
556
+ },
557
+ },
558
+ "to be a segment",
559
+ ),
560
+ "to throw",
561
+ "expected\n" +
562
+ "{\n" +
563
+ " component: () => null,\n" +
564
+ " label: { id: 'test.msg', defaultMessage: 'A label' },\n" +
565
+ " subpages: { '/foo': { component: 'FakeComponent' } }\n" +
566
+ "}\n" +
567
+ "to be a segment\n" +
568
+ "\n" +
569
+ "{\n" +
570
+ " component: () => null,\n" +
571
+ " label: { id: 'test.msg', defaultMessage: 'A label' },\n" +
572
+ " subpages:\n" +
573
+ " { '/foo': { component: 'FakeComponent' } }\n" +
574
+ " // should be a subpage list\n" +
575
+ " //\n" +
576
+ " // {\n" +
577
+ " // '/foo': {\n" +
578
+ " // component: 'FakeComponent' // should be a component\n" +
579
+ " // }\n" +
580
+ " // }\n" +
581
+ "}",
582
+ ));
583
+ });
584
+
585
+ describe("<object> to be a segment list", () => {
586
+ it("passes when subject is an index of only segments", () =>
587
+ expect(
588
+ () =>
589
+ expect(
590
+ {
591
+ "/foo": { component: FakeComponent, label: "A label" },
592
+ "/bar": {
593
+ component: FakeComponent,
594
+ label: { id: "test.msg", defaultMessage: "A label" },
595
+ subpages: {
596
+ "/foo": { component: FakeComponent },
597
+ },
598
+ },
599
+ },
600
+ "to be a segment list",
601
+ ),
602
+ "not to throw",
603
+ ));
604
+
605
+ it("fails when subject has keys not starting with /", () =>
606
+ expect(
607
+ () =>
608
+ expect(
609
+ {
610
+ foo: { component: FakeComponent, label: "A label" },
611
+ "/bar": {
612
+ component: FakeComponent,
613
+ label: { id: "test.msg", defaultMessage: "A label" },
614
+ subpages: {
615
+ "/foo": { component: FakeComponent },
616
+ },
617
+ },
618
+ },
619
+ "to be a segment list",
620
+ ),
621
+ "to throw",
622
+ "expected\n" +
623
+ "{\n" +
624
+ " foo: { component: () => null, label: 'A label' },\n" +
625
+ " '/bar': {\n" +
626
+ " component: () => null,\n" +
627
+ " label: { id: 'test.msg', defaultMessage: 'A label' },\n" +
628
+ " subpages: { '/foo': ... }\n" +
629
+ " }\n" +
630
+ "}\n" +
631
+ "to be a segment list\n" +
632
+ "\n" +
633
+ "[\n" +
634
+ " 'foo', // should start with '/'\n" +
635
+ " '/bar'\n" +
636
+ "]",
637
+ ));
638
+
639
+ it("fails when subject is an empty object", () =>
640
+ expect(() => expect({}, "to be a segment list"), "to throw", "expected {} to be a segment list"));
641
+
642
+ it("fails when subject contains something not a segment", () =>
643
+ expect(
644
+ () =>
645
+ expect(
646
+ {
647
+ "/foo": { component: FakeComponent, label: "A label" },
648
+ "/bar": {
649
+ label: { id: "test.msg", defaultMessage: "A label" },
650
+ subpages: {
651
+ "/foo": { component: FakeComponent },
652
+ },
653
+ },
654
+ },
655
+ "to be a segment list",
656
+ ),
657
+ "to throw",
658
+ "expected\n" +
659
+ "{\n" +
660
+ " '/foo': { component: () => null, label: 'A label' },\n" +
661
+ " '/bar': {\n" +
662
+ " label: { id: 'test.msg', defaultMessage: 'A label' },\n" +
663
+ " subpages: { '/foo': ... }\n" +
664
+ " }\n" +
665
+ "}\n" +
666
+ "to be a segment list\n" +
667
+ "\n" +
668
+ "{\n" +
669
+ " '/foo': { component: () => null, label: 'A label' },\n" +
670
+ " '/bar': {\n" +
671
+ " label: { id: 'test.msg', defaultMessage: 'A label' },\n" +
672
+ " subpages: { '/foo': { component: ... } }\n" +
673
+ " // missing: component: should be a component\n" +
674
+ " }\n" +
675
+ "}",
676
+ ));
677
+ });
678
+
679
+ describe("<object> to be a page", () => {
680
+ it("passes with a string label and component", () =>
681
+ expect(() => expect({ component: FakeComponent, label: "A label" }, "to be a page"), "not to throw"));
682
+
683
+ it("passes with a label, component and subpage list", () =>
684
+ expect(
685
+ () =>
686
+ expect(
687
+ {
688
+ label: { id: "test.msg", defaultMessage: "A label" },
689
+ component: FakeComponent,
690
+ subpages: {
691
+ "/foo": { component: FakeComponent },
692
+ "/bar": {
693
+ component: FakeComponent,
694
+ toolStateSelector: fakeSelector,
695
+ },
696
+ },
697
+ },
698
+ "to be a page",
699
+ ),
700
+ "not to throw",
701
+ ));
702
+
703
+ it("passes with an object label, component and page list", () =>
704
+ expect(
705
+ () =>
706
+ expect(
707
+ {
708
+ label: { id: "test.msg", defaultMessage: "A label" },
709
+ component: FakeComponent,
710
+ pages: {
711
+ "/foo": { component: FakeComponent, label: "A label" },
712
+ "/bar": {
713
+ component: FakeComponent,
714
+ label: { id: "test.msg", defaultMessage: "A label" },
715
+ subpages: {
716
+ "/foo": { component: FakeComponent },
717
+ },
718
+ },
719
+ },
720
+ },
721
+ "to be a page",
722
+ ),
723
+ "not to throw",
724
+ ));
725
+
726
+ it("passes with an object label and data path", () =>
727
+ expect(
728
+ () =>
729
+ expect(
730
+ {
731
+ label: { id: "test.msg", defaultMessage: "A label" },
732
+ dataPath: ["support", 2],
733
+ component: FakeComponent,
734
+ },
735
+ "to be a page",
736
+ ),
737
+ "not to throw",
738
+ ));
739
+
740
+ it("passes with an object label, data path and id parameter", () =>
741
+ expect(
742
+ () =>
743
+ expect(
744
+ {
745
+ label: { id: "test.msg", defaultMessage: "A label" },
746
+ dataPath: ["support", 2],
747
+ dataIdParam: "identity",
748
+ component: FakeComponent,
749
+ },
750
+ "to be a page",
751
+ ),
752
+ "not to throw",
753
+ ));
754
+
755
+ it("fails if id parameter contains non-word chars", () =>
756
+ expect(
757
+ () =>
758
+ expect(
759
+ {
760
+ label: { id: "test.msg", defaultMessage: "A label" },
761
+ dataPath: ["support", 2],
762
+ dataIdParam: "ident!ity",
763
+ component: FakeComponent,
764
+ },
765
+ "to be a page",
766
+ ),
767
+ "to throw",
768
+ "expected\n" +
769
+ "{\n" +
770
+ " label: { id: 'test.msg', defaultMessage: 'A label' },\n" +
771
+ " dataPath: [ 'support', 2 ],\n" +
772
+ " dataIdParam: 'ident!ity',\n" +
773
+ " component: () => null\n" +
774
+ "}\n" +
775
+ "to satisfy\n" +
776
+ "{\n" +
777
+ " label: expect.it('to be an object')\n" +
778
+ " .and('to be a label'),\n" +
779
+ " dataPath:\n" +
780
+ " expect.it('to be an array')\n" +
781
+ " .and('to have items satisfying', expect.it('to be a string')\n" +
782
+ " .or('to be a number')),\n" +
783
+ " dataIdParam: expect.it('to match', /^\\w+$/)\n" +
784
+ "}\n" +
785
+ "\n" +
786
+ "{\n" +
787
+ " label: { id: 'test.msg', defaultMessage: 'A label' },\n" +
788
+ " dataPath: [ 'support', 2 ],\n" +
789
+ " dataIdParam: 'ident!ity', // should match /^\\w+$/\n" +
790
+ " component: () => null\n" +
791
+ "}",
792
+ ));
793
+
794
+ it("passes with a string label and segment list", () =>
795
+ expect(
796
+ () =>
797
+ expect(
798
+ {
799
+ label: "A label",
800
+ segments: {
801
+ "/foo": { component: FakeComponent, label: "A label" },
802
+ "/bar": {
803
+ component: FakeComponent,
804
+ label: "A label",
805
+ },
806
+ },
807
+ },
808
+ "to be a page",
809
+ ),
810
+ "not to throw",
811
+ ));
812
+
813
+ it("passes with an object label and segment list", () =>
814
+ expect(
815
+ () =>
816
+ expect(
817
+ {
818
+ label: { id: "test.msg", defaultMessage: "A label" },
819
+ segments: {
820
+ "/foo": { component: FakeComponent, label: "A label" },
821
+ "/bar": {
822
+ component: FakeComponent,
823
+ label: "A label",
824
+ },
825
+ },
826
+ },
827
+ "to be a page",
828
+ ),
829
+ "not to throw",
830
+ ));
831
+
832
+ it("fails with a component and segment list", () =>
833
+ expect(
834
+ () =>
835
+ expect(
836
+ {
837
+ label: { id: "test.msg", defaultMessage: "A label" },
838
+ component: FakeComponent,
839
+ segments: {
840
+ "/foo": { component: FakeComponent, label: "A label" },
841
+ "/bar": {
842
+ component: FakeComponent,
843
+ label: "A label",
844
+ },
845
+ },
846
+ },
847
+ "to be a page",
848
+ ),
849
+ "to throw",
850
+ "expected\n" +
851
+ "{\n" +
852
+ " label: { id: 'test.msg', defaultMessage: 'A label' },\n" +
853
+ " component: () => null,\n" +
854
+ " segments: {\n" +
855
+ " '/foo': { component: ..., label: 'A label' },\n" +
856
+ " '/bar': { component: ..., label: 'A label' }\n" +
857
+ " }\n" +
858
+ "}\n" +
859
+ "not to have key 'segments'",
860
+ ));
861
+
862
+ it("fails with a segment list and pages list", () =>
863
+ expect(
864
+ () =>
865
+ expect(
866
+ {
867
+ label: "A label",
868
+ segments: {
869
+ "/foo": { component: FakeComponent, label: "A label" },
870
+ "/bar": {
871
+ component: FakeComponent,
872
+ label: "A label",
873
+ },
874
+ },
875
+ pages: {
876
+ "/foo": { component: FakeComponent, label: "A label" },
877
+ "/bar": {
878
+ component: FakeComponent,
879
+ label: "A label",
880
+ },
881
+ },
882
+ },
883
+ "to be a page",
884
+ ),
885
+ "to throw",
886
+ "expected\n" +
887
+ "{\n" +
888
+ " label: 'A label',\n" +
889
+ " segments: {\n" +
890
+ " '/foo': { component: ..., label: 'A label' },\n" +
891
+ " '/bar': { component: ..., label: 'A label' }\n" +
892
+ " },\n" +
893
+ " pages: {\n" +
894
+ " '/foo': { component: ..., label: 'A label' },\n" +
895
+ " '/bar': { component: ..., label: 'A label' }\n" +
896
+ " }\n" +
897
+ "}\n" +
898
+ "not to have key 'pages'",
899
+ ));
900
+
901
+ it("passes with a segment list and subpage list", () =>
902
+ expect(
903
+ () =>
904
+ expect(
905
+ {
906
+ label: "A label",
907
+ segments: {
908
+ "/foo": { component: FakeComponent, label: "A label" },
909
+ "/bar": {
910
+ component: FakeComponent,
911
+ label: "A label",
912
+ },
913
+ },
914
+ subpages: {
915
+ "/foo": { component: FakeComponent },
916
+ "/bar": {
917
+ component: FakeComponent,
918
+ toolStateSelector: fakeSelector,
919
+ },
920
+ },
921
+ },
922
+ "to be a page",
923
+ ),
924
+ "to throw",
925
+ "expected\n" +
926
+ "{\n" +
927
+ " label: 'A label',\n" +
928
+ " segments: {\n" +
929
+ " '/foo': { component: ..., label: 'A label' },\n" +
930
+ " '/bar': { component: ..., label: 'A label' }\n" +
931
+ " },\n" +
932
+ " subpages: {\n" +
933
+ " '/foo': { component: ... },\n" +
934
+ " '/bar': { component: ..., toolStateSelector: ... }\n" +
935
+ " }\n" +
936
+ "}\n" +
937
+ "not to have key 'subpages'",
938
+ ));
939
+ });
940
+
941
+ describe("<object> to be a page list", () => {
942
+ it("passes when subject is an index of only pages", () =>
943
+ expect(
944
+ () =>
945
+ expect(
946
+ {
947
+ "/foo": { component: FakeComponent, label: "A label" },
948
+ "/bar": {
949
+ component: FakeComponent,
950
+ label: { id: "test.msg", defaultMessage: "A label" },
951
+ subpages: {
952
+ "/foo": { component: FakeComponent },
953
+ },
954
+ },
955
+ },
956
+ "to be a page list",
957
+ ),
958
+ "not to throw",
959
+ ));
960
+
961
+ it("fails when subject has keys not starting with /", () =>
962
+ expect(
963
+ () =>
964
+ expect(
965
+ {
966
+ "/foo": { component: FakeComponent, label: "A label" },
967
+ bar: {
968
+ component: FakeComponent,
969
+ label: { id: "test.msg", defaultMessage: "A label" },
970
+ subpages: {
971
+ "/foo": { component: FakeComponent },
972
+ },
973
+ },
974
+ },
975
+ "to be a page list",
976
+ ),
977
+ "to throw",
978
+ "expected\n" +
979
+ "{\n" +
980
+ " '/foo': { component: () => null, label: 'A label' },\n" +
981
+ " bar: {\n" +
982
+ " component: () => null,\n" +
983
+ " label: { id: 'test.msg', defaultMessage: 'A label' },\n" +
984
+ " subpages: { '/foo': ... }\n" +
985
+ " }\n" +
986
+ "}\n" +
987
+ "to be a page list\n" +
988
+ "\n" +
989
+ "[\n" +
990
+ " '/foo',\n" +
991
+ " 'bar' // should start with '/'\n" +
992
+ "]",
993
+ ));
994
+
995
+ it("fails when subject is an empty object", () =>
996
+ expect(() => expect({}, "to be a page list"), "to throw", "expected {} to be a page list"));
997
+
998
+ it("fails when subject contains something not a page", () =>
999
+ expect(
1000
+ () =>
1001
+ expect(
1002
+ {
1003
+ "/foo": { component: FakeComponent, label: "A label" },
1004
+ "/bar": {
1005
+ component: FakeComponent,
1006
+ label: { id: "test.msg", defaultMessage: "A label" },
1007
+ segments: {
1008
+ "/foo": { component: FakeComponent, label: "A label" },
1009
+ },
1010
+ },
1011
+ },
1012
+ "to be a page list",
1013
+ ),
1014
+ "to throw",
1015
+ "expected\n" +
1016
+ "{\n" +
1017
+ " '/foo': { component: () => null, label: 'A label' },\n" +
1018
+ " '/bar': {\n" +
1019
+ " component: () => null,\n" +
1020
+ " label: { id: 'test.msg', defaultMessage: 'A label' },\n" +
1021
+ " segments: { '/foo': ... }\n" +
1022
+ " }\n" +
1023
+ "}\n" +
1024
+ "to be a page list\n" +
1025
+ "\n" +
1026
+ "{\n" +
1027
+ " '/foo': { component: () => null, label: 'A label' },\n" +
1028
+ " '/bar': {\n" +
1029
+ " component: () => null,\n" +
1030
+ " label: { id: 'test.msg', defaultMessage: 'A label' },\n" +
1031
+ " segments: { '/foo': ... }\n" +
1032
+ " }\n" +
1033
+ " // should not have key 'segments'\n" +
1034
+ "}",
1035
+ ));
1036
+ });
1037
+
1038
+ describe("<object> to be a module structure", () => {
1039
+ it("passes when subject is an index of only pages with icons", () =>
1040
+ expect(
1041
+ () =>
1042
+ expect(
1043
+ {
1044
+ foo: {
1045
+ icon: "icon1",
1046
+ component: FakeComponent,
1047
+ label: "A label",
1048
+ },
1049
+ bar: {
1050
+ icon: "icon2",
1051
+ component: FakeComponent,
1052
+ label: { id: "test.msg", defaultMessage: "A label" },
1053
+ subpages: {
1054
+ "/foo": { component: FakeComponent },
1055
+ },
1056
+ },
1057
+ },
1058
+ "to be a module structure",
1059
+ ),
1060
+ "not to throw",
1061
+ ));
1062
+
1063
+ it("fails when subject has keys starting with /", () =>
1064
+ expect(
1065
+ () =>
1066
+ expect(
1067
+ {
1068
+ "/foo": {
1069
+ icon: "icon1",
1070
+ component: FakeComponent,
1071
+ label: "A label",
1072
+ },
1073
+ bar: {
1074
+ icon: "icon2",
1075
+ component: FakeComponent,
1076
+ label: { id: "test.msg", defaultMessage: "A label" },
1077
+ subpages: {
1078
+ "/foo": { component: FakeComponent },
1079
+ },
1080
+ },
1081
+ },
1082
+ "to be a module structure",
1083
+ ),
1084
+ "to throw",
1085
+ "expected\n" +
1086
+ "{\n" +
1087
+ " '/foo': { icon: 'icon1', component: () => null, label: 'A label' },\n" +
1088
+ " bar: {\n" +
1089
+ " icon: 'icon2',\n" +
1090
+ " component: () => null,\n" +
1091
+ " label: { id: 'test.msg', defaultMessage: 'A label' },\n" +
1092
+ " subpages: { '/foo': ... }\n" +
1093
+ " }\n" +
1094
+ "}\n" +
1095
+ "to be a module structure\n" +
1096
+ "\n" +
1097
+ "[\n" +
1098
+ " '/foo', // should not start with '/'\n" +
1099
+ " //\n" +
1100
+ " // /foo\n" +
1101
+ " // ^\n" +
1102
+ " 'bar'\n" +
1103
+ "]",
1104
+ ));
1105
+ });
1106
+ });