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
5 changes: 5 additions & 0 deletions src/CONST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3440,6 +3440,11 @@ const CONST = {
UNAPPROVE: 'unapprove',
DEBUG: 'debug',
GO_TO_WORKSPACE: 'goToWorkspace',
TRACK: {
SUBMIT: 'submit',
CATEGORIZE: 'categorize',
SHARE: 'share',
},
},
EDIT_REQUEST_FIELD: {
AMOUNT: 'amount',
Expand Down
20 changes: 7 additions & 13 deletions src/pages/ReportDetailsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,7 @@ import type {PlatformStackScreenProps} from '@libs/Navigation/PlatformStackNavig
import type {ReportDetailsNavigatorParamList} from '@libs/Navigation/types';
import {getPersonalDetailsForAccountIDs} from '@libs/OptionsListUtils';
import {getConnectedIntegration, isPolicyAdmin as isPolicyAdminUtil, isPolicyEmployee as isPolicyEmployeeUtil, isSubmitAndClose, shouldShowPolicy} from '@libs/PolicyUtils';
import {
getOneTransactionThreadReportID,
getOriginalMessage,
getReportAction,
getTrackExpenseActionableWhisper,
isDeletedAction,
isMoneyRequestAction,
isTrackExpenseAction,
} from '@libs/ReportActionsUtils';
import {getOneTransactionThreadReportID, getOriginalMessage, getTrackExpenseActionableWhisper, isDeletedAction, isMoneyRequestAction, isTrackExpenseAction} from '@libs/ReportActionsUtils';
import {
canDeleteTransaction,
canEditReportDescription as canEditReportDescriptionUtil,
Expand Down Expand Up @@ -169,6 +161,9 @@ function ReportDetailsPage({policies, report, route, reportMetadata}: ReportDeta
// The app would crash due to subscribing to the entire report collection if parentReportID is an empty string. So we should have a fallback ID here.
/* eslint-disable @typescript-eslint/prefer-nullish-coalescing */
const [parentReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${report.parentReportID || CONST.DEFAULT_NUMBER_ID}`);
const [parentReportAction] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.parentReportID}`, {

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.

since we didn't add a fallback value for parentReportID it caused a regression here: #57698

selector: (actions) => (report?.parentReportActionID ? actions?.[report.parentReportActionID] : undefined),
});
const [reportNameValuePairs] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report?.reportID || CONST.DEFAULT_NUMBER_ID}`);
const [parentReportNameValuePairs] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report?.parentReportID || CONST.DEFAULT_NUMBER_ID}`);
/* eslint-enable @typescript-eslint/prefer-nullish-coalescing */
Expand Down Expand Up @@ -213,7 +208,6 @@ function ReportDetailsPage({policies, report, route, reportMetadata}: ReportDeta
const isTaskReport = useMemo(() => isTaskReportUtil(report), [report]);
const isSelfDM = useMemo(() => isSelfDMUtil(report), [report]);
const isTrackExpenseReport = useMemo(() => isTrackExpenseReportUtil(report), [report]);
const parentReportAction = getReportAction(report?.parentReportID, report?.parentReportActionID);
const isCanceledTaskReport = isCanceledTaskReportUtil(report, parentReportAction);
const canEditReportDescription = useMemo(() => canEditReportDescriptionUtil(report, policy), [report, policy]);
const shouldShowReportDescription = isChatRoom && (canEditReportDescription || report.description !== '');
Expand Down Expand Up @@ -460,7 +454,7 @@ function ReportDetailsPage({policies, report, route, reportMetadata}: ReportDeta
const whisperAction = getTrackExpenseActionableWhisper(iouTransactionID, moneyRequestReport?.reportID);
const actionableWhisperReportActionID = whisperAction?.reportActionID;
items.push({
key: CONST.REPORT_DETAILS_MENU_ITEM.SETTINGS,
key: CONST.REPORT_DETAILS_MENU_ITEM.TRACK.SUBMIT,
translationKey: 'actionableMentionTrackExpense.submit',
icon: Expensicons.Send,
isAnonymousAction: false,
Expand All @@ -470,7 +464,7 @@ function ReportDetailsPage({policies, report, route, reportMetadata}: ReportDeta
},
});
items.push({
key: CONST.REPORT_DETAILS_MENU_ITEM.SETTINGS,
key: CONST.REPORT_DETAILS_MENU_ITEM.TRACK.CATEGORIZE,
translationKey: 'actionableMentionTrackExpense.categorize',
icon: Expensicons.Folder,
isAnonymousAction: false,
Expand All @@ -480,7 +474,7 @@ function ReportDetailsPage({policies, report, route, reportMetadata}: ReportDeta
},
});
items.push({
key: CONST.REPORT_DETAILS_MENU_ITEM.SETTINGS,
key: CONST.REPORT_DETAILS_MENU_ITEM.TRACK.SHARE,
translationKey: 'actionableMentionTrackExpense.share',
icon: Expensicons.UserPlus,
isAnonymousAction: false,
Expand Down
117 changes: 117 additions & 0 deletions tests/ui/ReportDetailsPageTest.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
import {render, screen} from '@testing-library/react-native';
import React from 'react';
import Onyx from 'react-native-onyx';
import {LocaleContextProvider} from '@components/LocaleContextProvider';
import OnyxProvider from '@components/OnyxProvider';
import {translateLocal} from '@libs/Localize';
import type Navigation from '@libs/Navigation/Navigation';
import type {PlatformStackScreenProps} from '@libs/Navigation/PlatformStackNavigation/types';
import type {ReportDetailsNavigatorParamList} from '@libs/Navigation/types';
import ReportDetailsPage from '@pages/ReportDetailsPage';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import type SCREENS from '@src/SCREENS';
import type {Report} from '@src/types/onyx';
import createRandomReportAction from '../utils/collections/reportActions';
import createRandomReport from '../utils/collections/reports';

jest.mock('@react-navigation/native', () => {
const actualNav = jest.requireActual<typeof Navigation>('@react-navigation/native');
return {
...actualNav,
useIsFocused: jest.fn(),
useRoute: jest.fn(),
// eslint-disable-next-line @typescript-eslint/naming-convention
UNSTABLE_usePreventRemove: jest.fn(),
};
});

describe('ReportDetailsPage', () => {
beforeAll(() => {
Onyx.init({
keys: ONYXKEYS,
safeEvictionKeys: [ONYXKEYS.COLLECTION.REPORT_ACTIONS],
});
});

afterEach(async () => {
await Onyx.clear();
});

it('self DM track options should disappear when report moved to workspace', async () => {
const selfDMReportID = '1';
const trackExpenseReportID = '2';
const trackExpenseActionID = '123';
const trackExpenseReport: Report = {
...createRandomReport(Number(trackExpenseReportID)),
chatType: '' as Report['chatType'],
parentReportID: selfDMReportID,
parentReportActionID: trackExpenseActionID,
};
await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${selfDMReportID}`, {
...createRandomReport(Number(selfDMReportID)),
chatType: CONST.REPORT.CHAT_TYPE.SELF_DM,
});
await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${trackExpenseReportID}`, trackExpenseReport);
await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${selfDMReportID}`, {
[trackExpenseActionID]: {
...createRandomReportAction(Number(trackExpenseActionID)),
actionName: CONST.REPORT.ACTIONS.TYPE.IOU,
originalMessage: {
type: CONST.IOU.REPORT_ACTION_TYPE.TRACK,
},
},
});

const {rerender} = render(
<OnyxProvider>
<LocaleContextProvider>
<ReportDetailsPage
betas={[]}
isLoadingReportData={false}
navigation={{} as PlatformStackScreenProps<ReportDetailsNavigatorParamList, typeof SCREENS.REPORT_DETAILS.ROOT>['navigation']}
policies={{}}
report={trackExpenseReport}
reportMetadata={undefined}
route={{params: {reportID: trackExpenseReportID}} as PlatformStackScreenProps<ReportDetailsNavigatorParamList, typeof SCREENS.REPORT_DETAILS.ROOT>['route']}
/>
</LocaleContextProvider>
</OnyxProvider>,
);

const submitText = translateLocal('actionableMentionTrackExpense.submit');
const categorizeText = translateLocal('actionableMentionTrackExpense.categorize');
const shareText = translateLocal('actionableMentionTrackExpense.share');

await screen.findByText(submitText);
await screen.findByText(categorizeText);
await screen.findByText(shareText);

const movedTrackExpenseReport = {
...trackExpenseReport,
parentReportID: '3',
parentReportActionID: '234',
};
await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${trackExpenseReportID}`, movedTrackExpenseReport);

rerender(
<OnyxProvider>
<LocaleContextProvider>
<ReportDetailsPage
betas={[]}
isLoadingReportData={false}
navigation={{} as PlatformStackScreenProps<ReportDetailsNavigatorParamList, typeof SCREENS.REPORT_DETAILS.ROOT>['navigation']}
policies={{}}
report={movedTrackExpenseReport}
reportMetadata={undefined}
route={{params: {reportID: trackExpenseReportID}} as PlatformStackScreenProps<ReportDetailsNavigatorParamList, typeof SCREENS.REPORT_DETAILS.ROOT>['route']}
/>
</LocaleContextProvider>
</OnyxProvider>,
);

expect(screen.queryByText(submitText)).not.toBeVisible();
expect(screen.queryByText(categorizeText)).not.toBeVisible();
expect(screen.queryByText(shareText)).not.toBeVisible();
});
});