diff --git a/src/pages/OnboardingPurpose/BaseOnboardingPurpose.tsx b/src/pages/OnboardingPurpose/BaseOnboardingPurpose.tsx index 435e2fbaf273..40858a9131c5 100644 --- a/src/pages/OnboardingPurpose/BaseOnboardingPurpose.tsx +++ b/src/pages/OnboardingPurpose/BaseOnboardingPurpose.tsx @@ -27,7 +27,7 @@ import {expensifyLoginsSelector, isCurrentUserValidated} from '@libs/UserUtils'; import variables from '@styles/variables'; import {completeOnboarding} from '@userActions/Report'; -import {setOnboardingErrorMessage, setOnboardingPurposeSelected} from '@userActions/Welcome'; +import {clearOnboardingMergeAccountBlocked, setOnboardingErrorMessage, setOnboardingPurposeSelected} from '@userActions/Welcome'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; @@ -132,6 +132,9 @@ function BaseOnboardingPurpose({shouldUseNativeStyles, shouldEnableMaxHeight, ro // validation, so it still needs to add one; an unvalidated private-domain one already has one and // only needs to validate it. if (choice === CONST.ONBOARDING_CHOICES.JOIN_WORKSPACE) { + // A merge blocked earlier in onboarding leaves isMergingAccountBlocked set, which would make the work + // email step reopen in its blocked state instead of showing the form. + clearOnboardingMergeAccountBlocked(); const isCurrentPrimaryPublicDomain = PUBLIC_DOMAINS_SET.has(session?.email?.split('@').at(1)?.toLowerCase() ?? ''); if (isValidated && !isCurrentPrimaryPublicDomain) { Navigation.navigate(ROUTES.ONBOARDING_WORKSPACES.getRoute(ROUTES.ONBOARDING_PERSONAL_DETAILS.getRoute())); diff --git a/tests/ui/OnboardingPurpose.tsx b/tests/ui/OnboardingPurpose.tsx index 7266f827bd6a..80b19514c7aa 100644 --- a/tests/ui/OnboardingPurpose.tsx +++ b/tests/ui/OnboardingPurpose.tsx @@ -32,6 +32,7 @@ import React from 'react'; import Onyx from 'react-native-onyx'; import createMock from '../utils/createMock'; +import getOnyxValue from '../utils/getOnyxValue'; import * as TestHelper from '../utils/TestHelper'; import waitForBatchedUpdatesWithAct from '../utils/waitForBatchedUpdatesWithAct'; @@ -201,6 +202,30 @@ describe('OnboardingPurpose Page', () => { await waitForBatchedUpdatesWithAct(); }); + it('should clear a stale merge-blocked flag when a public-domain user selects Join Workspace', async () => { + // Given a public-domain user whose earlier work email merge was blocked + await TestHelper.signInWithTestUser(1, 'test@gmail.com'); + await act(async () => { + await Onyx.merge(ONYXKEYS.NVP_ONBOARDING, {isMergingAccountBlocked: true}); + }); + + const {unmount} = renderOnboardingPurposePage(SCREENS.ONBOARDING.PURPOSE, {backTo: ''}); + await waitForBatchedUpdatesWithAct(); + + // When they select Join Workspace + const user = userEvent.setup(); + await user.press(screen.getByLabelText(translatePurpose(CONST.ONBOARDING_CHOICES.JOIN_WORKSPACE))); + await waitForBatchedUpdatesWithAct(); + + // Then the flag is cleared so the work email step shows the form instead of the blocked view + expect(navigate).toHaveBeenCalledWith(ROUTES.ONBOARDING_WORK_EMAIL.getRoute()); + const onboarding = await getOnyxValue(ONYXKEYS.NVP_ONBOARDING); + expect(onboarding?.isMergingAccountBlocked).toBe(false); + + unmount(); + await waitForBatchedUpdatesWithAct(); + }); + it('should navigate to personal details page when user selects EMPLOYER and is from public domain', async () => { await TestHelper.signInWithTestUser();