From 1989e99f17539ff3bfbad7e06d007ab84ba8770c Mon Sep 17 00:00:00 2001 From: Bernhard Owen Josephus Date: Thu, 19 Dec 2024 16:32:38 +0800 Subject: [PATCH 1/2] fix blank screen when using invalid code and there is an exitTo param --- .../BlockingViews/FullPageNotFoundView.tsx | 9 +++- .../ValidateCode/ValidateCodeModal.tsx | 6 ++- src/pages/ValidateLoginPage/index.website.tsx | 9 ++-- tests/ui/ValidateLoginPageTest.tsx | 54 +++++++++++++++++++ 4 files changed, 70 insertions(+), 8 deletions(-) create mode 100644 tests/ui/ValidateLoginPageTest.tsx diff --git a/src/components/BlockingViews/FullPageNotFoundView.tsx b/src/components/BlockingViews/FullPageNotFoundView.tsx index 029b79b432cf..ad1a659e6d9f 100644 --- a/src/components/BlockingViews/FullPageNotFoundView.tsx +++ b/src/components/BlockingViews/FullPageNotFoundView.tsx @@ -11,6 +11,9 @@ import BlockingView from './BlockingView'; import ForceFullScreenView from './ForceFullScreenView'; type FullPageNotFoundViewProps = { + /** TestID for test */ + testID?: string; + /** Child elements */ children?: React.ReactNode; @@ -44,6 +47,7 @@ type FullPageNotFoundViewProps = { // eslint-disable-next-line rulesdir/no-negated-variables function FullPageNotFoundView({ + testID, children = null, shouldShow = false, titleKey = 'notFound.notHere', @@ -65,7 +69,10 @@ function FullPageNotFoundView({ onBackButtonPress={onBackButtonPress} shouldShowBackButton={shouldShowBackButton} /> - + { Navigation.goBack(); }} > - + { if (isUserClickedSignIn) { @@ -49,10 +50,6 @@ function ValidateLoginPage({ return; } - if (!ValidationUtils.isValidValidateCode(validateCode)) { - return; - } - // The user has initiated the sign in process on the same browser, in another tab. Session.signInWithValidateCode(Number(accountID), validateCode); @@ -83,7 +80,7 @@ function ValidateLoginPage({ {autoAuthStateWithDefault === CONST.AUTO_AUTH_STATE.JUST_SIGNED_IN && is2FARequired && !isSignedIn && !!login && } {autoAuthStateWithDefault === CONST.AUTO_AUTH_STATE.JUST_SIGNED_IN && isSignedIn && !exitTo && !!login && } {/* If session.autoAuthState isn't available yet, we use shouldStartSignInWithValidateCode to conditionally render the component instead of local autoAuthState which contains a default value of NOT_STARTED */} - {(!autoAuthState ? !shouldStartSignInWithValidateCode : autoAuthStateWithDefault === CONST.AUTO_AUTH_STATE.NOT_STARTED) && !exitTo && ( + {(!autoAuthState ? !shouldStartSignInWithValidateCode : autoAuthStateWithDefault === CONST.AUTO_AUTH_STATE.NOT_STARTED && !isNavigatingToExitTo) && ( (); + +const renderPage = (initialParams: PublicScreensParamList[typeof SCREENS.VALIDATE_LOGIN]) => { + return render( + + + + + , + ); +}; + +describe('ValidateLoginPage', () => { + beforeEach(() => { + jest.clearAllMocks(); + Onyx.clear(); + }); + + it('Should show not found view when the magic code is invalid and there is an exitTo param', async () => { + await Onyx.set(ONYXKEYS.SESSION, { + autoAuthState: CONST.AUTO_AUTH_STATE.NOT_STARTED, + }); + + renderPage({accountID: '1', validateCode: 'ABCDEF', exitTo: 'concierge'}); + + expect(screen.queryByTestId('validate-code-not-found')).not.toBeNull(); + }); + + it('Should not show ValidateCodeModal when signed in and there is an exitTo param', async () => { + await Onyx.set(ONYXKEYS.SESSION, { + authToken: 'abcd', + autoAuthState: CONST.AUTO_AUTH_STATE.NOT_STARTED, + }); + + renderPage({accountID: '1', validateCode: '123456', exitTo: 'concierge'}); + + expect(screen.queryByTestId('validate-code')).toBeNull(); + }); +}); From e2de781472a78adaf7fa48025813b0f66910cd3c Mon Sep 17 00:00:00 2001 From: Bernhard Owen Josephus Date: Thu, 19 Dec 2024 16:39:16 +0800 Subject: [PATCH 2/2] lint --- tests/ui/ValidateLoginPageTest.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/ui/ValidateLoginPageTest.tsx b/tests/ui/ValidateLoginPageTest.tsx index 24276af3f454..19a9a375d726 100644 --- a/tests/ui/ValidateLoginPageTest.tsx +++ b/tests/ui/ValidateLoginPageTest.tsx @@ -3,7 +3,7 @@ import {render, screen} from '@testing-library/react-native'; import React from 'react'; import Onyx from 'react-native-onyx'; import createResponsiveStackNavigator from '@libs/Navigation/AppNavigator/createResponsiveStackNavigator'; -import {PublicScreensParamList} from '@libs/Navigation/types'; +import type {PublicScreensParamList} from '@libs/Navigation/types'; import ValidateLoginPage from '@pages/ValidateLoginPage/index.website'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; @@ -38,7 +38,7 @@ describe('ValidateLoginPage', () => { renderPage({accountID: '1', validateCode: 'ABCDEF', exitTo: 'concierge'}); - expect(screen.queryByTestId('validate-code-not-found')).not.toBeNull(); + expect(screen.getByTestId('validate-code-not-found')).not.toBeNull(); }); it('Should not show ValidateCodeModal when signed in and there is an exitTo param', async () => {