-
Notifications
You must be signed in to change notification settings - Fork 2.9k
/
SidebarTest.ts
149 lines (135 loc) · 7.17 KB
/
SidebarTest.ts
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
import {screen} from '@testing-library/react-native';
import Onyx from 'react-native-onyx';
import DateUtils from '@libs/DateUtils';
import CONST from '@src/CONST';
import * as Localize from '@src/libs/Localize';
import ONYXKEYS from '@src/ONYXKEYS';
import type {ReportCollectionDataSet} from '@src/types/onyx/Report';
import type {ReportActionsCollectionDataSet} from '@src/types/onyx/ReportAction';
import * as LHNTestUtils from '../utils/LHNTestUtils';
import waitForBatchedUpdates from '../utils/waitForBatchedUpdates';
import wrapOnyxWithWaitForBatchedUpdates from '../utils/wrapOnyxWithWaitForBatchedUpdates';
// 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/hooks/useActiveWorkspaceFromNavigationState');
jest.mock('@src/components/Icon/Expensicons');
describe('Sidebar', () => {
beforeAll(() =>
Onyx.init({
keys: ONYXKEYS,
safeEvictionKeys: [ONYXKEYS.COLLECTION.REPORT_ACTIONS],
}),
);
beforeEach(() => {
// Wrap Onyx each onyx action with waitForBatchedUpdates
wrapOnyxWithWaitForBatchedUpdates(Onyx);
// Initialize the network key for OfflineWithFeedback
return Onyx.merge(ONYXKEYS.NETWORK, {isOffline: false});
});
// Clear out Onyx after each test so that each test starts with a clean slate
afterEach(() => {
Onyx.clear();
});
describe('archived chats', () => {
it('renders the archive reason as the preview message of the chat', () => {
const report = {
...LHNTestUtils.getFakeReport([1, 2], 3, true),
chatType: CONST.REPORT.CHAT_TYPE.POLICY_ROOM,
statusNum: CONST.REPORT.STATUS_NUM.CLOSED,
stateNum: CONST.REPORT.STATE_NUM.APPROVED,
// eslint-disable-next-line @typescript-eslint/naming-convention
private_isArchived: DateUtils.getDBTime(),
lastMessageText: 'test',
};
const action = {
...LHNTestUtils.getFakeReportAction('email1@test.com', 3),
actionName: 'CLOSED',
originalMessage: {
reason: CONST.REPORT.ARCHIVE_REASON.DEFAULT,
},
};
// Given the user is in all betas
const betas = [CONST.BETAS.DEFAULT_ROOMS];
return (
waitForBatchedUpdates()
.then(() => LHNTestUtils.getDefaultRenderedSidebarLinks('0'))
// When Onyx is updated with the data and the sidebar re-renders
.then(() => {
const reportCollection: ReportCollectionDataSet = {
[`${ONYXKEYS.COLLECTION.REPORT}${report.reportID}`]: report,
};
const reportAction: ReportActionsCollectionDataSet = {
[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.reportID}`]: {[action.reportActionID]: action},
} as ReportActionsCollectionDataSet;
return Onyx.multiSet({
[ONYXKEYS.BETAS]: betas,
[ONYXKEYS.NVP_PRIORITY_MODE]: CONST.PRIORITY_MODE.GSD,
[ONYXKEYS.PERSONAL_DETAILS_LIST]: LHNTestUtils.fakePersonalDetails,
[ONYXKEYS.IS_LOADING_APP]: false,
...reportCollection,
...reportAction,
});
})
.then(() => {
const hintText = Localize.translateLocal('accessibilityHints.chatUserDisplayNames');
const displayNames = screen.queryAllByLabelText(hintText);
expect(displayNames[0]).toHaveTextContent('Report (archived)');
const hintMessagePreviewText = Localize.translateLocal('accessibilityHints.lastChatMessagePreview');
const messagePreviewTexts = screen.queryAllByLabelText(hintMessagePreviewText);
expect(messagePreviewTexts[0]).toHaveTextContent('This chat room has been archived.');
})
);
});
it('renders the policy deleted archive reason as the preview message of the chat', () => {
const report = {
...LHNTestUtils.getFakeReport([1, 2], 3, true),
policyName: 'Vikings Policy',
chatType: CONST.REPORT.CHAT_TYPE.POLICY_ROOM,
statusNum: CONST.REPORT.STATUS_NUM.CLOSED,
stateNum: CONST.REPORT.STATE_NUM.APPROVED,
// eslint-disable-next-line @typescript-eslint/naming-convention
private_isArchived: DateUtils.getDBTime(),
lastMessageText: 'test',
};
const action = {
...LHNTestUtils.getFakeReportAction('email1@test.com', 3),
actionName: 'CLOSED',
originalMessage: {
policyName: 'Vikings Policy',
reason: 'policyDeleted',
},
};
// Given the user is in all betas
const betas = [CONST.BETAS.DEFAULT_ROOMS];
return (
waitForBatchedUpdates()
.then(() => LHNTestUtils.getDefaultRenderedSidebarLinks('0'))
// When Onyx is updated with the data and the sidebar re-renders
.then(() => {
const reportCollection: ReportCollectionDataSet = {
[`${ONYXKEYS.COLLECTION.REPORT}${report.reportID}`]: report,
};
const reportAction: ReportActionsCollectionDataSet = {
[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.reportID}`]: {[action.reportActionID]: action},
} as ReportActionsCollectionDataSet;
return Onyx.multiSet({
[ONYXKEYS.BETAS]: betas,
[ONYXKEYS.NVP_PRIORITY_MODE]: CONST.PRIORITY_MODE.GSD,
[ONYXKEYS.PERSONAL_DETAILS_LIST]: LHNTestUtils.fakePersonalDetails,
[ONYXKEYS.IS_LOADING_APP]: false,
...reportCollection,
...reportAction,
});
})
.then(() => {
const hintText = Localize.translateLocal('accessibilityHints.chatUserDisplayNames');
const displayNames = screen.queryAllByLabelText(hintText);
expect(displayNames[0]).toHaveTextContent('Report (archived)');
const hintMessagePreviewText = Localize.translateLocal('accessibilityHints.lastChatMessagePreview');
const messagePreviewTexts = screen.queryAllByLabelText(hintMessagePreviewText);
expect(messagePreviewTexts[0]).toHaveTextContent('This chat is no longer active because Vikings Policy is no longer an active workspace.');
})
);
});
});
});