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
7 changes: 4 additions & 3 deletions src/pages/ReportDetailsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -350,10 +350,11 @@ function ReportDetailsPage({policy, report, route, reportMetadata}: ReportDetail

const shouldShowLeaveButton = canLeaveChat(report, policy, !!reportNameValuePairs?.private_isArchived);
const shouldShowGoToWorkspace = shouldShowPolicy(policy, false, currentUserPersonalDetails?.email) && !policy?.isJoinRequestPending;

const reportForHeader = useMemo(() => getReportForHeader(report), [report]);
const reportName = isGroupChat
? getReportNameFromReportNameUtils(reportForHeader, reportAttributes)
: Parser.htmlToText(getReportNameFromReportNameUtils(reportForHeader, reportAttributes));
const shouldParseFullTitle = parentReportAction?.actionName !== CONST.REPORT.ACTIONS.TYPE.ADD_COMMENT && !isGroupChat;
const rawReportName = getReportNameFromReportNameUtils(reportForHeader, reportAttributes);
const reportName = shouldParseFullTitle ? Parser.htmlToText(rawReportName) : rawReportName;
const additionalRoomDetails =
(isPolicyExpenseChat && !!report?.isOwnPolicyExpenseChat) || isExpenseReportUtil(report) || isPolicyExpenseChat || isInvoiceRoom
? chatRoomSubtitle
Expand Down
94 changes: 94 additions & 0 deletions tests/unit/components/reportDetails/ReportDetailsPageTest.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import {act, render} from '@testing-library/react-native';
import React from 'react';
import Onyx from 'react-native-onyx';
import {LocaleContextProvider} from '@components/LocaleContextProvider';
import OnyxListItemProvider from '@components/OnyxListItemProvider';
import type Navigation from '@libs/Navigation/Navigation';
import type {PlatformStackScreenProps} from '@libs/Navigation/PlatformStackNavigation/types';
import type {ReportDetailsNavigatorParamList} from '@libs/Navigation/types';
import Parser from '@libs/Parser';
import ReportDetailsPage from '@pages/ReportDetailsPage';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import type SCREENS from '@src/SCREENS';
import type {Report, ReportAction} from '@src/types/onyx';
import createRandomReportAction from '../../../utils/collections/reportActions';
import {createRandomReport} from '../../../utils/collections/reports';
import waitForBatchedUpdatesWithAct from '../../../utils/waitForBatchedUpdatesWithAct';

jest.mock('@src/components/ConfirmedRoute.tsx');

jest.mock('@react-navigation/native', () => {
const actualNav = jest.requireActual<typeof Navigation>('@react-navigation/native');
return {
...actualNav,
useIsFocused: jest.fn(),
useRoute: jest.fn(),
usePreventRemove: jest.fn(),
};
});

const mockHtmlToText = jest.spyOn(Parser, 'htmlToText');

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

beforeEach(() => {
mockHtmlToText.mockClear();
});

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

it('should not call Parser.htmlToText when parentReportAction is ADD_COMMENT', async () => {
const reportID = '10';
const parentReportID = '20';
const parentActionID = '100';

const parentReportAction = {
...createRandomReportAction(Number(parentActionID)),
actionName: CONST.REPORT.ACTIONS.TYPE.ADD_COMMENT,
} as ReportAction;

const report: Report = {
...createRandomReport(Number(reportID), undefined),
parentReportID,
parentReportActionID: parentActionID,
};

await act(async () => {
await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${parentReportID}`, createRandomReport(Number(parentReportID), undefined));
await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${parentReportID}`, {
[parentActionID]: parentReportAction,
});
});

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

await waitForBatchedUpdatesWithAct();

expect(mockHtmlToText).not.toHaveBeenCalled();
});
});
Loading