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
4 changes: 2 additions & 2 deletions src/components/ReportActionItem/TaskPreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ import ControlSelection from '@libs/ControlSelection';
import {canUseTouchScreen} from '@libs/DeviceCapabilities';
import getButtonState from '@libs/getButtonState';
import getNonEmptyStringOnyxID from '@libs/getNonEmptyStringOnyxID';
import getReportRouteForCurrentContext from '@libs/Navigation/helpers/getReportRouteForCurrentContext';
import Navigation from '@libs/Navigation/Navigation';
import Parser from '@libs/Parser';
import {getOriginalMessage} from '@libs/ReportActionsUtils';
import {isCanceledTaskReport, isOpenTaskReport, isReportManager} from '@libs/ReportUtils';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import type {Report, ReportAction} from '@src/types/onyx';
import {isEmptyObject} from '@src/types/utils/EmptyObject';

Expand Down Expand Up @@ -121,7 +121,7 @@ function TaskPreview({action, chatReportID, currentUserPersonalDetails, isHovere
return (
<View style={[styles.chatItemMessage, !hasAssignee && styles.mv1]}>
<PressableWithoutFeedback
onPress={() => Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(taskReportID, undefined, undefined, Navigation.getActiveRoute()))}
onPress={() => Navigation.navigate(getReportRouteForCurrentContext({reportID: taskReportID}))}
onPressIn={() => canUseTouchScreen() && ControlSelection.block()}
onPressOut={() => ControlSelection.unblock()}
onLongPress={(event) =>
Expand Down
23 changes: 23 additions & 0 deletions src/libs/Navigation/helpers/getReportRouteForCurrentContext.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import Navigation from '@libs/Navigation/Navigation';
import type {Route} from '@src/ROUTES';
import ROUTES from '@src/ROUTES';
import isSearchTopmostFullScreenRoute from './isSearchTopmostFullScreenRoute';

type GetReportRouteForCurrentContextParams = {
reportID: string | undefined;
};

function getReportRouteForCurrentContext({reportID}: GetReportRouteForCurrentContextParams): Route {
if (!reportID) {
return ROUTES.REPORT_WITH_ID.getRoute('');
}

const backTo = Navigation.getActiveRoute();
if (isSearchTopmostFullScreenRoute()) {
return ROUTES.SEARCH_REPORT.getRoute({reportID, backTo});
}

return ROUTES.REPORT_WITH_ID.getRoute(reportID, undefined, undefined, backTo);
}

export default getReportRouteForCurrentContext;
36 changes: 36 additions & 0 deletions tests/unit/Navigation/getReportRouteForCurrentContextTest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import getReportRouteForCurrentContext from '@libs/Navigation/helpers/getReportRouteForCurrentContext';
import isSearchTopmostFullScreenRoute from '@libs/Navigation/helpers/isSearchTopmostFullScreenRoute';
import Navigation from '@libs/Navigation/Navigation';
import ROUTES from '@src/ROUTES';

jest.mock('@libs/Navigation/Navigation', () => ({
getActiveRoute: jest.fn(),
}));

jest.mock('@libs/Navigation/helpers/isSearchTopmostFullScreenRoute', () => jest.fn());

describe('getReportRouteForCurrentContext', () => {
const mockGetActiveRoute = Navigation.getActiveRoute as jest.MockedFunction<typeof Navigation.getActiveRoute>;
const mockIsSearchTopmostFullScreenRoute = isSearchTopmostFullScreenRoute as jest.MockedFunction<typeof isSearchTopmostFullScreenRoute>;

beforeEach(() => {
jest.clearAllMocks();
mockGetActiveRoute.mockReturnValue('search?q=type:chat');
mockIsSearchTopmostFullScreenRoute.mockReturnValue(false);
});

it('returns the default report route when Search is not the topmost fullscreen route', () => {
expect(getReportRouteForCurrentContext({reportID: '42'})).toBe(ROUTES.REPORT_WITH_ID.getRoute('42', undefined, undefined, 'search?q=type:chat'));
});

it('returns the search report route when Search is the topmost fullscreen route', () => {
mockIsSearchTopmostFullScreenRoute.mockReturnValue(true);

expect(getReportRouteForCurrentContext({reportID: '42'})).toBe(
ROUTES.SEARCH_REPORT.getRoute({
reportID: '42',
backTo: 'search?q=type:chat',
}),
);
});
});
Loading