Skip to content
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

fix: phone verification ends at CYA screen always #6266

Merged
merged 4 commits into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/navigator/types.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ export type StackParamList = {
registrationStep?: { step: number; totalSteps: number }
e164Number: string
countryCallingCode: string
verificationCompletionScreen: keyof StackParamList
}
[Screens.OnboardingSuccessScreen]: undefined
[Screens.WalletConnectRequest]:
Expand Down
1 change: 1 addition & 0 deletions src/verify/VerificationCodeInputScreen.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ const renderComponent = () =>
params={{
countryCode: '+31',
e164Number,
verificationCompletionScreen: Screens.OnboardingSuccessScreen,
}}
/>
</Provider>
Expand Down
5 changes: 3 additions & 2 deletions src/verify/VerificationCodeInputScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import React, { useLayoutEffect, useState } from 'react'
import { useTranslation } from 'react-i18next'
import { StyleSheet } from 'react-native'
import { SafeAreaView } from 'react-native-safe-area-context'
import { PhoneVerificationEvents } from 'src/analytics/Events'
import AppAnalytics from 'src/analytics/AppAnalytics'
import { PhoneVerificationEvents } from 'src/analytics/Events'
import BackButton from 'src/components/BackButton'
import InfoBottomSheet from 'src/components/InfoBottomSheet'
import { HeaderTitleWithSubtitle } from 'src/navigator/Headers'
Expand All @@ -21,6 +21,7 @@ function VerificationCodeInputScreen({
route,
navigation,
}: NativeStackScreenProps<StackParamList, Screens.VerificationCodeInputScreen>) {
const nextScreen = route.params.verificationCompletionScreen
const [showHelpDialog, setShowHelpDialog] = useState(false)

const { t } = useTranslation()
Expand Down Expand Up @@ -82,7 +83,7 @@ function VerificationCodeInputScreen({
setSmsCode={setSmsCode}
onResendSms={onResendSms}
onSuccess={() => {
navigate(Screens.OnboardingSuccessScreen)
navigate(nextScreen)
}}
containerStyle={{ marginTop: headerHeight }}
/>
Expand Down
76 changes: 39 additions & 37 deletions src/verify/VerificationStartScreen.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { act, fireEvent, render, waitFor, within } from '@testing-library/react-native'
import { fireEvent, render, waitFor, within } from '@testing-library/react-native'
import React from 'react'
import * as Keychain from 'react-native-keychain'
import { Provider } from 'react-redux'
Expand Down Expand Up @@ -60,10 +60,6 @@ describe('VerificationStartScreen', () => {
})
const { getByText, getByTestId, queryByTestId, queryByText } = renderComponent()

await act(() => {
Copy link
Collaborator Author

@kathaypacific kathaypacific Nov 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these changes are to fix the (unrelated) act warnings

jest.advanceTimersByTime(5000)
})

await waitFor(() => expect(getByText('phoneVerificationScreen.startButtonLabel')).toBeTruthy())
expect(getByText('phoneVerificationScreen.title')).toBeTruthy()
expect(getByText('phoneVerificationScreen.description')).toBeTruthy()
Expand All @@ -83,10 +79,6 @@ describe('VerificationStartScreen', () => {
})
const { getByText, getByTestId } = renderComponent({ hasOnboarded: false })

await act(() => {
jest.advanceTimersByTime(5000)
})

await waitFor(() => expect(getByText('phoneVerificationScreen.startButtonLabel')).toBeTruthy())
expect(getByText('phoneVerificationScreen.title')).toBeTruthy()
expect(getByText('phoneVerificationScreen.description')).toBeTruthy()
Expand All @@ -108,10 +100,6 @@ describe('VerificationStartScreen', () => {
})
const { getByText, getByTestId, queryByTestId } = renderComponent({ hasOnboarded: false }, true)

await act(() => {
jest.advanceTimersByTime(5000)
})

await waitFor(() => expect(getByText('phoneVerificationScreen.startButtonLabel')).toBeTruthy())
expect(getByText('phoneVerificationScreen.title')).toBeTruthy()
expect(getByText('phoneVerificationScreen.description')).toBeTruthy()
Expand All @@ -126,23 +114,18 @@ describe('VerificationStartScreen', () => {
mockedKeychain.getGenericPassword.mockResolvedValue(false)
const { queryByText, getByTestId } = renderComponent()

await act(() => {
jest.advanceTimersByTime(5000)
// enter a valid phone number
fireEvent.changeText(getByTestId('PhoneNumberField'), '619123456')
})
fireEvent.changeText(getByTestId('PhoneNumberField'), '619123456')

expect(getByTestId('PhoneVerificationContinue')).toBeDisabled()
await waitFor(() => expect(getByTestId('PhoneVerificationContinue')).toBeDisabled())
expect(getByTestId('Button/Loading')).toBeTruthy()
expect(queryByText('phoneVerificationScreen.startButtonLabel')).toBeFalsy()
})

it('shows the learn more dialog', async () => {
const { getByTestId, getByText } = renderComponent()

await act(() => {
fireEvent.press(getByText('phoneVerificationScreen.learnMore.buttonLabel'))
})
fireEvent.press(getByText('phoneVerificationScreen.learnMore.buttonLabel'))

await waitFor(() => expect(getByTestId('PhoneVerificationLearnMoreDialog')).toBeTruthy())
const LearnMoreDialog = getByTestId('PhoneVerificationLearnMoreDialog')
expect(
Expand All @@ -154,17 +137,17 @@ describe('VerificationStartScreen', () => {
it('skip button works', async () => {
const { getByText } = renderComponent({ hasOnboarded: false })

await act(() => {
fireEvent.press(getByText('skip'))
})
fireEvent.press(getByText('skip'))

expect(goToNextOnboardingScreen).toHaveBeenCalledWith({
firstScreenInCurrentStep: Screens.VerificationStartScreen,
onboardingProps: mockOnboardingProps,
})
await waitFor(() =>
expect(goToNextOnboardingScreen).toHaveBeenCalledWith({
firstScreenInCurrentStep: Screens.VerificationStartScreen,
onboardingProps: mockOnboardingProps,
})
)
})

it('proceeds to the next verification step', async () => {
it('proceeds to the next verification step during onboarding', async () => {
mockedKeychain.getGenericPassword.mockResolvedValue({
password: 'some signed message',
username: 'username',
Expand All @@ -173,10 +156,7 @@ describe('VerificationStartScreen', () => {
})
const { getByText, getByTestId } = renderComponent({ hasOnboarded: false })

await act(() => {
jest.advanceTimersByTime(5000)
fireEvent.changeText(getByTestId('PhoneNumberField'), '619123456')
})
fireEvent.changeText(getByTestId('PhoneNumberField'), '619123456')

await waitFor(() => expect(getByText('phoneVerificationScreen.startButtonLabel')).toBeTruthy())
fireEvent.press(getByText('phoneVerificationScreen.startButtonLabel'))
Expand All @@ -186,6 +166,7 @@ describe('VerificationStartScreen', () => {
countryCallingCode: '+31',
e164Number: '+31619123456',
registrationStep: { step: 3, totalSteps: 3 },
verificationCompletionScreen: 'OnboardingSuccessScreen',
})
})

Expand All @@ -198,10 +179,30 @@ describe('VerificationStartScreen', () => {
})
const { getByText, getByTestId } = renderComponent({ hasOnboarded: false }, true)

await act(() => {
jest.advanceTimersByTime(5000)
fireEvent.changeText(getByTestId('PhoneNumberField'), '619123456')
fireEvent.changeText(getByTestId('PhoneNumberField'), '619123456')

await waitFor(() => expect(getByText('phoneVerificationScreen.startButtonLabel')).toBeTruthy())
fireEvent.press(getByText('phoneVerificationScreen.startButtonLabel'))

expect(navigate).toHaveBeenCalledTimes(1)
expect(navigate).toHaveBeenCalledWith(Screens.VerificationCodeInputScreen, {
countryCallingCode: '+31',
e164Number: '+31619123456',
registrationStep: undefined,
verificationCompletionScreen: 'OnboardingSuccessScreen',
})
})

it('proceeds to the next verification step with the correct navigation props after onboarding', async () => {
mockedKeychain.getGenericPassword.mockResolvedValue({
password: 'some signed message',
username: 'username',
service: 'service',
storage: 'storage',
})
const { getByText, getByTestId } = renderComponent({ hasOnboarded: true }, false)

fireEvent.changeText(getByTestId('PhoneNumberField'), '619123456')

await waitFor(() => expect(getByText('phoneVerificationScreen.startButtonLabel')).toBeTruthy())
fireEvent.press(getByText('phoneVerificationScreen.startButtonLabel'))
Expand All @@ -211,6 +212,7 @@ describe('VerificationStartScreen', () => {
countryCallingCode: '+31',
e164Number: '+31619123456',
registrationStep: undefined,
verificationCompletionScreen: 'TabHome',
})
})
})
10 changes: 10 additions & 0 deletions src/verify/VerificationStartScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,20 @@ function VerificationStartScreen({
countryCallingCode: country?.countryCallingCode || '',
})

const routes = navigation.getState().routes
const prevRoute = routes[routes.length - 2] // -2 because -1 is the current route
// Usually it makes sense to navigate the user back to where they launched
// the verification flow after they complete it, but during onboarding we
// want to navigate to the next step.
const verificationCompletionScreen = !route.params?.hasOnboarded
? Screens.OnboardingSuccessScreen
: (prevRoute?.name ?? Screens.TabHome)

navigate(Screens.VerificationCodeInputScreen, {
registrationStep: showSteps ? { step, totalSteps } : undefined,
e164Number: phoneNumberInfo.e164Number,
countryCallingCode: country?.countryCallingCode || '',
verificationCompletionScreen,
})
}

Expand Down