Skip to content

Commit

Permalink
fix(onboarding): ensure success screen is shown always at the end
Browse files Browse the repository at this point in the history
  • Loading branch information
satish-ravi committed Jan 10, 2025
1 parent 0eedfa9 commit 7270a77
Show file tree
Hide file tree
Showing 9 changed files with 330 additions and 166 deletions.
14 changes: 13 additions & 1 deletion src/keylessBackup/SignInWithEmail.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,18 @@ import { KeylessBackupFlow, KeylessBackupOrigin } from 'src/keylessBackup/types'
import { noHeader } from 'src/navigator/Headers'
import { navigate } from 'src/navigator/NavigationService'
import { Screens } from 'src/navigator/Screens'
import { goToNextOnboardingScreen } from 'src/onboarding/steps'
import Logger from 'src/utils/Logger'
import MockedNavigator from 'test/MockedNavigator'
import { createMockStore } from 'test/utils'
import { mockOnboardingProps } from 'test/values'

const mockOnboardingPropsSelector = jest.fn(() => mockOnboardingProps)
jest.mock('src/onboarding/steps', () => ({
goToNextOnboardingScreen: jest.fn(),
getOnboardingStepValues: () => ({ step: 2, totalSteps: 3 }),
onboardingPropsSelector: () => mockOnboardingPropsSelector(),
}))

