From 22180b36f17ecdc3432ec3eb94242b40bbc28c36 Mon Sep 17 00:00:00 2001 From: "mkhutornyi (via MelvinBot)" Date: Mon, 20 Jul 2026 16:25:12 +0000 Subject: [PATCH 1/3] Reset public stack to sign-in page when requesting a new code from expired magic-link page Co-authored-by: mkhutornyi --- .../ValidateCode/ExpiredValidateCodeModal.tsx | 9 ++- tests/ui/ValidateLoginPageTest.tsx | 57 +++++++++++++++---- 2 files changed, 53 insertions(+), 13 deletions(-) diff --git a/src/components/ValidateCode/ExpiredValidateCodeModal.tsx b/src/components/ValidateCode/ExpiredValidateCodeModal.tsx index 2cad1ca73fe9..4df546804634 100644 --- a/src/components/ValidateCode/ExpiredValidateCodeModal.tsx +++ b/src/components/ValidateCode/ExpiredValidateCodeModal.tsx @@ -8,12 +8,13 @@ import useOnyx from '@hooks/useOnyx'; import useTheme from '@hooks/useTheme'; import useThemeStyles from '@hooks/useThemeStyles'; -import Navigation from '@libs/Navigation/Navigation'; +import Navigation, {navigationRef} from '@libs/Navigation/Navigation'; import variables from '@styles/variables'; import {beginSignIn} from '@userActions/Session'; +import NAVIGATORS from '@src/NAVIGATORS'; import ONYXKEYS from '@src/ONYXKEYS'; import React from 'react'; @@ -45,7 +46,11 @@ function ExpiredValidateCodeModal() { { beginSignIn(credentials?.login ?? ''); - Navigation.setNavigationActionToMicrotaskQueue(Navigation.goBack); + // navigate/goBack no-op from the public /v/ route when it's the stack root (magic link opened + // in a fresh tab), so reset the stack to TAB_NAVIGATOR (which hosts the public SignInPage). + Navigation.isNavigationReady().then(() => { + navigationRef.reset({index: 0, routes: [{name: NAVIGATORS.TAB_NAVIGATOR}]}); + }); }} > {translate('validateCodeModal.requestOneHere')} diff --git a/tests/ui/ValidateLoginPageTest.tsx b/tests/ui/ValidateLoginPageTest.tsx index 787f07239622..d35cf774d040 100644 --- a/tests/ui/ValidateLoginPageTest.tsx +++ b/tests/ui/ValidateLoginPageTest.tsx @@ -1,12 +1,13 @@ -import {act, render, screen} from '@testing-library/react-native'; +import {act, fireEvent, render, screen} from '@testing-library/react-native'; +import {LocaleContextProvider} from '@components/LocaleContextProvider'; import Navigation from '@libs/Navigation/Navigation'; import createPlatformStackNavigator from '@libs/Navigation/PlatformStackNavigation/createPlatformStackNavigator'; import type {PublicScreensParamList} from '@libs/Navigation/types'; import ValidateLoginPage from '@pages/ValidateLoginPage/index.web'; -import {handleExitToNavigation} from '@userActions/Session'; +import {beginSignIn, handleExitToNavigation} from '@userActions/Session'; import CONST from '@src/CONST'; import NAVIGATORS from '@src/NAVIGATORS'; @@ -18,6 +19,7 @@ import {NavigationContainer} from '@react-navigation/native'; import React from 'react'; import Onyx from 'react-native-onyx'; +import {translateLocal} from '../utils/TestHelper'; import waitForBatchedUpdatesWithAct from '../utils/waitForBatchedUpdatesWithAct'; // Controllable deferred so tests can assert the *ordering* guarantee (navigate only after @@ -65,21 +67,24 @@ jest.mock('@userActions/Session', () => ({ initAutoAuthState: jest.fn(), signInWithValidateCode: jest.fn(), handleExitToNavigation: jest.fn(), + beginSignIn: jest.fn(), })); const RootStack = createPlatformStackNavigator(); const renderPage = (initialParams: PublicScreensParamList[typeof SCREENS.VALIDATE_LOGIN]) => { return render( - - - - - , + + + + + + + , ); }; @@ -248,6 +253,36 @@ describe('ValidateLoginPage', () => { expect(mockNavigationReset).toHaveBeenCalledWith({index: 0, routes: [{name: NAVIGATORS.TAB_NAVIGATOR}]}); }); + it('Should request a new code and reset to the sign-in page when "request one here" is pressed on the expired-code page', async () => { + // Fresh-tab repro: the magic code expired (FAILED) so ExpiredValidateCodeModal renders. Pressing + // "request one here" must both request a new code and surface the sign-in page. goBack no-ops from + // the root /v/ route, so we reset the public stack to TAB_NAVIGATOR (which hosts SignInPage). + await act(async () => { + await Onyx.set(ONYXKEYS.SESSION, { + autoAuthState: CONST.AUTO_AUTH_STATE.FAILED, + }); + await Onyx.set(ONYXKEYS.CREDENTIALS, { + login: 'test@example.com', + }); + }); + + renderPage({accountID: '1', validateCode: '123456'}); + await waitForBatchedUpdatesWithAct(); + + fireEvent.press(screen.getByText(translateLocal('validateCodeModal.requestOneHere'))); + + expect(beginSignIn).toHaveBeenCalledWith('test@example.com'); + + // Resolve the navigation-ready gate, then the press handler resets the public stack to SignInPage. + await act(async () => { + mockIsNavigationReady.resolve(); + await Promise.resolve(); + }); + await waitForBatchedUpdatesWithAct(); + + expect(mockNavigationReset).toHaveBeenCalledWith({index: 0, routes: [{name: NAVIGATORS.TAB_NAVIGATOR}]}); + }); + it('Should route an exitTo 2FA magic link to the sign-in page AND keep the deferred exitTo navigation', async () => { // exitTo deep link on a 2FA account: the user must still reach the authenticator form (not the // dead-end "2FA required" modal), so we reset to the sign-in page. We also register From f947a9f1f0815e8c2252dd9941a9a710a30a272e Mon Sep 17 00:00:00 2001 From: "mkhutornyi (via MelvinBot)" Date: Mon, 20 Jul 2026 16:26:12 +0000 Subject: [PATCH 2/3] Pass synthetic event to TextLink press in test Co-authored-by: mkhutornyi --- tests/ui/ValidateLoginPageTest.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/ui/ValidateLoginPageTest.tsx b/tests/ui/ValidateLoginPageTest.tsx index d35cf774d040..4757a2154b7b 100644 --- a/tests/ui/ValidateLoginPageTest.tsx +++ b/tests/ui/ValidateLoginPageTest.tsx @@ -269,7 +269,8 @@ describe('ValidateLoginPage', () => { renderPage({accountID: '1', validateCode: '123456'}); await waitForBatchedUpdatesWithAct(); - fireEvent.press(screen.getByText(translateLocal('validateCodeModal.requestOneHere'))); + // TextLink's tap handler calls event.preventDefault(), so pass a minimal synthetic event. + fireEvent.press(screen.getByText(translateLocal('validateCodeModal.requestOneHere')), {preventDefault: () => {}}); expect(beginSignIn).toHaveBeenCalledWith('test@example.com'); From 764b074e2ac53947f4e64fcd4b3e41bf43ffe767 Mon Sep 17 00:00:00 2001 From: "mkhutornyi (via MelvinBot)" Date: Mon, 20 Jul 2026 16:26:58 +0000 Subject: [PATCH 3/3] Apply oxfmt formatting Co-authored-by: mkhutornyi --- tests/ui/ValidateLoginPageTest.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/ui/ValidateLoginPageTest.tsx b/tests/ui/ValidateLoginPageTest.tsx index 4757a2154b7b..ec22be9b291f 100644 --- a/tests/ui/ValidateLoginPageTest.tsx +++ b/tests/ui/ValidateLoginPageTest.tsx @@ -1,6 +1,7 @@ import {act, fireEvent, render, screen} from '@testing-library/react-native'; import {LocaleContextProvider} from '@components/LocaleContextProvider'; + import Navigation from '@libs/Navigation/Navigation'; import createPlatformStackNavigator from '@libs/Navigation/PlatformStackNavigation/createPlatformStackNavigator'; import type {PublicScreensParamList} from '@libs/Navigation/types';