orc-shared 5.10.0-dev.7 → 5.10.0-dev.9

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.
@@ -0,0 +1,710 @@
1
+ import ListHelper, { ListInfoPropertyName } from "./ListHelper";
2
+ import Immutable from "immutable";
3
+
4
+ describe("createInitialListInfo", () => {
5
+ it("created expected object", () => {
6
+ const obj = ListHelper.createInitialListInfo();
7
+ expect(obj, "to equal", {
8
+ [ListInfoPropertyName]: {
9
+ sorting: null,
10
+ filters: null,
11
+ scope: null,
12
+ page: null,
13
+ nextPageToLoad: 1,
14
+ index: {},
15
+ list: [],
16
+ totalCount: 0,
17
+ },
18
+ });
19
+ });
20
+
21
+ it("created expected object with additional properties", () => {
22
+ const obj = ListHelper.createInitialListInfo({
23
+ prop1: 123,
24
+ prop2: { subprop: "a" },
25
+ });
26
+ expect(obj, "to equal", {
27
+ [ListInfoPropertyName]: {
28
+ sorting: null,
29
+ filters: null,
30
+ scope: null,
31
+ page: null,
32
+ nextPageToLoad: 1,
33
+ index: {},
34
+ list: [],
35
+ totalCount: 0,
36
+ prop1: 123,
37
+ prop2: { subprop: "a" },
38
+ },
39
+ });
40
+ });
41
+
42
+ it("created expected object with additional properties and overriding default values", () => {
43
+ const obj = ListHelper.createInitialListInfo({
44
+ sorting: { a: 1 },
45
+ filters: { b: 1 },
46
+ scope: "canada",
47
+ page: 1,
48
+ nextPageToLoad: 2,
49
+ index: { c: 1 },
50
+ list: [1, 2, 3],
51
+ totalCount: 10,
52
+ prop1: 123,
53
+ prop2: { subprop: "a" },
54
+ });
55
+ expect(obj, "to equal", {
56
+ [ListInfoPropertyName]: {
57
+ sorting: { a: 1 },
58
+ filters: { b: 1 },
59
+ scope: "canada",
60
+ page: 1,
61
+ nextPageToLoad: 2,
62
+ index: { c: 1 },
63
+ list: [1, 2, 3],
64
+ totalCount: 10,
65
+ prop1: 123,
66
+ prop2: { subprop: "a" },
67
+ },
68
+ });
69
+ });
70
+ });
71
+
72
+ describe("createListInfoFrom", () => {
73
+ it("created expected object", () => {
74
+ const obj = ListHelper.createListInfoFrom();
75
+ expect(obj, "to equal", {
76
+ [ListInfoPropertyName]: {
77
+ sorting: null,
78
+ filters: null,
79
+ scope: null,
80
+ page: null,
81
+ nextPageToLoad: 1,
82
+ index: {},
83
+ list: [],
84
+ totalCount: 0,
85
+ },
86
+ });
87
+ });
88
+
89
+ it("created expected object with additional properties", () => {
90
+ const obj = ListHelper.createListInfoFrom({
91
+ prop1: 123,
92
+ prop2: { subprop: "a" },
93
+ });
94
+ expect(obj, "to equal", {
95
+ [ListInfoPropertyName]: {
96
+ sorting: null,
97
+ filters: null,
98
+ scope: null,
99
+ page: null,
100
+ nextPageToLoad: 1,
101
+ index: {},
102
+ list: [],
103
+ totalCount: 0,
104
+ prop1: 123,
105
+ prop2: { subprop: "a" },
106
+ },
107
+ });
108
+ });
109
+
110
+ it("created expected object with additional properties and overriding default values", () => {
111
+ const obj = ListHelper.createListInfoFrom({
112
+ sorting: { a: 1 },
113
+ filters: { b: 1 },
114
+ scope: "canada",
115
+ page: 1,
116
+ nextPageToLoad: 2,
117
+ index: { c: 1 },
118
+ list: [1, 2, 3],
119
+ totalCount: 10,
120
+ prop1: 123,
121
+ prop2: { subprop: "a" },
122
+ });
123
+ expect(obj, "to equal", {
124
+ [ListInfoPropertyName]: {
125
+ sorting: { a: 1 },
126
+ filters: { b: 1 },
127
+ scope: "canada",
128
+ page: 1,
129
+ nextPageToLoad: 2,
130
+ index: { c: 1 },
131
+ list: [1, 2, 3],
132
+ totalCount: 10,
133
+ prop1: 123,
134
+ prop2: { subprop: "a" },
135
+ },
136
+ });
137
+ });
138
+ });
139
+
140
+ describe("ListSelectorHelper", () => {
141
+ const initialState = Immutable.fromJS(
142
+ ListHelper.createListInfoFrom({
143
+ sorting: { a: 1 },
144
+ filters: { b: 1 },
145
+ scope: "canada",
146
+ page: 1,
147
+ nextPageToLoad: 2,
148
+ index: { c: 1 },
149
+ list: [1, 2, 3],
150
+ totalCount: 10,
151
+ prop1: 123,
152
+ prop2: { subprop: "a" },
153
+ }),
154
+ );
155
+
156
+ it("getNextPageToLoad", () => {
157
+ const value = ListHelper.selector.getNextPageToLoad(initialState);
158
+ expect(value, "to equal", 2);
159
+ });
160
+
161
+ it("getList", () => {
162
+ const value = ListHelper.selector.getList(initialState);
163
+ expect(value, "to equal", Immutable.fromJS([1, 2, 3]));
164
+ });
165
+
166
+ it("getIndex", () => {
167
+ const value = ListHelper.selector.getIndex(initialState);
168
+ expect(value, "to equal", Immutable.fromJS({ c: 1 }));
169
+ });
170
+
171
+ it("getCurrentInfo", () => {
172
+ const value = ListHelper.selector.getCurrentInfo(initialState);
173
+ expect(value, "to equal", {
174
+ currentSorting: { a: 1 },
175
+ currentFilters: { b: 1 },
176
+ currentScope: "canada",
177
+ currentPage: 1,
178
+ totalCount: 10,
179
+ prop1: 123,
180
+ prop2: { subprop: "a" },
181
+ });
182
+ });
183
+
184
+ it("getCurrentInfo without filters or sorting", () => {
185
+ const value = ListHelper.selector.getCurrentInfo(
186
+ initialState.setIn([ListInfoPropertyName, "filters"], null).setIn([ListInfoPropertyName, "sorting"], null),
187
+ );
188
+ expect(value, "to equal", {
189
+ currentSorting: undefined,
190
+ currentFilters: undefined,
191
+ currentScope: "canada",
192
+ currentPage: 1,
193
+ totalCount: 10,
194
+ prop1: 123,
195
+ prop2: { subprop: "a" },
196
+ });
197
+ });
198
+
199
+ it("getCurrentInfo with empty state", () => {
200
+ const value = ListHelper.selector.getCurrentInfo(initialState.set(ListInfoPropertyName));
201
+ expect(value, "to equal", {
202
+ currentSorting: undefined,
203
+ currentFilters: undefined,
204
+ currentScope: undefined,
205
+ currentPage: undefined,
206
+ totalCount: undefined,
207
+ });
208
+ });
209
+ });
210
+
211
+ describe("ListReducerHelper", () => {
212
+ const initialState = Immutable.fromJS(
213
+ ListHelper.createListInfoFrom({
214
+ sorting: { a: 1 },
215
+ filters: { b: 1 },
216
+ scope: "canada",
217
+ page: 1,
218
+ nextPageToLoad: 2,
219
+ index: { c: 1 },
220
+ list: [1, 2, 3],
221
+ totalCount: 10,
222
+ prop1: 123,
223
+ prop2: { subprop: "a" },
224
+ }),
225
+ );
226
+
227
+ it("setNextPageToLoad", () => {
228
+ const newState = ListHelper.reducer.setNextPageToLoad(initialState, 888);
229
+ expect(
230
+ newState,
231
+ "to equal",
232
+ Immutable.fromJS(
233
+ ListHelper.createListInfoFrom({
234
+ sorting: { a: 1 },
235
+ filters: { b: 1 },
236
+ scope: "canada",
237
+ page: 1,
238
+ nextPageToLoad: 888,
239
+ index: { c: 1 },
240
+ list: [1, 2, 3],
241
+ totalCount: 10,
242
+ prop1: 123,
243
+ prop2: { subprop: "a" },
244
+ }),
245
+ ),
246
+ );
247
+ });
248
+
249
+ it("setResults first page", () => {
250
+ const listInfo = {
251
+ indexEntities: { d: 1 },
252
+ listEntities: [4, 5, 6],
253
+ totalCount: 222,
254
+ };
255
+ const newState = ListHelper.reducer.setResults(
256
+ initialState.setIn([ListInfoPropertyName, "nextPageToLoad"], 1),
257
+ listInfo,
258
+ );
259
+ expect(
260
+ newState,
261
+ "to equal",
262
+ Immutable.fromJS(
263
+ ListHelper.createListInfoFrom({
264
+ sorting: { a: 1 },
265
+ filters: { b: 1 },
266
+ scope: "canada",
267
+ page: 1,
268
+ nextPageToLoad: 1,
269
+ index: { d: 1 },
270
+ list: [4, 5, 6],
271
+ totalCount: 222,
272
+ prop1: 123,
273
+ prop2: { subprop: "a" },
274
+ }),
275
+ ),
276
+ );
277
+ });
278
+
279
+ it("setResults with null entities", () => {
280
+ const listInfo = {
281
+ indexEntities: null,
282
+ listEntities: [4, 5, 6],
283
+ totalCount: 222,
284
+ };
285
+ const newState = ListHelper.reducer.setResults(
286
+ initialState.setIn([ListInfoPropertyName, "nextPageToLoad"], 1),
287
+ listInfo,
288
+ false,
289
+ );
290
+ expect(
291
+ newState,
292
+ "to equal",
293
+ Immutable.fromJS(
294
+ ListHelper.createListInfoFrom({
295
+ sorting: { a: 1 },
296
+ filters: { b: 1 },
297
+ scope: "canada",
298
+ page: 1,
299
+ nextPageToLoad: 1,
300
+ index: {},
301
+ list: [4, 5, 6],
302
+ totalCount: 222,
303
+ prop1: 123,
304
+ prop2: { subprop: "a" },
305
+ }),
306
+ ),
307
+ );
308
+ });
309
+
310
+ it("setResults another page", () => {
311
+ const listInfo = {
312
+ indexEntities: { d: 1 },
313
+ listEntities: [4, 5, 6],
314
+ totalCount: 222,
315
+ };
316
+ const newState = ListHelper.reducer.setResults(initialState, listInfo, false);
317
+ expect(
318
+ newState,
319
+ "to equal",
320
+ Immutable.fromJS(
321
+ ListHelper.createListInfoFrom({
322
+ sorting: { a: 1 },
323
+ filters: { b: 1 },
324
+ scope: "canada",
325
+ page: 1,
326
+ nextPageToLoad: 2,
327
+ index: { c: 1, d: 1 },
328
+ list: [1, 2, 3, 4, 5, 6],
329
+ totalCount: 222,
330
+ prop1: 123,
331
+ prop2: { subprop: "a" },
332
+ }),
333
+ ),
334
+ );
335
+ });
336
+
337
+ it("setResults force reset", () => {
338
+ const listInfo = {
339
+ indexEntities: { d: 1 },
340
+ listEntities: [4, 5, 6],
341
+ totalCount: 222,
342
+ };
343
+ const newState = ListHelper.reducer.setResults(initialState, listInfo, true);
344
+ expect(
345
+ newState,
346
+ "to equal",
347
+ Immutable.fromJS(
348
+ ListHelper.createListInfoFrom({
349
+ sorting: { a: 1 },
350
+ filters: { b: 1 },
351
+ scope: "canada",
352
+ page: 1,
353
+ nextPageToLoad: 2,
354
+ index: { d: 1 },
355
+ list: [4, 5, 6],
356
+ totalCount: 222,
357
+ prop1: 123,
358
+ prop2: { subprop: "a" },
359
+ }),
360
+ ),
361
+ );
362
+ });
363
+
364
+ it("setCurrentInfo with reset", () => {
365
+ const info = {
366
+ resetList: true,
367
+ scope: "usa",
368
+ filters: { e: 1 },
369
+ sorting: { f: 1 },
370
+ prop1: 456,
371
+ prop2: { subprop: "b" },
372
+ };
373
+ const newState = ListHelper.reducer.setCurrentInfo(initialState, info);
374
+ expect(
375
+ newState,
376
+ "to equal",
377
+ Immutable.fromJS(
378
+ ListHelper.createListInfoFrom({
379
+ sorting: { f: 1 },
380
+ filters: { e: 1 },
381
+ scope: "usa",
382
+ page: null,
383
+ nextPageToLoad: 1,
384
+ index: {},
385
+ list: [],
386
+ totalCount: 0,
387
+ prop1: 456,
388
+ prop2: { subprop: "b" },
389
+ }),
390
+ ),
391
+ );
392
+ });
393
+
394
+ it("setCurrentInfo without reset", () => {
395
+ const info = {
396
+ resetList: false,
397
+ scope: "usa",
398
+ filters: { e: 1 },
399
+ sorting: { f: 1 },
400
+ prop1: 456,
401
+ prop2: { subprop: "b" },
402
+ };
403
+ const newState = ListHelper.reducer.setCurrentInfo(initialState, info);
404
+ expect(
405
+ newState,
406
+ "to equal",
407
+ Immutable.fromJS(
408
+ ListHelper.createListInfoFrom({
409
+ sorting: { f: 1 },
410
+ filters: { e: 1 },
411
+ scope: "usa",
412
+ page: 2,
413
+ nextPageToLoad: 2,
414
+ index: { c: 1 },
415
+ list: [1, 2, 3],
416
+ totalCount: 10,
417
+ prop1: 456,
418
+ prop2: { subprop: "b" },
419
+ }),
420
+ ),
421
+ );
422
+ });
423
+
424
+ it("setCurrentInfo without reset and without all other props", () => {
425
+ const info = {
426
+ resetList: false,
427
+ scope: "usa",
428
+ filters: { e: 1 },
429
+ sorting: { f: 1 },
430
+ prop1: 456,
431
+ prop3: 789,
432
+ };
433
+ const newState = ListHelper.reducer.setCurrentInfo(initialState, info);
434
+ expect(
435
+ newState,
436
+ "to equal",
437
+ Immutable.fromJS(
438
+ ListHelper.createListInfoFrom({
439
+ sorting: { f: 1 },
440
+ filters: { e: 1 },
441
+ scope: "usa",
442
+ page: 2,
443
+ nextPageToLoad: 2,
444
+ index: { c: 1 },
445
+ list: [1, 2, 3],
446
+ totalCount: 10,
447
+ prop1: 456,
448
+ prop3: 789,
449
+ }),
450
+ ),
451
+ );
452
+ });
453
+
454
+ it("setCurrentInfo without reset and without any other props", () => {
455
+ const info = {
456
+ resetList: false,
457
+ scope: "usa",
458
+ filters: { e: 1 },
459
+ sorting: { f: 1 },
460
+ };
461
+ const newState = ListHelper.reducer.setCurrentInfo(initialState, info);
462
+ expect(
463
+ newState,
464
+ "to equal",
465
+ Immutable.fromJS(
466
+ ListHelper.createListInfoFrom({
467
+ sorting: { f: 1 },
468
+ filters: { e: 1 },
469
+ scope: "usa",
470
+ page: 2,
471
+ nextPageToLoad: 2,
472
+ index: { c: 1 },
473
+ list: [1, 2, 3],
474
+ totalCount: 10,
475
+ }),
476
+ ),
477
+ );
478
+ });
479
+
480
+ it("setCurrentInfo without filters and sorting", () => {
481
+ const info = {
482
+ resetList: false,
483
+ scope: "usa",
484
+ filters: null,
485
+ sorting: null,
486
+ prop1: 456,
487
+ prop2: { subprop: "b" },
488
+ };
489
+ const newState = ListHelper.reducer.setCurrentInfo(initialState, info);
490
+ expect(
491
+ newState,
492
+ "to equal",
493
+ Immutable.fromJS(
494
+ ListHelper.createListInfoFrom({
495
+ sorting: null,
496
+ filters: null,
497
+ scope: "usa",
498
+ page: 2,
499
+ nextPageToLoad: 2,
500
+ index: { c: 1 },
501
+ list: [1, 2, 3],
502
+ totalCount: 10,
503
+ prop1: 456,
504
+ prop2: { subprop: "b" },
505
+ }),
506
+ ),
507
+ );
508
+ });
509
+
510
+ it("setCurrentInfo without details", () => {
511
+ const newState = ListHelper.reducer.setCurrentInfo(initialState);
512
+ expect(
513
+ newState,
514
+ "to equal",
515
+ Immutable.fromJS(
516
+ ListHelper.createListInfoFrom({
517
+ sorting: null,
518
+ filters: null,
519
+ scope: null,
520
+ page: 2,
521
+ nextPageToLoad: 2,
522
+ index: { c: 1 },
523
+ list: [1, 2, 3],
524
+ totalCount: 10,
525
+ }),
526
+ ),
527
+ );
528
+ });
529
+
530
+ it("addIndexWithMutations", () => {
531
+ const newState = initialState.withMutations(s => ListHelper.reducer.addIndexWithMutations(s, "d", 888));
532
+ expect(
533
+ newState,
534
+ "to equal",
535
+ Immutable.fromJS(
536
+ ListHelper.createListInfoFrom({
537
+ sorting: { a: 1 },
538
+ filters: { b: 1 },
539
+ scope: "canada",
540
+ page: 1,
541
+ nextPageToLoad: 2,
542
+ index: { c: 1, d: 888 },
543
+ list: [1, 2, 3],
544
+ totalCount: 10,
545
+ prop1: 123,
546
+ prop2: { subprop: "a" },
547
+ }),
548
+ ),
549
+ );
550
+ });
551
+
552
+ it("appendIdToListWithMutations", () => {
553
+ const newState = initialState.withMutations(s => ListHelper.reducer.appendIdToListWithMutations(s, 888));
554
+ expect(
555
+ newState,
556
+ "to equal",
557
+ Immutable.fromJS(
558
+ ListHelper.createListInfoFrom({
559
+ sorting: { a: 1 },
560
+ filters: { b: 1 },
561
+ scope: "canada",
562
+ page: 1,
563
+ nextPageToLoad: 2,
564
+ index: { c: 1 },
565
+ list: [1, 2, 3, 888],
566
+ totalCount: 10,
567
+ prop1: 123,
568
+ prop2: { subprop: "a" },
569
+ }),
570
+ ),
571
+ );
572
+ });
573
+
574
+ it("updateIndexWithMutations existing", () => {
575
+ const newState = initialState.withMutations(s => ListHelper.reducer.updateIndexWithMutations(s, "c", 888));
576
+ expect(
577
+ newState,
578
+ "to equal",
579
+ Immutable.fromJS(
580
+ ListHelper.createListInfoFrom({
581
+ sorting: { a: 1 },
582
+ filters: { b: 1 },
583
+ scope: "canada",
584
+ page: 1,
585
+ nextPageToLoad: 2,
586
+ index: { c: 888 },
587
+ list: [1, 2, 3],
588
+ totalCount: 10,
589
+ prop1: 123,
590
+ prop2: { subprop: "a" },
591
+ }),
592
+ ),
593
+ );
594
+ });
595
+
596
+ it("updateIndexWithMutations missing", () => {
597
+ const newState = initialState.withMutations(s => ListHelper.reducer.updateIndexWithMutations(s, "d", 888));
598
+ expect(
599
+ newState,
600
+ "to equal",
601
+ Immutable.fromJS(
602
+ ListHelper.createListInfoFrom({
603
+ sorting: { a: 1 },
604
+ filters: { b: 1 },
605
+ scope: "canada",
606
+ page: 1,
607
+ nextPageToLoad: 2,
608
+ index: { c: 1 },
609
+ list: [1, 2, 3],
610
+ totalCount: 10,
611
+ prop1: 123,
612
+ prop2: { subprop: "a" },
613
+ }),
614
+ ),
615
+ );
616
+ });
617
+
618
+ it("removeFromIndexWithMutations existing", () => {
619
+ const newState = initialState.withMutations(s => ListHelper.reducer.removeFromIndexWithMutations(s, "c"));
620
+ expect(
621
+ newState,
622
+ "to equal",
623
+ Immutable.fromJS(
624
+ ListHelper.createListInfoFrom({
625
+ sorting: { a: 1 },
626
+ filters: { b: 1 },
627
+ scope: "canada",
628
+ page: 1,
629
+ nextPageToLoad: 2,
630
+ index: {},
631
+ list: [1, 2, 3],
632
+ totalCount: 10,
633
+ prop1: 123,
634
+ prop2: { subprop: "a" },
635
+ }),
636
+ ),
637
+ );
638
+ });
639
+
640
+ it("removeFromIndexWithMutations missing", () => {
641
+ const newState = initialState.withMutations(s => ListHelper.reducer.removeFromIndexWithMutations(s, "d"));
642
+ expect(
643
+ newState,
644
+ "to equal",
645
+ Immutable.fromJS(
646
+ ListHelper.createListInfoFrom({
647
+ sorting: { a: 1 },
648
+ filters: { b: 1 },
649
+ scope: "canada",
650
+ page: 1,
651
+ nextPageToLoad: 2,
652
+ index: { c: 1 },
653
+ list: [1, 2, 3],
654
+ totalCount: 10,
655
+ prop1: 123,
656
+ prop2: { subprop: "a" },
657
+ }),
658
+ ),
659
+ );
660
+ });
661
+
662
+ it("resetListInfo without properties to keep", () => {
663
+ const newState = ListHelper.reducer.resetListInfo(initialState);
664
+ expect(
665
+ newState,
666
+ "to equal",
667
+ Immutable.fromJS(
668
+ ListHelper.createListInfoFrom({
669
+ sorting: null,
670
+ filters: null,
671
+ scope: null,
672
+ page: null,
673
+ nextPageToLoad: 1,
674
+ index: {},
675
+ list: [],
676
+ totalCount: 0,
677
+ prop1: 123,
678
+ prop2: { subprop: "a" },
679
+ }),
680
+ ),
681
+ );
682
+ });
683
+
684
+ it("resetListInfo with properties to keep", () => {
685
+ const newState = ListHelper.reducer.resetListInfo(initialState, {
686
+ filters: true,
687
+ sorting: true,
688
+ scope: true,
689
+ page: true,
690
+ });
691
+ expect(
692
+ newState,
693
+ "to equal",
694
+ Immutable.fromJS(
695
+ ListHelper.createListInfoFrom({
696
+ sorting: { a: 1 },
697
+ filters: { b: 1 },
698
+ scope: "canada",
699
+ page: 1,
700
+ nextPageToLoad: 1,
701
+ index: {},
702
+ list: [],
703
+ totalCount: 0,
704
+ prop1: 123,
705
+ prop2: { subprop: "a" },
706
+ }),
707
+ ),
708
+ );
709
+ });
710
+ });