const mockAuthorize = jest.fn()
const mockGetCredentials = jest.fn()
Expand Down Expand Up @@ -247,7 +256,10 @@ describe('SignInWithEmail', () => {
expect(getByTestId('KeylessBackupSignInWithEmail/BottomSheet')).toBeTruthy()

fireEvent.press(getByText('signInWithEmail.bottomSheet.skip'))
expect(navigate).toHaveBeenCalledWith(Screens.VerificationStartScreen)
expect(goToNextOnboardingScreen).toHaveBeenCalledWith({
firstScreenInCurrentStep: Screens.SignInWithEmail,
onboardingProps: mockOnboardingProps,
})
expect(AppAnalytics.track).toHaveBeenCalledWith(
KeylessBackupEvents.cab_sign_in_with_email_screen_skip,
{
Expand Down
2 changes: 1 addition & 1 deletion src/navigator/types.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ export type StackParamList = {
registrationStep?: { step: number; totalSteps: number }
e164Number: string
countryCallingCode: string
verificationCompletionScreen: keyof StackParamList
hasOnboarded?: boolean
}
[Screens.OnboardingSuccessScreen]: undefined
[Screens.WalletConnectRequest]:
Expand Down
149 changes: 112 additions & 37 deletions src/onboarding/steps.test.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
import { BIOMETRY_TYPE } from 'react-native-keychain'
import { initializeAccount } from 'src/account/actions'
import { KeylessBackupFlow } from 'src/keylessBackup/types'
import { navigate, navigateClearingStack, popToScreen } from 'src/navigator/NavigationService'
import { Screens } from 'src/navigator/Screens'
import { StackParamList } from 'src/navigator/types'
import { updateStatsigAndNavigate } from 'src/onboarding/actions'
import {
onboardingCompleted,
updateLastOnboardingScreen,
updateStatsigAndNavigate,
} from 'src/onboarding/actions'
import {
firstOnboardingScreen,
getOnboardingStepValues,
goToNextOnboardingScreen,
} from 'src/onboarding/steps'
import { store } from 'src/redux/store'
import { mockOnboardingProps } from 'test/values'
import { onboardingCompleted, updateLastOnboardingScreen } from 'src/onboarding/actions'

jest.mock('src/redux/store', () => ({ store: { dispatch: jest.fn() } }))
jest.mock('src/config', () => ({
Expand All @@ -36,7 +40,7 @@ describe('onboarding steps', () => {
Screens.VerificationStartScreen,
],
name: 'newUserFlowWithEverythingEnabled',
finalScreen: Screens.ChooseYourAdventure,
finalScreen: Screens.OnboardingSuccessScreen,
}

const newUserFlowWithEverythingDisabled = {
Expand All @@ -48,7 +52,7 @@ describe('onboarding steps', () => {
},
screens: [Screens.PincodeSet, Screens.ProtectWallet],
name: 'newUserFlowWithEverythingDisabled',
finalScreen: Screens.ChooseYourAdventure,
finalScreen: Screens.OnboardingSuccessScreen,
}

const importWalletFlowEverythingEnabled = {
Expand All @@ -66,7 +70,7 @@ describe('onboarding steps', () => {
Screens.VerificationStartScreen,
],
name: 'importWalletFlowEverythingEnabled',
finalScreen: Screens.ChooseYourAdventure,
finalScreen: Screens.OnboardingSuccessScreen,
}

beforeEach(() => {
Expand Down Expand Up @@ -161,7 +165,25 @@ describe('onboarding steps', () => {
)
expect(navigate).toHaveBeenCalledWith(Screens.ImportWallet)
})
it('should navigate to ProtectWallet screen if choseToRestoreAccount is false', () => {
it('should navigate to CAB screen if choseToRestoreAccount is false and cloud backup is on', () => {
goToNextOnboardingScreen({
firstScreenInCurrentStep: Screens.EnableBiometry,
onboardingProps: {
...onboardingProps,
choseToRestoreAccount: false,
showCloudAccountBackupSetup: true,
},
})
expect(mockStore.dispatch).toHaveBeenCalledWith(initializeAccount())
expect(mockStore.dispatch).toHaveBeenCalledWith(
updateLastOnboardingScreen(Screens.SignInWithEmail)
)
expect(navigate).toHaveBeenCalledWith(Screens.SignInWithEmail, {
keylessBackupFlow: KeylessBackupFlow.Setup,
origin: 'Onboarding',
})
})
it('should navigate to ProtectWallet screen if choseToRestoreAccount is false and cloud backup is off', () => {
goToNextOnboardingScreen({
firstScreenInCurrentStep: Screens.EnableBiometry,
onboardingProps: {
Expand All @@ -175,20 +197,36 @@ describe('onboarding steps', () => {
)
expect(navigate).toHaveBeenCalledWith(Screens.ProtectWallet)
})
it('should navigate to the CYA screen', () => {
it('should navigate to Verification screen if choseToRestoreAccount is false, cloud backup is off and protect wallet is off', () => {
goToNextOnboardingScreen({
firstScreenInCurrentStep: Screens.EnableBiometry,
onboardingProps: {
...onboardingProps,
choseToRestoreAccount: false,
skipProtectWallet: true,
},
})
expect(mockStore.dispatch).toHaveBeenCalledWith(initializeAccount())
expect(mockStore.dispatch).toHaveBeenCalledWith(
updateLastOnboardingScreen(Screens.VerificationStartScreen)
)
expect(navigate).toHaveBeenCalledWith(Screens.VerificationStartScreen)
})
it('should navigate to end of onboarding if everything is disabled', () => {
goToNextOnboardingScreen({
firstScreenInCurrentStep: Screens.EnableBiometry,
onboardingProps: {
...onboardingProps,
skipProtectWallet: true,
skipVerification: true,
},
})
expect(mockStore.dispatch).toHaveBeenCalledWith(initializeAccount())
expect(mockStore.dispatch).toHaveBeenCalledWith(
updateLastOnboardingScreen(Screens.ChooseYourAdventure)
updateLastOnboardingScreen(Screens.OnboardingSuccessScreen)
)
expect(mockStore.dispatch).toHaveBeenCalledWith(
updateStatsigAndNavigate(Screens.ChooseYourAdventure)
updateStatsigAndNavigate(Screens.OnboardingSuccessScreen)
)
})
})
Expand Down Expand Up @@ -222,36 +260,73 @@ describe('onboarding steps', () => {

expect(navigate).toHaveBeenCalledWith(Screens.ImportWallet)
})
it('should navigate to ProtectWallet', () => {
it('should navigate to CAB screen if choseToRestoreAccount is false and cloud backup is on', () => {
goToNextOnboardingScreen({
firstScreenInCurrentStep: Screens.PincodeSet,
onboardingProps,
onboardingProps: {
...onboardingProps,
choseToRestoreAccount: false,
showCloudAccountBackupSetup: true,
},
})
expect(mockStore.dispatch).toHaveBeenCalledWith(initializeAccount())
expect(mockStore.dispatch).toHaveBeenCalledWith(
updateLastOnboardingScreen(Screens.SignInWithEmail)
)
expect(navigate).toHaveBeenCalledWith(Screens.SignInWithEmail, {
keylessBackupFlow: KeylessBackupFlow.Setup,
origin: 'Onboarding',
})
})
it('should navigate to ProtectWallet screen if choseToRestoreAccount is false and cloud backup is off', () => {
goToNextOnboardingScreen({
firstScreenInCurrentStep: Screens.PincodeSet,
onboardingProps: {
...onboardingProps,
choseToRestoreAccount: false,
},
})
expect(mockStore.dispatch).toHaveBeenCalledWith(initializeAccount())
expect(mockStore.dispatch).toHaveBeenCalledWith(
updateLastOnboardingScreen(Screens.ProtectWallet)
)
expect(navigate).toHaveBeenCalledWith(Screens.ProtectWallet)
})
it('should navigate to the CYA screen', () => {
it('should navigate to Verification screen if choseToRestoreAccount is false, cloud backup is off and protect wallet is off', () => {
goToNextOnboardingScreen({
firstScreenInCurrentStep: Screens.PincodeSet,
onboardingProps: {
...onboardingProps,
choseToRestoreAccount: false,
skipProtectWallet: true,
},
})
expect(mockStore.dispatch).toHaveBeenCalledWith(initializeAccount())
expect(mockStore.dispatch).toHaveBeenCalledWith(
updateStatsigAndNavigate(Screens.ChooseYourAdventure)
updateLastOnboardingScreen(Screens.VerificationStartScreen)
)
expect(navigate).toHaveBeenCalledWith(Screens.VerificationStartScreen)
})
it('should navigate to end of onboarding if everything is disabled', () => {
goToNextOnboardingScreen({
firstScreenInCurrentStep: Screens.PincodeSet,
onboardingProps: {
...onboardingProps,
skipProtectWallet: true,
skipVerification: true,
},
})
expect(mockStore.dispatch).toHaveBeenCalledWith(initializeAccount())
expect(mockStore.dispatch).toHaveBeenCalledWith(
updateLastOnboardingScreen(Screens.OnboardingSuccessScreen)
)
expect(mockStore.dispatch).toHaveBeenCalledWith(
updateLastOnboardingScreen(Screens.ChooseYourAdventure)
updateStatsigAndNavigate(Screens.OnboardingSuccessScreen)
)
})
})
describe('Screens.ImportWallet', () => {
it('should navigate to the CYA screen if skipVerification is true', () => {
it('should navigate to end of onboarding if skipVerification is true', () => {
goToNextOnboardingScreen({
firstScreenInCurrentStep: Screens.ImportWallet,
onboardingProps: {
Expand All @@ -260,13 +335,13 @@ describe('onboarding steps', () => {
},
})
expect(mockStore.dispatch).toHaveBeenCalledWith(
updateStatsigAndNavigate(Screens.ChooseYourAdventure)
updateStatsigAndNavigate(Screens.OnboardingSuccessScreen)
)
expect(mockStore.dispatch).toHaveBeenCalledWith(
updateLastOnboardingScreen(Screens.ChooseYourAdventure)
updateLastOnboardingScreen(Screens.OnboardingSuccessScreen)
)
})
it('should also navigate to the CYA screen if numberAlreadyVerifiedCentrally is true', () => {
it('should also navigate to end of onboarding if numberAlreadyVerifiedCentrally is true', () => {
goToNextOnboardingScreen({
firstScreenInCurrentStep: Screens.ImportWallet,
onboardingProps: {
Expand All @@ -275,10 +350,10 @@ describe('onboarding steps', () => {
},
})
expect(mockStore.dispatch).toHaveBeenCalledWith(
updateStatsigAndNavigate(Screens.ChooseYourAdventure)
updateStatsigAndNavigate(Screens.OnboardingSuccessScreen)
)
expect(mockStore.dispatch).toHaveBeenCalledWith(
updateLastOnboardingScreen(Screens.ChooseYourAdventure)
updateLastOnboardingScreen(Screens.OnboardingSuccessScreen)
)
})
it('should otherwise navigate to VerificationStartScreen', () => {
Expand All @@ -294,40 +369,40 @@ describe('onboarding steps', () => {
)
})
})
describe('Screens.ImportSelect', () => {
it('should navigate to the CYA screen if skipVerification is true', () => {
describe.each([Screens.ImportSelect, Screens.SignInWithEmail])('Screens.%s', (screen) => {
it('should navigate to end of onboarding if skipVerification is true', () => {
goToNextOnboardingScreen({
firstScreenInCurrentStep: Screens.ImportSelect,
firstScreenInCurrentStep: screen,
onboardingProps: {
...onboardingProps,
skipVerification: true,
},
})
expect(mockStore.dispatch).toHaveBeenCalledWith(
updateStatsigAndNavigate(Screens.ChooseYourAdventure)
updateStatsigAndNavigate(Screens.OnboardingSuccessScreen)
)
expect(mockStore.dispatch).toHaveBeenCalledWith(
updateLastOnboardingScreen(Screens.ChooseYourAdventure)
updateLastOnboardingScreen(Screens.OnboardingSuccessScreen)
)
})
it('should also navigate to the CYA screen if numberAlreadyVerifiedCentrally is true', () => {
it('should also navigate to end of onboarding if numberAlreadyVerifiedCentrally is true', () => {
goToNextOnboardingScreen({
firstScreenInCurrentStep: Screens.ImportSelect,
firstScreenInCurrentStep: screen,
onboardingProps: {
...onboardingProps,
numberAlreadyVerifiedCentrally: true,
},
})
expect(mockStore.dispatch).toHaveBeenCalledWith(
updateStatsigAndNavigate(Screens.ChooseYourAdventure)
updateStatsigAndNavigate(Screens.OnboardingSuccessScreen)
)
expect(mockStore.dispatch).toHaveBeenCalledWith(
updateLastOnboardingScreen(Screens.ChooseYourAdventure)
updateLastOnboardingScreen(Screens.OnboardingSuccessScreen)
)
})
it('should otherwise navigate to LinkPhoneNumber', () => {
goToNextOnboardingScreen({
firstScreenInCurrentStep: Screens.ImportSelect,
firstScreenInCurrentStep: screen,
onboardingProps: {
...onboardingProps,
},
Expand All @@ -340,23 +415,23 @@ describe('onboarding steps', () => {
})
describe('Screens.VerificationStartScreen and Screens.LinkPhoneNumber', () => {
it.each([Screens.VerificationStartScreen, Screens.LinkPhoneNumber])(
'From %s should navigate to the Screens.ChooseYourAdventure',
'From %s should navigate to the end of onboarding',
(screen) => {
goToNextOnboardingScreen({
firstScreenInCurrentStep: screen,
onboardingProps: { ...onboardingProps },
})
expect(mockStore.dispatch).toHaveBeenCalledWith(
updateStatsigAndNavigate(Screens.ChooseYourAdventure)
updateStatsigAndNavigate(Screens.OnboardingSuccessScreen)
)
expect(mockStore.dispatch).toHaveBeenCalledWith(
updateLastOnboardingScreen(Screens.ChooseYourAdventure)
updateLastOnboardingScreen(Screens.OnboardingSuccessScreen)
)
}
)
})
describe('Screens.ProtectWallet', () => {
it('should navigate to the CYA screen if skipVerification is true', () => {
it('should navigate to end of onboarding if skipVerification is true', () => {
goToNextOnboardingScreen({
firstScreenInCurrentStep: Screens.ProtectWallet,
onboardingProps: {
Expand All @@ -365,13 +440,13 @@ describe('onboarding steps', () => {
},
})
expect(mockStore.dispatch).toHaveBeenCalledWith(
updateStatsigAndNavigate(Screens.ChooseYourAdventure)
updateStatsigAndNavigate(Screens.OnboardingSuccessScreen)
)
expect(mockStore.dispatch).toHaveBeenCalledWith(
updateLastOnboardingScreen(Screens.ChooseYourAdventure)
updateLastOnboardingScreen(Screens.OnboardingSuccessScreen)
)
})
it('should navigate to VerficationStartScreen if skipVerification is false and choseToRestoreAccount is false', () => {
it('should navigate to VerificationStartScreen if skipVerification is false and choseToRestoreAccount is false', () => {
goToNextOnboardingScreen({
firstScreenInCurrentStep: Screens.ProtectWallet,
onboardingProps: {
Expand Down
Loading

0 comments on commit 7270a77

Please sign in to comment.