-
Notifications
You must be signed in to change notification settings - Fork 0
/
OptionsListUtilsTest.js
1001 lines (840 loc) · 44.8 KB
/
OptionsListUtilsTest.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import _ from 'underscore';
import Onyx from 'react-native-onyx';
import * as OptionsListUtils from '../../src/libs/OptionsListUtils';
import ONYXKEYS from '../../src/ONYXKEYS';
import waitForPromisesToResolve from '../utils/waitForPromisesToResolve';
import CONST from '../../src/CONST';
import * as Report from '../../src/libs/actions/Report';
describe('OptionsListUtils', () => {
// Given a set of reports with both single participants and multiple participants some pinned and some not
const REPORTS = {
1: {
lastVisitedTimestamp: 1610666739295,
lastMessageTimestamp: 15,
isPinned: false,
reportID: 1,
participants: ['tonystark@expensify.com', 'reedrichards@expensify.com'],
reportName: 'Iron Man, Mister Fantastic',
unreadActionCount: 1,
},
2: {
lastVisitedTimestamp: 1610666739296,
lastMessageTimestamp: 16,
isPinned: false,
reportID: 2,
participants: ['peterparker@expensify.com'],
reportName: 'Spider-Man',
unreadActionCount: 1,
},
// This is the only report we are pinning in this test
3: {
lastVisitedTimestamp: 1610666739297,
lastMessageTimestamp: 17,
isPinned: true,
reportID: 3,
participants: ['reedrichards@expensify.com'],
reportName: 'Mister Fantastic',
unreadActionCount: 0,
},
4: {
lastVisitedTimestamp: 1610666739298,
lastMessageTimestamp: 18,
isPinned: false,
reportID: 4,
participants: ['tchalla@expensify.com'],
reportName: 'Black Panther',
unreadActionCount: 1,
},
5: {
lastVisitedTimestamp: 1610666739299,
lastMessageTimestamp: 19,
isPinned: false,
reportID: 5,
participants: ['suestorm@expensify.com'],
reportName: 'Invisible Woman',
unreadActionCount: 1,
},
6: {
lastVisitedTimestamp: 1610666739300,
lastMessageTimestamp: 20,
isPinned: false,
reportID: 6,
participants: ['thor@expensify.com'],
reportName: 'Thor',
unreadActionCount: 0,
},
// Note: This report has the largest lastMessageTimestamp
7: {
lastVisitedTimestamp: 1610666739301,
lastMessageTimestamp: 1611282169,
isPinned: false,
reportID: 7,
participants: ['steverogers@expensify.com'],
reportName: 'Captain America',
unreadActionCount: 1,
},
// Note: This report has no lastMessageTimestamp
8: {
lastVisitedTimestamp: 1610666739301,
lastMessageTimestamp: 0,
isPinned: false,
reportID: 8,
participants: ['galactus_herald@expensify.com'],
reportName: 'Silver Surfer',
unreadActionCount: 0,
},
// Note: This report has an IOU
9: {
lastVisitedTimestamp: 1610666739302,
lastMessageTimestamp: 1611282168,
isPinned: false,
reportID: 9,
participants: ['mistersinister@marauders.com'],
reportName: 'Mister Sinister',
unreadActionCount: 0,
iouReportID: 100,
hasOutstandingIOU: true,
},
};
// And a set of personalDetails some with existing reports and some without
const PERSONAL_DETAILS = {
// These exist in our reports
'reedrichards@expensify.com': {
displayName: 'Mister Fantastic',
login: 'reedrichards@expensify.com',
},
'tonystark@expensify.com': {
displayName: 'Iron Man',
login: 'tonystark@expensify.com',
},
'peterparker@expensify.com': {
displayName: 'Spider-Man',
login: 'peterparker@expensify.com',
},
'tchalla@expensify.com': {
displayName: 'Black Panther',
login: 'tchalla@expensify.com',
},
'suestorm@expensify.com': {
displayName: 'Invisible Woman',
login: 'suestorm@expensify.com',
},
'thor@expensify.com': {
displayName: 'Thor',
login: 'thor@expensify.com',
},
'steverogers@expensify.com': {
displayName: 'Captain America',
login: 'steverogers@expensify.com',
},
'mistersinister@marauders.com': {
displayName: 'Mr Sinister',
login: 'mistersinister@marauders.com',
},
// These do not exist in reports at all
'natasharomanoff@expensify.com': {
displayName: 'Black Widow',
login: 'natasharomanoff@expensify.com',
},
'brucebanner@expensify.com': {
displayName: 'The Incredible Hulk',
login: 'brucebanner@expensify.com',
},
};
const REPORTS_WITH_CONCIERGE = {
...REPORTS,
10: {
lastVisitedTimestamp: 1610666739302,
lastMessageTimestamp: 22,
isPinned: false,
reportID: 10,
participants: ['concierge@expensify.com'],
reportName: 'Concierge',
unreadActionCount: 1,
},
};
const REPORTS_WITH_CHRONOS = {
...REPORTS,
11: {
lastVisitedTimestamp: 1610666739302,
lastMessageTimestamp: 22,
isPinned: false,
reportID: 10,
participants: ['chronos@expensify.com'],
reportName: 'Chronos',
unreadActionCount: 1,
},
};
const REPORTS_WITH_RECEIPTS = {
...REPORTS,
12: {
lastVisitedTimestamp: 1610666739302,
lastMessageTimestamp: 22,
isPinned: false,
reportID: 10,
participants: ['receipts@expensify.com'],
reportName: 'Receipts',
unreadActionCount: 1,
},
};
const REPORTS_WITH_MORE_PINS = {
...REPORTS,
13: {
lastVisitedTimestamp: 1610666739302,
lastMessageTimestamp: 22,
isPinned: true,
reportID: 13,
participants: ['d_email@email.com'],
reportName: 'D report name',
unreadActionCount: 0,
},
14: {
lastVisitedTimestamp: 1610666732302,
lastMessageTimestamp: 22,
isPinned: true,
reportID: 14,
participants: ['z_email@email.com'],
reportName: 'Z Report Name',
unreadActionCount: 0,
},
};
const PERSONAL_DETAILS_WITH_CONCIERGE = {
...PERSONAL_DETAILS,
'concierge@expensify.com': {
displayName: 'Concierge',
login: 'concierge@expensify.com',
},
};
const PERSONAL_DETAILS_WITH_CHRONOS = {
...PERSONAL_DETAILS,
'chronos@expensify.com': {
displayName: 'Chronos',
login: 'chronos@expensify.com',
},
};
const PERSONAL_DETAILS_WITH_RECEIPTS = {
...PERSONAL_DETAILS,
'receipts@expensify.com': {
displayName: 'Receipts',
login: 'receipts@expensify.com',
},
};
// Set the currently logged in user, report data, and personal details
beforeAll(() => {
Onyx.init({
keys: ONYXKEYS,
initialKeyStates: {
[ONYXKEYS.SESSION]: {email: 'tonystark@expensify.com'},
[`${ONYXKEYS.COLLECTION.REPORT_IOUS}100`]: {
ownerEmail: 'mistersinister@marauders.com',
total: '1000',
},
},
});
Onyx.registerLogger(() => {});
return waitForPromisesToResolve();
});
it('getSearchOptions()', () => {
// When we filter in the Search view without providing a searchValue
let results = OptionsListUtils.getSearchOptions(REPORTS, PERSONAL_DETAILS, '');
// Then the 2 personalDetails that don't have reports should be returned
expect(results.personalDetails.length).toBe(2);
// Then all of the reports should be shown, including the one that has no message on them.
expect(results.recentReports.length).toBe(_.size(REPORTS));
// When we filter again but provide a searchValue
results = OptionsListUtils.getSearchOptions(REPORTS, PERSONAL_DETAILS, 'spider');
// Then only one option should be returned and it's the one matching the search value
expect(results.recentReports.length).toBe(1);
expect(results.recentReports[0].login).toBe('peterparker@expensify.com');
// When we filter again but provide a searchValue that should match multiple times
results = OptionsListUtils.getSearchOptions(REPORTS, PERSONAL_DETAILS, 'fantastic');
// Then we get both values with the pinned value still on top
expect(results.recentReports.length).toBe(2);
expect(results.recentReports[0].text).toBe('Mister Fantastic');
});
it('getSearchOptions() with message timeStamp order', () => {
// When we filter in the Search view without providing a searchValue
let results = OptionsListUtils.getSearchOptions(REPORTS, PERSONAL_DETAILS, '', [], true);
// Then the 2 personalDetails that don't have reports should be returned
expect(results.personalDetails.length).toBe(2);
// Then all of the reports should be shown, including the one that has no message on them.
expect(results.recentReports.length).toBe(_.size(REPORTS));
// When we filter again but provide a searchValue
results = OptionsListUtils.getSearchOptions(REPORTS, PERSONAL_DETAILS, 'spider', [], true);
// Then only one option should be returned and it's the one matching the search value
expect(results.recentReports.length).toBe(1);
expect(results.recentReports[0].login).toBe('peterparker@expensify.com');
// When we filter again but provide a searchValue that should match multiple times
results = OptionsListUtils.getSearchOptions(REPORTS, PERSONAL_DETAILS, '.com', [], true);
// Then we get both values with the pinned value still on top
expect(results.recentReports.length).toBe(11);
expect(results.recentReports[0].text).toBe('Captain America');
// When we filter again but provide a searchValue that should match multiple times
results = OptionsListUtils.getSearchOptions(REPORTS, PERSONAL_DETAILS, '.com', [], false);
// Then we get both values with the pinned value still on top
expect(results.recentReports.length).toBe(11);
expect(results.recentReports[0].text).toBe('Mister Sinister');
});
it('getNewChatOptions()', () => {
// maxRecentReportsToShow in src/libs/OptionsListUtils.js
const MAX_RECENT_REPORTS = 5;
// When we call getNewChatOptions() with no search value
let results = OptionsListUtils.getNewChatOptions(REPORTS, PERSONAL_DETAILS, [], '');
// We should expect maximimum of 5 recent reports to be returned
expect(results.recentReports.length).toBe(MAX_RECENT_REPORTS);
// We should expect all personalDetails to be returned,
// minus the currently logged in user and recent reports count
expect(results.personalDetails.length).toBe(_.size(PERSONAL_DETAILS) - 1 - MAX_RECENT_REPORTS);
// Then the result which has an existing report should also have the reportID attached
const personalDetailWithExistingReport = _.find(
results.personalDetails,
personalDetail => personalDetail.login === 'peterparker@expensify.com',
);
expect(personalDetailWithExistingReport.reportID).toBe(2);
// When we provide a search value that does not match any personal details
results = OptionsListUtils.getNewChatOptions(REPORTS, PERSONAL_DETAILS, [], 'magneto');
// Then no options will be returned
expect(results.personalDetails.length).toBe(0);
// When we provide a search value that matches an email
results = OptionsListUtils.getNewChatOptions(REPORTS, PERSONAL_DETAILS, [], 'peterparker@expensify.com');
// Then one recentReports will be returned and it will be the correct option
// personalDetails should be empty array
expect(results.recentReports.length).toBe(1);
expect(results.recentReports[0].text).toBe('Spider-Man');
expect(results.personalDetails.length).toBe(0);
// When we provide a search value that matches a partial display name or email
results = OptionsListUtils.getNewChatOptions(REPORTS, PERSONAL_DETAILS, [], 'man');
// Then several options will be returned and they will be each have the search string in their email or name
// even though the currently logged in user matches they should not show.
expect(results.personalDetails.length).toBe(1);
expect(results.recentReports.length).toBe(2);
expect(results.personalDetails[0].login).toBe('natasharomanoff@expensify.com');
expect(results.recentReports[0].text).toBe('Invisible Woman');
expect(results.recentReports[1].text).toBe('Spider-Man');
// Test for Concierge's existence in chat options
results = OptionsListUtils.getNewChatOptions(REPORTS_WITH_CONCIERGE, PERSONAL_DETAILS_WITH_CONCIERGE);
// Concierge is included in the results by default. We should expect all the personalDetails to show
// (minus the 5 that are already showing and the currently logged in user)
expect(results.personalDetails.length).toBe(_.size(PERSONAL_DETAILS_WITH_CONCIERGE) - 1 - MAX_RECENT_REPORTS);
expect(results.recentReports).toEqual(
expect.arrayContaining([
expect.objectContaining({login: 'concierge@expensify.com'}),
]),
);
// Test by excluding Concierge from the results
results = OptionsListUtils.getNewChatOptions(
REPORTS_WITH_CONCIERGE, PERSONAL_DETAILS_WITH_CONCIERGE, [], '', [], [CONST.EMAIL.CONCIERGE],
);
// All the personalDetails should be returned minus the currently logged in user and Concierge
expect(results.personalDetails.length).toBe(_.size(PERSONAL_DETAILS_WITH_CONCIERGE) - 2 - MAX_RECENT_REPORTS);
expect(results.personalDetails).not.toEqual(
expect.arrayContaining([
expect.objectContaining({login: 'concierge@expensify.com'}),
]),
);
// Test by excluding Chronos from the results
results = OptionsListUtils.getNewChatOptions(
REPORTS_WITH_CHRONOS, PERSONAL_DETAILS_WITH_CHRONOS, [], '', [], [CONST.EMAIL.CHRONOS],
);
// All the personalDetails should be returned minus the currently logged in user and Concierge
expect(results.personalDetails.length).toBe(_.size(PERSONAL_DETAILS_WITH_CHRONOS) - 2 - MAX_RECENT_REPORTS);
expect(results.personalDetails).not.toEqual(
expect.arrayContaining([
expect.objectContaining({login: 'chronos@expensify.com'}),
]),
);
// Test by excluding Receipts from the results
results = OptionsListUtils.getNewChatOptions(
REPORTS_WITH_RECEIPTS, PERSONAL_DETAILS_WITH_RECEIPTS, [], '', [], [CONST.EMAIL.RECEIPTS],
);
// All the personalDetails should be returned minus the currently logged in user and Concierge
expect(results.personalDetails.length).toBe(_.size(PERSONAL_DETAILS_WITH_RECEIPTS) - 2 - MAX_RECENT_REPORTS);
expect(results.personalDetails).not.toEqual(
expect.arrayContaining([
expect.objectContaining({login: 'receipts@expensify.com'}),
]),
);
});
it('getNewChatOptions() using message timeStamp order', () => {
// maxRecentReportsToShow in src/libs/OptionsListUtils.js
const MAX_RECENT_REPORTS = 5;
// When we call getNewChatOptions() with no search value
let results = OptionsListUtils.getNewChatOptions(REPORTS, PERSONAL_DETAILS, [], '', [], [], true);
// We should expect maximimum of 5 recent reports to be returned
expect(results.recentReports.length).toBe(MAX_RECENT_REPORTS);
// We should expect all personalDetails to be returned,
// minus the currently logged in user and recent reports count
expect(results.personalDetails.length).toBe(_.size(PERSONAL_DETAILS) - 1 - MAX_RECENT_REPORTS);
// Then the result which has an existing report should also have the reportID attached
const personalDetailWithExistingReport = _.find(
results.personalDetails,
personalDetail => personalDetail.login === 'peterparker@expensify.com',
);
expect(personalDetailWithExistingReport.reportID).toBe(2);
// When we provide a search value that does not match any personal details
results = OptionsListUtils.getNewChatOptions(REPORTS, PERSONAL_DETAILS, [], 'magneto', [], [], true);
// Then no options will be returned
expect(results.personalDetails.length).toBe(0);
// When we provide a search value that matches an email
results = OptionsListUtils.getNewChatOptions(REPORTS, PERSONAL_DETAILS, [], 'peterparker@expensify.com', [], [], true);
// Then one recentReports will be returned and it will be the correct option
// personalDetails should be empty array
expect(results.recentReports.length).toBe(1);
expect(results.recentReports[0].text).toBe('Spider-Man');
expect(results.personalDetails.length).toBe(0);
// When we provide a search value that matches a partial display name or email
results = OptionsListUtils.getNewChatOptions(REPORTS, PERSONAL_DETAILS, [], '.com', [], [], true);
// Then several options will be returned and they will be each have the search string in their email or name
// even though the currently logged in user matches they should not show.
expect(results.personalDetails.length).toBe(4);
expect(results.recentReports.length).toBe(5);
expect(results.personalDetails[0].login).toBe('reedrichards@expensify.com');
expect(results.recentReports[0].text).toBe('Captain America');
expect(results.recentReports[1].text).toBe('Mister Sinister');
expect(results.recentReports[2].text).toBe('Thor');
// When we provide a search value that matches a partial display name or email
results = OptionsListUtils.getNewChatOptions(REPORTS, PERSONAL_DETAILS, [], '.com', [], [], false);
// Then several options will be returned and they will be each have the search string in their email or name
// even though the currently logged in user matches they should not show.
expect(results.personalDetails.length).toBe(4);
expect(results.recentReports.length).toBe(5);
expect(results.personalDetails[0].login).toBe('reedrichards@expensify.com');
expect(results.recentReports[0].text).toBe('Mister Sinister');
expect(results.recentReports[1].text).toBe('Captain America');
// Test for Concierge's existence in chat options
results = OptionsListUtils.getNewChatOptions(REPORTS_WITH_CONCIERGE, PERSONAL_DETAILS_WITH_CONCIERGE, [], '', [], [], true);
// Concierge is included in the results by default. We should expect all the personalDetails to show
// (minus the 5 that are already showing and the currently logged in user)
expect(results.personalDetails.length).toBe(_.size(PERSONAL_DETAILS_WITH_CONCIERGE) - 1 - MAX_RECENT_REPORTS);
expect(results.recentReports).toEqual(
expect.arrayContaining([
expect.objectContaining({login: 'concierge@expensify.com'}),
]),
);
// Test by excluding Concierge from the results
results = OptionsListUtils.getNewChatOptions(
REPORTS_WITH_CONCIERGE, PERSONAL_DETAILS_WITH_CONCIERGE, [], '', [], [CONST.EMAIL.CONCIERGE], true,
);
// All the personalDetails should be returned minus the currently logged in user and Concierge
expect(results.personalDetails.length).toBe(_.size(PERSONAL_DETAILS_WITH_CONCIERGE) - 2 - MAX_RECENT_REPORTS);
expect(results.personalDetails).not.toEqual(
expect.arrayContaining([
expect.objectContaining({login: 'concierge@expensify.com'}),
]),
);
// Test by excluding Chronos from the results
results = OptionsListUtils.getNewChatOptions(
REPORTS_WITH_CHRONOS, PERSONAL_DETAILS_WITH_CHRONOS, [], '', [], [CONST.EMAIL.CHRONOS], true,
);
// All the personalDetails should be returned minus the currently logged in user and Concierge
expect(results.personalDetails.length).toBe(_.size(PERSONAL_DETAILS_WITH_CHRONOS) - 2 - MAX_RECENT_REPORTS);
expect(results.personalDetails).not.toEqual(
expect.arrayContaining([
expect.objectContaining({login: 'chronos@expensify.com'}),
]),
);
// Test by excluding Receipts from the results
results = OptionsListUtils.getNewChatOptions(
REPORTS_WITH_RECEIPTS, PERSONAL_DETAILS_WITH_RECEIPTS, [], '', [], [CONST.EMAIL.RECEIPTS], true,
);
// All the personalDetails should be returned minus the currently logged in user and Concierge
expect(results.personalDetails.length).toBe(_.size(PERSONAL_DETAILS_WITH_RECEIPTS) - 2 - MAX_RECENT_REPORTS);
expect(results.personalDetails).not.toEqual(
expect.arrayContaining([
expect.objectContaining({login: 'receipts@expensify.com'}),
]),
);
});
it('getNewChatOptions() for group Chat', () => {
// When we call getNewChatOptions() with no search value
let results = OptionsListUtils.getNewChatOptions(REPORTS, PERSONAL_DETAILS, [], '');
// Then we should expect only a maxmimum of 5 recent reports to be returned
expect(results.recentReports.length).toBe(5);
// And we should expect all the personalDetails to show (minus the 5 that are already
// showing and the currently logged in user)
expect(results.personalDetails.length).toBe(_.size(PERSONAL_DETAILS) - 6);
// And none of our personalDetails should include any of the users with recent reports
const reportLogins = _.map(results.recentReports, reportOption => reportOption.login);
const personalDetailsOverlapWithReports = _.every(results.personalDetails, (
personalDetailOption => _.contains(reportLogins, personalDetailOption.login)
));
expect(personalDetailsOverlapWithReports).toBe(false);
// When we search for an option that is only in a personalDetail with no existing report
results = OptionsListUtils.getNewChatOptions(REPORTS, PERSONAL_DETAILS, [], 'hulk');
// Then reports should return no results
expect(results.recentReports.length).toBe(0);
// And personalDetails should show just one option and it will be the one we expect
expect(results.personalDetails.length).toBe(1);
expect(results.personalDetails[0].login).toBe('brucebanner@expensify.com');
// When we search for an option that matches things in both personalDetails and reports
results = OptionsListUtils.getNewChatOptions(REPORTS, PERSONAL_DETAILS, [], 'man');
// Then all single participant reports that match will show up in the recentReports array
expect(results.recentReports.length).toBe(2);
expect(results.recentReports[0].text).toBe('Invisible Woman');
expect(results.recentReports[1].text).toBe('Spider-Man');
// And logins with no single participant reports will show up in personalDetails
expect(results.personalDetails.length).toBe(1);
expect(results.personalDetails[0].login).toBe('natasharomanoff@expensify.com');
// When we provide no selected options to getNewChatOptions()
results = OptionsListUtils.getNewChatOptions(REPORTS, PERSONAL_DETAILS, [], '', []);
// Then one of our older report options (not in our five most recent) should appear in the personalDetails
// but not in recentReports
expect(_.every(results.recentReports, option => option.login !== 'peterparker@expensify.com')).toBe(true);
expect(_.every(results.personalDetails, option => option.login !== 'peterparker@expensify.com')).toBe(false);
// When we provide a "selected" option to getNewChatOptions()
results = OptionsListUtils.getNewChatOptions(
REPORTS,
PERSONAL_DETAILS,
[],
'',
[{login: 'peterparker@expensify.com'}],
);
// Then the option should not appear anywhere in either list
expect(_.every(results.recentReports, option => option.login !== 'peterparker@expensify.com')).toBe(true);
expect(_.every(results.personalDetails, option => option.login !== 'peterparker@expensify.com')).toBe(true);
// When we add a search term for which no options exist and the searchValue itself
// is not a potential email or phone
results = OptionsListUtils.getNewChatOptions(REPORTS, PERSONAL_DETAILS, [], 'marc@expensify');
// Then we should have no options or personal details at all and also that there is no userToInvite
expect(results.recentReports.length).toBe(0);
expect(results.personalDetails.length).toBe(0);
expect(results.userToInvite).toBe(null);
// When we add a search term for which no options exist and the searchValue itself
// is a potential email
results = OptionsListUtils.getNewChatOptions(REPORTS, PERSONAL_DETAILS, [], 'marc@expensify.com');
// Then we should have no options or personal details at all but there should be a userToInvite
expect(results.recentReports.length).toBe(0);
expect(results.personalDetails.length).toBe(0);
expect(results.userToInvite).not.toBe(null);
// When we add a search term for which no options exist and the searchValue itself
// is a potential phone number without country code added
results = OptionsListUtils.getNewChatOptions(REPORTS, PERSONAL_DETAILS, [], '5005550006');
// Then we should have no options or personal details at all but there should be a userToInvite and the login
// should have the country code included
expect(results.recentReports.length).toBe(0);
expect(results.personalDetails.length).toBe(0);
expect(results.userToInvite).not.toBe(null);
expect(results.userToInvite.login).toBe('+15005550006');
// When we add a search term for which no options exist and the searchValue itself
// is a potential phone number with country code added
results = OptionsListUtils.getNewChatOptions(REPORTS, PERSONAL_DETAILS, [], '+15005550006');
// Then we should have no options or personal details at all but there should be a userToInvite and the login
// should have the country code included
expect(results.recentReports.length).toBe(0);
expect(results.personalDetails.length).toBe(0);
expect(results.userToInvite).not.toBe(null);
expect(results.userToInvite.login).toBe('+15005550006');
// Test Concierge's existence in new group options
results = OptionsListUtils.getNewChatOptions(REPORTS_WITH_CONCIERGE, PERSONAL_DETAILS_WITH_CONCIERGE);
// Concierge is included in the results by default. We should expect all the personalDetails to show
// (minus the 5 that are already showing and the currently logged in user)
expect(results.personalDetails.length).toBe(_.size(PERSONAL_DETAILS_WITH_CONCIERGE) - 6);
expect(results.recentReports).toEqual(
expect.arrayContaining([
expect.objectContaining({login: 'concierge@expensify.com'}),
]),
);
// Test by excluding Concierge from the results
results = OptionsListUtils.getNewChatOptions(
REPORTS_WITH_CONCIERGE,
PERSONAL_DETAILS_WITH_CONCIERGE,
[],
'',
[],
[CONST.EMAIL.CONCIERGE],
);
// We should expect all the personalDetails to show (minus the 5 that are already showing,
// the currently logged in user and Concierge)
expect(results.personalDetails.length).toBe(_.size(PERSONAL_DETAILS_WITH_CONCIERGE) - 7);
expect(results.personalDetails).not.toEqual(
expect.arrayContaining([
expect.objectContaining({login: 'concierge@expensify.com'}),
]),
);
expect(results.recentReports).not.toEqual(
expect.arrayContaining([
expect.objectContaining({login: 'concierge@expensify.com'}),
]),
);
// Test by excluding Chronos from the results
results = OptionsListUtils.getNewChatOptions(
REPORTS_WITH_CHRONOS,
PERSONAL_DETAILS_WITH_CHRONOS,
[],
'',
[],
[CONST.EMAIL.CHRONOS],
);
// We should expect all the personalDetails to show (minus the 5 that are already showing,
// the currently logged in user and Concierge)
expect(results.personalDetails.length).toBe(_.size(PERSONAL_DETAILS_WITH_CHRONOS) - 7);
expect(results.personalDetails).not.toEqual(
expect.arrayContaining([
expect.objectContaining({login: 'chronos@expensify.com'}),
]),
);
expect(results.recentReports).not.toEqual(
expect.arrayContaining([
expect.objectContaining({login: 'chronos@expensify.com'}),
]),
);
// Test by excluding Receipts from the results
results = OptionsListUtils.getNewChatOptions(
REPORTS_WITH_RECEIPTS,
PERSONAL_DETAILS_WITH_RECEIPTS,
[],
'',
[],
[CONST.EMAIL.RECEIPTS],
);
// We should expect all the personalDetails to show (minus the 5 that are already showing,
// the currently logged in user and Concierge)
expect(results.personalDetails.length).toBe(_.size(PERSONAL_DETAILS_WITH_RECEIPTS) - 7);
expect(results.personalDetails).not.toEqual(
expect.arrayContaining([
expect.objectContaining({login: 'receipts@expensify.com'}),
]),
);
expect(results.recentReports).not.toEqual(
expect.arrayContaining([
expect.objectContaining({login: 'receipts@expensify.com'}),
]),
);
});
it('getNewChatOptions() for group Chat using message timeStamp order', () => {
// When we call getNewChatOptions() with no search value
let results = OptionsListUtils.getNewChatOptions(REPORTS, PERSONAL_DETAILS, [], '', [], [], true);
// Then we should expect only a maxmimum of 5 recent reports to be returned
expect(results.recentReports.length).toBe(5);
// And we should expect all the personalDetails to show (minus the 5 that are already
// showing and the currently logged in user)
expect(results.personalDetails.length).toBe(_.size(PERSONAL_DETAILS) - 6);
// And none of our personalDetails should include any of the users with recent reports
const reportLogins = _.map(results.recentReports, reportOption => reportOption.login);
const personalDetailsOverlapWithReports = _.every(results.personalDetails, (
personalDetailOption => _.contains(reportLogins, personalDetailOption.login)
));
expect(personalDetailsOverlapWithReports).toBe(false);
// When we search for an option that is only in a personalDetail with no existing report
results = OptionsListUtils.getNewChatOptions(REPORTS, PERSONAL_DETAILS, [], 'hulk', [], [], true);
// Then reports should return no results
expect(results.recentReports.length).toBe(0);
// And personalDetails should show just one option and it will be the one we expect
expect(results.personalDetails.length).toBe(1);
expect(results.personalDetails[0].login).toBe('brucebanner@expensify.com');
// When we search for an option that matches things in both personalDetails and reports
results = OptionsListUtils.getNewChatOptions(REPORTS, PERSONAL_DETAILS, [], '.com', [], [], true);
// Then all single participant reports that match will show up in the recentReports array
expect(results.recentReports.length).toBe(5);
expect(results.recentReports[0].text).toBe('Captain America');
// And logins with no single participant reports will show up in personalDetails
expect(results.personalDetails.length).toBe(4);
expect(results.personalDetails[0].login).toBe('reedrichards@expensify.com');
// When we search for an option that matches things in both personalDetails and reports
results = OptionsListUtils.getNewChatOptions(REPORTS, PERSONAL_DETAILS, [], '.com', [], [], false);
// Then all single participant reports that match will show up in the recentReports array
expect(results.recentReports.length).toBe(5);
expect(results.recentReports[0].text).toBe('Mister Sinister');
// And logins with no single participant reports will show up in personalDetails
expect(results.personalDetails.length).toBe(4);
expect(results.personalDetails[0].login).toBe('reedrichards@expensify.com');
// When we provide no selected options to getNewChatOptions()
results = OptionsListUtils.getNewChatOptions(REPORTS, PERSONAL_DETAILS, [], '', [], [], true);
// Then one of our older report options (not in our five most recent) should appear in the personalDetails
// but not in recentReports
expect(_.every(results.recentReports, option => option.login !== 'peterparker@expensify.com')).toBe(true);
expect(_.every(results.personalDetails, option => option.login !== 'peterparker@expensify.com')).toBe(false);
// When we provide a "selected" option to getNewChatOptions()
results = OptionsListUtils.getNewChatOptions(
REPORTS,
PERSONAL_DETAILS,
[],
'',
[{login: 'peterparker@expensify.com'}],
[],
true,
);
// Then the option should not appear anywhere in either list
expect(_.every(results.recentReports, option => option.login !== 'peterparker@expensify.com')).toBe(true);
expect(_.every(results.personalDetails, option => option.login !== 'peterparker@expensify.com')).toBe(true);
// When we add a search term for which no options exist and the searchValue itself
// is not a potential email or phone
results = OptionsListUtils.getNewChatOptions(REPORTS, PERSONAL_DETAILS, [], 'marc@expensify', [], [], true);
// Then we should have no options or personal details at all and also that there is no userToInvite
expect(results.recentReports.length).toBe(0);
expect(results.personalDetails.length).toBe(0);
expect(results.userToInvite).toBe(null);
// When we add a search term for which no options exist and the searchValue itself
// is a potential email
results = OptionsListUtils.getNewChatOptions(REPORTS, PERSONAL_DETAILS, [], 'marc@expensify.com', [], [], true);
// Then we should have no options or personal details at all but there should be a userToInvite
expect(results.recentReports.length).toBe(0);
expect(results.personalDetails.length).toBe(0);
expect(results.userToInvite).not.toBe(null);
// When we add a search term for which no options exist and the searchValue itself
// is a potential phone number without country code added
results = OptionsListUtils.getNewChatOptions(REPORTS, PERSONAL_DETAILS, [], '5005550006', [], [], true);
// Then we should have no options or personal details at all but there should be a userToInvite and the login
// should have the country code included
expect(results.recentReports.length).toBe(0);
expect(results.personalDetails.length).toBe(0);
expect(results.userToInvite).not.toBe(null);
expect(results.userToInvite.login).toBe('+15005550006');
// When we add a search term for which no options exist and the searchValue itself
// is a potential phone number with country code added
results = OptionsListUtils.getNewChatOptions(REPORTS, PERSONAL_DETAILS, [], '+15005550006', [], [], true);
// Then we should have no options or personal details at all but there should be a userToInvite and the login
// should have the country code included
expect(results.recentReports.length).toBe(0);
expect(results.personalDetails.length).toBe(0);
expect(results.userToInvite).not.toBe(null);
expect(results.userToInvite.login).toBe('+15005550006');
// Test Concierge's existence in new group options
results = OptionsListUtils.getNewChatOptions(REPORTS_WITH_CONCIERGE, PERSONAL_DETAILS_WITH_CONCIERGE, [], '', [], [CONST.EMAIL.RECEIPTS], true);
// Concierge is included in the results by default. We should expect all the personalDetails to show
// (minus the 5 that are already showing and the currently logged in user)
expect(results.personalDetails.length).toBe(_.size(PERSONAL_DETAILS_WITH_CONCIERGE) - 6);
expect(results.recentReports).toEqual(
expect.arrayContaining([
expect.objectContaining({login: 'concierge@expensify.com'}),
]),
);
// Test by excluding Concierge from the results
results = OptionsListUtils.getNewChatOptions(
REPORTS_WITH_CONCIERGE,
PERSONAL_DETAILS_WITH_CONCIERGE,
[],
'',
[],
[CONST.EMAIL.CONCIERGE],
true,
);
// We should expect all the personalDetails to show (minus the 5 that are already showing,
// the currently logged in user and Concierge)
expect(results.personalDetails.length).toBe(_.size(PERSONAL_DETAILS_WITH_CONCIERGE) - 7);
expect(results.personalDetails).not.toEqual(
expect.arrayContaining([
expect.objectContaining({login: 'concierge@expensify.com'}),
]),
);
expect(results.recentReports).not.toEqual(
expect.arrayContaining([
expect.objectContaining({login: 'concierge@expensify.com'}),
]),
);
// Test by excluding Chronos from the results
results = OptionsListUtils.getNewChatOptions(
REPORTS_WITH_CHRONOS,
PERSONAL_DETAILS_WITH_CHRONOS,
[],
'',
[],
[CONST.EMAIL.CHRONOS],
true,
);
// We should expect all the personalDetails to show (minus the 5 that are already showing,
// the currently logged in user and Concierge)
expect(results.personalDetails.length).toBe(_.size(PERSONAL_DETAILS_WITH_CHRONOS) - 7);
expect(results.personalDetails).not.toEqual(
expect.arrayContaining([
expect.objectContaining({login: 'chronos@expensify.com'}),
]),
);
expect(results.recentReports).not.toEqual(
expect.arrayContaining([
expect.objectContaining({login: 'chronos@expensify.com'}),
]),
);
// Test by excluding Receipts from the results
results = OptionsListUtils.getNewChatOptions(
REPORTS_WITH_RECEIPTS,
PERSONAL_DETAILS_WITH_RECEIPTS,
[],
'',
[],
[CONST.EMAIL.RECEIPTS],
true,
);
// We should expect all the personalDetails to show (minus the 5 that are already showing,
// the currently logged in user and Concierge)
expect(results.personalDetails.length).toBe(_.size(PERSONAL_DETAILS_WITH_RECEIPTS) - 7);
expect(results.personalDetails).not.toEqual(
expect.arrayContaining([
expect.objectContaining({login: 'receipts@expensify.com'}),
]),
);
expect(results.recentReports).not.toEqual(
expect.arrayContaining([
expect.objectContaining({login: 'receipts@expensify.com'}),
]),
);
});
it('getSidebarOptions() with default priority mode', () => {
const reportsWithAddedPinnedMessagelessReport = {
...REPORTS,
// Note: This report has no lastMessageTimestamp but is also pinned
10: {
lastVisitedTimestamp: 1610666739300,
lastMessageTimestamp: 0,
isPinned: true,
reportID: 10,
participants: ['captain_britain@expensify.com'],
reportName: 'Captain Britain',
},
};
return Report.setReportWithDraft(1, true)
.then(() => {
// When we call getSidebarOptions() with no search value and default priority mode
const results = OptionsListUtils.getSidebarOptions(
reportsWithAddedPinnedMessagelessReport,
PERSONAL_DETAILS,
0,
CONST.PRIORITY_MODE.DEFAULT,
);
// Then expect all of the reports to be shown both multiple and single participant except the
// unpinned report that has no lastMessageTimestamp
expect(results.recentReports.length).toBe(_.size(reportsWithAddedPinnedMessagelessReport) - 1);
const numberOfPinnedReports = _.filter(results.recentReports, report => report.isPinned).length;
expect(numberOfPinnedReports).toBe(2);
// That no personalDetails are shown
expect(results.personalDetails.length).toBe(0);
// And the most recent pinned report is first in the list of reports
expect(results.recentReports[0].login).toBe('captain_britain@expensify.com');
// And the third report is the report with an IOU debt
expect(results.recentReports[2].login).toBe('mistersinister@marauders.com');
// And the fourth report is the report with a draft comment
expect(results.recentReports[3].text).toBe('tonystark@expensify.com, reedrichards@expensify.com');
// And the fifth report is the report with the lastMessage timestamp
expect(results.recentReports[4].login).toBe('steverogers@expensify.com');
});
});
it('getSidebarOptions() with GSD priority mode',
() => Report.setReportWithDraft(1, true)
.then(() => {
// When we call getSidebarOptions() with no search value
const results = OptionsListUtils.getSidebarOptions(REPORTS_WITH_MORE_PINS, PERSONAL_DETAILS, 0, CONST.PRIORITY_MODE.GSD);
// Then expect all of the reports to be shown both multiple and single participant except the
// report that has no lastMessageTimestamp and the chat with Thor who's message is read
expect(results.recentReports.length).toBe(_.size(REPORTS_WITH_MORE_PINS) - 2);
// That no personalDetails are shown
expect(results.personalDetails.length).toBe(0);
// Pinned reports are always on the top in alphabetical order regardless of whether they are unread or have IOU debt.
// D report name (Alphabetically first among pinned reports)
expect(results.recentReports[0].login).toBe('d_email@email.com');
// Mister Fantastic report name (Alphabetically second among pinned reports)
expect(results.recentReports[1].login).toBe('reedrichards@expensify.com');
// Z report name (Alphabetically third among pinned reports)
expect(results.recentReports[2].login).toBe('z_email@email.com');
// Unpinned report name ordered alphabetically after pinned reports
// Black Panther report name has unread message
expect(results.recentReports[3].login).toBe('tchalla@expensify.com');
// Captain America report name has unread message
expect(results.recentReports[4].login).toBe('steverogers@expensify.com');
// Invisible woman report name has unread message
expect(results.recentReports[5].login).toBe('suestorm@expensify.com');
// Mister Sinister report name has IOU debt
expect(results.recentReports[7].login).toBe('mistersinister@marauders.com');
// Spider-Man report name is last report and has unread message
expect(results.recentReports[8].login).toBe('peterparker@expensify.com');
}));