-
Notifications
You must be signed in to change notification settings - Fork 3k
/
Copy pathSidebarOrderTest.js
732 lines (641 loc) · 37.5 KB
/
SidebarOrderTest.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
import Onyx from 'react-native-onyx';
import {cleanup, screen} from '@testing-library/react-native';
import lodashGet from 'lodash/get';
import waitForPromisesToResolve from '../utils/waitForPromisesToResolve';
import * as LHNTestUtils from '../utils/LHNTestUtils';
import CONST from '../../src/CONST';
import DateUtils from '../../src/libs/DateUtils';
import * as Localize from '../../src/libs/Localize';
// Be sure to include the mocked Permissions and Expensicons libraries or else the beta tests won't work
jest.mock('../../src/libs/Permissions');
jest.mock('../../src/components/Icon/Expensicons');
const ONYXKEYS = {
PERSONAL_DETAILS: 'personalDetails',
NVP_PRIORITY_MODE: 'nvp_priorityMode',
SESSION: 'session',
BETAS: 'betas',
COLLECTION: {
REPORT: 'report_',
REPORT_ACTIONS: 'reportActions_',
},
NETWORK: 'network',
};
describe('Sidebar', () => {
beforeAll(() => Onyx.init({
keys: ONYXKEYS,
registerStorageEventListener: () => {},
}));
// Initialize the network key for OfflineWithFeedback
beforeEach(() => Onyx.merge(ONYXKEYS.NETWORK, {isOffline: false}));
// Clear out Onyx after each test so that each test starts with a clean slate
afterEach(() => {
cleanup();
Onyx.clear();
});
describe('in default mode', () => {
it('is not rendered when there are no props passed to it', () => {
// Given all the default props are passed to SidebarLinks
// When it is rendered
LHNTestUtils.getDefaultRenderedSidebarLinks();
// Then it should render nothing and be null
// This is expected because there is an early return when there are no personal details
expect(screen.toJSON()).toBe(null);
});
it('is rendered with an empty list when personal details exist', () => {
// Given the sidebar is rendered with default props
LHNTestUtils.getDefaultRenderedSidebarLinks();
return waitForPromisesToResolve()
// When Onyx is updated with some personal details
.then(() => Onyx.multiSet({
[ONYXKEYS.PERSONAL_DETAILS]: LHNTestUtils.fakePersonalDetails,
}))
// Then the component should be rendered with an empty list since it will get past the early return
.then(() => {
expect(screen.toJSON()).not.toBe(null);
const navigatesToChatHintText = Localize.translateLocal('accessibilityHints.navigatesToChat');
expect(screen.queryAllByAccessibilityHint(navigatesToChatHintText)).toHaveLength(0);
});
});
it('contains one report when a report is in Onyx', () => {
// Given a single report
const report = LHNTestUtils.getFakeReport(['[email protected]', '[email protected]']);
LHNTestUtils.getDefaultRenderedSidebarLinks(report.reportID);
return waitForPromisesToResolve()
// When Onyx is updated with the data and the sidebar re-renders
.then(() => Onyx.multiSet({
[ONYXKEYS.NVP_PRIORITY_MODE]: CONST.PRIORITY_MODE.DEFAULT,
[ONYXKEYS.PERSONAL_DETAILS]: LHNTestUtils.fakePersonalDetails,
[`${ONYXKEYS.COLLECTION.REPORT}${report.reportID}`]: report,
}))
// Then the component should be rendered with an item for the report
.then(() => {
expect(screen.queryAllByText('One, Two')).toHaveLength(1);
});
});
it('orders items with most recently updated on top', () => {
LHNTestUtils.getDefaultRenderedSidebarLinks();
// Given three unread reports in the recently updated order of 3, 2, 1
const report1 = {
...LHNTestUtils.getFakeReport(['[email protected]', '[email protected]'], 3),
};
const report2 = {
...LHNTestUtils.getFakeReport(['[email protected]', '[email protected]'], 2),
};
const report3 = {
...LHNTestUtils.getFakeReport(['[email protected]', '[email protected]'], 1),
};
return waitForPromisesToResolve()
// When Onyx is updated with the data and the sidebar re-renders
.then(() => Onyx.multiSet({
[ONYXKEYS.NVP_PRIORITY_MODE]: CONST.PRIORITY_MODE.DEFAULT,
[ONYXKEYS.PERSONAL_DETAILS]: LHNTestUtils.fakePersonalDetails,
[`${ONYXKEYS.COLLECTION.REPORT}${report1.reportID}`]: report1,
[`${ONYXKEYS.COLLECTION.REPORT}${report2.reportID}`]: report2,
[`${ONYXKEYS.COLLECTION.REPORT}${report3.reportID}`]: report3,
}))
// Then the component should be rendered with the mostly recently updated report first
.then(() => {
const hintText = Localize.translateLocal('accessibilityHints.chatUserDisplayNames');
const displayNames = screen.queryAllByLabelText(hintText);
expect(displayNames).toHaveLength(3);
expect(lodashGet(displayNames, [0, 'props', 'children'])).toBe('Five, Six');
expect(lodashGet(displayNames, [1, 'props', 'children'])).toBe('Three, Four');
expect(lodashGet(displayNames, [2, 'props', 'children'])).toBe('One, Two');
});
});
it('changes the order when adding a draft to the active report', () => {
// Given three reports in the recently updated order of 3, 2, 1
// And the first report has a draft
// And the currently viewed report is the first report
const report1 = {
...LHNTestUtils.getFakeReport(['[email protected]', '[email protected]'], 3),
hasDraft: true,
};
const report2 = LHNTestUtils.getFakeReport(['[email protected]', '[email protected]'], 2);
const report3 = LHNTestUtils.getFakeReport(['[email protected]', '[email protected]'], 1);
const reportIDFromRoute = report1.reportID;
LHNTestUtils.getDefaultRenderedSidebarLinks(reportIDFromRoute);
return waitForPromisesToResolve()
// When Onyx is updated with the data and the sidebar re-renders
.then(() => Onyx.multiSet({
[ONYXKEYS.NVP_PRIORITY_MODE]: CONST.PRIORITY_MODE.DEFAULT,
[ONYXKEYS.PERSONAL_DETAILS]: LHNTestUtils.fakePersonalDetails,
[`${ONYXKEYS.COLLECTION.REPORT}${report1.reportID}`]: report1,
[`${ONYXKEYS.COLLECTION.REPORT}${report2.reportID}`]: report2,
[`${ONYXKEYS.COLLECTION.REPORT}${report3.reportID}`]: report3,
}))
// Then there should be a pencil icon and report one should be the first one because putting a draft on the active report should change its location
// in the ordered list
.then(() => {
const pencilIcon = screen.getAllByAccessibilityHint('Pencil Icon');
expect(pencilIcon).toHaveLength(1);
const hintText = Localize.translateLocal('accessibilityHints.chatUserDisplayNames');
const displayNames = screen.queryAllByLabelText(hintText);
expect(displayNames).toHaveLength(3);
expect(lodashGet(displayNames, [0, 'props', 'children'])).toBe('One, Two'); // this has `hasDraft` flag enabled so it will be on top
expect(lodashGet(displayNames, [1, 'props', 'children'])).toBe('Five, Six');
expect(lodashGet(displayNames, [2, 'props', 'children'])).toBe('Three, Four');
});
});
it('reorders the reports to always have the most recently updated one on top', () => {
LHNTestUtils.getDefaultRenderedSidebarLinks();
// Given three reports in the recently updated order of 3, 2, 1
const report1 = LHNTestUtils.getFakeReport(['[email protected]', '[email protected]'], 3);
const report2 = LHNTestUtils.getFakeReport(['[email protected]', '[email protected]'], 2);
const report3 = LHNTestUtils.getFakeReport(['[email protected]', '[email protected]'], 1);
return waitForPromisesToResolve()
// When Onyx is updated with the data and the sidebar re-renders
.then(() => Onyx.multiSet({
[ONYXKEYS.NVP_PRIORITY_MODE]: CONST.PRIORITY_MODE.DEFAULT,
[ONYXKEYS.PERSONAL_DETAILS]: LHNTestUtils.fakePersonalDetails,
[`${ONYXKEYS.COLLECTION.REPORT}${report1.reportID}`]: report1,
[`${ONYXKEYS.COLLECTION.REPORT}${report2.reportID}`]: report2,
[`${ONYXKEYS.COLLECTION.REPORT}${report3.reportID}`]: report3,
}))
// When a new comment is added to report 1 (eg. it's lastVisibleActionCreated is updated)
.then(() => Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${report1.reportID}`, {
lastVisibleActionCreated: DateUtils.getDBTime(),
}))
// Then the order of the reports should be 1 > 3 > 2
// ^--- (1 goes to the front and pushes other two down)
.then(() => {
const hintText = Localize.translateLocal('accessibilityHints.chatUserDisplayNames');
const displayNames = screen.queryAllByLabelText(hintText);
expect(displayNames).toHaveLength(3);
expect(lodashGet(displayNames, [0, 'props', 'children'])).toBe('One, Two');
expect(lodashGet(displayNames, [1, 'props', 'children'])).toBe('Five, Six');
expect(lodashGet(displayNames, [2, 'props', 'children'])).toBe('Three, Four');
});
});
it('reorders the reports to keep draft reports on top', () => {
// Given three reports in the recently updated order of 3, 2, 1
// And the second report has a draft
// And the currently viewed report is the second report
const report1 = LHNTestUtils.getFakeReport(['[email protected]', '[email protected]'], 3);
const report2 = {
...LHNTestUtils.getFakeReport(['[email protected]', '[email protected]'], 2),
hasDraft: true,
};
const report3 = LHNTestUtils.getFakeReport(['[email protected]', '[email protected]'], 1);
const reportIDFromRoute = report2.reportID;
LHNTestUtils.getDefaultRenderedSidebarLinks(reportIDFromRoute);
return waitForPromisesToResolve()
// When Onyx is updated with the data and the sidebar re-renders
.then(() => Onyx.multiSet({
[ONYXKEYS.NVP_PRIORITY_MODE]: CONST.PRIORITY_MODE.DEFAULT,
[ONYXKEYS.PERSONAL_DETAILS]: LHNTestUtils.fakePersonalDetails,
[`${ONYXKEYS.COLLECTION.REPORT}${report1.reportID}`]: report1,
[`${ONYXKEYS.COLLECTION.REPORT}${report2.reportID}`]: report2,
[`${ONYXKEYS.COLLECTION.REPORT}${report3.reportID}`]: report3,
}))
// When the currently active chat is switched to report 1 (the one on the bottom)
.then(() => {
// The changing of a route itself will re-render the component in the App, but since we are not performing this test
// inside the navigator and it has no access to the routes we need to trigger an update to the SidebarLinks manually.
LHNTestUtils.getDefaultRenderedSidebarLinks('1');
return waitForPromisesToResolve();
})
// Then the order of the reports should be 2 > 3 > 1
// ^--- (2 goes to the front and pushes 3 down)
.then(() => {
const hintText = Localize.translateLocal('accessibilityHints.chatUserDisplayNames');
const displayNames = screen.queryAllByLabelText(hintText);
expect(displayNames).toHaveLength(3);
expect(lodashGet(displayNames, [0, 'props', 'children'])).toBe('Three, Four');
expect(lodashGet(displayNames, [1, 'props', 'children'])).toBe('Five, Six');
expect(lodashGet(displayNames, [2, 'props', 'children'])).toBe('One, Two');
});
});
it('removes the pencil icon when draft is removed', () => {
LHNTestUtils.getDefaultRenderedSidebarLinks();
// Given a single report
// And the report has a draft
const report = {
...LHNTestUtils.getFakeReport(['[email protected]', '[email protected]']),
hasDraft: true,
};
return waitForPromisesToResolve()
// When Onyx is updated with the data and the sidebar re-renders
.then(() => Onyx.multiSet({
[ONYXKEYS.NVP_PRIORITY_MODE]: CONST.PRIORITY_MODE.DEFAULT,
[ONYXKEYS.PERSONAL_DETAILS]: LHNTestUtils.fakePersonalDetails,
[`${ONYXKEYS.COLLECTION.REPORT}${report.reportID}`]: report,
}))
// Then there should be a pencil icon showing
.then(() => {
expect(screen.getAllByAccessibilityHint('Pencil Icon')).toHaveLength(1);
})
// When the draft is removed
.then(() => Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${report.reportID}`, {hasDraft: null}))
// Then the pencil icon goes away
.then(() => {
expect(screen.queryAllByAccessibilityHint('Pencil Icon')).toHaveLength(0);
});
});
it('removes the pin icon when chat is unpinned', () => {
LHNTestUtils.getDefaultRenderedSidebarLinks();
// Given a single report
// And the report is pinned
const report = {
...LHNTestUtils.getFakeReport(['[email protected]', '[email protected]']),
isPinned: true,
};
return waitForPromisesToResolve()
// When Onyx is updated with the data and the sidebar re-renders
.then(() => Onyx.multiSet({
[ONYXKEYS.NVP_PRIORITY_MODE]: CONST.PRIORITY_MODE.DEFAULT,
[ONYXKEYS.PERSONAL_DETAILS]: LHNTestUtils.fakePersonalDetails,
[`${ONYXKEYS.COLLECTION.REPORT}${report.reportID}`]: report,
}))
// Then there should be a pencil icon showing
.then(() => {
expect(screen.getAllByAccessibilityHint('Pin Icon')).toHaveLength(1);
})
// When the draft is removed
.then(() => Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${report.reportID}`, {isPinned: false}))
// Then the pencil icon goes away
.then(() => {
expect(screen.queryAllByAccessibilityHint('Pin Icon')).toHaveLength(0);
});
});
it('sorts chats by pinned > IOU > draft', () => {
// Given three reports in the recently updated order of 3, 2, 1
// with the current user set to email9@ (someone not participating in any of the chats)
// with a report that has a draft, a report that is pinned, and
// an outstanding IOU report that doesn't belong to the current user
const report1 = {
...LHNTestUtils.getFakeReport(['[email protected]', '[email protected]'], 3),
isPinned: true,
};
const report2 = {
...LHNTestUtils.getFakeReport(['[email protected]', '[email protected]'], 2),
hasDraft: true,
};
const report3 = {
...LHNTestUtils.getFakeReport(['[email protected]', '[email protected]'], 1),
hasOutstandingIOU: true,
// This has to be added after the IOU report is generated
iouReportID: null,
};
const iouReport = {
...LHNTestUtils.getFakeReport(['[email protected]', '[email protected]']),
ownerEmail: '[email protected]',
hasOutstandingIOU: true,
total: 10000,
currency: 'USD',
chatReportID: report3.reportID,
};
report3.iouReportID = iouReport.reportID;
const reportIDFromRoute = report2.reportID;
const currentlyLoggedInUserEmail = '[email protected]';
LHNTestUtils.getDefaultRenderedSidebarLinks(reportIDFromRoute);
return waitForPromisesToResolve()
// When Onyx is updated with the data and the sidebar re-renders
.then(() => Onyx.multiSet({
[ONYXKEYS.NVP_PRIORITY_MODE]: CONST.PRIORITY_MODE.DEFAULT,
[ONYXKEYS.PERSONAL_DETAILS]: LHNTestUtils.fakePersonalDetails,
[ONYXKEYS.SESSION]: {email: currentlyLoggedInUserEmail},
[`${ONYXKEYS.COLLECTION.REPORT}${report1.reportID}`]: report1,
[`${ONYXKEYS.COLLECTION.REPORT}${report2.reportID}`]: report2,
[`${ONYXKEYS.COLLECTION.REPORT}${report3.reportID}`]: report3,
[`${ONYXKEYS.COLLECTION.REPORT}${iouReport.reportID}`]: iouReport,
}))
// Then the reports are ordered by Pinned > IOU > Draft
// there is a pencil icon
// there is a pinned icon
.then(() => {
const hintText = Localize.translateLocal('accessibilityHints.chatUserDisplayNames');
const displayNames = screen.queryAllByLabelText(hintText);
expect(displayNames).toHaveLength(3);
expect(screen.getAllByAccessibilityHint('Pin Icon')).toHaveLength(1);
expect(screen.getAllByAccessibilityHint('Pencil Icon')).toHaveLength(1);
expect(lodashGet(displayNames, [0, 'props', 'children'])).toBe('One, Two');
expect(lodashGet(displayNames, [1, 'props', 'children'])).toBe('Five, Six');
expect(lodashGet(displayNames, [2, 'props', 'children'])).toBe('Three, Four');
});
});
it('alphabetizes all the chats that are pinned', () => {
// Given three reports in the recently updated order of 3, 2, 1
// and they are all pinned
const report1 = {
...LHNTestUtils.getFakeReport(['[email protected]', '[email protected]'], 3),
isPinned: true,
};
const report2 = {
...LHNTestUtils.getFakeReport(['[email protected]', '[email protected]'], 2),
isPinned: true,
};
const report3 = {
...LHNTestUtils.getFakeReport(['[email protected]', '[email protected]'], 1),
isPinned: true,
};
const report4 = {
...LHNTestUtils.getFakeReport(['[email protected]', '[email protected]'], 0),
isPinned: true,
};
LHNTestUtils.getDefaultRenderedSidebarLinks('0');
return waitForPromisesToResolve()
// When Onyx is updated with the data and the sidebar re-renders
.then(() => Onyx.multiSet({
[ONYXKEYS.NVP_PRIORITY_MODE]: CONST.PRIORITY_MODE.DEFAULT,
[ONYXKEYS.PERSONAL_DETAILS]: LHNTestUtils.fakePersonalDetails,
[`${ONYXKEYS.COLLECTION.REPORT}${report1.reportID}`]: report1,
[`${ONYXKEYS.COLLECTION.REPORT}${report2.reportID}`]: report2,
[`${ONYXKEYS.COLLECTION.REPORT}${report3.reportID}`]: report3,
}))
// Then the reports are in alphabetical order
.then(() => {
const hintText = Localize.translateLocal('accessibilityHints.chatUserDisplayNames');
const displayNames = screen.queryAllByLabelText(hintText);
expect(displayNames).toHaveLength(3);
expect(lodashGet(displayNames, [0, 'props', 'children'])).toBe('Five, Six');
expect(lodashGet(displayNames, [1, 'props', 'children'])).toBe('One, Two');
expect(lodashGet(displayNames, [2, 'props', 'children'])).toBe('Three, Four');
})
// When a new report is added
.then(() => Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${report4.reportID}`, report4))
// Then they are still in alphabetical order
.then(() => {
const hintText = Localize.translateLocal('accessibilityHints.chatUserDisplayNames');
const displayNames = screen.queryAllByLabelText(hintText);
expect(displayNames).toHaveLength(4);
expect(lodashGet(displayNames, [0, 'props', 'children'])).toBe('Five, Six');
expect(lodashGet(displayNames, [1, 'props', 'children'])).toBe('One, Two');
expect(lodashGet(displayNames, [2, 'props', 'children'])).toBe('Seven, Eight');
expect(lodashGet(displayNames, [3, 'props', 'children'])).toBe('Three, Four');
});
});
it('alphabetizes all the chats that have drafts', () => {
// Given three reports in the recently updated order of 3, 2, 1
// and they all have drafts
const report1 = {
...LHNTestUtils.getFakeReport(['[email protected]', '[email protected]'], 3),
hasDraft: true,
};
const report2 = {
...LHNTestUtils.getFakeReport(['[email protected]', '[email protected]'], 2),
hasDraft: true,
};
const report3 = {
...LHNTestUtils.getFakeReport(['[email protected]', '[email protected]'], 1),
hasDraft: true,
};
const report4 = {
...LHNTestUtils.getFakeReport(['[email protected]', '[email protected]'], 0),
hasDraft: true,
};
LHNTestUtils.getDefaultRenderedSidebarLinks('0');
return waitForPromisesToResolve()
// When Onyx is updated with the data and the sidebar re-renders
.then(() => Onyx.multiSet({
[ONYXKEYS.NVP_PRIORITY_MODE]: CONST.PRIORITY_MODE.DEFAULT,
[ONYXKEYS.PERSONAL_DETAILS]: LHNTestUtils.fakePersonalDetails,
[`${ONYXKEYS.COLLECTION.REPORT}${report1.reportID}`]: report1,
[`${ONYXKEYS.COLLECTION.REPORT}${report2.reportID}`]: report2,
[`${ONYXKEYS.COLLECTION.REPORT}${report3.reportID}`]: report3,
}))
// Then the reports are in alphabetical order
.then(() => {
const hintText = Localize.translateLocal('accessibilityHints.chatUserDisplayNames');
const displayNames = screen.queryAllByLabelText(hintText);
expect(displayNames).toHaveLength(3);
expect(lodashGet(displayNames, [0, 'props', 'children'])).toBe('Five, Six');
expect(lodashGet(displayNames, [1, 'props', 'children'])).toBe('One, Two');
expect(lodashGet(displayNames, [2, 'props', 'children'])).toBe('Three, Four');
})
// When a new report is added
.then(() => Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${report4.reportID}`, report4))
// Then they are still in alphabetical order
.then(() => {
const hintText = Localize.translateLocal('accessibilityHints.chatUserDisplayNames');
const displayNames = screen.queryAllByLabelText(hintText);
expect(displayNames).toHaveLength(4);
expect(lodashGet(displayNames, [0, 'props', 'children'])).toBe('Five, Six');
expect(lodashGet(displayNames, [1, 'props', 'children'])).toBe('One, Two');
expect(lodashGet(displayNames, [2, 'props', 'children'])).toBe('Seven, Eight');
expect(lodashGet(displayNames, [3, 'props', 'children'])).toBe('Three, Four');
});
});
it('puts archived chats last', () => {
// Given three reports, with the first report being archived
const report1 = {
...LHNTestUtils.getFakeReport(['[email protected]', '[email protected]']),
chatType: CONST.REPORT.CHAT_TYPE.POLICY_ROOM,
statusNum: CONST.REPORT.STATUS.CLOSED,
stateNum: CONST.REPORT.STATE_NUM.SUBMITTED,
};
const report2 = LHNTestUtils.getFakeReport(['[email protected]', '[email protected]']);
const report3 = LHNTestUtils.getFakeReport(['[email protected]', '[email protected]']);
// Given the user is in all betas
const betas = [
CONST.BETAS.DEFAULT_ROOMS,
CONST.BETAS.POLICY_ROOMS,
CONST.BETAS.POLICY_EXPENSE_CHAT,
];
LHNTestUtils.getDefaultRenderedSidebarLinks('0');
return waitForPromisesToResolve()
// When Onyx is updated with the data and the sidebar re-renders
.then(() => Onyx.multiSet({
[ONYXKEYS.BETAS]: betas,
[ONYXKEYS.NVP_PRIORITY_MODE]: CONST.PRIORITY_MODE.DEFAULT,
[ONYXKEYS.PERSONAL_DETAILS]: LHNTestUtils.fakePersonalDetails,
[`${ONYXKEYS.COLLECTION.REPORT}${report1.reportID}`]: report1,
[`${ONYXKEYS.COLLECTION.REPORT}${report2.reportID}`]: report2,
[`${ONYXKEYS.COLLECTION.REPORT}${report3.reportID}`]: report3,
}))
// Then the first report is in last position
.then(() => {
const hintText = Localize.translateLocal('accessibilityHints.chatUserDisplayNames');
const displayNames = screen.queryAllByLabelText(hintText);
expect(displayNames).toHaveLength(3);
expect(lodashGet(displayNames, [0, 'props', 'children'])).toBe('Five, Six');
expect(lodashGet(displayNames, [1, 'props', 'children'])).toBe('Three, Four');
expect(lodashGet(displayNames, [2, 'props', 'children'])).toBe('Report (archived)');
});
});
});
describe('in #focus mode', () => {
it('alphabetizes chats', () => {
LHNTestUtils.getDefaultRenderedSidebarLinks();
const report1 = LHNTestUtils.getFakeReport(['[email protected]', '[email protected]'], 3, true);
const report2 = LHNTestUtils.getFakeReport(['[email protected]', '[email protected]'], 2, true);
const report3 = LHNTestUtils.getFakeReport(['[email protected]', '[email protected]'], 1, true);
const report4 = LHNTestUtils.getFakeReport(['[email protected]', '[email protected]'], 0, true);
return waitForPromisesToResolve()
// Given the sidebar is rendered in #focus mode (hides read chats)
// with all reports having unread comments
.then(() => Onyx.multiSet({
[ONYXKEYS.NVP_PRIORITY_MODE]: CONST.PRIORITY_MODE.GSD,
[ONYXKEYS.PERSONAL_DETAILS]: LHNTestUtils.fakePersonalDetails,
[`${ONYXKEYS.COLLECTION.REPORT}${report1.reportID}`]: report1,
[`${ONYXKEYS.COLLECTION.REPORT}${report2.reportID}`]: report2,
[`${ONYXKEYS.COLLECTION.REPORT}${report3.reportID}`]: report3,
}))
// Then the reports are in alphabetical order
.then(() => {
const hintText = Localize.translateLocal('accessibilityHints.chatUserDisplayNames');
const displayNames = screen.queryAllByLabelText(hintText);
expect(displayNames).toHaveLength(3);
expect(lodashGet(displayNames, [0, 'props', 'children'])).toBe('Five, Six');
expect(lodashGet(displayNames, [1, 'props', 'children'])).toBe('One, Two');
expect(lodashGet(displayNames, [2, 'props', 'children'])).toBe('Three, Four');
})
// When a new report is added
.then(() => Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${report4.reportID}`, report4))
// Then they are still in alphabetical order
.then(() => {
const hintText = Localize.translateLocal('accessibilityHints.chatUserDisplayNames');
const displayNames = screen.queryAllByLabelText(hintText);
expect(displayNames).toHaveLength(4);
expect(lodashGet(displayNames, [0, 'props', 'children'])).toBe('Five, Six');
expect(lodashGet(displayNames, [1, 'props', 'children'])).toBe('One, Two');
expect(lodashGet(displayNames, [2, 'props', 'children'])).toBe('Seven, Eight');
expect(lodashGet(displayNames, [3, 'props', 'children'])).toBe('Three, Four');
});
});
it('puts archived chats last', () => {
// Given three unread reports, with the first report being archived
const report1 = {
...LHNTestUtils.getFakeReport(['[email protected]', '[email protected]'], 3, true),
chatType: CONST.REPORT.CHAT_TYPE.POLICY_ROOM,
statusNum: CONST.REPORT.STATUS.CLOSED,
stateNum: CONST.REPORT.STATE_NUM.SUBMITTED,
};
const report2 = LHNTestUtils.getFakeReport(['[email protected]', '[email protected]'], 2, true);
const report3 = LHNTestUtils.getFakeReport(['[email protected]', '[email protected]'], 1, true);
// Given the user is in all betas
const betas = [
CONST.BETAS.DEFAULT_ROOMS,
CONST.BETAS.POLICY_ROOMS,
CONST.BETAS.POLICY_EXPENSE_CHAT,
];
LHNTestUtils.getDefaultRenderedSidebarLinks('0');
return waitForPromisesToResolve()
// When Onyx is updated with the data and the sidebar re-renders
.then(() => Onyx.multiSet({
[ONYXKEYS.BETAS]: betas,
[ONYXKEYS.NVP_PRIORITY_MODE]: CONST.PRIORITY_MODE.GSD,
[ONYXKEYS.PERSONAL_DETAILS]: LHNTestUtils.fakePersonalDetails,
[`${ONYXKEYS.COLLECTION.REPORT}${report1.reportID}`]: report1,
[`${ONYXKEYS.COLLECTION.REPORT}${report2.reportID}`]: report2,
[`${ONYXKEYS.COLLECTION.REPORT}${report3.reportID}`]: report3,
}))
// Then the first report is in last position
.then(() => {
const hintText = Localize.translateLocal('accessibilityHints.chatUserDisplayNames');
const displayNames = screen.queryAllByLabelText(hintText);
expect(displayNames).toHaveLength(3);
expect(lodashGet(displayNames, [0, 'props', 'children'])).toBe('Five, Six');
expect(lodashGet(displayNames, [1, 'props', 'children'])).toBe('Three, Four');
expect(lodashGet(displayNames, [2, 'props', 'children'])).toBe('Report (archived)');
});
});
it('orders IOU reports by displayName if amounts are the same', () => {
// Given three IOU reports containing the same IOU amounts
const report1 = {
...LHNTestUtils.getFakeReport(['[email protected]', '[email protected]']),
hasOutstandingIOU: true,
// This has to be added after the IOU report is generated
iouReportID: null,
};
const report2 = {
...LHNTestUtils.getFakeReport(['[email protected]', '[email protected]']),
hasOutstandingIOU: true,
// This has to be added after the IOU report is generated
iouReportID: null,
};
const report3 = {
...LHNTestUtils.getFakeReport(['[email protected]', '[email protected]']),
hasOutstandingIOU: true,
// This has to be added after the IOU report is generated
iouReportID: null,
};
const iouReport1 = {
...LHNTestUtils.getFakeReport(['[email protected]', '[email protected]']),
ownerEmail: '[email protected]',
hasOutstandingIOU: true,
total: 10000,
currency: 'USD',
chatReportID: report3.reportID,
};
const iouReport2 = {
...LHNTestUtils.getFakeReport(['[email protected]', '[email protected]']),
ownerEmail: '[email protected]',
hasOutstandingIOU: true,
total: 10000,
currency: 'USD',
chatReportID: report3.reportID,
};
const iouReport3 = {
...LHNTestUtils.getFakeReport(['[email protected]', '[email protected]']),
ownerEmail: '[email protected]',
hasOutstandingIOU: true,
total: 10000,
currency: 'USD',
chatReportID: report3.reportID,
};
report1.iouReportID = iouReport1.reportID;
report2.iouReportID = iouReport2.reportID;
report3.iouReportID = iouReport3.reportID;
const currentlyLoggedInUserEmail = '[email protected]';
LHNTestUtils.getDefaultRenderedSidebarLinks('0');
return waitForPromisesToResolve()
// When Onyx is updated with the data and the sidebar re-renders
.then(() => Onyx.multiSet({
[ONYXKEYS.NVP_PRIORITY_MODE]: CONST.PRIORITY_MODE.DEFAULT,
[ONYXKEYS.PERSONAL_DETAILS]: LHNTestUtils.fakePersonalDetails,
[ONYXKEYS.SESSION]: {email: currentlyLoggedInUserEmail},
[`${ONYXKEYS.COLLECTION.REPORT}${report1.reportID}`]: report1,
[`${ONYXKEYS.COLLECTION.REPORT}${report2.reportID}`]: report2,
[`${ONYXKEYS.COLLECTION.REPORT}${report3.reportID}`]: report3,
[`${ONYXKEYS.COLLECTION.REPORT}${iouReport1.reportID}`]: iouReport1,
[`${ONYXKEYS.COLLECTION.REPORT}${iouReport2.reportID}`]: iouReport2,
[`${ONYXKEYS.COLLECTION.REPORT}${iouReport3.reportID}`]: iouReport3,
}))
// Then the reports are ordered alphabetically since their amounts are the same
.then(() => {
const hintText = Localize.translateLocal('accessibilityHints.chatUserDisplayNames');
const displayNames = screen.queryAllByLabelText(hintText);
expect(displayNames).toHaveLength(3);
expect(lodashGet(displayNames, [0, 'props', 'children'])).toBe('Five, Six');
expect(lodashGet(displayNames, [1, 'props', 'children'])).toBe('One, Two');
expect(lodashGet(displayNames, [2, 'props', 'children'])).toBe('Three, Four');
});
});
it('orders nonArchived reports by displayName if created timestamps are the same', () => {
// Given three nonArchived reports created at the same time
const lastVisibleActionCreated = DateUtils.getDBTime();
const report1 = {
...LHNTestUtils.getFakeReport(['[email protected]', '[email protected]']),
lastVisibleActionCreated,
};
const report2 = {
...LHNTestUtils.getFakeReport(['[email protected]', '[email protected]']),
lastVisibleActionCreated,
};
const report3 = {
...LHNTestUtils.getFakeReport(['[email protected]', '[email protected]']),
lastVisibleActionCreated,
};
LHNTestUtils.getDefaultRenderedSidebarLinks('0');
return waitForPromisesToResolve()
// When Onyx is updated with the data and the sidebar re-renders
.then(() => Onyx.multiSet({
[ONYXKEYS.NVP_PRIORITY_MODE]: CONST.PRIORITY_MODE.DEFAULT,
[ONYXKEYS.PERSONAL_DETAILS]: LHNTestUtils.fakePersonalDetails,
[`${ONYXKEYS.COLLECTION.REPORT}${report1.reportID}`]: report1,
[`${ONYXKEYS.COLLECTION.REPORT}${report2.reportID}`]: report2,
[`${ONYXKEYS.COLLECTION.REPORT}${report3.reportID}`]: report3,
}))
// Then the reports are ordered alphabetically since their lastVisibleActionCreated are the same
.then(() => {
const hintText = Localize.translateLocal('accessibilityHints.chatUserDisplayNames');
const displayNames = screen.queryAllByLabelText(hintText);
expect(displayNames).toHaveLength(3);
expect(lodashGet(displayNames, [0, 'props', 'children'])).toBe('Five, Six');
expect(lodashGet(displayNames, [1, 'props', 'children'])).toBe('One, Two');
expect(lodashGet(displayNames, [2, 'props', 'children'])).toBe('Three, Four');
});
});
});
});