Skip to content
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
5 changes: 4 additions & 1 deletion src/pages/OnboardingPurpose/BaseOnboardingPurpose.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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()));
Expand Down
25 changes: 25 additions & 0 deletions tests/ui/OnboardingPurpose.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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();

Expand Down
Loading