diff --git a/tests/perf-test/ReportScreen.perf-test.js b/tests/perf-test/ReportScreen.perf-test.js index dbc7775d066e..5a144e715f5b 100644 --- a/tests/perf-test/ReportScreen.perf-test.js +++ b/tests/perf-test/ReportScreen.perf-test.js @@ -15,10 +15,7 @@ import * as Localize from '../../src/libs/Localize'; import ONYXKEYS from '../../src/ONYXKEYS'; import {ReportAttachmentsProvider} from '../../src/pages/home/report/ReportAttachmentsContext'; import ReportScreen from '../../src/pages/home/ReportScreen'; -import createCollection from '../utils/collections/createCollection'; -import createPersonalDetails from '../utils/collections/personalDetails'; -import createRandomPolicy from '../utils/collections/policies'; -import createRandomReport from '../utils/collections/reports'; +import * as LHNTestUtils from '../utils/LHNTestUtils'; import PusherHelper from '../utils/PusherHelper'; import * as ReportTestUtils from '../utils/ReportTestUtils'; import * as TestHelper from '../utils/TestHelper'; @@ -59,7 +56,6 @@ jest.mock('../../src/hooks/useEnvironment', () => jest.mock('../../src/libs/Permissions', () => ({ canUseLinkPreviews: jest.fn(() => true), - canUseDefaultRooms: jest.fn(() => true), })); jest.mock('../../src/hooks/usePermissions.ts'); @@ -107,18 +103,6 @@ afterEach(() => { PusherHelper.teardown(); }); -const policies = createCollection( - (item) => `${ONYXKEYS.COLLECTION.POLICY}${item.id}`, - (index) => createRandomPolicy(index), - 10, -); - -const personalDetails = createCollection( - (item) => item.accountID, - (index) => createPersonalDetails(index), - 20, -); - /** * This is a helper function to create a mock for the addListener function of the react-navigation library. * The reason we need this is because we need to trigger the transitionEnd event in our tests to simulate @@ -168,11 +152,7 @@ function ReportScreenWrapper(args) { ); } -const report = {...createRandomReport(1), policyID: '1'}; -const reportActions = ReportTestUtils.getMockedReportActionsMap(500); -const mockRoute = {params: {reportID: '1'}}; - -test('[ReportScreen] should render ReportScreen with composer interactions', () => { +test.skip('[ReportScreen] should render ReportScreen with composer interactions', () => { const {triggerTransitionEnd, addListener} = createAddListenerMock(); const scenario = async () => { /** @@ -186,6 +166,9 @@ test('[ReportScreen] should render ReportScreen with composer interactions', () await act(triggerTransitionEnd); + // Query for the report list + await screen.findByTestId('report-actions-list'); + // Query for the composer const composer = await screen.findByTestId('composer'); @@ -206,6 +189,15 @@ test('[ReportScreen] should render ReportScreen with composer interactions', () await screen.findByLabelText(hintHeaderText); }; + const policy = { + policyID: 1, + name: 'Testing Policy', + }; + + const report = LHNTestUtils.getFakeReport(); + const reportActions = ReportTestUtils.getMockedReportActionsMap(1000); + const mockRoute = {params: {reportID: '1'}}; + const navigation = {addListener}; return waitForBatchedUpdates() @@ -214,9 +206,9 @@ test('[ReportScreen] should render ReportScreen with composer interactions', () [ONYXKEYS.IS_SIDEBAR_LOADED]: true, [`${ONYXKEYS.COLLECTION.REPORT}${mockRoute.params.reportID}`]: report, [`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${mockRoute.params.reportID}`]: reportActions, - [ONYXKEYS.PERSONAL_DETAILS_LIST]: personalDetails, + [ONYXKEYS.PERSONAL_DETAILS_LIST]: LHNTestUtils.fakePersonalDetails, [ONYXKEYS.BETAS]: [CONST.BETAS.DEFAULT_ROOMS], - [`${ONYXKEYS.COLLECTION.POLICY}`]: policies, + [`${ONYXKEYS.COLLECTION.POLICY}${policy.policyID}`]: policy, [`${ONYXKEYS.COLLECTION.REPORT_METADATA}${mockRoute.params.reportID}`]: { isLoadingReportActions: false, }, @@ -233,7 +225,7 @@ test('[ReportScreen] should render ReportScreen with composer interactions', () ); }); -test('[ReportScreen] should press of the report item', () => { +test.skip('[ReportScreen] should press of the report item', () => { const {triggerTransitionEnd, addListener} = createAddListenerMock(); const scenario = async () => { /** @@ -250,6 +242,9 @@ test('[ReportScreen] should press of the report item', () => { // Query for the report list await screen.findByTestId('report-actions-list'); + // Query for the composer + await screen.findByTestId('composer'); + const hintReportPreviewText = Localize.translateLocal('iou.viewDetails'); // Query for report preview buttons @@ -259,6 +254,15 @@ test('[ReportScreen] should press of the report item', () => { fireEvent.press(reportPreviewButtons[0]); }; + const policy = { + policyID: 123, + name: 'Testing Policy', + }; + + const report = LHNTestUtils.getFakeReport(); + const reportActions = ReportTestUtils.getMockedReportActionsMap(1000); + const mockRoute = {params: {reportID: '2'}}; + const navigation = {addListener}; return waitForBatchedUpdates() @@ -267,9 +271,9 @@ test('[ReportScreen] should press of the report item', () => { [ONYXKEYS.IS_SIDEBAR_LOADED]: true, [`${ONYXKEYS.COLLECTION.REPORT}${mockRoute.params.reportID}`]: report, [`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${mockRoute.params.reportID}`]: reportActions, - [ONYXKEYS.PERSONAL_DETAILS_LIST]: personalDetails, + [ONYXKEYS.PERSONAL_DETAILS_LIST]: LHNTestUtils.fakePersonalDetails, [ONYXKEYS.BETAS]: [CONST.BETAS.DEFAULT_ROOMS], - [`${ONYXKEYS.COLLECTION.POLICY}`]: policies, + [`${ONYXKEYS.COLLECTION.POLICY}${policy.policyID}`]: policy, [`${ONYXKEYS.COLLECTION.REPORT_METADATA}${mockRoute.params.reportID}`]: { isLoadingReportActions: false, }, diff --git a/tests/utils/ReportTestUtils.js b/tests/utils/ReportTestUtils.js index 86899e4045f6..910f2200876b 100644 --- a/tests/utils/ReportTestUtils.js +++ b/tests/utils/ReportTestUtils.js @@ -1,5 +1,4 @@ import _ from 'underscore'; -import createRandomReportAction from './collections/reportActions'; const actionNames = ['ADDCOMMENT', 'IOU', 'REPORTPREVIEW', 'CLOSED']; @@ -52,13 +51,7 @@ const getMockedReportActionsMap = (length = 100) => { const mockReports = Array.from({length}, (__, i) => { const reportID = i + 1; const actionName = i === 0 ? 'CREATED' : actionNames[i % actionNames.length]; - const reportAction = { - ...createRandomReportAction(reportID), - actionName, - originalMessage: { - linkedReportID: reportID.toString(), - }, - }; + const reportAction = getFakeReportAction(reportID, actionName); return {[reportID]: reportAction}; }); diff --git a/tests/utils/collections/reportActions.ts b/tests/utils/collections/reportActions.ts index bb14a2c7a41b..cc258e89c041 100644 --- a/tests/utils/collections/reportActions.ts +++ b/tests/utils/collections/reportActions.ts @@ -1,5 +1,4 @@ -import {rand, randAggregation, randBoolean, randWord} from '@ngneat/falso'; -import {format} from 'date-fns'; +import {rand, randAggregation, randBoolean, randPastDate, randWord} from '@ngneat/falso'; import CONST from '@src/CONST'; import type {ReportAction} from '@src/types/onyx'; @@ -18,15 +17,6 @@ const flattenActionNamesValues = (actionNames: any) => { return result; }; -const getRandomDate = (): string => { - const randomTimestamp = Math.random() * new Date().getTime(); - const randomDate = new Date(randomTimestamp); - - const formattedDate = format(randomDate, CONST.DATE.FNS_DB_FORMAT_STRING); - - return formattedDate; -}; - export default function createRandomReportAction(index: number): ReportAction { return { // we need to add any here because of the way we are generating random values @@ -42,7 +32,7 @@ export default function createRandomReportAction(index: number): ReportAction { text: randWord(), }, ], - created: getRandomDate(), + created: randPastDate().toISOString(), message: [ { type: randWord(), @@ -67,13 +57,13 @@ export default function createRandomReportAction(index: number): ReportAction { ], originalMessage: { html: randWord(), - lastModified: getRandomDate(), + type: rand(Object.values(CONST.IOU.REPORT_ACTION_TYPE)), }, whisperedToAccountIDs: randAggregation(), avatar: randWord(), automatic: randBoolean(), shouldShow: randBoolean(), - lastModified: getRandomDate(), + lastModified: randPastDate().toISOString(), pendingAction: rand(Object.values(CONST.RED_BRICK_ROAD_PENDING_ACTION)), delegateAccountID: index, errors: {},