Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/components/Search/SearchFiltersChatsSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ function SearchFiltersChatsSelector({initialReportIDs, onFiltersUpdate, isScreen
const isReportArchived = !!privateIsArchived;
const policy = allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${reportData?.policyID}`];
const reportPolicyTags = policyTags?.[`${ONYXKEYS.COLLECTION.POLICY_TAGS}${getNonEmptyStringOnyxID(report?.policyID)}`];
const alternateText = getAlternateText(report, {}, isReportArchived, currentUserEmail, policy, {}, undefined, undefined, reportAttributesDerived, reportPolicyTags);
const alternateText = getAlternateText(report, {}, isReportArchived, currentUserAccountID, policy, {}, undefined, undefined, reportAttributesDerived, reportPolicyTags);
return {...report, alternateText};
});

Expand Down
350 changes: 11 additions & 339 deletions src/libs/ModifiedExpenseMessage.ts

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import EXPENSIFY_ICON_URL from '@assets/images/expensify-logo-round-clearspace.p
import * as AppUpdate from '@libs/actions/AppUpdate';
// eslint-disable-next-line @typescript-eslint/no-deprecated -- translateLocal is deprecated; BrowserNotifications is non-React code that cannot use the translate hook
import {translateLocal} from '@libs/Localize';
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ CONSISTENCY-5 (docs)

The eslint-disable-next-line @typescript-eslint/no-deprecated on the translateLocal import lacks a justification comment. Other newly added eslint-disables in this same PR include justification (e.g., -- Onyx.connectWithoutView is being removed in ...).

Add a justification explaining why the deprecated API is used:

// eslint-disable-next-line @typescript-eslint/no-deprecated -- translateLocal is deprecated; BrowserNotifications is non-React code that cannot use the translate hook
import {translateLocal} from '@libs/Localize';

Please rate this suggestion with 👍 or 👎 to help us improve! Reactions are used to monitor reviewer efficiency.

import {getForReportActionTemp} from '@libs/ModifiedExpenseMessage';
import {getForReportAction} from '@libs/ModifiedExpenseMessage';
import {getTextFromHtml} from '@libs/ReportActionsUtils';
import * as ReportUtils from '@libs/ReportUtils';
import playSound, {SOUNDS} from '@libs/Sound';
Expand Down Expand Up @@ -144,7 +144,7 @@ export default {
currentUserLogin,
}: LocalNotificationModifiedExpensePushParams) {
const title = reportAction.person?.map((f) => f.text).join(', ') ?? '';
const bodyWithHTML = getForReportActionTemp({
const bodyWithHTML = getForReportAction({
// eslint-disable-next-line @typescript-eslint/no-deprecated -- translateLocal is deprecated; BrowserNotifications is non-React code that cannot use the translate hook
translate: translateLocal,
reportAction,
Expand Down
52 changes: 19 additions & 33 deletions src/libs/OptionsListUtils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import {appendCountryCode, getPhoneNumberWithoutSpecialChars} from '@libs/LoginUtils';
import {MaxHeap} from '@libs/MaxHeap';
import {MinHeap} from '@libs/MinHeap';
import {getForReportAction, getForReportActionTemp} from '@libs/ModifiedExpenseMessage';
import {getForReportAction} from '@libs/ModifiedExpenseMessage';
import Navigation from '@libs/Navigation/Navigation';
import Parser from '@libs/Parser';
import Permissions from '@libs/Permissions';
Expand Down Expand Up @@ -96,7 +96,6 @@
isPendingRemove,
isReimbursementDeQueuedOrCanceledAction,
isReimbursementQueuedAction,
isRejectedAction,
isRenamedAction,
isReportActionVisible,
isReportPreviewAction,
Expand Down Expand Up @@ -208,7 +207,7 @@
*/

let allReports: OnyxCollection<Report>;
Onyx.connect({

Check warning on line 210 in src/libs/OptionsListUtils/index.ts

View workflow job for this annotation

GitHub Actions / ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function

Check warning on line 210 in src/libs/OptionsListUtils/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.REPORT,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -220,7 +219,7 @@
const allSortedReportActions: Record<string, ReportAction[]> = {};
const cachedOneTransactionThreadReportIDs: Record<string, string | undefined> = {};
let allReportActions: OnyxCollection<ReportActions>;
Onyx.connect({

Check warning on line 222 in src/libs/OptionsListUtils/index.ts

View workflow job for this annotation

GitHub Actions / ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function

Check warning on line 222 in src/libs/OptionsListUtils/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.REPORT_ACTIONS,
waitForCollectionCallback: true,
callback: (actions) => {
Expand Down Expand Up @@ -265,7 +264,7 @@
});

let activePolicyID: OnyxEntry<string>;
Onyx.connect({

Check warning on line 267 in src/libs/OptionsListUtils/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.NVP_ACTIVE_POLICY_ID,
callback: (value) => (activePolicyID = value),
});
Expand Down Expand Up @@ -421,7 +420,7 @@
option: OptionData,
{showChatPreviewLine = false, forcePolicyNamePreview = false}: PreviewConfig,
isReportArchived: boolean | undefined,
currentUserLogin: string,
currentUserAccountID: number,
// We'll make it required in the next PR. Ref: https://github.com/Expensify/App/issues/66415
policy?: OnyxEntry<Policy>,
lastActorDetails: Partial<PersonalDetails> | null = {},
Expand All @@ -448,7 +447,6 @@
visibleReportActionsDataParam: visibleReportActionsData,
reportAttributesDerived,
policyTags,
currentUserLogin,
});
const reportPrefix = getReportSubtitlePrefix(report);
const formattedLastMessageTextWithPrefix = reportPrefix + formattedLastMessageText;
Expand Down Expand Up @@ -594,7 +592,6 @@
movedToReport,
policy,
isReportArchived = false,
policyForMovingExpensesID,
reportMetadata,
visibleReportActionsDataParam,
lastAction,
Expand All @@ -615,7 +612,7 @@
lastAction?: OnyxEntry<ReportAction>;
reportAttributesDerived?: ReportAttributesDerivedValue['reports'];
policyTags?: OnyxEntry<PolicyTagLists>;
currentUserLogin: string;
currentUserLogin?: string;
}): string {
const reportID = report?.reportID;
const canUserPerformWrite = canUserPerformWriteAction(report, isReportArchived);
Expand Down Expand Up @@ -725,24 +722,15 @@
} else if (isReportMessageAttachment({text: report?.lastMessageText ?? '', html: report?.lastMessageHtml, type: ''})) {
lastMessageTextFromReport = `[${translate('common.attachment')}]`;
} else if (isModifiedExpenseAction(lastReportAction)) {
const properSchemaForModifiedExpenseMessageWithHTML = policyTags
? getForReportActionTemp({
translate,
reportAction: lastReportAction,
policy,
movedFromReport,
movedToReport,
policyTags,
currentUserLogin,
})
: getForReportAction({
reportAction: lastReportAction,
policyID: report?.policyID,
movedFromReport,
movedToReport,
policyForMovingExpensesID,
currentUserLogin,
});
const properSchemaForModifiedExpenseMessageWithHTML = getForReportAction({
translate,
reportAction: lastReportAction,
policy,
movedFromReport,
movedToReport,
policyTags,
currentUserLogin: currentUserLogin ?? '',
Comment on lines +728 to +732
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve policy context for modified-expense list previews

This path now always uses getForReportAction with whatever policy, policyTags, and currentUserLogin were passed into getLastMessageTextForReport, but several options-list callers invoke this helper without those fields. In that common case, modified-expense previews lose workspace-specific tag labels and policy-aware attribution (e.g., policy-rules/MCC context) and fall back to generic text. The previous fallback branch (getForReportAction with policyID) still resolved that context from Onyx for these callers.

Useful? React with 👍 / 👎.

});
// Strip HTML tags for plain text display in options list
const properSchemaForModifiedExpenseMessage = Parser.htmlToText(properSchemaForModifiedExpenseMessageWithHTML);
lastMessageTextFromReport = formatReportLastMessageText(properSchemaForModifiedExpenseMessage, true);
Expand Down Expand Up @@ -791,7 +779,7 @@
} else {
lastMessageTextFromReport = translate('iou.forwarded');
}
} else if (isRejectedAction(lastReportAction)) {
} else if (lastReportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.REJECTED) {
lastMessageTextFromReport = translate('iou.rejectedThisReport');
} else if (lastReportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.POLICY_CHANGE_LOG.CORPORATE_UPGRADE) {
lastMessageTextFromReport = translate('workspaceActions.upgradedWorkspace');
Expand Down Expand Up @@ -1032,7 +1020,6 @@

// If displaying chat preview line is needed, let's overwrite the default alternate text
const lastActorDetails = personalDetails?.[report?.lastActorAccountID ?? String(CONST.DEFAULT_NUMBER_ID)] ?? {};
const currentUserLogin = personalDetails?.[currentUserAccountID]?.login ?? '';
// eslint-disable-next-line @typescript-eslint/no-deprecated
const translateFn = translate ?? translateLocal;
result.lastMessageText = getLastMessageTextForReport({
Expand All @@ -1043,7 +1030,6 @@
visibleReportActionsDataParam: visibleReportActionsData,
reportAttributesDerived,
policyTags,
currentUserLogin,
});
result.alternateText =
showPersonalDetails && personalDetail?.login
Expand All @@ -1052,7 +1038,7 @@
result,
{showChatPreviewLine, forcePolicyNamePreview},
!!result.private_isArchived,
currentUserLogin,
currentUserAccountID,
// TODO: Remove this in the next PR that will refactor prepareReportOptionsForDisplay. Ref: https://github.com/Expensify/App/issues/66415
undefined,
lastActorDetails,
Expand Down Expand Up @@ -2236,7 +2222,7 @@
function prepareReportOptionsForDisplay(
options: Array<SearchOption<Report>>,
policiesCollection: OnyxCollection<Policy>,
currentUserLogin: string,
currentUserAccountID: number,
config: GetValidReportsConfig,
visibleReportActionsData: VisibleReportActionsDerivedValue = {},
reportAttributesDerived?: ReportAttributesDerivedValue['reports'],
Expand Down Expand Up @@ -2277,7 +2263,7 @@
option,
{showChatPreviewLine, forcePolicyNamePreview},
!!option.private_isArchived,
currentUserLogin,
currentUserAccountID,
// TODO: Remove this in the next PR that will refactor prepareReportOptionsForDisplay. Ref: https://github.com/Expensify/App/issues/66415
undefined,
null,
Expand Down Expand Up @@ -2522,7 +2508,7 @@
selfDMChat = prepareReportOptionsForDisplay(
selfDMChats,
policiesCollection,
currentUserEmail,
currentUserAccountID,
{
...getValidReportsConfig,
selectedOptions,
Expand All @@ -2544,7 +2530,7 @@
recentReportOptions = prepareReportOptionsForDisplay(
recentReportOptions,
policiesCollection,
currentUserEmail,
currentUserAccountID,
{
...getValidReportsConfig,
selectedOptions,
Expand All @@ -2562,7 +2548,7 @@
workspaceChats = prepareReportOptionsForDisplay(
workspaceChats,
policiesCollection,
currentUserEmail,
currentUserAccountID,
{
...getValidReportsConfig,
selectedOptions,
Expand Down
30 changes: 10 additions & 20 deletions src/libs/ReportNameUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import {formatPhoneNumber as formatPhoneNumberPhoneUtils} from './LocalePhoneNum
// eslint-disable-next-line @typescript-eslint/no-deprecated
import {translateLocal} from './Localize';
// eslint-disable-next-line import/no-cycle
import {getForReportAction, getForReportActionTemp, getMovedReportID} from './ModifiedExpenseMessage';
import {getForReportAction, getMovedReportID} from './ModifiedExpenseMessage';
import Parser from './Parser';
import {getDisplayNameOrDefault} from './PersonalDetailsUtils';
import {getCleanedTagName, isPolicyAdmin, isPolicyFieldListEmpty} from './PolicyUtils';
Expand Down Expand Up @@ -747,27 +747,17 @@ function computeChatThreadReportName(
return generateArchivedReportName(reportActionMessage);
}
if (!isEmptyObject(parentReportAction) && isModifiedExpenseAction(parentReportAction)) {
const policyID = reports?.[`${ONYXKEYS.COLLECTION.REPORT}${report?.reportID}`]?.policyID;

const movedFromReport = reports?.[`${ONYXKEYS.COLLECTION.REPORT}${getMovedReportID(parentReportAction, CONST.REPORT.MOVE_TYPE.FROM)}`];
const movedToReport = reports?.[`${ONYXKEYS.COLLECTION.REPORT}${getMovedReportID(parentReportAction, CONST.REPORT.MOVE_TYPE.TO)}`];
const modifiedMessageWithHTML = policyTags
? getForReportActionTemp({
translate,
reportAction: parentReportAction,
movedFromReport,
movedToReport,
policyTags,
policy,
currentUserLogin,
})
: getForReportAction({
reportAction: parentReportAction,
policyID,
movedFromReport,
movedToReport,
currentUserLogin,
});
const modifiedMessageWithHTML = getForReportAction({
translate,
reportAction: parentReportAction,
movedFromReport,
movedToReport,
policyTags,
policy,
currentUserLogin,
});
// Strip HTML tags for plain text display in report previews
const modifiedMessage = Parser.htmlToText(modifiedMessageWithHTML);
return formatReportLastMessageText(modifiedMessage);
Expand Down
5 changes: 2 additions & 3 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1051,7 +1051,7 @@
};

let conciergeReportIDOnyxConnect: OnyxEntry<string>;
Onyx.connect({

Check warning on line 1054 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.CONCIERGE_REPORT_ID,
callback: (value) => {
conciergeReportIDOnyxConnect = value;
Expand All @@ -1059,7 +1059,7 @@
});

const defaultAvatarBuildingIconTestID = 'SvgDefaultAvatarBuilding Icon';
Onyx.connect({

Check warning on line 1062 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.SESSION,
callback: (value) => {
// When signed out, val is undefined
Expand All @@ -1077,7 +1077,7 @@
let allPersonalDetails: OnyxEntry<PersonalDetailsList>;
let allPersonalDetailLogins: string[];
let currentUserPersonalDetails: OnyxEntry<PersonalDetails>;
Onyx.connect({

Check warning on line 1080 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
callback: (value) => {
if (currentUserAccountID) {
Expand All @@ -1089,7 +1089,7 @@
});

let allReportsDraft: OnyxCollection<Report>;
Onyx.connect({

Check warning on line 1092 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.REPORT_DRAFT,
waitForCollectionCallback: true,
callback: (value) => (allReportsDraft = value),
Expand All @@ -1097,7 +1097,7 @@

let allPolicies: OnyxCollection<Policy>;
let policiesArray: Policy[] = [];
Onyx.connect({

Check warning on line 1100 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.POLICY,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -1107,7 +1107,7 @@
});

let allPolicyDrafts: OnyxCollection<Policy>;
Onyx.connect({

Check warning on line 1110 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.POLICY_DRAFTS,
waitForCollectionCallback: true,
callback: (value) => (allPolicyDrafts = value),
Expand All @@ -1115,7 +1115,7 @@

let allReports: OnyxCollection<Report>;
let reportsByPolicyID: ReportByPolicyMap;
Onyx.connect({

Check warning on line 1118 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.REPORT,
waitForCollectionCallback: true,
callback: (value) => {
Expand Down Expand Up @@ -5912,13 +5912,12 @@
return generateArchivedReportName(reportActionMessage);
}
if (!isEmptyObject(parentReportAction) && isModifiedExpenseAction(parentReportAction)) {
const policyID = report?.policyID;

const movedFromReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${getMovedReportID(parentReportAction, CONST.REPORT.MOVE_TYPE.FROM)}`];
const movedToReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${getMovedReportID(parentReportAction, CONST.REPORT.MOVE_TYPE.TO)}`];
const modifiedMessageWithHTML = getForReportAction({
// eslint-disable-next-line @typescript-eslint/no-deprecated -- translateLocal is deprecated; getReportName is non-React code that cannot use the translate hook
translate: translateLocal,
reportAction: parentReportAction,
policyID,
movedFromReport,
movedToReport,
// Temporarily retrieves current user email from getCurrentUserEmail, since getReportName is deprecated and no longer requires this parameter to be passed explicitly.
Expand Down
11 changes: 10 additions & 1 deletion src/libs/actions/OnyxDerived/configs/reportAttributes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ export default createOnyxDerivedValueConfig({
const reportNameValuePairsUpdates = sourceValues?.[ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS] ?? {};
const transactionsUpdates = sourceValues?.[ONYXKEYS.COLLECTION.TRANSACTION];
const transactionViolationsUpdates = sourceValues?.[ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS];
const policyTagsUpdates = sourceValues?.[ONYXKEYS.COLLECTION.POLICY_TAGS];

let dataToIterate = Object.keys(reports);
// check if there are any report-related updates

Expand Down Expand Up @@ -144,7 +146,7 @@ export default createOnyxDerivedValueConfig({

if (useIncrementalUpdates) {
// if there are report-related updates, iterate over the updates
if (updates.length > 0 || !!transactionsUpdates || !!transactionViolationsUpdates) {
if (updates.length > 0 || !!transactionsUpdates || !!transactionViolationsUpdates || !!policyTagsUpdates) {
if (updates.length > 0) {
dataToIterate = prepareReportKeys(updates);

Expand Down Expand Up @@ -183,6 +185,13 @@ export default createOnyxDerivedValueConfig({
}
dataToIterate.push(...prepareReportKeys(transactionReportIDs));
}
if (policyTagsUpdates) {
const changedPolicyIDs = new Set(Object.keys(policyTagsUpdates).map((key) => key.replace(ONYXKEYS.COLLECTION.POLICY_TAGS, '')));
const affectedReportKeys = Object.values(reports)
.filter((report) => !!report?.policyID && changedPolicyIDs.has(report.policyID))
.map((report) => `${ONYXKEYS.COLLECTION.REPORT}${report?.reportID}`);
dataToIterate.push(...prepareReportKeys(affectedReportKeys));
}
} else {
// No updates to process, return current value to prevent unnecessary computation
return currentValue ?? {reports: {}, locale: null};
Expand Down
4 changes: 2 additions & 2 deletions src/pages/inbox/report/ContextMenu/ContextMenuActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {getEnvironmentURL} from '@libs/Environment/Environment';
import fileDownload from '@libs/fileDownload';
import getAttachmentDetails from '@libs/fileDownload/getAttachmentDetails';
import {formatPhoneNumber as formatPhoneNumberPhoneUtils} from '@libs/LocalePhoneNumber';
import {getForReportActionTemp} from '@libs/ModifiedExpenseMessage';
import {getForReportAction} from '@libs/ModifiedExpenseMessage';
import Navigation from '@libs/Navigation/Navigation';
import Parser from '@libs/Parser';
import {getCleanedTagName, isPolicyAdmin} from '@libs/PolicyUtils';
Expand Down Expand Up @@ -774,7 +774,7 @@ const ContextMenuActions: ContextMenuAction[] = [
const displayMessage = html ?? text;
setClipboardMessage(displayMessage);
} else if (isModifiedExpenseAction(reportAction)) {
const modifyExpenseMessageWithHTML = getForReportActionTemp({
const modifyExpenseMessageWithHTML = getForReportAction({
translate,
reportAction,
policy,
Expand Down
4 changes: 2 additions & 2 deletions src/pages/inbox/report/ReportActionItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import usePolicyForMovingExpenses from '@hooks/usePolicyForMovingExpenses';
import useReportIsArchived from '@hooks/useReportIsArchived';
import useReportTransactions from '@hooks/useReportTransactions';
import getNonEmptyStringOnyxID from '@libs/getNonEmptyStringOnyxID';
import {getForReportActionTemp, getMovedReportID} from '@libs/ModifiedExpenseMessage';
import {getForReportAction, getMovedReportID} from '@libs/ModifiedExpenseMessage';
import {getIOUReportIDFromReportActionPreview, getOriginalMessage, isMoneyRequestAction} from '@libs/ReportActionsUtils';
import {
chatIncludesChronosWithID,
Expand Down Expand Up @@ -169,7 +169,7 @@ function ReportActionItem({
action as OnyxEntry<ReportAction<typeof CONST.REPORT.ACTIONS.TYPE.REIMBURSEMENT_DEQUEUED | typeof CONST.REPORT.ACTIONS.TYPE.REIMBURSEMENT_ACH_CANCELED>>,
report,
)}
modifiedExpenseMessage={getForReportActionTemp({
modifiedExpenseMessage={getForReportAction({
translate,
reportAction: action,
policy,
Expand Down
18 changes: 12 additions & 6 deletions tests/perf-test/ModifiedExpenseMessage.perf-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,27 @@ import {randAmount} from '@ngneat/falso';
import Onyx from 'react-native-onyx';
import {measureFunction} from 'reassure';
import CONST from '@src/CONST';
import IntlStore from '@src/languages/IntlStore';
import ONYXKEYS from '@src/ONYXKEYS';
import type {Policy, Report} from '@src/types/onyx';
import {getForReportAction} from '../../src/libs/ModifiedExpenseMessage';
import createCollection from '../utils/collections/createCollection';
import createRandomPolicy from '../utils/collections/policies';
import createRandomPolicyTags from '../utils/collections/policyTags';
import createRandomReportAction from '../utils/collections/reportActions';
import {createRandomReport} from '../utils/collections/reports';
import {translateLocal} from '../utils/TestHelper';
import waitForBatchedUpdates from '../utils/waitForBatchedUpdates';

beforeAll(() =>
Onyx.init({
const CURRENT_USER_LOGIN = 'test@example.com';

beforeAll(() => {
IntlStore.load(CONST.LOCALES.EN);
return Onyx.init({
keys: ONYXKEYS,
evictableKeys: [ONYXKEYS.COLLECTION.REPORT_ACTIONS],
}),
);
});
});

// Clear out Onyx after each test so that each test starts with a clean state
afterEach(() => {
Expand All @@ -39,9 +45,9 @@ const getMockedPolicies = (length = 500) =>

const mockedReportsMap = getMockedReports(1000) as Record<`${typeof ONYXKEYS.COLLECTION.REPORT}`, Report>;
const mockedPoliciesMap = getMockedPolicies(1000) as Record<`${typeof ONYXKEYS.COLLECTION.POLICY}`, Policy>;
const mockedPolicyTags = createRandomPolicyTags('Department', 5);

test('[ModifiedExpenseMessage] getForReportAction on 1k reports and policies', async () => {
const report = createRandomReport(1, undefined);
const reportAction = {
...createRandomReportAction(1),
actionName: CONST.REPORT.ACTIONS.TYPE.MODIFIED_EXPENSE,
Expand All @@ -59,5 +65,5 @@ test('[ModifiedExpenseMessage] getForReportAction on 1k reports and policies', a
});

await waitForBatchedUpdates();
await measureFunction(() => getForReportAction({reportAction, policyID: report.policyID, currentUserLogin: 'test@example.com'}));
await measureFunction(() => getForReportAction({translate: translateLocal, reportAction, policyTags: mockedPolicyTags, currentUserLogin: CURRENT_USER_LOGIN}));
});
Loading
Loading