|
1 | 1 | import type * as Navigation from '@react-navigation/native'; |
2 | 2 | import {fireEvent, screen, waitFor} from '@testing-library/react-native'; |
3 | | -import type {OnyxCollection} from 'react-native-onyx'; |
4 | 3 | import Onyx from 'react-native-onyx'; |
5 | 4 | import {measureRenders} from 'reassure'; |
6 | 5 | import CONST from '@src/CONST'; |
7 | 6 | import ONYXKEYS from '@src/ONYXKEYS'; |
8 | 7 | import type {OnyxValues} from '@src/ONYXKEYS'; |
9 | | -import type {PersonalDetails, Report, ReportActions, ReportMetadata, ReportNameValuePairs} from '@src/types/onyx'; |
10 | | -import type Policy from '@src/types/onyx/Policy'; |
11 | | -import createPersonalDetails from '../utils/collections/personalDetails'; |
12 | | -import createRandomPolicy from '../utils/collections/policies'; |
| 8 | +import type {ReportActions} from '@src/types/onyx'; |
13 | 9 | import createRandomReportAction from '../utils/collections/reportActions'; |
14 | | -import {createRandomReport} from '../utils/collections/reports'; |
| 10 | +import {createSidebarReportsWithActions as createReportsWithActions} from '../utils/collections/sidebarReports'; |
15 | 11 | import * as LHNTestUtils from '../utils/LHNTestUtils'; |
16 | 12 | import * as TestHelper from '../utils/TestHelper'; |
17 | 13 | import waitForBatchedUpdates from '../utils/waitForBatchedUpdates'; |
@@ -75,70 +71,6 @@ const getMockedReportsMap = (length = 100) => { |
75 | 71 | const mockedResponseMap = getMockedReportsMap(500); |
76 | 72 |
|
77 | 73 | const REPORTS_COUNT = 150; |
78 | | -const ACTIONS_PER_REPORT = 50; |
79 | | - |
80 | | -const createMockReportActions = (reportID: string, count: number): ReportActions => { |
81 | | - const actions: ReportActions = {}; |
82 | | - for (let i = 0; i < count; i++) { |
83 | | - actions[`${reportID}_${i}`] = createRandomReportAction(i); |
84 | | - } |
85 | | - return actions; |
86 | | -}; |
87 | | - |
88 | | -const createReportsWithActions = (count: number) => { |
89 | | - const reports: OnyxCollection<Report> = {}; |
90 | | - const reportActions: OnyxCollection<ReportActions> = {}; |
91 | | - const reportNameValuePairs: OnyxCollection<ReportNameValuePairs> = {}; |
92 | | - const policies: OnyxCollection<Policy> = {}; |
93 | | - const personalDetails: OnyxCollection<PersonalDetails> = {}; |
94 | | - const reportMetadata: OnyxCollection<ReportMetadata> = {}; |
95 | | - |
96 | | - const basePolicy = createRandomPolicy(1); |
97 | | - policies[`${ONYXKEYS.COLLECTION.POLICY}${basePolicy.id}`] = basePolicy; |
98 | | - |
99 | | - for (let i = 1; i <= count; i++) { |
100 | | - const reportID = String(i); |
101 | | - const report = createRandomReport(i, undefined); |
102 | | - |
103 | | - const isArchived = i % 10 === 0; |
104 | | - const reportTypeMod = i % 4; |
105 | | - let reportType: string; |
106 | | - if (reportTypeMod === 0) { |
107 | | - reportType = CONST.REPORT.TYPE.IOU; |
108 | | - } else if (reportTypeMod === 1) { |
109 | | - reportType = CONST.REPORT.TYPE.EXPENSE; |
110 | | - } else { |
111 | | - reportType = CONST.REPORT.TYPE.CHAT; |
112 | | - } |
113 | | - |
114 | | - reports[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`] = { |
115 | | - ...report, |
116 | | - type: reportType, |
117 | | - }; |
118 | | - reportActions[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`] = createMockReportActions(reportID, ACTIONS_PER_REPORT); |
119 | | - reportNameValuePairs[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${reportID}`] = { |
120 | | - private_isArchived: isArchived ? 'true' : 'false', |
121 | | - }; |
122 | | - |
123 | | - const lastActorAccountID = report.lastActorAccountID ?? i; |
124 | | - personalDetails[String(lastActorAccountID)] = createPersonalDetails(lastActorAccountID); |
125 | | - |
126 | | - if (i % 5 === 0) { |
127 | | - reportMetadata[`${ONYXKEYS.COLLECTION.REPORT_METADATA}${reportID}`] = { |
128 | | - lastVisitTime: new Date().toISOString(), |
129 | | - }; |
130 | | - } |
131 | | - } |
132 | | - |
133 | | - return { |
134 | | - reports, |
135 | | - reportActions, |
136 | | - reportNameValuePairs, |
137 | | - policies, |
138 | | - personalDetails, |
139 | | - reportMetadata, |
140 | | - }; |
141 | | -}; |
142 | 74 |
|
143 | 75 | describe('SidebarLinks', () => { |
144 | 76 | beforeAll(() => { |
@@ -248,7 +180,8 @@ describe('SidebarLinks', () => { |
248 | 180 | const scenario = async () => { |
249 | 181 | await screen.findByTestId('lhn-options-list'); |
250 | 182 | const firstReportID = '1'; |
251 | | - const firstReportActions = reportActions[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${firstReportID}`]; |
| 183 | + const actionsCollection = reportActions ?? {}; |
| 184 | + const firstReportActions = actionsCollection[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${firstReportID}`]; |
252 | 185 | if (firstReportActions) { |
253 | 186 | const newAction = createRandomReportAction(999); |
254 | 187 | const updatedActions = { |
@@ -283,9 +216,10 @@ describe('SidebarLinks', () => { |
283 | 216 | const scenario = async () => { |
284 | 217 | await screen.findByTestId('lhn-options-list'); |
285 | 218 | const updates: Record<string, ReportActions> = {}; |
| 219 | + const actionsCollection = reportActions ?? {}; |
286 | 220 | for (let i = 1; i <= 10; i++) { |
287 | 221 | const reportID = String(i); |
288 | | - const existingActions = reportActions[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`]; |
| 222 | + const existingActions = actionsCollection[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`]; |
289 | 223 | if (existingActions) { |
290 | 224 | const newAction = createRandomReportAction(1000 + i); |
291 | 225 | updates[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`] = { |
@@ -350,7 +284,8 @@ describe('SidebarLinks', () => { |
350 | 284 | const scenario = async () => { |
351 | 285 | await screen.findByTestId('lhn-options-list'); |
352 | 286 | const firstReportID = '1'; |
353 | | - const currentArchivedStatus = reportNameValuePairs[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${firstReportID}`]?.private_isArchived; |
| 287 | + const nameValuePairsCollection = reportNameValuePairs ?? {}; |
| 288 | + const currentArchivedStatus = nameValuePairsCollection[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${firstReportID}`]?.private_isArchived; |
354 | 289 | await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${firstReportID}`, { |
355 | 290 | private_isArchived: currentArchivedStatus === 'true' ? 'false' : 'true', |
356 | 291 | }); |
|
0 commit comments