diff --git a/src/components/MoneyReportHeader.tsx b/src/components/MoneyReportHeader.tsx index 0f8ce631fb72..698ed7ebc3e4 100644 --- a/src/components/MoneyReportHeader.tsx +++ b/src/components/MoneyReportHeader.tsx @@ -7,6 +7,7 @@ import type {ValueOf} from 'type-fest'; import useLocalize from '@hooks/useLocalize'; import useNetwork from '@hooks/useNetwork'; import usePaymentAnimations from '@hooks/usePaymentAnimations'; +import useReportIsArchived from '@hooks/useReportIsArchived'; import useResponsiveLayout from '@hooks/useResponsiveLayout'; import useSelectedTransactionsActions from '@hooks/useSelectedTransactionsActions'; import useTheme from '@hooks/useTheme'; @@ -31,7 +32,6 @@ import { hasOnlyHeldExpenses as hasOnlyHeldExpensesReportUtils, hasUpdatedTotal, isAllowedToApproveExpenseReport, - isArchivedReportWithID, isExported as isExportedUtils, isInvoiceReport, isProcessingReport, @@ -183,7 +183,7 @@ function MoneyReportHeader({policy, report: moneyRequestReport, transactionThrea const shouldShowBrokenConnectionViolation = shouldShowBrokenConnectionViolationForMultipleTransactions(transactionIDs, moneyRequestReport, policy, violations); const hasOnlyHeldExpenses = hasOnlyHeldExpensesReportUtils(moneyRequestReport?.reportID); const isPayAtEndExpense = isPayAtEndExpenseTransactionUtils(transaction); - const isArchivedReport = isArchivedReportWithID(moneyRequestReport?.reportID); + const isArchivedReport = useReportIsArchived(moneyRequestReport?.reportID); const [archiveReason] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${moneyRequestReport?.reportID}`, {selector: getArchiveReason, canBeMissing: true}); const [reportNameValuePairs] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${moneyRequestReport?.reportID}`, {canBeMissing: true}); diff --git a/src/components/MoneyReportHeaderOld.tsx b/src/components/MoneyReportHeaderOld.tsx index f4ced95e3507..923e976d2edc 100644 --- a/src/components/MoneyReportHeaderOld.tsx +++ b/src/components/MoneyReportHeaderOld.tsx @@ -6,6 +6,7 @@ import {useOnyx} from 'react-native-onyx'; import useLocalize from '@hooks/useLocalize'; import useNetwork from '@hooks/useNetwork'; import usePaymentAnimations from '@hooks/usePaymentAnimations'; +import useReportIsArchived from '@hooks/useReportIsArchived'; import useResponsiveLayout from '@hooks/useResponsiveLayout'; import useSelectedTransactionsActions from '@hooks/useSelectedTransactionsActions'; import useTheme from '@hooks/useTheme'; @@ -33,7 +34,6 @@ import { hasWarningTypeViolations, isAllowedToApproveExpenseReport, isAllowedToSubmitDraftExpenseReport, - isArchivedReportWithID, isInvoiceReport, isProcessingReport, isReportApproved, @@ -184,7 +184,7 @@ function MoneyReportHeaderOld({policy, report: moneyRequestReport, transactionTh const shouldShowBrokenConnectionViolation = shouldShowBrokenConnectionViolationForMultipleTransactions(transactionIDs, moneyRequestReport, policy, violations); const hasOnlyHeldExpenses = hasOnlyHeldExpensesReportUtils(moneyRequestReport?.reportID); const isPayAtEndExpense = isPayAtEndExpenseTransactionUtils(transaction); - const isArchivedReport = isArchivedReportWithID(moneyRequestReport?.reportID); + const isArchivedReport = useReportIsArchived(moneyRequestReport?.reportID); const [archiveReason] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${moneyRequestReport?.reportID}`, {selector: getArchiveReason, canBeMissing: true}); const getCanIOUBePaid = useCallback( diff --git a/src/components/ReportActionItem/ReportPreview.tsx b/src/components/ReportActionItem/ReportPreview.tsx index 72756135e4a0..0bb94a35bb2f 100644 --- a/src/components/ReportActionItem/ReportPreview.tsx +++ b/src/components/ReportActionItem/ReportPreview.tsx @@ -23,6 +23,7 @@ import useNetwork from '@hooks/useNetwork'; import useOnyx from '@hooks/useOnyx'; import usePaymentAnimations from '@hooks/usePaymentAnimations'; import usePolicy from '@hooks/usePolicy'; +import useReportIsArchived from '@hooks/useReportIsArchived'; import useReportWithTransactionsAndViolations from '@hooks/useReportWithTransactionsAndViolations'; import useTheme from '@hooks/useTheme'; import useThemeStyles from '@hooks/useThemeStyles'; @@ -60,7 +61,6 @@ import { hasUpdatedTotal, hasViolations, hasWarningTypeViolations, - isArchivedReportWithID, isInvoiceReport as isInvoiceReportUtils, isInvoiceRoom as isInvoiceRoomReportUtils, isPayAtEndExpenseReport, @@ -250,7 +250,7 @@ function ReportPreview({ formattedMerchant = null; } - const isArchived = isArchivedReportWithID(iouReport?.reportID); + const isArchived = useReportIsArchived(iouReport?.reportID); // The submit button should be success green color only if the user is submitter and the policy does not have Scheduled Submit turned on const isWaitingForSubmissionFromCurrentUser = useMemo(() => isWaitingForSubmissionFromCurrentUserReportUtils(chatReport, policy), [chatReport, policy]); diff --git a/src/components/ReportActionItem/ReportPreviewOld.tsx b/src/components/ReportActionItem/ReportPreviewOld.tsx index deef6a1a99d3..ac9fdccaf513 100644 --- a/src/components/ReportActionItem/ReportPreviewOld.tsx +++ b/src/components/ReportActionItem/ReportPreviewOld.tsx @@ -23,6 +23,7 @@ import useNetwork from '@hooks/useNetwork'; import useOnyx from '@hooks/useOnyx'; import usePaymentAnimations from '@hooks/usePaymentAnimations'; import usePolicy from '@hooks/usePolicy'; +import useReportIsArchived from '@hooks/useReportIsArchived'; import useReportWithTransactionsAndViolations from '@hooks/useReportWithTransactionsAndViolations'; import useTheme from '@hooks/useTheme'; import useThemeStyles from '@hooks/useThemeStyles'; @@ -63,7 +64,6 @@ import { hasWarningTypeViolations, isAllowedToApproveExpenseReport, isAllowedToSubmitDraftExpenseReport, - isArchivedReportWithID, isInvoiceReport as isInvoiceReportUtils, isInvoiceRoom as isInvoiceRoomReportUtils, isPayAtEndExpenseReport, @@ -257,7 +257,7 @@ function ReportPreviewOld({ formattedMerchant = null; } - const isArchived = isArchivedReportWithID(iouReport?.reportID); + const isArchived = useReportIsArchived(iouReport?.reportID); const isAdmin = policy?.role === CONST.POLICY.ROLE.ADMIN; const filteredTransactions = transactions?.filter((transaction) => transaction) ?? []; const shouldShowSubmitButton = canSubmitReport(iouReport, policy, filteredTransactions, violations); diff --git a/src/libs/DebugUtils.ts b/src/libs/DebugUtils.ts index 69f863e33cb1..632d5b1fa838 100644 --- a/src/libs/DebugUtils.ts +++ b/src/libs/DebugUtils.ts @@ -11,7 +11,7 @@ import ONYXKEYS from '@src/ONYXKEYS'; import type {Beta, Policy, Report, ReportAction, ReportActions, ReportNameValuePairs, Transaction, TransactionViolation} from '@src/types/onyx'; import type {Comment} from '@src/types/onyx/Transaction'; import {getLinkedTransactionID} from './ReportActionsUtils'; -import {getReasonAndReportActionThatRequiresAttention, reasonForReportToBeInOptionList, shouldDisplayViolationsRBRInLHN} from './ReportUtils'; +import {getReasonAndReportActionThatRequiresAttention, getReportNameValuePairs, isArchivedReport, reasonForReportToBeInOptionList, shouldDisplayViolationsRBRInLHN} from './ReportUtils'; import SidebarUtils from './SidebarUtils'; import {getTransactionID as TransactionUtilsGetTransactionID} from './TransactionUtils'; @@ -1356,7 +1356,12 @@ type RBRReasonAndReportAction = { * Gets the report action that is causing the RBR to show up in LHN */ function getReasonAndReportActionForRBRInLHNRow(report: Report, reportActions: OnyxEntry, hasViolations: boolean): RBRReasonAndReportAction | null { - const {reason, reportAction} = SidebarUtils.getReasonAndReportActionThatHasRedBrickRoad(report, reportActions, hasViolations, transactionViolations) ?? {}; + // This will get removed as part of https://github.com/Expensify/App/issues/59961 + // eslint-disable-next-line deprecation/deprecation + const reportNameValuePairs = getReportNameValuePairs(report?.reportID); + + const {reason, reportAction} = + SidebarUtils.getReasonAndReportActionThatHasRedBrickRoad(report, reportActions, hasViolations, transactionViolations, isArchivedReport(reportNameValuePairs)) ?? {}; if (reason) { return {reason: `debug.reasonRBR.${reason}`, reportAction}; diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 9b40aee8f927..312b168e18b9 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -1873,7 +1873,14 @@ function findLastAccessedReport(ignoreDomainRooms: boolean, openOnAdminRoom = fa // Filter out the system chat (Expensify chat) because the composer is disabled in it, // and it prompts the user to use the Concierge chat instead. - reportsValues = reportsValues.filter((report) => !isSystemChat(report) && !isArchivedReportWithID(report?.reportID)) ?? []; + reportsValues = + reportsValues.filter((report) => { + // This will get removed as part of https://github.com/Expensify/App/issues/59961 + // eslint-disable-next-line deprecation/deprecation + const reportNameValuePairs = getReportNameValuePairs(report?.reportID); + + return !isSystemChat(report) && !isArchivedReport(reportNameValuePairs); + }) ?? []; // At least two reports remain: self DM and Concierge chat. // Return the most recently visited report. Get the last read report from the report metadata. @@ -1931,20 +1938,6 @@ function isArchivedNonExpenseReportWithID(report?: OnyxInputOrEntry, isR return !(isExpenseReport(report) || isExpenseRequest(report)) && isReportArchived; } -/** - * Whether the report with the provided reportID is an archived report - */ -function isArchivedReportWithID(reportOrID?: string | SearchReport) { - if (!reportOrID) { - return false; - } - - // This will get removed as part of https://github.com/Expensify/App/issues/59961 - // eslint-disable-next-line deprecation/deprecation - const reportNameValuePairs = typeof reportOrID === 'string' ? getReportNameValuePairs(reportOrID) : getReportNameValuePairs(reportOrID.reportID); - return isArchivedReport(reportNameValuePairs); -} - /** * Whether the provided report is a closed report */ @@ -2295,7 +2288,11 @@ function getChildReportNotificationPreference(reportAction: OnyxInputOrEntry): boolean { - if (!isMoneyRequestReport(moneyRequestReport) || isArchivedReportWithID(moneyRequestReport?.reportID)) { + // This will get removed as part of https://github.com/Expensify/App/issues/59961 + // eslint-disable-next-line deprecation/deprecation + const reportNameValuePairs = getReportNameValuePairs(moneyRequestReport?.reportID); + + if (!isMoneyRequestReport(moneyRequestReport) || isArchivedReport(reportNameValuePairs)) { return false; } @@ -7554,7 +7551,11 @@ function getAllReportActionsErrorsAndReportActionThatRequiresAttention(report: O ? undefined : allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.parentReportID}`]?.[report.parentReportActionID]; - if (!isArchivedReportWithID(report?.reportID)) { + // This will get removed as part of https://github.com/Expensify/App/issues/59961 + // eslint-disable-next-line deprecation/deprecation + const reportNameValuePairs = getReportNameValuePairs(report?.reportID); + + if (!isArchivedReport(reportNameValuePairs)) { if (wasActionTakenByCurrentUser(parentReportAction) && isTransactionThread(parentReportAction)) { const transactionID = isMoneyRequestAction(parentReportAction) ? getOriginalMessage(parentReportAction)?.IOUTransactionID : null; const transaction = allTransactions?.[`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`]; @@ -7812,7 +7813,11 @@ function getChatByParticipants( return Object.values(reports ?? {}).find((report) => { const participantAccountIDs = Object.keys(report?.participants ?? {}); - if (shouldExcludeClosedReports && isArchivedReportWithID(report?.reportID)) { + // This will get removed as part of https://github.com/Expensify/App/issues/59961 + // eslint-disable-next-line deprecation/deprecation + const reportNameValuePairs = getReportNameValuePairs(report?.reportID); + + if (shouldExcludeClosedReports && isArchivedReport(reportNameValuePairs)) { return false; } @@ -8124,8 +8129,12 @@ function isGroupChatAdmin(report: OnyxEntry, accountID: number) { * as a participant of the report. */ function getMoneyRequestOptions(report: OnyxEntry, policy: OnyxEntry, reportParticipants: number[], filterDeprecatedTypes = false): IOUType[] { + // This will get removed as part of https://github.com/Expensify/App/issues/59961 + // eslint-disable-next-line deprecation/deprecation + const reportNameValuePairs = getReportNameValuePairs(report?.reportID); + // In any thread, task report or trip room, we do not allow any new expenses - if (isChatThread(report) || isTaskReport(report) || isInvoiceReport(report) || isSystemChat(report) || isArchivedReportWithID(report?.reportID) || isTripRoom(report)) { + if (isChatThread(report) || isTaskReport(report) || isInvoiceReport(report) || isSystemChat(report) || isArchivedReport(reportNameValuePairs) || isTripRoom(report)) { return []; } @@ -10633,7 +10642,6 @@ export { isArchivedNonExpenseReport, isArchivedReport, isArchivedNonExpenseReportWithID, - isArchivedReportWithID, isClosedReport, isCanceledTaskReport, isChatReport, diff --git a/src/libs/SidebarUtils.ts b/src/libs/SidebarUtils.ts index 1b1ff0407c73..ac02ff01d4b0 100644 --- a/src/libs/SidebarUtils.ts +++ b/src/libs/SidebarUtils.ts @@ -76,6 +76,7 @@ import { getPolicyName, getReportDescription, getReportName, + getReportNameValuePairs, getReportNotificationPreference, getReportParticipantsTitle, getReportSubtitlePrefix, @@ -86,7 +87,6 @@ import { isAnnounceRoom, isArchivedNonExpenseReport, isArchivedReport, - isArchivedReportWithID, isChatRoom, isChatThread, isConciergeChatReport, @@ -241,7 +241,7 @@ function getOrderedReportIDs( isSystemChat || // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing report.isPinned || - (!isInFocusMode && isArchivedReportWithID(report.reportID)) || + (!isInFocusMode && isArchivedReport(reportNameValuePairs)) || requiresAttentionFromCurrentUser(report, parentReportAction); if (isHidden && !shouldOverrideHidden) { return; @@ -345,12 +345,13 @@ function getReasonAndReportActionThatHasRedBrickRoad( reportActions: OnyxEntry, hasViolations: boolean, transactionViolations?: OnyxCollection, + isReportArchived = false, ): ReasonAndReportActionThatHasRedBrickRoad | null { const {reportAction} = getAllReportActionsErrorsAndReportActionThatRequiresAttention(report, reportActions); const errors = getAllReportErrors(report, reportActions); const hasErrors = Object.keys(errors).length !== 0; - if (isArchivedReportWithID(report.reportID)) { + if (isReportArchived) { return null; } @@ -394,8 +395,14 @@ function getReasonAndReportActionThatHasRedBrickRoad( return null; } -function shouldShowRedBrickRoad(report: Report, reportActions: OnyxEntry, hasViolations: boolean, transactionViolations?: OnyxCollection) { - return !!getReasonAndReportActionThatHasRedBrickRoad(report, reportActions, hasViolations, transactionViolations); +function shouldShowRedBrickRoad( + report: Report, + reportActions: OnyxEntry, + hasViolations: boolean, + transactionViolations?: OnyxCollection, + isReportArchived = false, +) { + return !!getReasonAndReportActionThatHasRedBrickRoad(report, reportActions, hasViolations, transactionViolations, isReportArchived); } /** @@ -487,7 +494,9 @@ function getOptionData({ result.isMoneyRequestReport = isMoneyRequestReport(report); result.shouldShowSubscript = shouldReportShowSubscript(report); result.pendingAction = report.pendingFields?.addWorkspaceRoom ?? report.pendingFields?.createChat; - result.brickRoadIndicator = shouldShowRedBrickRoad(report, reportActions, hasViolations, transactionViolations) ? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR : ''; + result.brickRoadIndicator = shouldShowRedBrickRoad(report, reportActions, hasViolations, transactionViolations, !!result.private_isArchived) + ? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR + : ''; result.ownerAccountID = report.ownerAccountID; result.managerID = report.managerID; result.reportID = report.reportID; @@ -782,7 +791,11 @@ function getRoomWelcomeMessage(report: OnyxEntry): WelcomeMessage { return welcomeMessage; } - if (isArchivedReportWithID(report?.reportID)) { + // This will get removed as part of https://github.com/Expensify/App/issues/59961 + // eslint-disable-next-line deprecation/deprecation + const reportNameValuePairs = getReportNameValuePairs(report?.reportID); + + if (isArchivedReport(reportNameValuePairs)) { welcomeMessage.phrase1 = translateLocal('reportActionsView.beginningOfArchivedRoomPartOne'); welcomeMessage.phrase2 = translateLocal('reportActionsView.beginningOfArchivedRoomPartTwo'); } else if (isDomainRoom(report)) { diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index 8cc3ee6602a8..035afae6bd63 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -122,6 +122,7 @@ import { getOutstandingChildRequest, getParsedComment, getPersonalDetailsForAccountID, + getReportNameValuePairs, getReportNotificationPreference, getReportOrDraftReport, getReportTransactions, @@ -129,7 +130,6 @@ import { hasHeldExpenses as hasHeldExpensesReportUtils, hasNonReimbursableTransactions as hasNonReimbursableTransactionsReportUtils, isArchivedReport, - isArchivedReportWithID, isClosedReport as isClosedReportUtil, isDraftReport, isExpenseReport, @@ -8782,7 +8782,12 @@ function canSubmitReport( ) { const currentUserAccountID = getCurrentUserAccountID(); const isOpenExpenseReport = isOpenExpenseReportReportUtils(report); - const isArchived = isArchivedReportWithID(report?.reportID); + + // This will get removed as part of https://github.com/Expensify/App/issues/59961 + // eslint-disable-next-line deprecation/deprecation + const reportNameValuePairs = getReportNameValuePairs(report?.reportID); + + const isArchived = isArchivedReport(reportNameValuePairs); const isAdmin = policy?.role === CONST.POLICY.ROLE.ADMIN; const transactionIDList = transactions.map((transaction) => transaction.transactionID); const hasAllPendingRTERViolations = allHavePendingRTERViolation(transactionIDList, allViolations); diff --git a/src/libs/actions/OnyxDerived/configs/conciergeChatReportID.ts b/src/libs/actions/OnyxDerived/configs/conciergeChatReportID.ts index 5ce9dd6cb439..151d35be5db0 100644 --- a/src/libs/actions/OnyxDerived/configs/conciergeChatReportID.ts +++ b/src/libs/actions/OnyxDerived/configs/conciergeChatReportID.ts @@ -1,8 +1,9 @@ import Log from '@libs/Log'; -import {isArchivedReportWithID, isThread} from '@libs/ReportUtils'; +import {isArchivedReport, isThread} from '@libs/ReportUtils'; import createOnyxDerivedValueConfig from '@userActions/OnyxDerived/createOnyxDerivedValueConfig'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; +import type {OnyxInputOrEntry, ReportNameValuePairs} from '@src/types/onyx'; export default createOnyxDerivedValueConfig({ key: ONYXKEYS.DERIVED.CONCIERGE_CHAT_REPORT_ID, @@ -13,8 +14,14 @@ export default createOnyxDerivedValueConfig({ } const conciergeReport = Object.values(reports).find((report) => { + if (!report) { + return; + } + + const reportNameValuePairs = (allReportNameValuePair[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report?.reportID}`] ?? {}) as OnyxInputOrEntry; + // Merged accounts can have multiple conceirge chats, exclude archived chats. - if (!report?.participants || isThread(report) || isArchivedReportWithID(report?.reportID)) { + if (!report?.participants || isThread(report) || isArchivedReport(reportNameValuePairs)) { return false; } diff --git a/tests/unit/SidebarUtilsTest.ts b/tests/unit/SidebarUtilsTest.ts index 49e88a8b31fb..206e1b9d90e2 100644 --- a/tests/unit/SidebarUtilsTest.ts +++ b/tests/unit/SidebarUtilsTest.ts @@ -1,6 +1,8 @@ /* eslint-disable @typescript-eslint/naming-convention */ +import {renderHook} from '@testing-library/react-native'; import type {OnyxCollection, OnyxEntry} from 'react-native-onyx'; import Onyx from 'react-native-onyx'; +import useReportIsArchived from '@hooks/useReportIsArchived'; import DateUtils from '@libs/DateUtils'; import {getReportActionMessageText} from '@libs/ReportActionsUtils'; import SidebarUtils from '@libs/SidebarUtils'; @@ -77,8 +79,17 @@ describe('SidebarUtils', () => { [`${ONYXKEYS.COLLECTION.TRANSACTION}${MOCK_TRANSACTION.transactionID}` as const]: MOCK_TRANSACTION, }); + // Simulate how components determind if a report is archived by using this hook + const {result: isReportArchived} = renderHook(() => useReportIsArchived(MOCK_REPORT?.reportID)); + const {reason} = - SidebarUtils.getReasonAndReportActionThatHasRedBrickRoad(MOCK_REPORT, MOCK_REPORT_ACTIONS, false, MOCK_TRANSACTION_VIOLATIONS as OnyxCollection) ?? {}; + SidebarUtils.getReasonAndReportActionThatHasRedBrickRoad( + MOCK_REPORT, + MOCK_REPORT_ACTIONS, + false, + MOCK_TRANSACTION_VIOLATIONS as OnyxCollection, + isReportArchived.current, + ) ?? {}; expect(reason).toBe(CONST.RBR_REASONS.HAS_TRANSACTION_THREAD_VIOLATIONS); }); @@ -95,7 +106,8 @@ describe('SidebarUtils', () => { const MOCK_REPORT_ACTIONS: OnyxEntry = {}; const MOCK_TRANSACTION_VIOLATIONS: OnyxCollection = {}; - const {reason} = SidebarUtils.getReasonAndReportActionThatHasRedBrickRoad(MOCK_REPORT, MOCK_REPORT_ACTIONS, false, MOCK_TRANSACTION_VIOLATIONS) ?? {}; + const {result: isReportArchived} = renderHook(() => useReportIsArchived(MOCK_REPORT?.reportID)); + const {reason} = SidebarUtils.getReasonAndReportActionThatHasRedBrickRoad(MOCK_REPORT, MOCK_REPORT_ACTIONS, false, MOCK_TRANSACTION_VIOLATIONS, isReportArchived.current) ?? {}; expect(reason).toBe(CONST.RBR_REASONS.HAS_ERRORS); }); @@ -107,7 +119,9 @@ describe('SidebarUtils', () => { const MOCK_REPORT_ACTIONS: OnyxEntry = {}; const MOCK_TRANSACTION_VIOLATIONS: OnyxCollection = {}; - const {reason} = SidebarUtils.getReasonAndReportActionThatHasRedBrickRoad(MOCK_REPORT, MOCK_REPORT_ACTIONS, true, MOCK_TRANSACTION_VIOLATIONS) ?? {}; + // Simulate how components determind if a report is archived by using this hook + const {result: isReportArchived} = renderHook(() => useReportIsArchived(MOCK_REPORT?.reportID)); + const {reason} = SidebarUtils.getReasonAndReportActionThatHasRedBrickRoad(MOCK_REPORT, MOCK_REPORT_ACTIONS, true, MOCK_TRANSACTION_VIOLATIONS, isReportArchived.current) ?? {}; expect(reason).toBe(CONST.RBR_REASONS.HAS_VIOLATIONS); }); @@ -136,7 +150,9 @@ describe('SidebarUtils', () => { }; const MOCK_TRANSACTION_VIOLATIONS: OnyxCollection = {}; - const {reason} = SidebarUtils.getReasonAndReportActionThatHasRedBrickRoad(MOCK_REPORT, MOCK_REPORT_ACTIONS, false, MOCK_TRANSACTION_VIOLATIONS) ?? {}; + // Simulate how components determind if a report is archived by using this hook + const {result: isReportArchived} = renderHook(() => useReportIsArchived(MOCK_REPORT?.reportID)); + const {reason} = SidebarUtils.getReasonAndReportActionThatHasRedBrickRoad(MOCK_REPORT, MOCK_REPORT_ACTIONS, false, MOCK_TRANSACTION_VIOLATIONS, isReportArchived.current) ?? {}; expect(reason).toBe(CONST.RBR_REASONS.HAS_ERRORS); }); @@ -153,7 +169,9 @@ describe('SidebarUtils', () => { const MOCK_REPORT_ACTIONS: OnyxEntry = {}; const MOCK_TRANSACTION_VIOLATIONS: OnyxCollection = {}; - const {reason} = SidebarUtils.getReasonAndReportActionThatHasRedBrickRoad(MOCK_REPORT, MOCK_REPORT_ACTIONS, false, MOCK_TRANSACTION_VIOLATIONS) ?? {}; + // Simulate how components determind if a report is archived by using this hook + const {result: isReportArchived} = renderHook(() => useReportIsArchived(MOCK_REPORT?.reportID)); + const {reason} = SidebarUtils.getReasonAndReportActionThatHasRedBrickRoad(MOCK_REPORT, MOCK_REPORT_ACTIONS, false, MOCK_TRANSACTION_VIOLATIONS, isReportArchived.current) ?? {}; expect(reason).toBe(CONST.RBR_REASONS.HAS_ERRORS); }); @@ -183,7 +201,10 @@ describe('SidebarUtils', () => { }; const MOCK_TRANSACTION_VIOLATIONS: OnyxCollection = {}; - const {reportAction} = SidebarUtils.getReasonAndReportActionThatHasRedBrickRoad(MOCK_REPORT, MOCK_REPORT_ACTIONS, false, MOCK_TRANSACTION_VIOLATIONS) ?? {}; + // Simulate how components determind if a report is archived by using this hook + const {result: isReportArchived} = renderHook(() => useReportIsArchived(MOCK_REPORT?.reportID)); + const {reportAction} = + SidebarUtils.getReasonAndReportActionThatHasRedBrickRoad(MOCK_REPORT, MOCK_REPORT_ACTIONS, false, MOCK_TRANSACTION_VIOLATIONS, isReportArchived.current) ?? {}; expect(reportAction).toMatchObject(MOCK_REPORT_ACTION); }); @@ -195,7 +216,9 @@ describe('SidebarUtils', () => { const MOCK_REPORT_ACTIONS: OnyxEntry = {}; const MOCK_TRANSACTION_VIOLATIONS: OnyxCollection = {}; - const result = SidebarUtils.getReasonAndReportActionThatHasRedBrickRoad(MOCK_REPORT, MOCK_REPORT_ACTIONS, false, MOCK_TRANSACTION_VIOLATIONS); + // Simulate how components determind if a report is archived by using this hook + const {result: isReportArchived} = renderHook(() => useReportIsArchived(MOCK_REPORT?.reportID)); + const result = SidebarUtils.getReasonAndReportActionThatHasRedBrickRoad(MOCK_REPORT, MOCK_REPORT_ACTIONS, false, MOCK_TRANSACTION_VIOLATIONS, isReportArchived.current); expect(result).toBeNull(); }); @@ -273,7 +296,9 @@ describe('SidebarUtils', () => { }; const MOCK_TRANSACTION_VIOLATIONS: OnyxCollection = {}; - const result = SidebarUtils.getReasonAndReportActionThatHasRedBrickRoad(MOCK_REPORT, MOCK_REPORT_ACTIONS, false, MOCK_TRANSACTION_VIOLATIONS); + // Simulate how components determind if a report is archived by using this hook + const {result: isReportArchived} = renderHook(() => useReportIsArchived(MOCK_REPORT?.reportID)); + const result = SidebarUtils.getReasonAndReportActionThatHasRedBrickRoad(MOCK_REPORT, MOCK_REPORT_ACTIONS, false, MOCK_TRANSACTION_VIOLATIONS, isReportArchived.current); expect(result).toBeNull(); }); @@ -331,7 +356,15 @@ describe('SidebarUtils', () => { [`${ONYXKEYS.COLLECTION.TRANSACTION}${MOCK_TRANSACTION.transactionID}` as const]: MOCK_TRANSACTION, }); - const result = SidebarUtils.shouldShowRedBrickRoad(MOCK_REPORT, MOCK_REPORT_ACTIONS, false, MOCK_TRANSACTION_VIOLATIONS as OnyxCollection); + // Simulate how components determind if a report is archived by using this hook + const {result: isReportArchived} = renderHook(() => useReportIsArchived(MOCK_REPORT?.reportID)); + const result = SidebarUtils.shouldShowRedBrickRoad( + MOCK_REPORT, + MOCK_REPORT_ACTIONS, + false, + MOCK_TRANSACTION_VIOLATIONS as OnyxCollection, + isReportArchived.current, + ); expect(result).toBe(true); }); @@ -387,7 +420,14 @@ describe('SidebarUtils', () => { [`${ONYXKEYS.COLLECTION.TRANSACTION}${MOCK_TRANSACTION.transactionID}` as const]: MOCK_TRANSACTION, }); - const result = SidebarUtils.shouldShowRedBrickRoad(MOCK_REPORT, MOCK_REPORT_ACTIONS, false, MOCK_TRANSACTION_VIOLATIONS as OnyxCollection); + const {result: isReportArchived} = renderHook(() => useReportIsArchived(MOCK_REPORT?.reportID)); + const result = SidebarUtils.shouldShowRedBrickRoad( + MOCK_REPORT, + MOCK_REPORT_ACTIONS, + false, + MOCK_TRANSACTION_VIOLATIONS as OnyxCollection, + isReportArchived.current, + ); expect(result).toBe(true); }); @@ -404,7 +444,8 @@ describe('SidebarUtils', () => { const MOCK_REPORT_ACTIONS: OnyxEntry = {}; const MOCK_TRANSACTION_VIOLATIONS: OnyxCollection = {}; - const result = SidebarUtils.shouldShowRedBrickRoad(MOCK_REPORT, MOCK_REPORT_ACTIONS, false, MOCK_TRANSACTION_VIOLATIONS); + const {result: isReportArchived} = renderHook(() => useReportIsArchived(MOCK_REPORT?.reportID)); + const result = SidebarUtils.shouldShowRedBrickRoad(MOCK_REPORT, MOCK_REPORT_ACTIONS, false, MOCK_TRANSACTION_VIOLATIONS, isReportArchived.current); expect(result).toBe(true); }); @@ -416,7 +457,8 @@ describe('SidebarUtils', () => { const MOCK_REPORT_ACTIONS: OnyxEntry = {}; const MOCK_TRANSACTION_VIOLATIONS: OnyxCollection = {}; - const result = SidebarUtils.shouldShowRedBrickRoad(MOCK_REPORT, MOCK_REPORT_ACTIONS, true, MOCK_TRANSACTION_VIOLATIONS); + const {result: isReportArchived} = renderHook(() => useReportIsArchived(MOCK_REPORT?.reportID)); + const result = SidebarUtils.shouldShowRedBrickRoad(MOCK_REPORT, MOCK_REPORT_ACTIONS, true, MOCK_TRANSACTION_VIOLATIONS, isReportArchived.current); expect(result).toBe(true); }); @@ -445,7 +487,8 @@ describe('SidebarUtils', () => { }; const MOCK_TRANSACTION_VIOLATIONS: OnyxCollection = {}; - const result = SidebarUtils.shouldShowRedBrickRoad(MOCK_REPORT, MOCK_REPORT_ACTIONS, false, MOCK_TRANSACTION_VIOLATIONS); + const {result: isReportArchived} = renderHook(() => useReportIsArchived(MOCK_REPORT?.reportID)); + const result = SidebarUtils.shouldShowRedBrickRoad(MOCK_REPORT, MOCK_REPORT_ACTIONS, false, MOCK_TRANSACTION_VIOLATIONS, isReportArchived.current); expect(result).toBe(true); }); @@ -462,7 +505,8 @@ describe('SidebarUtils', () => { const MOCK_REPORT_ACTIONS: OnyxEntry = {}; const MOCK_TRANSACTION_VIOLATIONS: OnyxCollection = {}; - const result = SidebarUtils.shouldShowRedBrickRoad(MOCK_REPORT, MOCK_REPORT_ACTIONS, false, MOCK_TRANSACTION_VIOLATIONS); + const {result: isReportArchived} = renderHook(() => useReportIsArchived(MOCK_REPORT?.reportID)); + const result = SidebarUtils.shouldShowRedBrickRoad(MOCK_REPORT, MOCK_REPORT_ACTIONS, false, MOCK_TRANSACTION_VIOLATIONS, isReportArchived.current); expect(result).toBe(true); }); @@ -474,7 +518,8 @@ describe('SidebarUtils', () => { const MOCK_REPORT_ACTIONS: OnyxEntry = {}; const MOCK_TRANSACTION_VIOLATIONS: OnyxCollection = {}; - const result = SidebarUtils.shouldShowRedBrickRoad(MOCK_REPORT, MOCK_REPORT_ACTIONS, false, MOCK_TRANSACTION_VIOLATIONS); + const {result: isReportArchived} = renderHook(() => useReportIsArchived(MOCK_REPORT?.reportID)); + const result = SidebarUtils.shouldShowRedBrickRoad(MOCK_REPORT, MOCK_REPORT_ACTIONS, false, MOCK_TRANSACTION_VIOLATIONS, isReportArchived.current); expect(result).toBe(false); }); @@ -493,7 +538,9 @@ describe('SidebarUtils', () => { const MOCK_REPORT_ACTIONS: OnyxEntry = {}; const MOCK_TRANSACTION_VIOLATIONS: OnyxCollection = {}; - const result = SidebarUtils.shouldShowRedBrickRoad(MOCK_REPORT, MOCK_REPORT_ACTIONS, false, MOCK_TRANSACTION_VIOLATIONS); + // Simulate how components determind if a report is archived by using this hook + const {result: isReportArchived} = renderHook(() => useReportIsArchived(MOCK_REPORT?.reportID)); + const result = SidebarUtils.shouldShowRedBrickRoad(MOCK_REPORT, MOCK_REPORT_ACTIONS, false, MOCK_TRANSACTION_VIOLATIONS, isReportArchived.current); expect(result).toBe(false); }); diff --git a/tests/unit/navigateAfterOnboardingTest.ts b/tests/unit/navigateAfterOnboardingTest.ts index da5d6ff4493f..f2392bb4e03e 100644 --- a/tests/unit/navigateAfterOnboardingTest.ts +++ b/tests/unit/navigateAfterOnboardingTest.ts @@ -33,7 +33,7 @@ jest.mock('@libs/ReportUtils', () => ({ findLastAccessedReport: () => mockFindLastAccessedReport() as OnyxEntry, parseReportRouteParams: jest.fn(() => ({})), isConciergeChatReport: jest.requireActual('@libs/ReportUtils').isConciergeChatReport, - isArchivedReportWithID: jest.requireActual('@libs/ReportUtils').isArchivedReportWithID, + isArchivedReport: jest.requireActual('@libs/ReportUtils').isArchivedReport, isThread: jest.requireActual('@libs/ReportUtils').isThread, generateReportName: jest.requireActual('@libs/ReportUtils').generateReportName, getAllPolicyReports: jest.requireActual('@libs/ReportUtils').getAllPolicyReports,