Skip to content

Commit

Permalink
Merge pull request #35545 from Expensify/revert-35384-feat/refactor-r…
Browse files Browse the repository at this point in the history
…eportscreen-tests

[NoQA] Revert "[NoQA] Enable and refactor ReportScreen perf tests"
  • Loading branch information
techievivek authored Feb 1, 2024
2 parents c675857 + b9bd10b commit eab0086
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 49 deletions.
58 changes: 31 additions & 27 deletions tests/perf-test/ReportScreen.perf-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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');

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 () => {
/**
Expand All @@ -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');

Expand All @@ -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()
Expand All @@ -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,
},
Expand All @@ -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 () => {
/**
Expand All @@ -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
Expand All @@ -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()
Expand All @@ -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,
},
Expand Down
9 changes: 1 addition & 8 deletions tests/utils/ReportTestUtils.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import _ from 'underscore';
import createRandomReportAction from './collections/reportActions';

const actionNames = ['ADDCOMMENT', 'IOU', 'REPORTPREVIEW', 'CLOSED'];

Expand Down Expand Up @@ -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};
});
Expand Down
18 changes: 4 additions & 14 deletions tests/utils/collections/reportActions.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -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
Expand All @@ -42,7 +32,7 @@ export default function createRandomReportAction(index: number): ReportAction {
text: randWord(),
},
],
created: getRandomDate(),
created: randPastDate().toISOString(),
message: [
{
type: randWord(),
Expand All @@ -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: {},
Expand Down

0 comments on commit eab0086

Please sign in to comment.