Repository navigation
Keep the current tab when opening an exitTo link from a signed-in val… #101335
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
mollfpr
merged 2 commits into
Expensify:main
from
yusufdeveloper2903:fix-100680-exitto-keep-tab
Sep 23, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,171 @@ | ||
| import {act, render} from '@testing-library/react-native'; | ||
|
|
||
| import useResponsiveLayout from '@hooks/useResponsiveLayout'; | ||
|
|
||
| import getIsNarrowLayout from '@libs/getIsNarrowLayout'; | ||
| import Navigation from '@libs/Navigation/Navigation'; | ||
| import navigationRef from '@libs/Navigation/navigationRef'; | ||
|
|
||
| import {handleExitToNavigation} from '@userActions/Session'; | ||
|
|
||
| import CONST from '@src/CONST'; | ||
| import NAVIGATORS from '@src/NAVIGATORS'; | ||
| import ONYXKEYS from '@src/ONYXKEYS'; | ||
| import ROUTES from '@src/ROUTES'; | ||
| import SCREENS from '@src/SCREENS'; | ||
|
|
||
| import type {InitialState} from '@react-navigation/native'; | ||
|
|
||
| import React from 'react'; | ||
| import Onyx from 'react-native-onyx'; | ||
|
|
||
| import TestNavigationContainer from '../utils/TestNavigationContainer'; | ||
| import waitForBatchedUpdates from '../utils/waitForBatchedUpdates'; | ||
|
|
||
| jest.mock('@hooks/useResponsiveLayout', () => jest.fn()); | ||
| jest.mock('@libs/getIsNarrowLayout', () => jest.fn()); | ||
|
|
||
| jest.mock('@pages/inbox/sidebar/NavigationTabBarAvatar'); | ||
|
|
||
| const mockedGetIsNarrowLayout = jest.mocked(getIsNarrowLayout); | ||
| const mockedUseResponsiveLayout = jest.mocked(useResponsiveLayout); | ||
|
|
||
| const REPORT_ID = '1'; | ||
|
|
||
| function getRoutesWithTabNavigatorUnderValidateLogin(activeTabIndex: number): InitialState['routes'] { | ||
| return [ | ||
| { | ||
| name: NAVIGATORS.TAB_NAVIGATOR, | ||
| state: { | ||
| index: activeTabIndex, | ||
| routes: [ | ||
| {name: SCREENS.HOME}, | ||
| { | ||
| name: NAVIGATORS.REPORTS_SPLIT_NAVIGATOR, | ||
| state: {index: 0, routes: [{name: SCREENS.INBOX}]}, | ||
| }, | ||
| { | ||
| name: NAVIGATORS.SEARCH_FULLSCREEN_NAVIGATOR, | ||
| state: {index: 0, routes: [{name: SCREENS.SEARCH.ROOT}]}, | ||
| }, | ||
| {name: SCREENS.INSIGHTS}, | ||
| {name: NAVIGATORS.SETTINGS_SPLIT_NAVIGATOR}, | ||
| {name: NAVIGATORS.WORKSPACE_NAVIGATOR}, | ||
| ], | ||
| }, | ||
| }, | ||
| {name: SCREENS.VALIDATE_LOGIN}, | ||
| ]; | ||
| } | ||
|
|
||
| function getTabNavigatorStates() { | ||
| return navigationRef.current | ||
| ?.getRootState() | ||
| .routes.filter((route) => route.name === NAVIGATORS.TAB_NAVIGATOR) | ||
| .map((route) => route.state); | ||
| } | ||
|
|
||
| function hasValidateLoginRoute() { | ||
| return !!navigationRef.current?.getRootState().routes.some((route) => route.name === SCREENS.VALIDATE_LOGIN); | ||
| } | ||
|
|
||
| async function runHandleExitToNavigation() { | ||
| await act(async () => { | ||
| handleExitToNavigation(ROUTES.REPORT_WITH_ID.getRoute(REPORT_ID)); | ||
| await waitForBatchedUpdates(); | ||
| }); | ||
| } | ||
|
|
||
| describe('handleExitToNavigation', () => { | ||
| beforeAll(() => { | ||
| Onyx.init({keys: ONYXKEYS}); | ||
| }); | ||
|
|
||
| beforeEach(async () => { | ||
| mockedGetIsNarrowLayout.mockReturnValue(true); | ||
| mockedUseResponsiveLayout.mockReturnValue({ | ||
| ...CONST.NAVIGATION_TESTS.DEFAULT_USE_RESPONSIVE_LAYOUT_VALUE, | ||
| shouldUseNarrowLayout: true, | ||
| }); | ||
| jest.spyOn(Navigation, 'waitForProtectedRoutes').mockResolvedValue(); | ||
| await Onyx.set(ONYXKEYS.SESSION, {authToken: 'authToken', accountID: 1}); | ||
| await waitForBatchedUpdates(); | ||
| }); | ||
|
|
||
| afterEach(async () => { | ||
| jest.restoreAllMocks(); | ||
| await Onyx.clear(); | ||
| }); | ||
|
|
||
| it('opens the report inside the Inbox tab when the link is opened from Inbox', async () => { | ||
| render( | ||
| <TestNavigationContainer | ||
| initialState={{ | ||
| index: 1, | ||
| routes: getRoutesWithTabNavigatorUnderValidateLogin(1), | ||
| }} | ||
| />, | ||
| ); | ||
|
|
||
| await runHandleExitToNavigation(); | ||
|
|
||
| expect(hasValidateLoginRoute()).toBe(false); | ||
| const tabState = getTabNavigatorStates()?.at(-1); | ||
| const focusedTab = tabState?.routes.at(tabState.index ?? 0); | ||
| expect(focusedTab?.name).toBe(NAVIGATORS.REPORTS_SPLIT_NAVIGATOR); | ||
| expect(focusedTab?.state?.routes.at(-1)?.name).toBe(SCREENS.REPORT); | ||
| }); | ||
|
|
||
| it('keeps Spend under the report when the link is opened from Spend', async () => { | ||
| render( | ||
| <TestNavigationContainer | ||
| initialState={{ | ||
| index: 1, | ||
| routes: getRoutesWithTabNavigatorUnderValidateLogin(2), | ||
| }} | ||
| />, | ||
| ); | ||
|
|
||
| await runHandleExitToNavigation(); | ||
|
|
||
| expect(hasValidateLoginRoute()).toBe(false); | ||
| const tabStates = getTabNavigatorStates(); | ||
| const focusedTabState = tabStates?.at(-1); | ||
| const focusedTab = focusedTabState?.routes.at(focusedTabState.index ?? 0); | ||
| expect(focusedTab?.name).toBe(NAVIGATORS.REPORTS_SPLIT_NAVIGATOR); | ||
| expect(focusedTab?.state?.routes.at(-1)?.name).toBe(SCREENS.REPORT); | ||
| expect(tabStates?.at(0)?.index).toBe(2); | ||
| }); | ||
|
|
||
| it('removes ValidateLogin even when a pop to sidebar is pending', async () => { | ||
| render( | ||
| <TestNavigationContainer | ||
| initialState={{ | ||
| index: 1, | ||
| routes: getRoutesWithTabNavigatorUnderValidateLogin(1), | ||
| }} | ||
| />, | ||
| ); | ||
| Navigation.setShouldPopToSidebar(true); | ||
|
|
||
| await runHandleExitToNavigation(); | ||
|
|
||
| expect(hasValidateLoginRoute()).toBe(false); | ||
| const tabState = getTabNavigatorStates()?.at(-1); | ||
| const focusedTab = tabState?.routes.at(tabState.index ?? 0); | ||
| expect(focusedTab?.name).toBe(NAVIGATORS.REPORTS_SPLIT_NAVIGATOR); | ||
| expect(focusedTab?.state?.routes.at(-1)?.name).toBe(SCREENS.REPORT); | ||
| Navigation.setShouldPopToSidebar(false); | ||
| }); | ||
|
|
||
| it('goes back to Home when ValidateLogin is the only route', async () => { | ||
| const goBackSpy = jest.spyOn(Navigation, 'goBack'); | ||
| render(<TestNavigationContainer initialState={{index: 0, routes: [{name: SCREENS.VALIDATE_LOGIN}]}} />); | ||
|
|
||
| await runHandleExitToNavigation(); | ||
|
|
||
| expect(goBackSpy).toHaveBeenCalledWith(ROUTES.HOME, { | ||
| waitForTransition: true, | ||
| }); | ||
| }); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not questioning it, just curious why you went with this approach instead of your original proposal. In what scenario would these two approaches behave differently, so I can test it?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Short answer on why I moved off my proposal's line.
goBack(undefined)doesn't always popValidateLogin. WhenshouldPopToSidebaris set,goBacktakes thepopToSidebar()branch first, andpopToSidebar()clears the flag and returns without popping anything, because the top root route isValidateLoginand not a split navigator.NavigationRootsets that flag on any wide → narrow change while a split navigator is on top (e.g. rotating landscape → portrait with a report open), and it stays set until the next parameterlessgoBack().I ran both versions through the real navigators in Jest with the flag set. The report opens on the right tab either way, so the fix for this issue holds in both, but the resulting root stack differs:
[TabNavigator → Inbox split: Inbox, Report][TabNavigator(Inbox), ValidateLogin, TabNavigator(Inbox split: Report)]So with the proposal's line the consumed
ValidateLoginstays in the stack and the report is pushed above it in a second tab navigator: Back from the report shows the/v/loading screen, and only the second Back returns to the report list.Navigation.pop(navigationRef.getRootState().key)is dispatched at the root stack directly, so the flag can't redirect it and the only route it can remove isValidateLogin. The lone-route case is unchanged: stillgoBack(ROUTES.HOME, {waitForTransition: true}). This is covered byremoves ValidateLogin even when a pop to sidebar is pending— it fails with my original line (Expected: false Received: true) and passes with this one.