-
Notifications
You must be signed in to change notification settings - Fork 3.1k
/
Copy pathReportTestUtils.ts
72 lines (66 loc) · 2.48 KB
/
ReportTestUtils.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
import type {ReportAction, ReportActions} from '@src/types/onyx';
import type ReportActionName from '@src/types/onyx/ReportActionName';
import createRandomReportAction from './collections/reportActions';
const actionNames: ReportActionName[] = ['ADDCOMMENT', 'IOU', 'REPORTPREVIEW', 'CLOSED'];
const getFakeReportAction = (index: number, actionName?: ReportActionName): ReportAction =>
({
actionName,
actorAccountID: index,
automatic: false,
avatar: '',
created: '2023-09-12 16:27:35.124',
isAttachment: true,
isFirstItem: false,
lastModified: '2021-07-14T15:00:00Z',
message: [
{
html: 'hey',
isDeletedParentAction: false,
isEdited: false,
text: 'test',
type: 'TEXT',
whisperedTo: [],
},
],
originalMessage: {
html: 'hey',
lastModified: '2021-07-14T15:00:00Z',
// IOUReportID: index,
linkedReportID: index.toString(),
whisperedTo: [],
reason: '',
violationName: '',
},
pendingAction: null,
person: [
{
type: 'TEXT',
style: 'strong',
text: 'email@test.com',
},
],
reportActionID: index.toString(),
sequenceNumber: 0,
shouldShow: true,
} as ReportAction);
const getMockedSortedReportActions = (length = 100): ReportAction[] =>
Array.from({length}, (element, index): ReportAction => {
const actionName: ReportActionName = index === 0 ? 'CREATED' : 'ADDCOMMENT';
return getFakeReportAction(index + 1, actionName);
}).reverse();
const getMockedReportActionsMap = (length = 100): ReportActions => {
const mockReports: ReportActions[] = Array.from({length}, (element, index): ReportActions => {
const reportID = index + 1;
const actionName: ReportActionName = index === 0 ? 'CREATED' : actionNames[index % actionNames.length];
const reportAction = {
...createRandomReportAction(reportID),
actionName,
originalMessage: {
linkedReportID: reportID.toString(),
},
} as ReportAction;
return {[reportID]: reportAction};
});
return Object.assign({}, ...mockReports) as ReportActions;
};
export {getFakeReportAction, getMockedSortedReportActions, getMockedReportActionsMap};