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/ROUTES.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ const DYNAMIC_ROUTES = {
},
WORKSPACE_CONFIRMATION: {
path: 'workspace/confirmation',
entryScreens: [SCREENS.HOME, SCREENS.INBOX, SCREENS.REPORT, SCREENS.SEARCH.ROOT, SCREENS.WORKSPACES_LIST, SCREENS.SETTINGS.ROOT],
entryScreens: ['*'],
},
WORKSPACE_CONFIRMATION_CURRENCY: {
path: 'currency',
Expand Down
40 changes: 39 additions & 1 deletion tests/navigation/workspaceConfirmationEntryScreensTest.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,44 @@
import {DYNAMIC_ROUTES} from '@src/ROUTES';
import createDynamicRoute from '@libs/Navigation/helpers/dynamicRoutesUtils/createDynamicRoute';
import getStateFromPath from '@libs/Navigation/helpers/getStateFromPath';

import CONST from '@src/CONST';
import ROUTES, {DYNAMIC_ROUTES} from '@src/ROUTES';
import SCREENS from '@src/SCREENS';

import type {NavigationState, PartialState} from '@react-navigation/native';

function getFocusedRouteName(state: PartialState<NavigationState>): string | undefined {
let current: PartialState<NavigationState> | undefined = state;
let name: string | undefined;

while (current?.routes) {
const nextRoute = current.routes.at(current.index ?? current.routes.length - 1);
name = nextRoute?.name;
current = nextRoute?.state;
}

return name;
}

/**
* The FAB "New workspace" item opens the confirmation route appended to whichever screen is active,
* and the FAB is reachable from every tab. A host missing from `entryScreens` fails validation in
* getStateFromPath, so the user lands on Not Found instead of the confirmation page.
*/
describe('WORKSPACE_CONFIRMATION', () => {
it.each([
['the Account tab profile page', ROUTES.SETTINGS_PROFILE.route],
['the Insights tab', ROUTES.INSIGHTS.getRoute(CONST.INSIGHTS.DASHBOARD.SPEND)],
])('opens the confirmation page from %s', (_label, basePath) => {
// Given the user is on a tab outside the original entry screens (the wide Account tab lands on the profile page)
// When the FAB builds the confirmation route on top of that page
const url = createDynamicRoute(DYNAMIC_ROUTES.WORKSPACE_CONFIRMATION.path, basePath);

// Then the path resolves to the confirmation screen instead of Not Found
expect(getFocusedRouteName(getStateFromPath(url))).toBe(SCREENS.WORKSPACE_CONFIRMATION.DYNAMIC_ROOT);
});
});

/**
* The confirm workspace form always renders the currency row, and that row opens the `currency`
* dynamic route appended to whichever screen is hosting the form. A host missing from
Expand Down
Loading