-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #34228 from gedu/edu/reassure_sign_in
[No QA] [Reassure] Sign in base perf flow
- Loading branch information
Showing
8 changed files
with
185 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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,148 @@ | ||
import type * as NativeNavigation from '@react-navigation/native'; | ||
import {fireEvent, screen} from '@testing-library/react-native'; | ||
import React from 'react'; | ||
import Onyx from 'react-native-onyx'; | ||
import {measurePerformance} from 'reassure'; | ||
import ComposeProviders from '@components/ComposeProviders'; | ||
import {LocaleContextProvider} from '@components/LocaleContextProvider'; | ||
import OnyxProvider from '@components/OnyxProvider'; | ||
import {WindowDimensionsProvider} from '@components/withWindowDimensions'; | ||
import * as Localize from '@libs/Localize'; | ||
import type * as Navigation from '@libs/Navigation/Navigation'; | ||
import ONYXKEYS from '@src/ONYXKEYS'; | ||
import SignInPage from '@src/pages/signin/SignInPage'; | ||
import getValidCodeCredentials from '../utils/collections/getValidCodeCredentials'; | ||
import userAccount, {getValidAccount} from '../utils/collections/userAccount'; | ||
import PusherHelper from '../utils/PusherHelper'; | ||
import * as TestHelper from '../utils/TestHelper'; | ||
import waitForBatchedUpdates from '../utils/waitForBatchedUpdates'; | ||
import wrapOnyxWithWaitForBatchedUpdates from '../utils/wrapOnyxWithWaitForBatchedUpdates'; | ||
|
||
jest.mock('../../src/libs/Navigation/Navigation', () => { | ||
const actualNav = jest.requireActual('../../src/libs/Navigation/Navigation'); | ||
return { | ||
...actualNav, | ||
navigationRef: { | ||
addListener: () => jest.fn(), | ||
removeListener: () => jest.fn(), | ||
}, | ||
} as typeof Navigation; | ||
}); | ||
|
||
const mockedNavigate = jest.fn(); | ||
jest.mock('@react-navigation/native', () => { | ||
const actualNav = jest.requireActual('@react-navigation/native'); | ||
return { | ||
...actualNav, | ||
useFocusEffect: jest.fn(), | ||
useIsFocused: () => ({ | ||
navigate: mockedNavigate, | ||
}), | ||
useRoute: () => jest.fn(), | ||
useNavigation: () => ({ | ||
navigate: jest.fn(), | ||
addListener: () => jest.fn(), | ||
}), | ||
createNavigationContainerRef: jest.fn(), | ||
} as typeof NativeNavigation; | ||
}); | ||
|
||
type Props = Partial<typeof SignInPage> & {navigation: Partial<typeof Navigation.navigationRef>}; | ||
|
||
function SignInPageWrapper(args: Props) { | ||
return ( | ||
<ComposeProviders components={[OnyxProvider, WindowDimensionsProvider, LocaleContextProvider]}> | ||
<SignInPage | ||
// eslint-disable-next-line react/jsx-props-no-spreading | ||
{...args} | ||
navigation={args.navigation} | ||
/> | ||
</ComposeProviders> | ||
); | ||
} | ||
|
||
const login = '[email protected]'; | ||
|
||
describe('SignInPage', () => { | ||
beforeAll(() => { | ||
Onyx.init({ | ||
keys: ONYXKEYS, | ||
safeEvictionKeys: [ONYXKEYS.COLLECTION.REPORT_ACTIONS], | ||
}); | ||
}); | ||
|
||
// Initialize the network key for OfflineWithFeedback | ||
beforeEach(() => { | ||
global.fetch = TestHelper.getGlobalFetchMock() as typeof fetch; | ||
wrapOnyxWithWaitForBatchedUpdates(Onyx); | ||
Onyx.merge(ONYXKEYS.NETWORK, {isOffline: false}); | ||
}); | ||
|
||
// Clear out Onyx after each test so that each test starts with a clean state | ||
afterEach(() => { | ||
Onyx.clear(); | ||
PusherHelper.teardown(); | ||
}); | ||
|
||
test('[SignInPage] should add username and click continue button', () => { | ||
const addListener = jest.fn(); | ||
const scenario = async () => { | ||
// Checking the SignInPage is mounted | ||
await screen.findByTestId('SignInPage'); | ||
|
||
const usernameInput = screen.getByTestId('username'); | ||
|
||
fireEvent.changeText(usernameInput, login); | ||
|
||
const hintContinueButtonText = Localize.translateLocal('common.continue'); | ||
|
||
const continueButton = await screen.findByText(hintContinueButtonText); | ||
|
||
fireEvent.press(continueButton); | ||
}; | ||
|
||
const navigation = {addListener}; | ||
|
||
return waitForBatchedUpdates() | ||
.then(() => | ||
Onyx.multiSet({ | ||
[ONYXKEYS.ACCOUNT]: userAccount, | ||
[ONYXKEYS.IS_SIDEBAR_LOADED]: false, | ||
}), | ||
) | ||
.then(() => measurePerformance(<SignInPageWrapper navigation={navigation} />, {scenario})); | ||
}); | ||
|
||
test('[SignInPage] should add magic code and click Sign In button', () => { | ||
const addListener = jest.fn(); | ||
const scenario = async () => { | ||
// Checking the SignInPage is mounted | ||
await screen.findByTestId('SignInPage'); | ||
|
||
const welcomeBackText = Localize.translateLocal('welcomeText.welcomeBack'); | ||
const enterMagicCodeText = Localize.translateLocal('welcomeText.welcomeEnterMagicCode', {login}); | ||
|
||
await screen.findByText(`${welcomeBackText} ${enterMagicCodeText}`); | ||
const magicCodeInput = screen.getByTestId('validateCode'); | ||
|
||
fireEvent.changeText(magicCodeInput, '123456'); | ||
|
||
const signInButtonText = Localize.translateLocal('common.signIn'); | ||
const signInButton = await screen.findByText(signInButtonText); | ||
|
||
fireEvent.press(signInButton); | ||
}; | ||
|
||
const navigation = {addListener}; | ||
|
||
return waitForBatchedUpdates() | ||
.then(() => | ||
Onyx.multiSet({ | ||
[ONYXKEYS.ACCOUNT]: getValidAccount(login), | ||
[ONYXKEYS.CREDENTIALS]: getValidCodeCredentials(login), | ||
[ONYXKEYS.IS_SIDEBAR_LOADED]: false, | ||
}), | ||
) | ||
.then(() => measurePerformance(<SignInPageWrapper navigation={navigation} />, {scenario})); | ||
}); | ||
}); |
This file contains 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,11 @@ | ||
import {randEmail, randNumber} from '@ngneat/falso'; | ||
import type {Credentials} from '@src/types/onyx'; | ||
|
||
function getValidCodeCredentials(login = randEmail()): Credentials { | ||
return { | ||
login, | ||
validateCode: `${randNumber()}`, | ||
}; | ||
} | ||
|
||
export default getValidCodeCredentials; |
This file contains 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,14 @@ | ||
import CONST from '@src/CONST'; | ||
import type {Account} from '@src/types/onyx'; | ||
|
||
function getValidAccount(credentialLogin = ''): Account { | ||
return { | ||
validated: true, | ||
primaryLogin: credentialLogin, | ||
isLoading: false, | ||
requiresTwoFactorAuth: false, | ||
}; | ||
} | ||
|
||
export default CONST.DEFAULT_ACCOUNT_DATA; | ||
export {getValidAccount}; |