diff --git a/src/CONST/index.ts b/src/CONST/index.ts index 00de7b87ae51..24e2033b9a99 100644 --- a/src/CONST/index.ts +++ b/src/CONST/index.ts @@ -147,9 +147,7 @@ const signupQualifiers = { SMB: 'smb', } as const; -type NoneAccountingKey = 'none'; - -type OnboardingAccounting = keyof typeof CONST.POLICY.CONNECTIONS.NAME_USER_FRIENDLY | NoneAccountingKey | null; +type OnboardingAccounting = keyof typeof CONST.POLICY.CONNECTIONS.NAME_USER_FRIENDLY | (string & Record) | null; const onboardingInviteTypes = { IOU: 'iou', diff --git a/src/ONYXKEYS.ts b/src/ONYXKEYS.ts index 25a2457f367c..031ae2d57af5 100755 --- a/src/ONYXKEYS.ts +++ b/src/ONYXKEYS.ts @@ -3,6 +3,7 @@ import type {ValueOf} from 'type-fest'; import type CONST from './CONST'; import type {OnboardingAccounting} from './CONST'; import type {TranslationPaths} from './languages/types'; +import type {OnboardingFeatureMapItem} from './libs/actions/Welcome/OnboardingFeatures'; import type {OnboardingCompanySize} from './libs/actions/Welcome/OnboardingFlow'; import type Platform from './libs/getPlatform/types'; import type {TransactionThreadNavigationDescriptor} from './libs/TransactionThreadNavigationUtils'; @@ -531,6 +532,12 @@ const ONYXKEYS = { /** Onboarding user reported integration selected by the user during Onboarding flow */ ONBOARDING_USER_REPORTED_INTEGRATION: 'onboardingUserReportedIntegration', + /** Whether the user kept Accounting enabled during Onboarding feature selection */ + ONBOARDING_ACCOUNTING_ENABLED: 'onboardingAccountingEnabled', + + /** Onboarding interested features persisted before navigating to the Accounting step */ + ONBOARDING_INTERESTED_FEATURES_MAP: 'onboardingInterestedFeaturesMap', + /** Onboarding Purpose selected by the user during Onboarding flow */ ONBOARDING_ADMINS_CHAT_REPORT_ID: 'onboardingAdminsChatReportID', @@ -1750,6 +1757,8 @@ type OnyxValuesMapping = { [ONYXKEYS.TRANSACTION_THREAD_NAVIGATION_THREAD_REPORT_IDS]: Record; [ONYXKEYS.NVP_INTEGRATION_SERVER_EXPORT_TEMPLATES]: OnyxTypes.ExportTemplate[]; [ONYXKEYS.ONBOARDING_USER_REPORTED_INTEGRATION]: OnboardingAccounting; + [ONYXKEYS.ONBOARDING_ACCOUNTING_ENABLED]: boolean; + [ONYXKEYS.ONBOARDING_INTERESTED_FEATURES_MAP]: OnboardingFeatureMapItem[]; [ONYXKEYS.HYBRID_APP]: OnyxTypes.HybridApp; [ONYXKEYS.NVP_CSV_EXPORT_LAYOUTS]: Record; [ONYXKEYS.NVP_EXPENSE_RULES]: OnyxTypes.ExpenseRule[]; diff --git a/src/components/OnboardingMergingAccountBlockedView.tsx b/src/components/OnboardingMergingAccountBlockedView.tsx index 83e60c1d7735..6715b797d7b3 100644 --- a/src/components/OnboardingMergingAccountBlockedView.tsx +++ b/src/components/OnboardingMergingAccountBlockedView.tsx @@ -57,7 +57,7 @@ function OnboardingMergingAccountBlockedView({workEmail, isVsb}: OnboardingMergi onPress={() => { setOnboardingErrorMessage(null); if (isVsb) { - Navigation.navigate(ROUTES.ONBOARDING_EMPLOYEES.getRoute()); + Navigation.navigate(ROUTES.ONBOARDING_EMPLOYEES.getRoute(), {forceReplace: true}); return; } Navigation.navigate(ROUTES.ONBOARDING_PURPOSE.getRoute()); diff --git a/src/components/SidePanel/RHPVariantTest/index.ts b/src/components/SidePanel/RHPVariantTest/index.ts index 1ab833b45289..a859526d94c3 100644 --- a/src/components/SidePanel/RHPVariantTest/index.ts +++ b/src/components/SidePanel/RHPVariantTest/index.ts @@ -64,12 +64,12 @@ const shouldOpenRHPVariant: ShouldOpenRHPVariant = (variantOverride) => { * All variants open the side panel without overlay. * The control variant is handled separately in navigateAfterOnboarding. */ -const handleRHPVariantNavigation: HandleRHPVariantNavigation = (onboardingPolicyID, variantOverride) => { +const handleRHPVariantNavigation: HandleRHPVariantNavigation = (onboardingPolicyID, variantOverride, navigationOptions) => { const variant = variantOverride ?? onboardingRHPVariant; if (variant === CONST.ONBOARDING_RHP_VARIANT.TRACK_EXPENSES_WITH_CONCIERGE) { const shouldPreserveRevealedReport = isReportTopmostSplitNavigator(); if (!shouldPreserveRevealedReport) { - Navigation.navigate(ROUTES.HOME); + Navigation.navigate(ROUTES.HOME, navigationOptions); } SidePanelActions.openSidePanel(true); return; @@ -80,10 +80,10 @@ const handleRHPVariantNavigation: HandleRHPVariantNavigation = (onboardingPolicy if (isRHPHomePage) { const shouldPreserveRevealedReport = isReportTopmostSplitNavigator(); if (!shouldPreserveRevealedReport) { - Navigation.navigate(ROUTES.HOME); + Navigation.navigate(ROUTES.HOME, navigationOptions); } } else { - Navigation.navigate(ROUTES.WORKSPACE_OVERVIEW.getRoute(onboardingPolicyID)); + Navigation.navigate(ROUTES.WORKSPACE_OVERVIEW.getRoute(onboardingPolicyID), navigationOptions); } SidePanelActions.openSidePanel(true); }; diff --git a/src/components/SidePanel/RHPVariantTest/types.ts b/src/components/SidePanel/RHPVariantTest/types.ts index 15dff41a1af6..f784b356f025 100644 --- a/src/components/SidePanel/RHPVariantTest/types.ts +++ b/src/components/SidePanel/RHPVariantTest/types.ts @@ -1,6 +1,8 @@ +import type {LinkToOptions} from '@libs/Navigation/helpers/linkTo/types'; + import type {OnboardingRHPVariant} from '@src/types/onyx'; type ShouldOpenRHPVariant = (variantOverride?: OnboardingRHPVariant | null) => boolean; -type HandleRHPVariantNavigation = (onboardingPolicyID?: string, variantOverride?: OnboardingRHPVariant | null) => void; +type HandleRHPVariantNavigation = (onboardingPolicyID: string | undefined, variantOverride?: OnboardingRHPVariant | null, navigationOptions?: LinkToOptions) => void; export type {ShouldOpenRHPVariant, HandleRHPVariantNavigation}; diff --git a/src/hooks/useAutoCreateTrackWorkspace.ts b/src/hooks/useAutoCreateTrackWorkspace.ts index 0142b323d62b..a5969cb0858e 100644 --- a/src/hooks/useAutoCreateTrackWorkspace.ts +++ b/src/hooks/useAutoCreateTrackWorkspace.ts @@ -140,7 +140,7 @@ function useAutoCreateTrackWorkspace() { newPolicyID, mergedAccountConciergeReportID, false, - rhpVariant, + {variantOverride: rhpVariant}, ); } }, diff --git a/src/hooks/useCompleteOnboarding.ts b/src/hooks/useCompleteOnboarding.ts new file mode 100644 index 000000000000..7b87525b6551 --- /dev/null +++ b/src/hooks/useCompleteOnboarding.ts @@ -0,0 +1,155 @@ +import isSidePanelReportSupported from '@components/SidePanel/isSidePanelReportSupported'; + +import {createWorkspace, generateDefaultWorkspaceName, generatePolicyID} from '@libs/actions/Policy/Policy'; +import {completeOnboarding, extractRHPVariantFromResponse} from '@libs/actions/Report'; +import {setOnboardingAdminsChatReportID, setOnboardingPolicyID} from '@libs/actions/Welcome'; +import type {OnboardingFeatureMapItem} from '@libs/actions/Welcome/OnboardingFeatures'; +import Log from '@libs/Log'; +import {navigateAfterOnboardingWithMicrotaskQueue} from '@libs/navigateAfterOnboarding'; +import TransitionTracker from '@libs/Navigation/TransitionTracker'; +import {isGroupPolicy, isPolicyAdmin} from '@libs/PolicyUtils'; + +import CONST from '@src/CONST'; +import type {OnboardingAccounting} from '@src/CONST'; +import ONYXKEYS from '@src/ONYXKEYS'; + +import {hasSeenTourSelector} from '@selectors/Onboarding'; +import {useState} from 'react'; + +import useActivePolicy from './useActivePolicy'; +import useCurrentUserPersonalDetails from './useCurrentUserPersonalDetails'; +import useHasActiveAdminPolicies from './useHasActiveAdminPolicies'; +import useLastWorkspaceNumber from './useLastWorkspaceNumber'; +import useLocalize from './useLocalize'; +import useOnboardingMessages from './useOnboardingMessages'; +import useOnyx from './useOnyx'; +import usePermissions from './usePermissions'; +import useResponsiveLayout from './useResponsiveLayout'; + +type CompleteOnboardingParams = { + featuresMap: OnboardingFeatureMapItem[]; + userReportedIntegration?: OnboardingAccounting; +}; + +function useCompleteOnboarding() { + // We need to use isSmallScreenWidth, see navigateAfterOnboarding function comment + // eslint-disable-next-line rulesdir/prefer-shouldUseNarrowLayout-instead-of-isSmallScreenWidth + const {isSmallScreenWidth} = useResponsiveLayout(); + const {translate} = useLocalize(); + const {onboardingMessages} = useOnboardingMessages(); + const currentUserPersonalDetails = useCurrentUserPersonalDetails(); + const {isBetaEnabled} = usePermissions(); + const activePolicy = useActivePolicy(); + const hasActiveAdminPolicies = useHasActiveAdminPolicies(); + const lastWorkspaceNumber = useLastWorkspaceNumber(); + + const [onboardingPurposeSelected] = useOnyx(ONYXKEYS.ONBOARDING_PURPOSE_SELECTED); + const [onboardingPolicyID] = useOnyx(ONYXKEYS.ONBOARDING_POLICY_ID); + const [onboardingAdminsChatReportID] = useOnyx(ONYXKEYS.ONBOARDING_ADMINS_CHAT_REPORT_ID); + const [onboardingCompanySize] = useOnyx(ONYXKEYS.ONBOARDING_COMPANY_SIZE); + const [introSelected] = useOnyx(ONYXKEYS.NVP_INTRO_SELECTED); + const [betas] = useOnyx(ONYXKEYS.BETAS); + const [isSelfTourViewed] = useOnyx(ONYXKEYS.NVP_ONBOARDING, {selector: hasSeenTourSelector}); + const [session] = useOnyx(ONYXKEYS.SESSION); + const [conciergeReportID = ''] = useOnyx(ONYXKEYS.CONCIERGE_REPORT_ID); + const [conciergeChat] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${conciergeReportID}`); + const [adminsChatReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${onboardingAdminsChatReportID}`); + const [allPolicies] = useOnyx(ONYXKEYS.COLLECTION.POLICY); + const [reportNameValuePairs] = useOnyx(ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS); + const [isLoading, setIsLoading] = useState(false); + + const groupPolicy = Object.values(allPolicies ?? {}).find((policy) => isGroupPolicy(policy) && isPolicyAdmin(policy, session?.email)); + + const completeOnboardingFlow = async ({featuresMap, userReportedIntegration}: CompleteOnboardingParams) => { + if (!onboardingPurposeSelected || !onboardingCompanySize) { + return; + } + + try { + setIsLoading(true); + + const shouldCreateWorkspace = !onboardingPolicyID && !groupPolicy; + const isAccountingEnabled = featuresMap.some((feature) => feature.id === CONST.POLICY.MORE_FEATURES.ARE_CONNECTIONS_ENABLED && feature.enabled); + const resolvedIntegration = isAccountingEnabled ? userReportedIntegration : undefined; + const email = currentUserPersonalDetails.email ?? ''; + + const {adminsChatReportID, policyID} = shouldCreateWorkspace + ? createWorkspace({ + policyOwnerEmail: undefined, + makeMeAdmin: true, + policyName: generateDefaultWorkspaceName(email, lastWorkspaceNumber, translate), + policyID: generatePolicyID(), + engagementChoice: CONST.ONBOARDING_CHOICES.MANAGE_TEAM, + currency: currentUserPersonalDetails?.localCurrencyCode ?? '', + file: undefined, + shouldAddOnboardingTasks: false, + companySize: onboardingCompanySize, + userReportedIntegration: resolvedIntegration, + featuresMap, + introSelected, + activePolicy, + currentUserAccountIDParam: currentUserPersonalDetails.accountID, + currentUserEmailParam: email, + shouldAddGuideWelcomeMessage: false, + betas, + isSelfTourViewed, + hasActiveAdminPolicies, + }) + : {adminsChatReportID: onboardingAdminsChatReportID, policyID: onboardingPolicyID}; + + if (shouldCreateWorkspace) { + setOnboardingAdminsChatReportID(adminsChatReportID); + setOnboardingPolicyID(policyID); + } + + const response = await completeOnboarding({ + engagementChoice: onboardingPurposeSelected, + onboardingMessage: onboardingMessages[onboardingPurposeSelected], + adminsChatReportID, + onboardingPolicyID: policyID, + companySize: onboardingCompanySize, + userReportedIntegration: resolvedIntegration, + firstName: currentUserPersonalDetails?.firstName, + lastName: currentUserPersonalDetails?.lastName, + selectedInterestedFeatures: featuresMap.filter((feature) => feature.enabled).map((feature) => feature.id), + shouldWaitForRHPVariantInitialization: isSidePanelReportSupported, + introSelected, + isSelfTourViewed, + conciergeChat, + adminsChatReport, + }); + const rhpVariant = isSidePanelReportSupported ? extractRHPVariantFromResponse(response) : undefined; + + TransitionTracker.runAfterTransitions({ + callback: () => { + setOnboardingAdminsChatReportID(); + setOnboardingPolicyID(); + }, + waitForUpcomingTransition: true, + }); + + navigateAfterOnboardingWithMicrotaskQueue( + isSmallScreenWidth, + isBetaEnabled(CONST.BETAS.DEFAULT_ROOMS), + conciergeReportID, + reportNameValuePairs, + policyID, + adminsChatReportID, + (session?.email ?? '').includes('+'), + { + variantOverride: rhpVariant, + }, + ); + } catch (error) { + Log.warn('[useCompleteOnboarding] Error completing onboarding', {error}); + setIsLoading(false); + return; + } + + setIsLoading(false); + }; + + return {completeOnboardingFlow, isLoading}; +} + +export default useCompleteOnboarding; diff --git a/src/hooks/useOnboardingStepCounter.ts b/src/hooks/useOnboardingStepCounter.ts index 2518a6f06a8f..abdbbb4eeadd 100644 --- a/src/hooks/useOnboardingStepCounter.ts +++ b/src/hooks/useOnboardingStepCounter.ts @@ -1,5 +1,5 @@ import {getOnboardingStepCounter} from '@libs/getOnboardingStepCounter'; -import type {OnboardingScreen, OnboardingStepResult} from '@libs/getOnboardingStepCounter'; +import type {OnboardingFlowContext, OnboardingScreen, OnboardingStepResult} from '@libs/getOnboardingStepCounter'; import {getVisibleJoinablePoliciesCount} from '@libs/OnboardingUtils'; import {expensifyLoginsSelector, isCurrentUserValidated} from '@libs/UserUtils'; @@ -9,10 +9,11 @@ import ONYXKEYS from '@src/ONYXKEYS'; import useOnyx from './useOnyx'; import usePermissions from './usePermissions'; -function useOnboardingStepCounter(page: OnboardingScreen): OnboardingStepResult | undefined { +function useOnboardingStepCounter(page: OnboardingScreen, overrides: Partial> = {}): OnboardingStepResult | undefined { const [onboarding] = useOnyx(ONYXKEYS.NVP_ONBOARDING); const [purposeSelected] = useOnyx(ONYXKEYS.ONBOARDING_PURPOSE_SELECTED); const [account] = useOnyx(ONYXKEYS.ACCOUNT); + const [isAccountingEnabled] = useOnyx(ONYXKEYS.ONBOARDING_ACCOUNTING_ENABLED); const [joinablePolicies] = useOnyx(ONYXKEYS.JOINABLE_POLICIES); const [loginList] = useOnyx(ONYXKEYS.LOGINS, {selector: expensifyLoginsSelector}); const [session] = useOnyx(ONYXKEYS.SESSION); @@ -24,6 +25,7 @@ function useOnboardingStepCounter(page: OnboardingScreen): OnboardingStepResult hasAccessibleDomainPolicies: account?.hasAccessibleDomainPolicies, purposeSelected: purposeSelected ?? undefined, isMergeAccountStepSkipped: onboarding?.isMergeAccountStepSkipped, + isAccountingEnabled: overrides.isAccountingEnabled ?? isAccountingEnabled ?? undefined, isAccountValidated: isCurrentUserValidated(loginList, session?.email), hasJoinablePolicies: getVisibleJoinablePoliciesCount(joinablePolicies, isBetaEnabled(CONST.BETAS.SUBMIT_2026)) > 0, }); diff --git a/src/libs/ExportOnyxState/common.ts b/src/libs/ExportOnyxState/common.ts index 7080baabedaf..136afb7fe29f 100644 --- a/src/libs/ExportOnyxState/common.ts +++ b/src/libs/ExportOnyxState/common.ts @@ -267,10 +267,12 @@ const safeOnyxKeys = new Set([ ONYXKEYS.NVP_SUBMIT_MIGRATION_MODAL_SHOWN, ONYXKEYS.NVP_TRY_FOCUS_MODE, ONYXKEYS.NVP_TRY_NEW_DOT, + ONYXKEYS.ONBOARDING_ACCOUNTING_ENABLED, ONYXKEYS.ONBOARDING_ADMINS_CHAT_REPORT_ID, ONYXKEYS.ONBOARDING_COMPANY_SIZE, ONYXKEYS.ONBOARDING_CUSTOM_CHOICES, ONYXKEYS.ONBOARDING_ERROR_MESSAGE_TRANSLATION_KEY, + ONYXKEYS.ONBOARDING_INTERESTED_FEATURES_MAP, ONYXKEYS.ONBOARDING_POLICY_ID, ONYXKEYS.ONBOARDING_PURPOSE_SELECTED, ONYXKEYS.ONBOARDING_USER_REPORTED_INTEGRATION, diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 9b3d8ca23dc0..8a3b56936225 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -12107,7 +12107,9 @@ function prepareOnboardingOnyxData({ return; } - const integrationName = userReportedIntegration ? CONST.ONBOARDING_ACCOUNTING_MAPPING[userReportedIntegration as keyof typeof CONST.ONBOARDING_ACCOUNTING_MAPPING] : ''; + const integrationName = userReportedIntegration + ? (CONST.ONBOARDING_ACCOUNTING_MAPPING[userReportedIntegration as keyof typeof CONST.ONBOARDING_ACCOUNTING_MAPPING] ?? userReportedIntegration) + : ''; const assignedGuideEmail = getPolicy(targetChatPolicyID)?.assignedGuide?.email ?? CONST.EMAIL.QA_GUIDE; const assignedGuidePersonalDetail = getPersonalDetailByEmail(assignedGuideEmail); let assignedGuideAccountID: number; diff --git a/src/libs/actions/Welcome/OnboardingFeatures.ts b/src/libs/actions/Welcome/OnboardingFeatures.ts new file mode 100644 index 000000000000..a80c1f880ba1 --- /dev/null +++ b/src/libs/actions/Welcome/OnboardingFeatures.ts @@ -0,0 +1,35 @@ +import CONST from '@src/CONST'; + +type OnboardingFeatureConfig = { + id: string; + enabledByDefault?: boolean; + requiresUpdate?: boolean; +}; + +type OnboardingFeatureMapItem = OnboardingFeatureConfig & { + enabled: boolean; +}; + +const ONBOARDING_FEATURES: OnboardingFeatureConfig[] = [ + {id: CONST.POLICY.MORE_FEATURES.ARE_CATEGORIES_ENABLED, enabledByDefault: true}, + {id: CONST.POLICY.MORE_FEATURES.ARE_CONNECTIONS_ENABLED, enabledByDefault: true}, + {id: CONST.POLICY.MORE_FEATURES.ARE_COMPANY_CARDS_ENABLED, enabledByDefault: true}, + {id: CONST.POLICY.MORE_FEATURES.ARE_WORKFLOWS_ENABLED, enabledByDefault: true}, + {id: CONST.POLICY.MORE_FEATURES.IS_TRAVEL_ENABLED}, + {id: CONST.POLICY.MORE_FEATURES.ARE_RULES_ENABLED, requiresUpdate: true}, + {id: CONST.POLICY.MORE_FEATURES.ARE_DISTANCE_RATES_ENABLED}, + {id: CONST.POLICY.MORE_FEATURES.ARE_EXPENSIFY_CARDS_ENABLED}, + {id: CONST.POLICY.MORE_FEATURES.ARE_TAGS_ENABLED}, + {id: CONST.POLICY.MORE_FEATURES.ARE_PER_DIEM_RATES_ENABLED, requiresUpdate: true}, + {id: CONST.POLICY.MORE_FEATURES.IS_TIME_TRACKING_ENABLED}, +]; + +function getDefaultOnboardingFeaturesMap(): OnboardingFeatureMapItem[] { + return ONBOARDING_FEATURES.map((feature) => ({ + ...feature, + enabled: !!feature.enabledByDefault, + })); +} + +export {getDefaultOnboardingFeaturesMap, ONBOARDING_FEATURES}; +export type {OnboardingFeatureMapItem}; diff --git a/src/libs/actions/Welcome/OnboardingFlow.ts b/src/libs/actions/Welcome/OnboardingFlow.ts index efc259422a43..7b1f67fa1d17 100644 --- a/src/libs/actions/Welcome/OnboardingFlow.ts +++ b/src/libs/actions/Welcome/OnboardingFlow.ts @@ -119,13 +119,11 @@ function getOnboardingInitialPath(getOnboardingInitialPathParams: GetOnboardingI const currentOnboardingValues = onboardingValuesParam ?? onboardingValues; const isVsb = currentOnboardingValues?.signupQualifier === CONST.ONBOARDING_SIGNUP_QUALIFIERS.VSB; const isSmb = currentOnboardingValues?.signupQualifier === CONST.ONBOARDING_SIGNUP_QUALIFIERS.SMB; + const isVsbOrSmb = isVsb || isSmb; const isIndividual = currentOnboardingValues?.signupQualifier === CONST.ONBOARDING_SIGNUP_QUALIFIERS.INDIVIDUAL; const isCurrentOnboardingPurposeManageTeam = currentOnboardingPurposeSelected === CONST.ONBOARDING_CHOICES.MANAGE_TEAM; - if (isVsb) { - Onyx.set(ONYXKEYS.ONBOARDING_PURPOSE_SELECTED, CONST.ONBOARDING_CHOICES.MANAGE_TEAM); - } - if (isSmb) { + if (isVsbOrSmb) { Onyx.set(ONYXKEYS.ONBOARDING_PURPOSE_SELECTED, CONST.ONBOARDING_CHOICES.MANAGE_TEAM); } @@ -140,10 +138,7 @@ function getOnboardingInitialPath(getOnboardingInitialPathParams: GetOnboardingI // PRIVATE_DOMAIN ("People you may know are already here") only makes sense for users on a private domain. Only redirect // validated accounts; unvalidated users mid-AddWorkEmail can legitimately land here while isFromPublicDomain is stale. if (isUserFromPublicDomain && isAccountValidated && initialPath.includes(ROUTES.ONBOARDING_PRIVATE_DOMAIN.route)) { - if (isVsb) { - return `/${ROUTES.ONBOARDING_ACCOUNTING.route}`; - } - if (isSmb) { + if (isVsbOrSmb) { return `/${ROUTES.ONBOARDING_EMPLOYEES.route}`; } return `/${ROUTES.ONBOARDING_PURPOSE.route}`; @@ -156,10 +151,7 @@ function getOnboardingInitialPath(getOnboardingInitialPathParams: GetOnboardingI return `/${ROUTES.ONBOARDING_PERSONAL_DETAILS.route}`; } - if (isVsb) { - return `/${ROUTES.ONBOARDING_EMPLOYEES.route}`; - } - if (isSmb) { + if (isVsbOrSmb) { return `/${ROUTES.ONBOARDING_EMPLOYEES.route}`; } @@ -172,7 +164,7 @@ function getOnboardingInitialPath(getOnboardingInitialPathParams: GetOnboardingI } if ( - initialPath.includes(ROUTES.ONBOARDING_ACCOUNTING.route) && + (initialPath.includes(ROUTES.ONBOARDING_ACCOUNTING.route) || initialPath.includes(ROUTES.ONBOARDING_INTERESTED_FEATURES.route)) && ((currentOnboardingPurposeSelected !== null && !isCurrentOnboardingPurposeManageTeam) || (currentOnboardingCompanySize === null && currentOnboardingPurposeSelected !== null)) ) { return `/${ROUTES.ONBOARDING_PURPOSE.route}`; diff --git a/src/libs/actions/Welcome/index.ts b/src/libs/actions/Welcome/index.ts index 472d0f323317..2c98d1722d4b 100644 --- a/src/libs/actions/Welcome/index.ts +++ b/src/libs/actions/Welcome/index.ts @@ -60,6 +60,13 @@ function setOnboardingUserReportedIntegration(value: OnboardingAccounting | null Onyx.set(ONYXKEYS.ONBOARDING_USER_REPORTED_INTEGRATION, value); } +function setOnboardingAccountingEnabled(value: boolean | null) { + Onyx.set(ONYXKEYS.ONBOARDING_ACCOUNTING_ENABLED, value); +} + +function setOnboardingInterestedFeaturesMap(value: Array<{id: string; enabled: boolean; enabledByDefault?: boolean; requiresUpdate?: boolean}> | null) { + Onyx.set(ONYXKEYS.ONBOARDING_INTERESTED_FEATURES_MAP, value); +} function setOnboardingPersonalTrackGoal(value: string) { Onyx.set(ONYXKEYS.ONBOARDING_PERSONAL_TRACK_GOAL, value); } @@ -222,6 +229,8 @@ export { setOnboardingMergeAccountStepValue, updateOnboardingValuesAndNavigation, setOnboardingUserReportedIntegration, + setOnboardingAccountingEnabled, + setOnboardingInterestedFeaturesMap, setOnboardingPersonalTrackGoal, addWorkEmailFormError, clearWorkEmailFormErrors, diff --git a/src/libs/getOnboardingStepCounter.ts b/src/libs/getOnboardingStepCounter.ts index 8489bbe89100..5b924c265207 100644 --- a/src/libs/getOnboardingStepCounter.ts +++ b/src/libs/getOnboardingStepCounter.ts @@ -15,6 +15,7 @@ type OnboardingFlowContext = { hasAccessibleDomainPolicies?: boolean; purposeSelected?: ValueOf; isMergeAccountStepSkipped?: boolean; + isAccountingEnabled?: boolean; isAccountValidated?: boolean; hasJoinablePolicies?: boolean; }; @@ -44,7 +45,7 @@ const screenResolution: Record = { const TRACK_PURPOSE_SUFFIXES = [ONBOARDING.PERSONAL_DETAILS]; const purposeSuffixes = { - [ONBOARDING_CHOICES.MANAGE_TEAM]: [ONBOARDING.EMPLOYEES, ONBOARDING.ACCOUNTING, ONBOARDING.INTERESTED_FEATURES], + [ONBOARDING_CHOICES.MANAGE_TEAM]: [ONBOARDING.EMPLOYEES, ONBOARDING.INTERESTED_FEATURES, ONBOARDING.ACCOUNTING], [ONBOARDING_CHOICES.TRACK_BUSINESS]: TRACK_PURPOSE_SUFFIXES, [ONBOARDING_CHOICES.TRACK_PERSONAL]: [ONBOARDING.PERSONAL_TRACK_GOAL, ...TRACK_PURPOSE_SUFFIXES], [ONBOARDING_CHOICES.PERSONAL_SPEND]: TRACK_PURPOSE_SUFFIXES, @@ -58,14 +59,21 @@ const purposeSuffixes = { // VSB/SMB have fixed suffixes; individual (null) is handled via purposeSuffixes. const qualifierSuffixes = { - [ONBOARDING_SIGNUP_QUALIFIERS.VSB]: [ONBOARDING.EMPLOYEES, ONBOARDING.ACCOUNTING, ONBOARDING.INTERESTED_FEATURES], - [ONBOARDING_SIGNUP_QUALIFIERS.SMB]: [ONBOARDING.EMPLOYEES, ONBOARDING.ACCOUNTING, ONBOARDING.INTERESTED_FEATURES], + [ONBOARDING_SIGNUP_QUALIFIERS.VSB]: [ONBOARDING.EMPLOYEES, ONBOARDING.INTERESTED_FEATURES, ONBOARDING.ACCOUNTING], + [ONBOARDING_SIGNUP_QUALIFIERS.SMB]: [ONBOARDING.EMPLOYEES, ONBOARDING.INTERESTED_FEATURES, ONBOARDING.ACCOUNTING], [ONBOARDING_SIGNUP_QUALIFIERS.INDIVIDUAL]: null, } satisfies Record, OnboardingScreen[] | null>; const maxSuffixLength = Math.max(...Object.values(purposeSuffixes).map((s) => s.length)); const maxPrivateSuffixLength = Math.max(...Object.values(purposeSuffixes).map((s) => s.filter((p) => p !== ONBOARDING.PERSONAL_DETAILS).length)); +function getAdjustedSuffix(suffix: OnboardingScreen[], context: OnboardingFlowContext): OnboardingScreen[] { + if (context.isAccountingEnabled === false) { + return suffix.filter((screen) => screen !== ONBOARDING.ACCOUNTING); + } + return suffix; +} + function getResolvedPage(page: OnboardingScreen, context: OnboardingFlowContext): OnboardingScreen { // In public domain flows, PRIVATE_DOMAIN is used as a variant of WORK_EMAIL_VALIDATION if (page === ONBOARDING.PRIVATE_DOMAIN && context.isFromPublicDomain) { @@ -106,7 +114,7 @@ function getOnboardingFlow(context: OnboardingFlowContext): OnboardingScreen[] | const qualifierSuffix = context.signupQualifier ? qualifierSuffixes[context.signupQualifier] : null; if (qualifierSuffix) { - return [...prefix, ...qualifierSuffix]; + return [...prefix, ...getAdjustedSuffix(qualifierSuffix, context)]; } if (!context.purposeSelected) { @@ -114,7 +122,7 @@ function getOnboardingFlow(context: OnboardingFlowContext): OnboardingScreen[] | } const suffix = purposeSuffixes[context.purposeSelected]; - const adjustedSuffix = isPrivateDomain ? suffix.filter((s) => s !== ONBOARDING.PERSONAL_DETAILS) : suffix; + const adjustedSuffix = getAdjustedSuffix(isPrivateDomain ? suffix.filter((s) => s !== ONBOARDING.PERSONAL_DETAILS) : suffix, context); return [...prefix, ONBOARDING.PURPOSE, ...adjustedSuffix]; } diff --git a/src/libs/navigateAfterOnboarding.ts b/src/libs/navigateAfterOnboarding.ts index 07eacf9333be..67156c392ea6 100644 --- a/src/libs/navigateAfterOnboarding.ts +++ b/src/libs/navigateAfterOnboarding.ts @@ -27,6 +27,11 @@ Onyx.connectWithoutView({ }, }); +type NavigateAfterOnboardingOptions = { + afterTransition?: () => void; + variantOverride?: OnboardingRHPVariant | null; +}; + /** * Determines the report ID to navigate to after onboarding for control variant or ineligible users. * On large screens, navigates to the admins chat if available. On small screens, finds the last @@ -71,7 +76,7 @@ function navigateAfterOnboarding( onboardingPolicyID?: string, onboardingAdminsChatReportID?: string, shouldPreventOpenAdminRoom = false, - variantOverride?: OnboardingRHPVariant | null, + options?: NavigateAfterOnboardingOptions, ) { setDisableDismissOnEscape(false); @@ -79,14 +84,16 @@ function navigateAfterOnboarding( // should navigate directly to the Concierge DM (which contains onboarding tasks). // This check is outside shouldOpenRHPVariant because that function returns false on native // (Side Panel doesn't exist on native), but we still need to navigate to Concierge on mobile. + const navigationOptions = options?.afterTransition ? {afterTransition: options.afterTransition} : undefined; + const variantOverride = options?.variantOverride; const variant = variantOverride ?? onboardingRHPVariant; if (isSmallScreenWidth && variant === CONST.ONBOARDING_RHP_VARIANT.TRACK_EXPENSES_WITH_CONCIERGE) { - Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(conciergeReportID)); + Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(conciergeReportID), navigationOptions); return; } if (shouldOpenRHPVariant(variantOverride)) { - handleRHPVariantNavigation(onboardingPolicyID, variantOverride); + handleRHPVariantNavigation(onboardingPolicyID, variantOverride, navigationOptions); return; } @@ -100,10 +107,10 @@ function navigateAfterOnboarding( shouldPreventOpenAdminRoom, ); if (reportID) { - Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(reportID)); + Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(reportID), navigationOptions); } else if (!isReportTopmostSplitNavigator()) { // Navigate to home to trigger guard evaluation - Navigation.navigate(ROUTES.HOME); + Navigation.navigate(ROUTES.HOME, navigationOptions); } } @@ -115,7 +122,7 @@ function navigateAfterOnboardingWithMicrotaskQueue( onboardingPolicyID?: string, onboardingAdminsChatReportID?: string, shouldPreventOpenAdminRoom = false, - variantOverride?: OnboardingRHPVariant | null, + options?: NavigateAfterOnboardingOptions, ) { dismissOnboardingModalBeforeExit(); Navigation.setNavigationActionToMicrotaskQueue(() => { @@ -127,7 +134,7 @@ function navigateAfterOnboardingWithMicrotaskQueue( onboardingPolicyID, onboardingAdminsChatReportID, shouldPreventOpenAdminRoom, - variantOverride, + options, ); }); } diff --git a/src/pages/OnboardingAccounting/BaseOnboardingAccounting.tsx b/src/pages/OnboardingAccounting/BaseOnboardingAccounting.tsx index f29570db0df0..9db38928cc81 100644 --- a/src/pages/OnboardingAccounting/BaseOnboardingAccounting.tsx +++ b/src/pages/OnboardingAccounting/BaseOnboardingAccounting.tsx @@ -10,8 +10,10 @@ import ScrollView from '@components/ScrollView'; import type {ListItem} from '@components/SelectionList/types'; import Text from '@components/Text'; +import useCompleteOnboarding from '@hooks/useCompleteOnboarding'; import {useMemoizedLazyExpensifyIcons} from '@hooks/useLazyAsset'; import useLocalize from '@hooks/useLocalize'; +import useNetwork from '@hooks/useNetwork'; import useOnboardingStepCounter from '@hooks/useOnboardingStepCounter'; import useOnyx from '@hooks/useOnyx'; import useResponsiveLayout from '@hooks/useResponsiveLayout'; @@ -19,9 +21,10 @@ import useStyleUtils from '@hooks/useStyleUtils'; import useTheme from '@hooks/useTheme'; import useThemeStyles from '@hooks/useThemeStyles'; -import {setOnboardingAdminsChatReportID, setOnboardingPolicyID, setOnboardingUserReportedIntegration} from '@libs/actions/Welcome'; +import {setOnboardingAccountingEnabled, setOnboardingAdminsChatReportID, setOnboardingPolicyID, setOnboardingUserReportedIntegration} from '@libs/actions/Welcome'; +import {getDefaultOnboardingFeaturesMap} from '@libs/actions/Welcome/OnboardingFeatures'; import Navigation from '@libs/Navigation/Navigation'; -import {isPaidGroupPolicy, isPolicyAdmin} from '@libs/PolicyUtils'; +import {isGroupPolicy, isPolicyAdmin} from '@libs/PolicyUtils'; import variables from '@styles/variables'; @@ -39,11 +42,13 @@ import {View} from 'react-native'; import type {BaseOnboardingAccountingProps} from './types'; type Integration = { - key: OnboardingAccounting; + key: keyof typeof CONST.POLICY.CONNECTIONS.NAME_USER_FRIENDLY; iconName: 'QBOCircle' | 'QBDSquare' | 'XeroCircle' | 'NetSuiteSquare' | 'IntacctSquare' | 'SapSquare' | 'OracleSquare' | 'MicrosoftDynamicsSquare'; translationKey: TranslationPaths; }; +type AccountingOptionKey = Integration['key'] | 'other'; + const integrations: Integration[] = [ { key: 'quickbooksOnline', @@ -87,8 +92,12 @@ const integrations: Integration[] = [ }, ]; +function isIntegrationKey(integrationKey: OnboardingAccounting | undefined): integrationKey is Integration['key'] { + return integrations.some((integration) => integration.key === integrationKey); +} + type OnboardingListItem = ListItem & { - keyForList: OnboardingAccounting; + keyForList: AccountingOptionKey; }; function BaseOnboardingAccounting({shouldUseNativeStyles}: BaseOnboardingAccountingProps) { @@ -97,7 +106,6 @@ function BaseOnboardingAccounting({shouldUseNativeStyles}: BaseOnboardingAccount const StyleUtils = useStyleUtils(); const {translate} = useLocalize(); const expensifyIcons = useMemoizedLazyExpensifyIcons([ - 'CircleSlash', 'Connect', 'QBOCircle', 'QBDSquare', @@ -115,25 +123,36 @@ function BaseOnboardingAccounting({shouldUseNativeStyles}: BaseOnboardingAccount const [allPolicies] = useOnyx(ONYXKEYS.COLLECTION.POLICY); const [session] = useOnyx(ONYXKEYS.SESSION); const [onboardingUserReportedIntegration] = useOnyx(ONYXKEYS.ONBOARDING_USER_REPORTED_INTEGRATION); - const onboardingStep = useOnboardingStepCounter(SCREENS.ONBOARDING.ACCOUNTING); + const [onboardingFeaturesMap] = useOnyx(ONYXKEYS.ONBOARDING_INTERESTED_FEATURES_MAP); + const onboardingStep = useOnboardingStepCounter(SCREENS.ONBOARDING.ACCOUNTING, {isAccountingEnabled: true}); - const [userReportedIntegration, setUserReportedIntegration] = useState(onboardingUserReportedIntegration ?? undefined); + const isKnownIntegration = isIntegrationKey(onboardingUserReportedIntegration); + let initialSelectedIntegration: AccountingOptionKey | undefined; + if (isKnownIntegration) { + initialSelectedIntegration = onboardingUserReportedIntegration; + } else if (onboardingUserReportedIntegration) { + initialSelectedIntegration = 'other'; + } + const [selectedIntegration, setSelectedIntegration] = useState(initialSelectedIntegration); const [error, setError] = useState(''); - const paidGroupPolicy = Object.values(allPolicies ?? {}).find((policy) => isPaidGroupPolicy(policy) && isPolicyAdmin(policy, session?.email)); + const groupPolicy = Object.values(allPolicies ?? {}).find((policy) => isGroupPolicy(policy) && isPolicyAdmin(policy, session?.email)); + const {isOffline} = useNetwork(); + const {completeOnboardingFlow, isLoading: isCompletingOnboarding} = useCompleteOnboarding(); + // Set onboardingPolicyID and onboardingAdminsChatReportID if a workspace is created by the backend for OD signup useEffect(() => { - if (!paidGroupPolicy || onboardingPolicyID) { + if (!groupPolicy || onboardingPolicyID) { return; } - setOnboardingAdminsChatReportID(paidGroupPolicy.chatReportIDAdmins?.toString()); - setOnboardingPolicyID(paidGroupPolicy.id); - }, [paidGroupPolicy, onboardingPolicyID]); + setOnboardingAdminsChatReportID(groupPolicy.chatReportIDAdmins?.toString()); + setOnboardingPolicyID(groupPolicy.id); + }, [groupPolicy, onboardingPolicyID]); const createAccountingOption = (integration: Integration): OnboardingListItem => { const icon = expensifyIcons[integration.iconName] as IconAsset | undefined; return { - keyForList: integration.key ?? 'none', + keyForList: integration.key, text: translate(integration.translationKey), leftElement: ( ), - isSelected: userReportedIntegration === integration.key, + isSelected: selectedIntegration === integration.key, }; }; - const noneAccountingOption: OnboardingListItem = { - keyForList: 'none', - text: translate('onboarding.accounting.none'), - leftElement: ( - - ), - isSelected: userReportedIntegration === null, - }; - const othersAccountingOption: OnboardingListItem = { keyForList: 'other', text: translate('workspace.accounting.other'), @@ -174,25 +178,25 @@ function BaseOnboardingAccounting({shouldUseNativeStyles}: BaseOnboardingAccount additionalStyles={[StyleUtils.getAvatarBorderStyle(CONST.AVATAR_SIZE.DEFAULT, CONST.ICON_TYPE_AVATAR), styles.mr3, styles.onboardingSmallIcon]} /> ), - isSelected: userReportedIntegration === 'other', + isSelected: selectedIntegration === 'other', }; - const accountingOptions: OnboardingListItem[] = [...integrations.map(createAccountingOption), othersAccountingOption, noneAccountingOption]; + const accountingOptions: OnboardingListItem[] = [...integrations.map(createAccountingOption), othersAccountingOption]; - const submitAccounting = () => { - if (userReportedIntegration === undefined) { + const submitAccounting = async () => { + if (!selectedIntegration) { setError(translate('onboarding.errorSelection')); return; } - setOnboardingUserReportedIntegration(userReportedIntegration); - - // Navigate to the next onboarding step interested features with the selected integration - Navigation.navigate(ROUTES.ONBOARDING_INTERESTED_FEATURES.getRoute()); + const integrationValue: OnboardingAccounting = selectedIntegration; + setOnboardingAccountingEnabled(true); + setOnboardingUserReportedIntegration(integrationValue); + await completeOnboardingFlow({featuresMap: onboardingFeaturesMap ?? getDefaultOnboardingFeaturesMap(), userReportedIntegration: integrationValue}); }; const handleIntegrationSelect = (integrationKey: OnboardingListItem['keyForList']) => { - setUserReportedIntegration(integrationKey === 'none' ? null : integrationKey); + setSelectedIntegration(integrationKey); setError(''); }; @@ -235,7 +239,7 @@ function BaseOnboardingAccounting({shouldUseNativeStyles}: BaseOnboardingAccount shouldShowBackButton stepCounter={onboardingStep?.stepCounter} progressBarPercentage={onboardingStep?.progressBarPercentage} - onBackButtonPress={() => Navigation.goBack(ROUTES.ONBOARDING_EMPLOYEES.getRoute())} + onBackButtonPress={() => Navigation.goBack(ROUTES.ONBOARDING_INTERESTED_FEATURES.getRoute())} shouldDisplayHelpButton={false} /> @@ -246,7 +250,10 @@ function BaseOnboardingAccounting({shouldUseNativeStyles}: BaseOnboardingAccount {translate('onboarding.accounting.title')} - + {accountingOptions.map(renderOption)} @@ -262,6 +269,8 @@ function BaseOnboardingAccounting({shouldUseNativeStyles}: BaseOnboardingAccount variant={CONST.BUTTON_VARIANT.SUCCESS} size={CONST.BUTTON_SIZE.LARGE} onPress={submitAccounting} + isDisabled={isOffline} + isLoading={isCompletingOnboarding} sentryLabel={CONST.SENTRY_LABEL.ONBOARDING.CONTINUE} > diff --git a/src/pages/OnboardingEmployees/BaseOnboardingEmployees.tsx b/src/pages/OnboardingEmployees/BaseOnboardingEmployees.tsx index 2b3f7158cc0f..4be6121231c0 100644 --- a/src/pages/OnboardingEmployees/BaseOnboardingEmployees.tsx +++ b/src/pages/OnboardingEmployees/BaseOnboardingEmployees.tsx @@ -122,7 +122,7 @@ function BaseOnboardingEmployees({shouldUseNativeStyles, route}: BaseOnboardingE return; } setOnboardingCompanySize(selectedCompanySize); - Navigation.navigate(ROUTES.ONBOARDING_ACCOUNTING.getRoute()); + Navigation.navigate(ROUTES.ONBOARDING_INTERESTED_FEATURES.getRoute()); }; const footerContent = ( diff --git a/src/pages/OnboardingInterestedFeatures/BaseOnboardingInterestedFeatures.tsx b/src/pages/OnboardingInterestedFeatures/BaseOnboardingInterestedFeatures.tsx index 592ad47bca69..7ddae24db3e5 100644 --- a/src/pages/OnboardingInterestedFeatures/BaseOnboardingInterestedFeatures.tsx +++ b/src/pages/OnboardingInterestedFeatures/BaseOnboardingInterestedFeatures.tsx @@ -7,31 +7,28 @@ import {PressableWithoutFeedback} from '@components/Pressable'; import ScreenWrapper from '@components/ScreenWrapper'; import ScrollView from '@components/ScrollView'; import Section from '@components/Section'; -import isSidePanelReportSupported from '@components/SidePanel/isSidePanelReportSupported'; import Text from '@components/Text'; -import useActivePolicy from '@hooks/useActivePolicy'; -import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails'; -import useHasActiveAdminPolicies from '@hooks/useHasActiveAdminPolicies'; -import useLastWorkspaceNumber from '@hooks/useLastWorkspaceNumber'; +import useCompleteOnboarding from '@hooks/useCompleteOnboarding'; import {useMemoizedLazyIllustrations} from '@hooks/useLazyAsset'; import useLocalize from '@hooks/useLocalize'; import useNetwork from '@hooks/useNetwork'; -import useOnboardingMessages from '@hooks/useOnboardingMessages'; import useOnboardingStepCounter from '@hooks/useOnboardingStepCounter'; import useOnyx from '@hooks/useOnyx'; -import usePermissions from '@hooks/usePermissions'; import useResponsiveLayout from '@hooks/useResponsiveLayout'; import useThemeStyles from '@hooks/useThemeStyles'; -import {createWorkspace, generateDefaultWorkspaceName, generatePolicyID} from '@libs/actions/Policy/Policy'; -import {completeOnboarding, extractRHPVariantFromResponse} from '@libs/actions/Report'; -import {setOnboardingAdminsChatReportID, setOnboardingPolicyID} from '@libs/actions/Welcome'; -import Log from '@libs/Log'; -import {navigateAfterOnboardingWithMicrotaskQueue} from '@libs/navigateAfterOnboarding'; +import { + setOnboardingAccountingEnabled, + setOnboardingAdminsChatReportID, + setOnboardingInterestedFeaturesMap, + setOnboardingPolicyID, + setOnboardingUserReportedIntegration, +} from '@libs/actions/Welcome'; +import {ONBOARDING_FEATURES} from '@libs/actions/Welcome/OnboardingFeatures'; +import type {OnboardingFeatureMapItem} from '@libs/actions/Welcome/OnboardingFeatures'; import Navigation from '@libs/Navigation/Navigation'; -import TransitionTracker from '@libs/Navigation/TransitionTracker'; -import {isPaidGroupPolicy, isPolicyAdmin} from '@libs/PolicyUtils'; +import {isGroupPolicy, isPolicyAdmin} from '@libs/PolicyUtils'; import CONST from '@src/CONST'; import type {TranslationPaths} from '@src/languages/types'; @@ -39,7 +36,6 @@ import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; import SCREENS from '@src/SCREENS'; -import {hasSeenTourSelector} from '@selectors/Onboarding'; import React, {useCallback, useEffect, useMemo, useState} from 'react'; import {View} from 'react-native'; @@ -48,102 +44,49 @@ import type {BaseOnboardingInterestedFeaturesProps, Feature, SectionObject} from function BaseOnboardingInterestedFeatures({shouldUseNativeStyles}: BaseOnboardingInterestedFeaturesProps) { const styles = useThemeStyles(); const {translate} = useLocalize(); - const {onboardingMessages} = useOnboardingMessages(); const illustrations = useMemoizedLazyIllustrations(['FolderOpen', 'Accounting', 'CompanyCard', 'Workflows', 'Rules', 'Car', 'Tag', 'PerDiem', 'HandCard', 'Luggage', 'Clock']); // We need to use isSmallScreenWidth, see navigateAfterOnboarding function comment // eslint-disable-next-line rulesdir/prefer-shouldUseNarrowLayout-instead-of-isSmallScreenWidth const {onboardingIsMediumOrLargerScreenWidth, isSmallScreenWidth} = useResponsiveLayout(); - const [onboardingPurposeSelected] = useOnyx(ONYXKEYS.ONBOARDING_PURPOSE_SELECTED); - const onboardingStep = useOnboardingStepCounter(SCREENS.ONBOARDING.INTERESTED_FEATURES); const [onboardingPolicyID] = useOnyx(ONYXKEYS.ONBOARDING_POLICY_ID); - const currentUserPersonalDetails = useCurrentUserPersonalDetails(); + const [onboardingInterestedFeaturesMap] = useOnyx(ONYXKEYS.ONBOARDING_INTERESTED_FEATURES_MAP); const [allPolicies] = useOnyx(ONYXKEYS.COLLECTION.POLICY); - const [onboardingAdminsChatReportID] = useOnyx(ONYXKEYS.ONBOARDING_ADMINS_CHAT_REPORT_ID); - const [onboardingCompanySize] = useOnyx(ONYXKEYS.ONBOARDING_COMPANY_SIZE); - const [userReportedIntegration] = useOnyx(ONYXKEYS.ONBOARDING_USER_REPORTED_INTEGRATION); - const [introSelected] = useOnyx(ONYXKEYS.NVP_INTRO_SELECTED); - const [betas] = useOnyx(ONYXKEYS.BETAS); - const [isSelfTourViewed] = useOnyx(ONYXKEYS.NVP_ONBOARDING, {selector: hasSeenTourSelector}); - - const {isBetaEnabled} = usePermissions(); const [session] = useOnyx(ONYXKEYS.SESSION); - const [conciergeReportID] = useOnyx(ONYXKEYS.CONCIERGE_REPORT_ID); - const [conciergeChat] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${conciergeReportID}`); - const [adminsChatReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${onboardingAdminsChatReportID}`); - const [reportNameValuePairs] = useOnyx(ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS); - const activePolicy = useActivePolicy(); - const hasActiveAdminPolicies = useHasActiveAdminPolicies(); - const lastWorkspaceNumber = useLastWorkspaceNumber(); - const paidGroupPolicy = Object.values(allPolicies ?? {}).find((policy) => isPaidGroupPolicy(policy) && isPolicyAdmin(policy, session?.email)); + const groupPolicy = Object.values(allPolicies ?? {}).find((policy) => isGroupPolicy(policy) && isPolicyAdmin(policy, session?.email)); const {isOffline} = useNetwork(); - const [isLoading, setIsLoading] = useState(false); + const {completeOnboardingFlow, isLoading} = useCompleteOnboarding(); const features: Feature[] = useMemo(() => { - return [ - { - id: CONST.POLICY.MORE_FEATURES.ARE_CATEGORIES_ENABLED, - title: translate('workspace.moreFeatures.categories.title'), - icon: illustrations.FolderOpen, - enabledByDefault: true, - }, - { - id: CONST.POLICY.MORE_FEATURES.ARE_CONNECTIONS_ENABLED, - title: translate('workspace.moreFeatures.connections.title'), - icon: illustrations.Accounting, - enabledByDefault: !!userReportedIntegration, - }, - { - id: CONST.POLICY.MORE_FEATURES.ARE_COMPANY_CARDS_ENABLED, - title: translate('workspace.moreFeatures.companyCards.title'), - icon: illustrations.CompanyCard, - enabledByDefault: true, - }, - { - id: CONST.POLICY.MORE_FEATURES.ARE_WORKFLOWS_ENABLED, - title: translate('workspace.moreFeatures.workflows.title'), - icon: illustrations.Workflows, - enabledByDefault: true, - }, - { - id: CONST.POLICY.MORE_FEATURES.IS_TRAVEL_ENABLED, - title: translate('workspace.moreFeatures.travel.title'), - icon: illustrations.Luggage, - }, - { - id: CONST.POLICY.MORE_FEATURES.ARE_RULES_ENABLED, - title: translate('workspace.moreFeatures.rules.title'), - icon: illustrations.Rules, - requiresUpdate: true, - }, - { - id: CONST.POLICY.MORE_FEATURES.ARE_DISTANCE_RATES_ENABLED, - title: translate('workspace.moreFeatures.distanceRates.title'), - icon: illustrations.Car, - }, - { - id: CONST.POLICY.MORE_FEATURES.ARE_EXPENSIFY_CARDS_ENABLED, - title: translate('workspace.moreFeatures.expensifyCard.title'), - icon: illustrations.HandCard, - }, - { - id: CONST.POLICY.MORE_FEATURES.ARE_TAGS_ENABLED, - title: translate('workspace.moreFeatures.tags.title'), - icon: illustrations.Tag, - }, - { - id: CONST.POLICY.MORE_FEATURES.ARE_PER_DIEM_RATES_ENABLED, - title: translate('workspace.moreFeatures.perDiem.title'), - icon: illustrations.PerDiem, - requiresUpdate: true, - }, - { - id: CONST.POLICY.MORE_FEATURES.IS_TIME_TRACKING_ENABLED, - title: translate('workspace.moreFeatures.timeTracking.title'), - icon: illustrations.Clock, - }, - ]; + return ONBOARDING_FEATURES.map((feature) => { + switch (feature.id) { + case CONST.POLICY.MORE_FEATURES.ARE_CATEGORIES_ENABLED: + return {...feature, title: translate('workspace.moreFeatures.categories.title'), icon: illustrations.FolderOpen}; + case CONST.POLICY.MORE_FEATURES.ARE_CONNECTIONS_ENABLED: + return {...feature, title: translate('workspace.moreFeatures.connections.title'), icon: illustrations.Accounting}; + case CONST.POLICY.MORE_FEATURES.ARE_COMPANY_CARDS_ENABLED: + return {...feature, title: translate('workspace.moreFeatures.companyCards.title'), icon: illustrations.CompanyCard}; + case CONST.POLICY.MORE_FEATURES.ARE_WORKFLOWS_ENABLED: + return {...feature, title: translate('workspace.moreFeatures.workflows.title'), icon: illustrations.Workflows}; + case CONST.POLICY.MORE_FEATURES.IS_TRAVEL_ENABLED: + return {...feature, title: translate('workspace.moreFeatures.travel.title'), icon: illustrations.Luggage}; + case CONST.POLICY.MORE_FEATURES.ARE_RULES_ENABLED: + return {...feature, title: translate('workspace.moreFeatures.rules.title'), icon: illustrations.Rules}; + case CONST.POLICY.MORE_FEATURES.ARE_DISTANCE_RATES_ENABLED: + return {...feature, title: translate('workspace.moreFeatures.distanceRates.title'), icon: illustrations.Car}; + case CONST.POLICY.MORE_FEATURES.ARE_EXPENSIFY_CARDS_ENABLED: + return {...feature, title: translate('workspace.moreFeatures.expensifyCard.title'), icon: illustrations.HandCard}; + case CONST.POLICY.MORE_FEATURES.ARE_TAGS_ENABLED: + return {...feature, title: translate('workspace.moreFeatures.tags.title'), icon: illustrations.Tag}; + case CONST.POLICY.MORE_FEATURES.ARE_PER_DIEM_RATES_ENABLED: + return {...feature, title: translate('workspace.moreFeatures.perDiem.title'), icon: illustrations.PerDiem}; + case CONST.POLICY.MORE_FEATURES.IS_TIME_TRACKING_ENABLED: + return {...feature, title: translate('workspace.moreFeatures.timeTracking.title'), icon: illustrations.Clock}; + default: + return {...feature, title: feature.id, icon: illustrations.FolderOpen}; + } + }); }, [ illustrations.FolderOpen, illustrations.Accounting, @@ -157,153 +100,47 @@ function BaseOnboardingInterestedFeatures({shouldUseNativeStyles}: BaseOnboardin illustrations.Luggage, illustrations.Clock, translate, - userReportedIntegration, ]); - const [userToggledFeatures, setUserToggledFeatures] = useState>(new Set()); + const defaultSelectedFeatures = useMemo(() => features.filter((feature) => !!feature.enabledByDefault).map((feature) => feature.id), [features]); + const persistedSelectedFeatures = useMemo(() => onboardingInterestedFeaturesMap?.filter((feature) => feature.enabled).map((feature) => feature.id), [onboardingInterestedFeaturesMap]); + const [selectedFeatureIDs, setSelectedFeatureIDs] = useState>(); const selectedFeatures = useMemo(() => { - return features - .filter((feature) => { - if (userToggledFeatures.has(feature.id)) { - return !feature.enabledByDefault; - } - return feature.enabledByDefault; - }) - .map((feature) => feature.id); - }, [features, userToggledFeatures]); + return Array.from(selectedFeatureIDs ?? new Set(persistedSelectedFeatures ?? defaultSelectedFeatures)); + }, [defaultSelectedFeatures, persistedSelectedFeatures, selectedFeatureIDs]); + const isAccountingEnabled = selectedFeatures.includes(CONST.POLICY.MORE_FEATURES.ARE_CONNECTIONS_ENABLED); + const onboardingStep = useOnboardingStepCounter(SCREENS.ONBOARDING.INTERESTED_FEATURES, {isAccountingEnabled}); // Set onboardingPolicyID and onboardingAdminsChatReportID if a workspace is created by the backend for OD signup useEffect(() => { - if (!paidGroupPolicy || onboardingPolicyID) { + if (!groupPolicy || onboardingPolicyID) { return; } - setOnboardingAdminsChatReportID(paidGroupPolicy.chatReportIDAdmins?.toString()); - setOnboardingPolicyID(paidGroupPolicy.id); - }, [paidGroupPolicy, onboardingPolicyID]); + setOnboardingAdminsChatReportID(groupPolicy.chatReportIDAdmins?.toString()); + setOnboardingPolicyID(groupPolicy.id); + }, [groupPolicy, onboardingPolicyID]); const submitInterestedFeatures = useCallback(async () => { - if (!onboardingPurposeSelected || !onboardingCompanySize) { - return; - } - - try { - setIsLoading(true); - - const shouldCreateWorkspace = !onboardingPolicyID && !paidGroupPolicy; - const newUserReportedIntegration = selectedFeatures.some((feature) => feature === CONST.POLICY.MORE_FEATURES.ARE_CONNECTIONS_ENABLED) ? userReportedIntegration : undefined; - const featuresMap = features.map((feature) => ({ - ...feature, - enabled: selectedFeatures.includes(feature.id), - })); - - const email = currentUserPersonalDetails.email ?? ''; - // We need `adminsChatReportID` for `completeOnboarding`, but at the same time, we don't want to call `createWorkspace` more than once. - // If we have already created a workspace, we want to reuse the `onboardingAdminsChatReportID` and `onboardingPolicyID`. - const {adminsChatReportID, policyID} = shouldCreateWorkspace - ? createWorkspace({ - policyOwnerEmail: undefined, - makeMeAdmin: true, - policyName: generateDefaultWorkspaceName(email, lastWorkspaceNumber, translate), - policyID: generatePolicyID(), - engagementChoice: CONST.ONBOARDING_CHOICES.MANAGE_TEAM, - currency: currentUserPersonalDetails?.localCurrencyCode ?? '', - file: undefined, - shouldAddOnboardingTasks: false, - companySize: onboardingCompanySize, - userReportedIntegration: newUserReportedIntegration, - featuresMap, - introSelected, - activePolicy, - currentUserAccountIDParam: currentUserPersonalDetails.accountID, - currentUserEmailParam: email, - shouldAddGuideWelcomeMessage: false, - betas, - isSelfTourViewed, - hasActiveAdminPolicies, - }) - : {adminsChatReportID: onboardingAdminsChatReportID, policyID: onboardingPolicyID}; - - if (shouldCreateWorkspace) { - setOnboardingAdminsChatReportID(adminsChatReportID); - setOnboardingPolicyID(policyID); - } + const featuresMap: OnboardingFeatureMapItem[] = features.map((feature) => ({ + id: feature.id, + enabled: selectedFeatures.includes(feature.id), + enabledByDefault: feature.enabledByDefault, + requiresUpdate: feature.requiresUpdate, + })); - const response = await completeOnboarding({ - engagementChoice: onboardingPurposeSelected, - onboardingMessage: onboardingMessages[onboardingPurposeSelected], - adminsChatReportID, - onboardingPolicyID: policyID, - companySize: onboardingCompanySize, - userReportedIntegration: newUserReportedIntegration, - firstName: currentUserPersonalDetails?.firstName, - lastName: currentUserPersonalDetails?.lastName, - selectedInterestedFeatures: featuresMap.filter((feature) => feature.enabled).map((feature) => feature.id), - shouldWaitForRHPVariantInitialization: isSidePanelReportSupported, - introSelected, - isSelfTourViewed, - conciergeChat, - adminsChatReport, - }); - const rhpVariant = isSidePanelReportSupported ? extractRHPVariantFromResponse(response) : undefined; + setOnboardingAccountingEnabled(isAccountingEnabled); + setOnboardingInterestedFeaturesMap(featuresMap); - // Avoid creating new WS because onboardingPolicyID is cleared before unmounting - TransitionTracker.runAfterTransitions({ - callback: () => { - setOnboardingAdminsChatReportID(); - setOnboardingPolicyID(); - }, - waitForUpcomingTransition: true, - }); - - // We need to wait the policy is created before navigating out the onboarding flow - navigateAfterOnboardingWithMicrotaskQueue( - isSmallScreenWidth, - isBetaEnabled(CONST.BETAS.DEFAULT_ROOMS), - conciergeReportID, - reportNameValuePairs, - policyID, - adminsChatReportID, - // Onboarding tasks would show in Concierge instead of admins room for testing accounts, we should open where onboarding tasks are located - // See https://github.com/Expensify/App/issues/57167 for more details - (session?.email ?? '').includes('+'), - rhpVariant, - ); - } catch (error) { - Log.warn('[BaseOnboardingInterestedFeatures] Error completing onboarding', {error}); - } finally { - setIsLoading(false); + if (isAccountingEnabled) { + setOnboardingUserReportedIntegration(null); + Navigation.navigate(ROUTES.ONBOARDING_ACCOUNTING.getRoute()); + return; } - }, [ - isBetaEnabled, - isSmallScreenWidth, - reportNameValuePairs, - onboardingAdminsChatReportID, - onboardingCompanySize, - onboardingMessages, - onboardingPolicyID, - onboardingPurposeSelected, - paidGroupPolicy, - session?.email, - userReportedIntegration, - features, - selectedFeatures, - currentUserPersonalDetails?.firstName, - currentUserPersonalDetails?.lastName, - currentUserPersonalDetails?.localCurrencyCode, - activePolicy, - currentUserPersonalDetails.accountID, - currentUserPersonalDetails.email, - introSelected, - isSelfTourViewed, - conciergeReportID, - betas, - hasActiveAdminPolicies, - lastWorkspaceNumber, - translate, - conciergeChat, - adminsChatReport, - ]); + + setOnboardingUserReportedIntegration(null); + await completeOnboardingFlow({featuresMap}); + }, [completeOnboardingFlow, features, isAccountingEnabled, selectedFeatures]); // Create items for enabled features const enabledFeatures: Feature[] = features @@ -331,17 +168,20 @@ function BaseOnboardingInterestedFeatures({shouldUseNativeStyles}: BaseOnboardin }, ]; - const handleFeatureSelect = useCallback((featureId: string) => { - setUserToggledFeatures((prev) => { - const newSet = new Set(prev); - if (newSet.has(featureId)) { - newSet.delete(featureId); - } else { - newSet.add(featureId); - } - return newSet; - }); - }, []); + const handleFeatureSelect = useCallback( + (featureId: string) => { + setSelectedFeatureIDs((prev) => { + const newSet = new Set(prev ?? persistedSelectedFeatures ?? defaultSelectedFeatures); + if (newSet.has(featureId)) { + newSet.delete(featureId); + } else { + newSet.add(featureId); + } + return newSet; + }); + }, + [defaultSelectedFeatures, persistedSelectedFeatures], + ); const renderItem = useCallback( (item: Feature) => { @@ -405,10 +245,9 @@ function BaseOnboardingInterestedFeatures({shouldUseNativeStyles}: BaseOnboardin shouldEnableMaxHeight > Navigation.goBack(ROUTES.ONBOARDING_ACCOUNTING.getRoute())} + onBackButtonPress={() => Navigation.goBack(ROUTES.ONBOARDING_EMPLOYEES.getRoute())} shouldDisplayHelpButton={false} /> @@ -427,7 +266,7 @@ function BaseOnboardingInterestedFeatures({shouldUseNativeStyles}: BaseOnboardin variant={CONST.BUTTON_VARIANT.SUCCESS} size={CONST.BUTTON_SIZE.LARGE} onPress={submitInterestedFeatures} - isDisabled={isOffline} + isDisabled={isOffline && !isAccountingEnabled} isLoading={isLoading} sentryLabel={CONST.SENTRY_LABEL.ONBOARDING.CONTINUE} > diff --git a/tests/actions/IOUTest/TrackExpenseTest.ts b/tests/actions/IOUTest/TrackExpenseTest.ts index 1ea58855a4d5..ef1d84c4492d 100644 --- a/tests/actions/IOUTest/TrackExpenseTest.ts +++ b/tests/actions/IOUTest/TrackExpenseTest.ts @@ -491,6 +491,8 @@ describe('actions/IOU/TrackExpense', () => { const selfDMReport: Report = { ...createRandomReport(1, CONST.REPORT.CHAT_TYPE.SELF_DM), reportID: '10', + isPinned: false, + isOwnPolicyExpenseChat: false, }; const policyExpenseChat: Report = { ...createRandomReport(1, CONST.REPORT.CHAT_TYPE.POLICY_EXPENSE_CHAT), @@ -629,6 +631,8 @@ describe('actions/IOU/TrackExpense', () => { const selfDMReport: Report = { ...createRandomReport(1, CONST.REPORT.CHAT_TYPE.SELF_DM), reportID: '10', + isPinned: false, + isOwnPolicyExpenseChat: false, }; const policyExpenseChat: Report = { ...createRandomReport(1, CONST.REPORT.CHAT_TYPE.POLICY_EXPENSE_CHAT), @@ -773,6 +777,8 @@ describe('actions/IOU/TrackExpense', () => { const selfDMReport: Report = { ...createRandomReport(1, CONST.REPORT.CHAT_TYPE.SELF_DM), reportID: '10', + isPinned: false, + isOwnPolicyExpenseChat: false, }; const policyExpenseChat: Report = { ...createRandomReport(1, CONST.REPORT.CHAT_TYPE.POLICY_EXPENSE_CHAT), @@ -2264,11 +2270,14 @@ describe('actions/IOU/TrackExpense', () => { await signInWithTestUser(TEST_USER_ACCOUNT_ID, TEST_USER_LOGIN); subscribeToUserEvents(TEST_USER_ACCOUNT_ID, TEST_USER_LOGIN, () => {}, undefined); await waitForBatchedUpdates(); + await Onyx.merge(ONYXKEYS.SESSION, {accountID: TEST_USER_ACCOUNT_ID, email: TEST_USER_LOGIN}); await setPersonalDetails(TEST_USER_LOGIN, TEST_USER_ACCOUNT_ID); selfDMReport = { ...createRandomReport(1, CONST.REPORT.CHAT_TYPE.SELF_DM), reportID: '10', + isPinned: false, + isOwnPolicyExpenseChat: false, }; await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}${selfDMReport.reportID}`, selfDMReport); diff --git a/tests/ui/OnboardingAccountingAndInterestedFeatures.tsx b/tests/ui/OnboardingAccountingAndInterestedFeatures.tsx new file mode 100644 index 000000000000..3935fd98342e --- /dev/null +++ b/tests/ui/OnboardingAccountingAndInterestedFeatures.tsx @@ -0,0 +1,173 @@ +import {act, fireEvent, render, screen, waitFor} from '@testing-library/react-native'; + +import ComposeProviders from '@components/ComposeProviders'; +import {LocaleContextProvider} from '@components/LocaleContextProvider'; +import OnyxListItemProvider from '@components/OnyxListItemProvider'; + +import {CurrentReportIDContextProvider} from '@hooks/useCurrentReportID'; +import * as useResponsiveLayoutModule from '@hooks/useResponsiveLayout'; +import type ResponsiveLayoutResult from '@hooks/useResponsiveLayout/types'; + +import Navigation from '@libs/Navigation/Navigation'; + +import BaseOnboardingAccounting from '@pages/OnboardingAccounting/BaseOnboardingAccounting'; +import BaseOnboardingInterestedFeatures from '@pages/OnboardingInterestedFeatures/BaseOnboardingInterestedFeatures'; + +import CONST from '@src/CONST'; +import type {OnboardingModalNavigatorParamList} from '@src/libs/Navigation/types'; +import ONYXKEYS from '@src/ONYXKEYS'; +import ROUTES from '@src/ROUTES'; +import SCREENS from '@src/SCREENS'; + +import {NavigationContainer} from '@react-navigation/native'; +import {createStackNavigator} from '@react-navigation/stack'; +import React from 'react'; +import Onyx from 'react-native-onyx'; + +import * as TestHelper from '../utils/TestHelper'; +import waitForBatchedUpdatesWithAct from '../utils/waitForBatchedUpdatesWithAct'; + +type MockCompleteOnboardingParams = { + featuresMap: Array<{id: string; enabled: boolean}>; + userReportedIntegration?: string | null; +}; + +const mockCompleteOnboardingFlow = jest.fn(); + +jest.mock('@hooks/useCompleteOnboarding', () => () => ({ + completeOnboardingFlow: mockCompleteOnboardingFlow, + isLoading: false, +})); + +TestHelper.setupGlobalFetchMock(); + +const Stack = createStackNavigator(); +const navigate = jest.spyOn(Navigation, 'navigate'); +const goBack = jest.spyOn(Navigation, 'goBack'); +jest.spyOn(Navigation, 'getTopmostReportId').mockReturnValue(undefined); + +function renderInterestedFeaturesPage() { + return render( + + + + + {(props) => ( + + )} + + + + , + ); +} + +function renderAccountingPage() { + return render( + + + + + {(props) => ( + + )} + + + + , + ); +} + +describe('Onboarding interested features and accounting pages', () => { + beforeAll(() => { + Onyx.init({ + keys: ONYXKEYS, + }); + }); + + beforeEach(() => { + jest.spyOn(useResponsiveLayoutModule, 'default').mockReturnValue({ + isSmallScreenWidth: false, + shouldUseNarrowLayout: false, + isInNarrowPaneModal: false, + isExtraSmallScreenHeight: false, + isMediumScreenWidth: false, + isLargeScreenWidth: true, + isExtraLargeScreenWidth: false, + isExtraSmallScreenWidth: false, + isSmallScreen: false, + onboardingIsMediumOrLargerScreenWidth: true, + isInLandscapeMode: false, + } satisfies ResponsiveLayoutResult); + }); + + afterEach(async () => { + await act(async () => { + await Onyx.clear(); + }); + jest.clearAllMocks(); + }); + + it('navigates to accounting when accounting remains enabled', async () => { + renderInterestedFeaturesPage(); + + await waitForBatchedUpdatesWithAct(); + fireEvent.press(screen.getByText(TestHelper.translateLocal('common.continue'))); + + await waitFor(() => { + expect(navigate).toHaveBeenCalledWith(ROUTES.ONBOARDING_ACCOUNTING.getRoute()); + }); + expect(mockCompleteOnboardingFlow).not.toHaveBeenCalled(); + }); + + it('completes onboarding immediately when accounting is disabled', async () => { + renderInterestedFeaturesPage(); + + await waitForBatchedUpdatesWithAct(); + const accountingCheckbox = screen.getAllByLabelText(TestHelper.translateLocal('workspace.moreFeatures.connections.title')).at(0); + if (!accountingCheckbox) { + throw new Error('Accounting checkbox not found'); + } + fireEvent.press(accountingCheckbox); + fireEvent.press(screen.getByText(TestHelper.translateLocal('common.continue'))); + + await waitFor(() => { + expect(mockCompleteOnboardingFlow).toHaveBeenCalledTimes(1); + }); + const featuresMap = mockCompleteOnboardingFlow.mock.calls.at(0)?.at(0)?.featuresMap; + expect(featuresMap?.find((feature) => feature.id === CONST.POLICY.MORE_FEATURES.ARE_CONNECTIONS_ENABLED)?.enabled).toBe(false); + expect(navigate).not.toHaveBeenCalledWith(ROUTES.ONBOARDING_ACCOUNTING.getRoute()); + }); + + it('completes direct accounting access with Other and fallback features', async () => { + renderAccountingPage(); + + await waitForBatchedUpdatesWithAct(); + expect(screen.queryByText(TestHelper.translateLocal('onboarding.accounting.none'))).not.toBeOnTheScreen(); + + fireEvent.press(screen.getByText(TestHelper.translateLocal('workspace.accounting.other'))); + fireEvent.press(screen.getByText(TestHelper.translateLocal('common.continue'))); + + await waitFor(() => { + expect(mockCompleteOnboardingFlow).toHaveBeenCalledWith({ + featuresMap: expect.arrayContaining([{id: CONST.POLICY.MORE_FEATURES.ARE_CONNECTIONS_ENABLED, enabled: true, enabledByDefault: true}]), + userReportedIntegration: 'other', + }); + }); + }); + + it('returns to interested features from accounting', async () => { + renderAccountingPage(); + + await waitForBatchedUpdatesWithAct(); + fireEvent.press(screen.getByLabelText(TestHelper.translateLocal('common.back'))); + + expect(goBack).toHaveBeenCalledWith(ROUTES.ONBOARDING_INTERESTED_FEATURES.getRoute()); + }); +}); diff --git a/tests/ui/OnboardingEmployees.tsx b/tests/ui/OnboardingEmployees.tsx index 51db403076e2..bd66e428004b 100644 --- a/tests/ui/OnboardingEmployees.tsx +++ b/tests/ui/OnboardingEmployees.tsx @@ -8,8 +8,6 @@ import {CurrentReportIDContextProvider} from '@hooks/useCurrentReportID'; import * as useResponsiveLayoutModule from '@hooks/useResponsiveLayout'; import type ResponsiveLayoutResult from '@hooks/useResponsiveLayout/types'; -import createPlatformStackNavigator from '@libs/Navigation/PlatformStackNavigation/createPlatformStackNavigator'; - import type {OnboardingModalNavigatorParamList} from '@navigation/types'; import OnboardingEmployees from '@pages/OnboardingEmployees'; @@ -20,6 +18,7 @@ import SCREENS from '@src/SCREENS'; import {PortalProvider} from '@gorhom/portal'; import {NavigationContainer} from '@react-navigation/native'; +import {createStackNavigator} from '@react-navigation/stack'; import React from 'react'; import Onyx from 'react-native-onyx'; @@ -40,7 +39,7 @@ jest.mock('@rnmapbox/maps', () => { TestHelper.setupGlobalFetchMock(); -const Stack = createPlatformStackNavigator(); +const Stack = createStackNavigator(); const renderOnboardingEmployeesPage = (initialRouteName: typeof SCREENS.ONBOARDING.EMPLOYEES, initialParams: OnboardingModalNavigatorParamList[typeof SCREENS.ONBOARDING.EMPLOYEES]) => { return render( @@ -134,13 +133,13 @@ describe('OnboardingEmployees Page', () => { await waitForBatchedUpdatesWithAct(); }); - it('should hide the back button for VSB when employees is the first onboarding step', async () => { + it('should hide the back button for SMB when employees is the first onboarding step', async () => { await TestHelper.signInWithTestUser(); await act(async () => { await Onyx.merge(ONYXKEYS.NVP_ONBOARDING, { hasCompletedGuidedSetupFlow: false, - signupQualifier: CONST.ONBOARDING_SIGNUP_QUALIFIERS.VSB, + signupQualifier: CONST.ONBOARDING_SIGNUP_QUALIFIERS.SMB, }); }); @@ -157,13 +156,13 @@ describe('OnboardingEmployees Page', () => { await waitForBatchedUpdatesWithAct(); }); - it('should show the back button for VSB when employees is not the first onboarding step', async () => { + it('should show the back button for SMB when employees is not the first onboarding step', async () => { await TestHelper.signInWithTestUser(); await act(async () => { await Onyx.merge(ONYXKEYS.NVP_ONBOARDING, { hasCompletedGuidedSetupFlow: false, - signupQualifier: CONST.ONBOARDING_SIGNUP_QUALIFIERS.VSB, + signupQualifier: CONST.ONBOARDING_SIGNUP_QUALIFIERS.SMB, }); await Onyx.merge(ONYXKEYS.ACCOUNT, { hasAccessibleDomainPolicies: true, @@ -183,13 +182,13 @@ describe('OnboardingEmployees Page', () => { await waitForBatchedUpdatesWithAct(); }); - it('should hide the back button for a public-domain VSB user who skipped the work email step', async () => { + it('should hide the back button for a public-domain SMB user who skipped the work email step', async () => { await TestHelper.signInWithTestUser(); await act(async () => { await Onyx.merge(ONYXKEYS.NVP_ONBOARDING, { hasCompletedGuidedSetupFlow: false, - signupQualifier: CONST.ONBOARDING_SIGNUP_QUALIFIERS.VSB, + signupQualifier: CONST.ONBOARDING_SIGNUP_QUALIFIERS.SMB, isMergeAccountStepSkipped: true, }); await Onyx.merge(ONYXKEYS.ACCOUNT, { diff --git a/tests/ui/WorkEmailOnboarding.tsx b/tests/ui/WorkEmailOnboarding.tsx index 2974dde56766..b41b38fc8a9e 100644 --- a/tests/ui/WorkEmailOnboarding.tsx +++ b/tests/ui/WorkEmailOnboarding.tsx @@ -440,6 +440,30 @@ describe('OnboardingWorkEmail Page', () => { await waitForBatchedUpdatesWithAct(); }); + it('should navigate to Onboarding employees page when skip is pressed and user is routed app via vsb', async () => { + await TestHelper.signInWithTestUser(); + + await act(async () => { + await Onyx.merge(ONYXKEYS.NVP_ONBOARDING, { + hasCompletedGuidedSetupFlow: false, + signupQualifier: CONST.ONBOARDING_SIGNUP_QUALIFIERS.VSB, + }); + }); + + const {unmount} = renderOnboardingWorkEmailPage(SCREENS.ONBOARDING.WORK_EMAIL, undefined); + + await waitForBatchedUpdatesWithAct(); + + fireEvent.press(screen.getByTestId('onboardingPrivateEmailSkipButton')); + + await waitFor(() => { + expect(navigate).toHaveBeenCalledWith(ROUTES.ONBOARDING_EMPLOYEES.getRoute(), {forceReplace: true}); + }); + + unmount(); + await waitForBatchedUpdatesWithAct(); + }); + it('should navigate VSB users to Onboarding employees page when merge is blocked and Got it is pressed', async () => { await TestHelper.signInWithTestUser(); @@ -470,7 +494,7 @@ describe('OnboardingWorkEmail Page', () => { fireEvent.press(gotItButton, mockEvent); await waitFor(() => { - expect(navigate).toHaveBeenCalledWith(ROUTES.ONBOARDING_EMPLOYEES.getRoute()); + expect(navigate).toHaveBeenCalledWith(ROUTES.ONBOARDING_EMPLOYEES.getRoute(), {forceReplace: true}); }); unmount(); @@ -828,6 +852,36 @@ describe('OnboardingWorkEmailValidation Page', () => { await waitForBatchedUpdatesWithAct(); }); + it('should navigate to Onboarding employees page when validate code step is successful and user is routed app via vsb', async () => { + await TestHelper.signInWithTestUser(); + + await act(async () => { + await Onyx.merge(ONYXKEYS.NVP_ONBOARDING, { + hasCompletedGuidedSetupFlow: false, + shouldValidate: true, + signupQualifier: CONST.ONBOARDING_SIGNUP_QUALIFIERS.VSB, + }); + await Onyx.merge(ONYXKEYS.FORMS.ONBOARDING_WORK_EMAIL_FORM, { + onboardingWorkEmail: workEmail, + }); + }); + + const {unmount} = renderOnboardingWorkEmailValidationPage(SCREENS.ONBOARDING.WORK_EMAIL_VALIDATION, undefined); + + await waitForBatchedUpdatesWithAct(); + + MergeIntoAccountAndLoginSuccessful(); + + await waitForBatchedUpdatesWithAct(); + + await waitFor(() => { + expect(navigate).toHaveBeenCalledWith(ROUTES.ONBOARDING_EMPLOYEES.getRoute(), {forceReplace: true}); + }); + + unmount(); + await waitForBatchedUpdatesWithAct(); + }); + it('should display specific error message when ONBOARDING_ERROR_MESSAGE is set', async () => { await TestHelper.signInWithTestUser(); @@ -914,7 +968,7 @@ describe('OnboardingWorkEmailValidation Page', () => { fireEvent.press(gotItButton, mockEvent); await waitFor(() => { - expect(navigate).toHaveBeenCalledWith(ROUTES.ONBOARDING_EMPLOYEES.getRoute()); + expect(navigate).toHaveBeenCalledWith(ROUTES.ONBOARDING_EMPLOYEES.getRoute(), {forceReplace: true}); }); unmount(); diff --git a/tests/unit/components/SidePanel/RHPVariantTest.test.ts b/tests/unit/components/SidePanel/RHPVariantTest.test.ts index 7a301751d0e2..4878523f3712 100644 --- a/tests/unit/components/SidePanel/RHPVariantTest.test.ts +++ b/tests/unit/components/SidePanel/RHPVariantTest.test.ts @@ -74,7 +74,7 @@ describe('handleRHPVariantNavigation', () => { it('navigates home for the rhpHomePage variant when no report is topmost', () => { handleRHPVariantNavigation('policyID', CONST.ONBOARDING_RHP_VARIANT.RHP_HOME_PAGE); - expect(Navigation.navigate).toHaveBeenCalledWith(ROUTES.HOME); + expect(Navigation.navigate).toHaveBeenCalledWith(ROUTES.HOME, undefined); expect(SidePanelActions.openSidePanel).toHaveBeenCalledWith(true); }); @@ -90,7 +90,7 @@ describe('handleRHPVariantNavigation', () => { it('navigates home for the trackExpensesWithConcierge variant when no report is topmost', () => { handleRHPVariantNavigation('policyID', CONST.ONBOARDING_RHP_VARIANT.TRACK_EXPENSES_WITH_CONCIERGE); - expect(Navigation.navigate).toHaveBeenCalledWith(ROUTES.HOME); + expect(Navigation.navigate).toHaveBeenCalledWith(ROUTES.HOME, undefined); expect(SidePanelActions.openSidePanel).toHaveBeenCalledWith(true); }); }); diff --git a/tests/unit/getOnboardingStepCounterTest.ts b/tests/unit/getOnboardingStepCounterTest.ts index 207545052aa4..38446ada27fe 100644 --- a/tests/unit/getOnboardingStepCounterTest.ts +++ b/tests/unit/getOnboardingStepCounterTest.ts @@ -4,24 +4,20 @@ import type {OnboardingFlowContext, OnboardingScreen} from '@src/libs/getOnboard import ROUTES from '@src/ROUTES'; import SCREENS from '@src/SCREENS'; +const O = SCREENS.ONBOARDING; const {ONBOARDING_CHOICES, ONBOARDING_SIGNUP_QUALIFIERS} = CONST; describe('getOnboardingFlow', () => { - it('returns [EMPLOYEES, ACCOUNTING, INTERESTED_FEATURES] for VSB without domain context', () => { - expect(getOnboardingFlow({signupQualifier: 'vsb'})).toEqual([SCREENS.ONBOARDING.EMPLOYEES, SCREENS.ONBOARDING.ACCOUNTING, SCREENS.ONBOARDING.INTERESTED_FEATURES]); + it('returns [EMPLOYEES, INTERESTED_FEATURES, ACCOUNTING] for VSB without domain context', () => { + expect(getOnboardingFlow({signupQualifier: 'vsb'})).toEqual([O.EMPLOYEES, O.INTERESTED_FEATURES, O.ACCOUNTING]); }); - it('returns [EMPLOYEES, ACCOUNTING, INTERESTED_FEATURES] for SMB without domain context', () => { - expect(getOnboardingFlow({signupQualifier: 'smb'})).toEqual([SCREENS.ONBOARDING.EMPLOYEES, SCREENS.ONBOARDING.ACCOUNTING, SCREENS.ONBOARDING.INTERESTED_FEATURES]); + it('returns [EMPLOYEES, INTERESTED_FEATURES, ACCOUNTING] for SMB without domain context', () => { + expect(getOnboardingFlow({signupQualifier: 'smb'})).toEqual([O.EMPLOYEES, O.INTERESTED_FEATURES, O.ACCOUNTING]); }); - it('returns [PURPOSE, EMPLOYEES, ACCOUNTING, INTERESTED_FEATURES] for individual + MANAGE_TEAM', () => { - expect(getOnboardingFlow({signupQualifier: 'individual', purposeSelected: ONBOARDING_CHOICES.MANAGE_TEAM})).toEqual([ - SCREENS.ONBOARDING.PURPOSE, - SCREENS.ONBOARDING.EMPLOYEES, - SCREENS.ONBOARDING.ACCOUNTING, - SCREENS.ONBOARDING.INTERESTED_FEATURES, - ]); + it('returns [PURPOSE, EMPLOYEES, INTERESTED_FEATURES, ACCOUNTING] for individual + MANAGE_TEAM', () => { + expect(getOnboardingFlow({signupQualifier: 'individual', purposeSelected: ONBOARDING_CHOICES.MANAGE_TEAM})).toEqual([O.PURPOSE, O.EMPLOYEES, O.INTERESTED_FEATURES, O.ACCOUNTING]); }); it('returns [PURPOSE, PERSONAL_DETAILS] for individual + PERSONAL_SPEND', () => { @@ -40,41 +36,29 @@ describe('getOnboardingFlow', () => { }); it('returns [PURPOSE, PERSONAL_DETAILS] for individual + EMPLOYER', () => { - expect(getOnboardingFlow({signupQualifier: 'individual', purposeSelected: ONBOARDING_CHOICES.EMPLOYER})).toEqual([SCREENS.ONBOARDING.PURPOSE, SCREENS.ONBOARDING.PERSONAL_DETAILS]); + expect(getOnboardingFlow({signupQualifier: 'individual', purposeSelected: ONBOARDING_CHOICES.EMPLOYER})).toEqual([O.PURPOSE, O.PERSONAL_DETAILS]); }); it('returns undefined for individual without purposeSelected', () => { expect(getOnboardingFlow({signupQualifier: 'individual'})).toBeUndefined(); }); - it('returns [WORK_EMAIL, WORK_EMAIL_VALIDATION, EMPLOYEES, ACCOUNTING, INTERESTED_FEATURES] for public + VSB', () => { - expect(getOnboardingFlow({signupQualifier: 'vsb', isFromPublicDomain: true})).toEqual([ - SCREENS.ONBOARDING.WORK_EMAIL, - SCREENS.ONBOARDING.WORK_EMAIL_VALIDATION, - SCREENS.ONBOARDING.EMPLOYEES, - SCREENS.ONBOARDING.ACCOUNTING, - SCREENS.ONBOARDING.INTERESTED_FEATURES, - ]); + it('returns [WORK_EMAIL, WORK_EMAIL_VALIDATION, EMPLOYEES, INTERESTED_FEATURES, ACCOUNTING] for public + VSB', () => { + expect(getOnboardingFlow({signupQualifier: 'vsb', isFromPublicDomain: true})).toEqual([O.WORK_EMAIL, O.WORK_EMAIL_VALIDATION, O.EMPLOYEES, O.INTERESTED_FEATURES, O.ACCOUNTING]); }); - it('returns [WORK_EMAIL, WORK_EMAIL_VALIDATION, EMPLOYEES, ACCOUNTING, INTERESTED_FEATURES] for public + SMB', () => { - expect(getOnboardingFlow({signupQualifier: 'smb', isFromPublicDomain: true})).toEqual([ - SCREENS.ONBOARDING.WORK_EMAIL, - SCREENS.ONBOARDING.WORK_EMAIL_VALIDATION, - SCREENS.ONBOARDING.EMPLOYEES, - SCREENS.ONBOARDING.ACCOUNTING, - SCREENS.ONBOARDING.INTERESTED_FEATURES, - ]); + it('returns [WORK_EMAIL, WORK_EMAIL_VALIDATION, EMPLOYEES, INTERESTED_FEATURES, ACCOUNTING] for public + SMB', () => { + expect(getOnboardingFlow({signupQualifier: 'smb', isFromPublicDomain: true})).toEqual([O.WORK_EMAIL, O.WORK_EMAIL_VALIDATION, O.EMPLOYEES, O.INTERESTED_FEATURES, O.ACCOUNTING]); }); it('returns 6-step flow for public + individual + MANAGE_TEAM', () => { expect(getOnboardingFlow({signupQualifier: 'individual', isFromPublicDomain: true, purposeSelected: ONBOARDING_CHOICES.MANAGE_TEAM})).toEqual([ - SCREENS.ONBOARDING.WORK_EMAIL, - SCREENS.ONBOARDING.WORK_EMAIL_VALIDATION, - SCREENS.ONBOARDING.PURPOSE, - SCREENS.ONBOARDING.EMPLOYEES, - SCREENS.ONBOARDING.ACCOUNTING, - SCREENS.ONBOARDING.INTERESTED_FEATURES, + O.WORK_EMAIL, + O.WORK_EMAIL_VALIDATION, + O.PURPOSE, + O.EMPLOYEES, + O.INTERESTED_FEATURES, + O.ACCOUNTING, ]); }); @@ -99,33 +83,33 @@ describe('getOnboardingFlow', () => { it('returns 4-step flow for public + individual + LOOKING_AROUND', () => { expect(getOnboardingFlow({signupQualifier: 'individual', isFromPublicDomain: true, purposeSelected: ONBOARDING_CHOICES.LOOKING_AROUND})).toEqual([ - SCREENS.ONBOARDING.WORK_EMAIL, - SCREENS.ONBOARDING.WORK_EMAIL_VALIDATION, - SCREENS.ONBOARDING.PURPOSE, - SCREENS.ONBOARDING.PERSONAL_DETAILS, + O.WORK_EMAIL, + O.WORK_EMAIL_VALIDATION, + O.PURPOSE, + O.PERSONAL_DETAILS, ]); }); it('returns 6-step flow for public + merge + VSB', () => { expect(getOnboardingFlow({signupQualifier: 'vsb', isFromPublicDomain: true, isMergeAccountStepSkipped: false})).toEqual([ - SCREENS.ONBOARDING.WORK_EMAIL, - SCREENS.ONBOARDING.WORK_EMAIL_VALIDATION, - SCREENS.ONBOARDING.WORKSPACES, - SCREENS.ONBOARDING.EMPLOYEES, - SCREENS.ONBOARDING.ACCOUNTING, - SCREENS.ONBOARDING.INTERESTED_FEATURES, + O.WORK_EMAIL, + O.WORK_EMAIL_VALIDATION, + O.WORKSPACES, + O.EMPLOYEES, + O.INTERESTED_FEATURES, + O.ACCOUNTING, ]); }); it('returns 7-step flow for public + merge + individual + MANAGE_TEAM', () => { expect(getOnboardingFlow({signupQualifier: 'individual', isFromPublicDomain: true, isMergeAccountStepSkipped: false, purposeSelected: ONBOARDING_CHOICES.MANAGE_TEAM})).toEqual([ - SCREENS.ONBOARDING.WORK_EMAIL, - SCREENS.ONBOARDING.WORK_EMAIL_VALIDATION, - SCREENS.ONBOARDING.WORKSPACES, - SCREENS.ONBOARDING.PURPOSE, - SCREENS.ONBOARDING.EMPLOYEES, - SCREENS.ONBOARDING.ACCOUNTING, - SCREENS.ONBOARDING.INTERESTED_FEATURES, + O.WORK_EMAIL, + O.WORK_EMAIL_VALIDATION, + O.WORKSPACES, + O.PURPOSE, + O.EMPLOYEES, + O.INTERESTED_FEATURES, + O.ACCOUNTING, ]); }); @@ -170,97 +154,85 @@ describe('getOnboardingFlow', () => { it('returns 4-step flow for public + skipped + individual + MANAGE_TEAM', () => { // A skipped work email step is no longer part of the navigable flow, so it is excluded. expect(getOnboardingFlow({signupQualifier: 'individual', isFromPublicDomain: true, isMergeAccountStepSkipped: true, purposeSelected: ONBOARDING_CHOICES.MANAGE_TEAM})).toEqual([ - SCREENS.ONBOARDING.PURPOSE, - SCREENS.ONBOARDING.EMPLOYEES, - SCREENS.ONBOARDING.ACCOUNTING, - SCREENS.ONBOARDING.INTERESTED_FEATURES, + O.PURPOSE, + O.EMPLOYEES, + O.INTERESTED_FEATURES, + O.ACCOUNTING, ]); }); - it('returns 3-step flow for public + skipped + VSB (employees is the first step)', () => { - // A skipped work email step is no longer part of the navigable flow, so EMPLOYEES becomes the first step. - expect(getOnboardingFlow({signupQualifier: 'vsb', isFromPublicDomain: true, isMergeAccountStepSkipped: true})).toEqual([ - SCREENS.ONBOARDING.EMPLOYEES, - SCREENS.ONBOARDING.ACCOUNTING, - SCREENS.ONBOARDING.INTERESTED_FEATURES, - ]); + it('returns 3-step flow for public + skipped + VSB', () => { + // A skipped work email step is no longer part of the navigable flow, so Employees becomes the first step. + expect(getOnboardingFlow({signupQualifier: 'vsb', isFromPublicDomain: true, isMergeAccountStepSkipped: true})).toEqual([O.EMPLOYEES, O.INTERESTED_FEATURES, O.ACCOUNTING]); }); - it('returns 3-step flow for public + validated + VSB (employees is the first step)', () => { - // A validated work email is no longer part of the navigable flow, so EMPLOYEES becomes the first step. - expect(getOnboardingFlow({signupQualifier: 'vsb', isFromPublicDomain: true, isAccountValidated: true})).toEqual([ - SCREENS.ONBOARDING.EMPLOYEES, - SCREENS.ONBOARDING.ACCOUNTING, - SCREENS.ONBOARDING.INTERESTED_FEATURES, - ]); + it('returns 3-step flow for public + validated + VSB', () => { + // A validated work email is no longer part of the navigable flow, so Employees becomes the first step. + expect(getOnboardingFlow({signupQualifier: 'vsb', isFromPublicDomain: true, isAccountValidated: true})).toEqual([O.EMPLOYEES, O.INTERESTED_FEATURES, O.ACCOUNTING]); }); - it('returns 3-step flow for public + validated + merge + VSB (employees is the first step)', () => { + it('returns 3-step flow for public + validated + merge + VSB', () => { // Validated accounts skip work email even when merge is not completed, matching navigation behavior. expect(getOnboardingFlow({signupQualifier: 'vsb', isFromPublicDomain: true, isAccountValidated: true, isMergeAccountStepSkipped: false})).toEqual([ - SCREENS.ONBOARDING.EMPLOYEES, - SCREENS.ONBOARDING.ACCOUNTING, - SCREENS.ONBOARDING.INTERESTED_FEATURES, + O.EMPLOYEES, + O.INTERESTED_FEATURES, + O.ACCOUNTING, ]); }); it('returns 3-step flow for public + validated + SMB (employees is the first step)', () => { - expect(getOnboardingFlow({signupQualifier: 'smb', isFromPublicDomain: true, isAccountValidated: true})).toEqual([ - SCREENS.ONBOARDING.EMPLOYEES, - SCREENS.ONBOARDING.ACCOUNTING, - SCREENS.ONBOARDING.INTERESTED_FEATURES, - ]); + expect(getOnboardingFlow({signupQualifier: 'smb', isFromPublicDomain: true, isAccountValidated: true})).toEqual([O.EMPLOYEES, O.INTERESTED_FEATURES, O.ACCOUNTING]); }); // Unvalidated private-domain users traverse PERSONAL_DETAILS -> PRIVATE_DOMAIN, then skip straight to the qualifier/purpose suffix. it('returns 5-step flow for unvalidated private domain + VSB', () => { expect(getOnboardingFlow({signupQualifier: 'vsb', hasAccessibleDomainPolicies: true})).toEqual([ - SCREENS.ONBOARDING.PERSONAL_DETAILS, - SCREENS.ONBOARDING.PRIVATE_DOMAIN, - SCREENS.ONBOARDING.EMPLOYEES, - SCREENS.ONBOARDING.ACCOUNTING, - SCREENS.ONBOARDING.INTERESTED_FEATURES, + O.PERSONAL_DETAILS, + O.PRIVATE_DOMAIN, + O.EMPLOYEES, + O.INTERESTED_FEATURES, + O.ACCOUNTING, ]); }); it('returns 5-step flow for unvalidated private domain + SMB', () => { expect(getOnboardingFlow({signupQualifier: 'smb', hasAccessibleDomainPolicies: true})).toEqual([ - SCREENS.ONBOARDING.PERSONAL_DETAILS, - SCREENS.ONBOARDING.PRIVATE_DOMAIN, - SCREENS.ONBOARDING.EMPLOYEES, - SCREENS.ONBOARDING.ACCOUNTING, - SCREENS.ONBOARDING.INTERESTED_FEATURES, + O.PERSONAL_DETAILS, + O.PRIVATE_DOMAIN, + O.EMPLOYEES, + O.INTERESTED_FEATURES, + O.ACCOUNTING, ]); }); // Validated private-domain users skip PRIVATE_DOMAIN and traverse WORKSPACES only when joinable workspaces exist. it('returns 5-step flow for validated private domain + VSB with joinable workspaces', () => { expect(getOnboardingFlow({signupQualifier: 'vsb', hasAccessibleDomainPolicies: true, isAccountValidated: true, hasJoinablePolicies: true})).toEqual([ - SCREENS.ONBOARDING.PERSONAL_DETAILS, - SCREENS.ONBOARDING.WORKSPACES, - SCREENS.ONBOARDING.EMPLOYEES, - SCREENS.ONBOARDING.ACCOUNTING, - SCREENS.ONBOARDING.INTERESTED_FEATURES, + O.PERSONAL_DETAILS, + O.WORKSPACES, + O.EMPLOYEES, + O.INTERESTED_FEATURES, + O.ACCOUNTING, ]); }); it('returns 4-step flow for validated private domain + VSB without joinable workspaces', () => { expect(getOnboardingFlow({signupQualifier: 'vsb', hasAccessibleDomainPolicies: true, isAccountValidated: true, hasJoinablePolicies: false})).toEqual([ - SCREENS.ONBOARDING.PERSONAL_DETAILS, - SCREENS.ONBOARDING.EMPLOYEES, - SCREENS.ONBOARDING.ACCOUNTING, - SCREENS.ONBOARDING.INTERESTED_FEATURES, + O.PERSONAL_DETAILS, + O.EMPLOYEES, + O.INTERESTED_FEATURES, + O.ACCOUNTING, ]); }); it('returns 6-step flow for unvalidated private domain + individual + MANAGE_TEAM', () => { expect(getOnboardingFlow({signupQualifier: 'individual', hasAccessibleDomainPolicies: true, purposeSelected: ONBOARDING_CHOICES.MANAGE_TEAM})).toEqual([ - SCREENS.ONBOARDING.PERSONAL_DETAILS, - SCREENS.ONBOARDING.PRIVATE_DOMAIN, - SCREENS.ONBOARDING.PURPOSE, - SCREENS.ONBOARDING.EMPLOYEES, - SCREENS.ONBOARDING.ACCOUNTING, - SCREENS.ONBOARDING.INTERESTED_FEATURES, + O.PERSONAL_DETAILS, + O.PRIVATE_DOMAIN, + O.PURPOSE, + O.EMPLOYEES, + O.INTERESTED_FEATURES, + O.ACCOUNTING, ]); }); @@ -283,9 +255,9 @@ describe('getOnboardingFlow', () => { it('returns 3-step flow for unvalidated private domain + individual + EMPLOYER', () => { expect(getOnboardingFlow({signupQualifier: 'individual', hasAccessibleDomainPolicies: true, purposeSelected: ONBOARDING_CHOICES.EMPLOYER})).toEqual([ - SCREENS.ONBOARDING.PERSONAL_DETAILS, - SCREENS.ONBOARDING.PRIVATE_DOMAIN, - SCREENS.ONBOARDING.PURPOSE, + O.PERSONAL_DETAILS, + O.PRIVATE_DOMAIN, + O.PURPOSE, ]); }); }); @@ -293,24 +265,30 @@ describe('getOnboardingFlow', () => { describe('getOnboardingStepCounter', () => { it('returns correct step/total/percentage for each page in VSB flow', () => { const ctx: OnboardingFlowContext = {signupQualifier: 'vsb'}; - expect(getOnboardingStepCounter(SCREENS.ONBOARDING.EMPLOYEES, ctx)).toEqual({stepCounter: {step: 1, total: 3}, progressBarPercentage: 33}); - expect(getOnboardingStepCounter(SCREENS.ONBOARDING.ACCOUNTING, ctx)).toEqual({stepCounter: {step: 2, total: 3}, progressBarPercentage: 67}); - expect(getOnboardingStepCounter(SCREENS.ONBOARDING.INTERESTED_FEATURES, ctx)).toEqual({stepCounter: {step: 3, total: 3}, progressBarPercentage: 100}); + expect(getOnboardingStepCounter(O.EMPLOYEES, ctx)).toEqual({stepCounter: {step: 1, total: 3}, progressBarPercentage: 33}); + expect(getOnboardingStepCounter(O.INTERESTED_FEATURES, ctx)).toEqual({stepCounter: {step: 2, total: 3}, progressBarPercentage: 67}); + expect(getOnboardingStepCounter(O.ACCOUNTING, ctx)).toEqual({stepCounter: {step: 3, total: 3}, progressBarPercentage: 100}); }); it('returns correct step/total/percentage for each page in SMB flow', () => { const ctx: OnboardingFlowContext = {signupQualifier: 'smb'}; - expect(getOnboardingStepCounter(SCREENS.ONBOARDING.EMPLOYEES, ctx)).toEqual({stepCounter: {step: 1, total: 3}, progressBarPercentage: 33}); - expect(getOnboardingStepCounter(SCREENS.ONBOARDING.ACCOUNTING, ctx)).toEqual({stepCounter: {step: 2, total: 3}, progressBarPercentage: 67}); - expect(getOnboardingStepCounter(SCREENS.ONBOARDING.INTERESTED_FEATURES, ctx)).toEqual({stepCounter: {step: 3, total: 3}, progressBarPercentage: 100}); + expect(getOnboardingStepCounter(O.EMPLOYEES, ctx)).toEqual({stepCounter: {step: 1, total: 3}, progressBarPercentage: 33}); + expect(getOnboardingStepCounter(O.INTERESTED_FEATURES, ctx)).toEqual({stepCounter: {step: 2, total: 3}, progressBarPercentage: 67}); + expect(getOnboardingStepCounter(O.ACCOUNTING, ctx)).toEqual({stepCounter: {step: 3, total: 3}, progressBarPercentage: 100}); }); it('returns correct step/total/percentage for individual + MANAGE_TEAM', () => { const ctx: OnboardingFlowContext = {signupQualifier: 'individual', purposeSelected: ONBOARDING_CHOICES.MANAGE_TEAM}; - expect(getOnboardingStepCounter(SCREENS.ONBOARDING.PURPOSE, ctx)).toEqual({stepCounter: {step: 1, total: 4}, progressBarPercentage: 25}); - expect(getOnboardingStepCounter(SCREENS.ONBOARDING.EMPLOYEES, ctx)).toEqual({stepCounter: {step: 2, total: 4}, progressBarPercentage: 50}); - expect(getOnboardingStepCounter(SCREENS.ONBOARDING.ACCOUNTING, ctx)).toEqual({stepCounter: {step: 3, total: 4}, progressBarPercentage: 75}); - expect(getOnboardingStepCounter(SCREENS.ONBOARDING.INTERESTED_FEATURES, ctx)).toEqual({stepCounter: {step: 4, total: 4}, progressBarPercentage: 100}); + expect(getOnboardingStepCounter(O.PURPOSE, ctx)).toEqual({stepCounter: {step: 1, total: 4}, progressBarPercentage: 25}); + expect(getOnboardingStepCounter(O.EMPLOYEES, ctx)).toEqual({stepCounter: {step: 2, total: 4}, progressBarPercentage: 50}); + expect(getOnboardingStepCounter(O.INTERESTED_FEATURES, ctx)).toEqual({stepCounter: {step: 3, total: 4}, progressBarPercentage: 75}); + expect(getOnboardingStepCounter(O.ACCOUNTING, ctx)).toEqual({stepCounter: {step: 4, total: 4}, progressBarPercentage: 100}); + }); + + it('omits Accounting from the counter when Accounting is disabled', () => { + const ctx: OnboardingFlowContext = {signupQualifier: 'individual', purposeSelected: ONBOARDING_CHOICES.MANAGE_TEAM, isAccountingEnabled: false}; + expect(getOnboardingStepCounter(O.INTERESTED_FEATURES, ctx)).toEqual({stepCounter: {step: 3, total: 3}, progressBarPercentage: 100}); + expect(getOnboardingStepCounter(O.ACCOUNTING, ctx)).toBeUndefined(); }); it('returns correct step/total/percentage for individual + PERSONAL_SPEND', () => { @@ -328,39 +306,39 @@ describe('getOnboardingStepCounter', () => { it('returns correct step/total/percentage for individual + other purpose', () => { const ctx: OnboardingFlowContext = {signupQualifier: 'individual', purposeSelected: ONBOARDING_CHOICES.EMPLOYER}; - expect(getOnboardingStepCounter(SCREENS.ONBOARDING.PURPOSE, ctx)).toEqual({stepCounter: {step: 1, total: 2}, progressBarPercentage: 50}); - expect(getOnboardingStepCounter(SCREENS.ONBOARDING.PERSONAL_DETAILS, ctx)).toEqual({stepCounter: {step: 2, total: 2}, progressBarPercentage: 100}); + expect(getOnboardingStepCounter(O.PURPOSE, ctx)).toEqual({stepCounter: {step: 1, total: 2}, progressBarPercentage: 50}); + expect(getOnboardingStepCounter(O.PERSONAL_DETAILS, ctx)).toEqual({stepCounter: {step: 2, total: 2}, progressBarPercentage: 100}); }); it('returns correct step/total/percentage for public + individual + MANAGE_TEAM', () => { const ctx: OnboardingFlowContext = {signupQualifier: 'individual', isFromPublicDomain: true, purposeSelected: ONBOARDING_CHOICES.MANAGE_TEAM}; - expect(getOnboardingStepCounter(SCREENS.ONBOARDING.WORK_EMAIL, ctx)).toEqual({stepCounter: {step: 1, total: 6}, progressBarPercentage: 17}); - expect(getOnboardingStepCounter(SCREENS.ONBOARDING.WORK_EMAIL_VALIDATION, ctx)).toEqual({stepCounter: {step: 2, total: 6}, progressBarPercentage: 33}); - expect(getOnboardingStepCounter(SCREENS.ONBOARDING.PURPOSE, ctx)).toEqual({stepCounter: {step: 3, total: 6}, progressBarPercentage: 50}); - expect(getOnboardingStepCounter(SCREENS.ONBOARDING.EMPLOYEES, ctx)).toEqual({stepCounter: {step: 4, total: 6}, progressBarPercentage: 67}); - expect(getOnboardingStepCounter(SCREENS.ONBOARDING.ACCOUNTING, ctx)).toEqual({stepCounter: {step: 5, total: 6}, progressBarPercentage: 83}); - expect(getOnboardingStepCounter(SCREENS.ONBOARDING.INTERESTED_FEATURES, ctx)).toEqual({stepCounter: {step: 6, total: 6}, progressBarPercentage: 100}); + expect(getOnboardingStepCounter(O.WORK_EMAIL, ctx)).toEqual({stepCounter: {step: 1, total: 6}, progressBarPercentage: 17}); + expect(getOnboardingStepCounter(O.WORK_EMAIL_VALIDATION, ctx)).toEqual({stepCounter: {step: 2, total: 6}, progressBarPercentage: 33}); + expect(getOnboardingStepCounter(O.PURPOSE, ctx)).toEqual({stepCounter: {step: 3, total: 6}, progressBarPercentage: 50}); + expect(getOnboardingStepCounter(O.EMPLOYEES, ctx)).toEqual({stepCounter: {step: 4, total: 6}, progressBarPercentage: 67}); + expect(getOnboardingStepCounter(O.INTERESTED_FEATURES, ctx)).toEqual({stepCounter: {step: 5, total: 6}, progressBarPercentage: 83}); + expect(getOnboardingStepCounter(O.ACCOUNTING, ctx)).toEqual({stepCounter: {step: 6, total: 6}, progressBarPercentage: 100}); }); it('returns correct step/total/percentage for public + merge + individual + MANAGE_TEAM', () => { const ctx: OnboardingFlowContext = {signupQualifier: 'individual', isFromPublicDomain: true, isMergeAccountStepSkipped: false, purposeSelected: ONBOARDING_CHOICES.MANAGE_TEAM}; - expect(getOnboardingStepCounter(SCREENS.ONBOARDING.WORK_EMAIL, ctx)).toEqual({stepCounter: {step: 1, total: 7}, progressBarPercentage: 14}); - expect(getOnboardingStepCounter(SCREENS.ONBOARDING.WORK_EMAIL_VALIDATION, ctx)).toEqual({stepCounter: {step: 2, total: 7}, progressBarPercentage: 29}); - expect(getOnboardingStepCounter(SCREENS.ONBOARDING.WORKSPACES, ctx)).toEqual({stepCounter: {step: 3, total: 7}, progressBarPercentage: 43}); - expect(getOnboardingStepCounter(SCREENS.ONBOARDING.PURPOSE, ctx)).toEqual({stepCounter: {step: 4, total: 7}, progressBarPercentage: 57}); - expect(getOnboardingStepCounter(SCREENS.ONBOARDING.EMPLOYEES, ctx)).toEqual({stepCounter: {step: 5, total: 7}, progressBarPercentage: 71}); - expect(getOnboardingStepCounter(SCREENS.ONBOARDING.ACCOUNTING, ctx)).toEqual({stepCounter: {step: 6, total: 7}, progressBarPercentage: 86}); - expect(getOnboardingStepCounter(SCREENS.ONBOARDING.INTERESTED_FEATURES, ctx)).toEqual({stepCounter: {step: 7, total: 7}, progressBarPercentage: 100}); + expect(getOnboardingStepCounter(O.WORK_EMAIL, ctx)).toEqual({stepCounter: {step: 1, total: 7}, progressBarPercentage: 14}); + expect(getOnboardingStepCounter(O.WORK_EMAIL_VALIDATION, ctx)).toEqual({stepCounter: {step: 2, total: 7}, progressBarPercentage: 29}); + expect(getOnboardingStepCounter(O.WORKSPACES, ctx)).toEqual({stepCounter: {step: 3, total: 7}, progressBarPercentage: 43}); + expect(getOnboardingStepCounter(O.PURPOSE, ctx)).toEqual({stepCounter: {step: 4, total: 7}, progressBarPercentage: 57}); + expect(getOnboardingStepCounter(O.EMPLOYEES, ctx)).toEqual({stepCounter: {step: 5, total: 7}, progressBarPercentage: 71}); + expect(getOnboardingStepCounter(O.INTERESTED_FEATURES, ctx)).toEqual({stepCounter: {step: 6, total: 7}, progressBarPercentage: 86}); + expect(getOnboardingStepCounter(O.ACCOUNTING, ctx)).toEqual({stepCounter: {step: 7, total: 7}, progressBarPercentage: 100}); }); it('returns correct step/total/percentage for public + skipped + individual + MANAGE_TEAM (no gaps)', () => { const ctx: OnboardingFlowContext = {signupQualifier: 'individual', isFromPublicDomain: true, isMergeAccountStepSkipped: true, purposeSelected: ONBOARDING_CHOICES.MANAGE_TEAM}; // The skipped work email step is excluded from the flow, so it has no step counter. - expect(getOnboardingStepCounter(SCREENS.ONBOARDING.WORK_EMAIL, ctx)).toBeUndefined(); - expect(getOnboardingStepCounter(SCREENS.ONBOARDING.PURPOSE, ctx)).toEqual({stepCounter: {step: 1, total: 4}, progressBarPercentage: 25}); - expect(getOnboardingStepCounter(SCREENS.ONBOARDING.EMPLOYEES, ctx)).toEqual({stepCounter: {step: 2, total: 4}, progressBarPercentage: 50}); - expect(getOnboardingStepCounter(SCREENS.ONBOARDING.ACCOUNTING, ctx)).toEqual({stepCounter: {step: 3, total: 4}, progressBarPercentage: 75}); - expect(getOnboardingStepCounter(SCREENS.ONBOARDING.INTERESTED_FEATURES, ctx)).toEqual({stepCounter: {step: 4, total: 4}, progressBarPercentage: 100}); + expect(getOnboardingStepCounter(O.WORK_EMAIL, ctx)).toBeUndefined(); + expect(getOnboardingStepCounter(O.PURPOSE, ctx)).toEqual({stepCounter: {step: 1, total: 4}, progressBarPercentage: 25}); + expect(getOnboardingStepCounter(O.EMPLOYEES, ctx)).toEqual({stepCounter: {step: 2, total: 4}, progressBarPercentage: 50}); + expect(getOnboardingStepCounter(O.INTERESTED_FEATURES, ctx)).toEqual({stepCounter: {step: 3, total: 4}, progressBarPercentage: 75}); + expect(getOnboardingStepCounter(O.ACCOUNTING, ctx)).toEqual({stepCounter: {step: 4, total: 4}, progressBarPercentage: 100}); }); it('returns correct step/total/percentage for public + skipped + individual + PERSONAL_SPEND (no gaps)', () => { @@ -371,23 +349,23 @@ describe('getOnboardingStepCounter', () => { expect(getOnboardingStepCounter(SCREENS.ONBOARDING.PERSONAL_DETAILS, ctx)).toEqual({stepCounter: {step: 2, total: 2}, progressBarPercentage: 100}); }); - it('returns correct step/total/percentage for public + skipped + VSB (employees is the first step)', () => { + it('returns correct step/total/percentage for public + skipped + VSB', () => { const ctx: OnboardingFlowContext = {signupQualifier: 'vsb', isFromPublicDomain: true, isMergeAccountStepSkipped: true}; // The skipped work email step is excluded from the flow, so it has no step counter. - expect(getOnboardingStepCounter(SCREENS.ONBOARDING.WORK_EMAIL, ctx)).toBeUndefined(); - expect(getOnboardingStepCounter(SCREENS.ONBOARDING.EMPLOYEES, ctx)).toEqual({stepCounter: {step: 1, total: 3}, progressBarPercentage: 33}); - expect(getOnboardingStepCounter(SCREENS.ONBOARDING.ACCOUNTING, ctx)).toEqual({stepCounter: {step: 2, total: 3}, progressBarPercentage: 67}); - expect(getOnboardingStepCounter(SCREENS.ONBOARDING.INTERESTED_FEATURES, ctx)).toEqual({stepCounter: {step: 3, total: 3}, progressBarPercentage: 100}); + expect(getOnboardingStepCounter(O.WORK_EMAIL, ctx)).toBeUndefined(); + expect(getOnboardingStepCounter(O.EMPLOYEES, ctx)).toEqual({stepCounter: {step: 1, total: 3}, progressBarPercentage: 33}); + expect(getOnboardingStepCounter(O.INTERESTED_FEATURES, ctx)).toEqual({stepCounter: {step: 2, total: 3}, progressBarPercentage: 67}); + expect(getOnboardingStepCounter(O.ACCOUNTING, ctx)).toEqual({stepCounter: {step: 3, total: 3}, progressBarPercentage: 100}); }); - it('returns correct step/total/percentage for public + validated + VSB (employees is the first step)', () => { + it('returns correct step/total/percentage for public + validated + VSB', () => { const ctx: OnboardingFlowContext = {signupQualifier: 'vsb', isFromPublicDomain: true, isAccountValidated: true, isMergeAccountStepSkipped: false}; // The validated work email step is excluded from the flow, so it has no step counter. - expect(getOnboardingStepCounter(SCREENS.ONBOARDING.WORK_EMAIL, ctx)).toBeUndefined(); - expect(getOnboardingStepCounter(SCREENS.ONBOARDING.WORK_EMAIL_VALIDATION, ctx)).toBeUndefined(); - expect(getOnboardingStepCounter(SCREENS.ONBOARDING.EMPLOYEES, ctx)).toEqual({stepCounter: {step: 1, total: 3}, progressBarPercentage: 33}); - expect(getOnboardingStepCounter(SCREENS.ONBOARDING.ACCOUNTING, ctx)).toEqual({stepCounter: {step: 2, total: 3}, progressBarPercentage: 67}); - expect(getOnboardingStepCounter(SCREENS.ONBOARDING.INTERESTED_FEATURES, ctx)).toEqual({stepCounter: {step: 3, total: 3}, progressBarPercentage: 100}); + expect(getOnboardingStepCounter(O.WORK_EMAIL, ctx)).toBeUndefined(); + expect(getOnboardingStepCounter(O.WORK_EMAIL_VALIDATION, ctx)).toBeUndefined(); + expect(getOnboardingStepCounter(O.EMPLOYEES, ctx)).toEqual({stepCounter: {step: 1, total: 3}, progressBarPercentage: 33}); + expect(getOnboardingStepCounter(O.INTERESTED_FEATURES, ctx)).toEqual({stepCounter: {step: 2, total: 3}, progressBarPercentage: 67}); + expect(getOnboardingStepCounter(O.ACCOUNTING, ctx)).toEqual({stepCounter: {step: 3, total: 3}, progressBarPercentage: 100}); }); it('returns correct step/total/percentage for public + skipped + individual + TRACK_PERSONAL (no gaps)', () => { @@ -401,17 +379,17 @@ describe('getOnboardingStepCounter', () => { it('returns correct step/total/percentage for unvalidated private domain + individual + MANAGE_TEAM (6-step flow)', () => { const ctx: OnboardingFlowContext = {signupQualifier: 'individual', hasAccessibleDomainPolicies: true, purposeSelected: ONBOARDING_CHOICES.MANAGE_TEAM}; - expect(getOnboardingStepCounter(SCREENS.ONBOARDING.PERSONAL_DETAILS, ctx)).toEqual({stepCounter: {step: 1, total: 6}, progressBarPercentage: 17}); - expect(getOnboardingStepCounter(SCREENS.ONBOARDING.PRIVATE_DOMAIN, ctx)).toEqual({stepCounter: {step: 2, total: 6}, progressBarPercentage: 33}); + expect(getOnboardingStepCounter(O.PERSONAL_DETAILS, ctx)).toEqual({stepCounter: {step: 1, total: 6}, progressBarPercentage: 17}); + expect(getOnboardingStepCounter(O.PRIVATE_DOMAIN, ctx)).toEqual({stepCounter: {step: 2, total: 6}, progressBarPercentage: 33}); // WORKSPACES is not traversed by an unvalidated private-domain user, so it has no step counter. - expect(getOnboardingStepCounter(SCREENS.ONBOARDING.WORKSPACES, ctx)).toBeUndefined(); - expect(getOnboardingStepCounter(SCREENS.ONBOARDING.PURPOSE, ctx)).toEqual({stepCounter: {step: 3, total: 6}, progressBarPercentage: 50}); - expect(getOnboardingStepCounter(SCREENS.ONBOARDING.EMPLOYEES, ctx)).toEqual({stepCounter: {step: 4, total: 6}, progressBarPercentage: 67}); - expect(getOnboardingStepCounter(SCREENS.ONBOARDING.ACCOUNTING, ctx)).toEqual({stepCounter: {step: 5, total: 6}, progressBarPercentage: 83}); - expect(getOnboardingStepCounter(SCREENS.ONBOARDING.INTERESTED_FEATURES, ctx)).toEqual({stepCounter: {step: 6, total: 6}, progressBarPercentage: 100}); + expect(getOnboardingStepCounter(O.WORKSPACES, ctx)).toBeUndefined(); + expect(getOnboardingStepCounter(O.PURPOSE, ctx)).toEqual({stepCounter: {step: 3, total: 6}, progressBarPercentage: 50}); + expect(getOnboardingStepCounter(O.EMPLOYEES, ctx)).toEqual({stepCounter: {step: 4, total: 6}, progressBarPercentage: 67}); + expect(getOnboardingStepCounter(O.INTERESTED_FEATURES, ctx)).toEqual({stepCounter: {step: 5, total: 6}, progressBarPercentage: 83}); + expect(getOnboardingStepCounter(O.ACCOUNTING, ctx)).toEqual({stepCounter: {step: 6, total: 6}, progressBarPercentage: 100}); }); - it('returns correct step/total/percentage for validated private domain + individual + MANAGE_TEAM with joinable workspaces (7-step flow)', () => { + it('returns correct step/total/percentage for validated private domain + individual + MANAGE_TEAM with joinable workspaces (6-step flow)', () => { const ctx: OnboardingFlowContext = { signupQualifier: 'individual', hasAccessibleDomainPolicies: true, @@ -425,18 +403,20 @@ describe('getOnboardingStepCounter', () => { expect(getOnboardingStepCounter(SCREENS.ONBOARDING.WORKSPACES, ctx)).toEqual({stepCounter: {step: 2, total: 6}, progressBarPercentage: 33}); expect(getOnboardingStepCounter(SCREENS.ONBOARDING.PURPOSE, ctx)).toEqual({stepCounter: {step: 3, total: 6}, progressBarPercentage: 50}); expect(getOnboardingStepCounter(SCREENS.ONBOARDING.EMPLOYEES, ctx)).toEqual({stepCounter: {step: 4, total: 6}, progressBarPercentage: 67}); + expect(getOnboardingStepCounter(SCREENS.ONBOARDING.INTERESTED_FEATURES, ctx)).toEqual({stepCounter: {step: 5, total: 6}, progressBarPercentage: 83}); + expect(getOnboardingStepCounter(SCREENS.ONBOARDING.ACCOUNTING, ctx)).toEqual({stepCounter: {step: 6, total: 6}, progressBarPercentage: 100}); }); describe('sub-page mappings', () => { it('PRIVATE_DOMAIN resolves to WORK_EMAIL_VALIDATION step in public domain flows', () => { const ctx: OnboardingFlowContext = {signupQualifier: 'individual', isFromPublicDomain: true, isMergeAccountStepSkipped: false, purposeSelected: ONBOARDING_CHOICES.MANAGE_TEAM}; - expect(getOnboardingStepCounter(SCREENS.ONBOARDING.PRIVATE_DOMAIN, ctx)).toEqual(getOnboardingStepCounter(SCREENS.ONBOARDING.WORK_EMAIL_VALIDATION, ctx)); + expect(getOnboardingStepCounter(O.PRIVATE_DOMAIN, ctx)).toEqual(getOnboardingStepCounter(O.WORK_EMAIL_VALIDATION, ctx)); }); it('PRIVATE_DOMAIN is its own step in private domain flows', () => { const ctx: OnboardingFlowContext = {signupQualifier: 'vsb', hasAccessibleDomainPolicies: true}; - expect(getOnboardingStepCounter(SCREENS.ONBOARDING.PRIVATE_DOMAIN, ctx)).toBeDefined(); - expect(getOnboardingStepCounter(SCREENS.ONBOARDING.WORK_EMAIL_VALIDATION, ctx)).toBeUndefined(); + expect(getOnboardingStepCounter(O.PRIVATE_DOMAIN, ctx)).toBeDefined(); + expect(getOnboardingStepCounter(O.WORK_EMAIL_VALIDATION, ctx)).toBeUndefined(); }); }); @@ -461,8 +441,8 @@ describe('getOnboardingStepCounter', () => { expectedPurposeStep: 3, expectedPurposePct: 50, prefixPages: [ - {page: SCREENS.ONBOARDING.WORK_EMAIL, step: 1, pct: 17}, - {page: SCREENS.ONBOARDING.WORK_EMAIL_VALIDATION, step: 2, pct: 33}, + {page: O.WORK_EMAIL, step: 1, pct: 17}, + {page: O.WORK_EMAIL_VALIDATION, step: 2, pct: 33}, ], }, { @@ -478,9 +458,9 @@ describe('getOnboardingStepCounter', () => { expectedPurposeStep: 4, expectedPurposePct: 57, prefixPages: [ - {page: SCREENS.ONBOARDING.WORK_EMAIL, step: 1, pct: 14}, - {page: SCREENS.ONBOARDING.WORK_EMAIL_VALIDATION, step: 2, pct: 29}, - {page: SCREENS.ONBOARDING.WORKSPACES, step: 3, pct: 43}, + {page: O.WORK_EMAIL, step: 1, pct: 14}, + {page: O.WORK_EMAIL_VALIDATION, step: 2, pct: 29}, + {page: O.WORKSPACES, step: 3, pct: 43}, ], }, { @@ -489,14 +469,14 @@ describe('getOnboardingStepCounter', () => { expectedPurposeStep: 3, expectedPurposePct: 50, prefixPages: [ - {page: SCREENS.ONBOARDING.PERSONAL_DETAILS, step: 1, pct: 17}, - {page: SCREENS.ONBOARDING.PRIVATE_DOMAIN, step: 2, pct: 33}, + {page: O.PERSONAL_DETAILS, step: 1, pct: 17}, + {page: O.PRIVATE_DOMAIN, step: 2, pct: 33}, ], }, ]; it.each(domainVariants)('$label: PURPOSE returns step $expectedPurposeStep without total', ({ctx, expectedPurposeStep, expectedPurposePct}) => { - const result = getOnboardingStepCounter(SCREENS.ONBOARDING.PURPOSE, ctx); + const result = getOnboardingStepCounter(O.PURPOSE, ctx); expect(result).toEqual({stepCounter: {step: expectedPurposeStep}, progressBarPercentage: expectedPurposePct}); }); @@ -509,7 +489,7 @@ describe('getOnboardingStepCounter', () => { it('PRIVATE_DOMAIN resolves to WORK_EMAIL_VALIDATION step in indeterminate public merge flow', () => { const ctx: OnboardingFlowContext = {signupQualifier: 'individual', isFromPublicDomain: true, isMergeAccountStepSkipped: false}; - expect(getOnboardingStepCounter(SCREENS.ONBOARDING.PRIVATE_DOMAIN, ctx)).toEqual(getOnboardingStepCounter(SCREENS.ONBOARDING.WORK_EMAIL_VALIDATION, ctx)); + expect(getOnboardingStepCounter(O.PRIVATE_DOMAIN, ctx)).toEqual(getOnboardingStepCounter(O.WORK_EMAIL_VALIDATION, ctx)); }); }); @@ -522,9 +502,9 @@ describe('getOnboardingStepCounter', () => { {label: 'private', ctx: {hasAccessibleDomainPolicies: true}}, ]; - it.each(domainVariants)('$label: PURPOSE indeterminate % ≤ min next-page % across all purposes', ({ctx}) => { + it.each(domainVariants)('$label: PURPOSE indeterminate percent is less than or equal to min next-page percent across all purposes', ({ctx}) => { const indeterminateCtx: OnboardingFlowContext = {signupQualifier: 'individual', ...ctx}; - const purposeResult = getOnboardingStepCounter(SCREENS.ONBOARDING.PURPOSE, indeterminateCtx); + const purposeResult = getOnboardingStepCounter(O.PURPOSE, indeterminateCtx); expect(purposeResult).toBeDefined(); for (const purpose of Object.values(ONBOARDING_CHOICES)) { @@ -532,7 +512,7 @@ describe('getOnboardingStepCounter', () => { if (!flow) { continue; } - const purposeIndex = flow.indexOf(SCREENS.ONBOARDING.PURPOSE); + const purposeIndex = flow.indexOf(O.PURPOSE); if (purposeIndex === -1 || purposeIndex >= flow.length - 1) { continue; } @@ -548,7 +528,7 @@ describe('getOnboardingStepCounter', () => { }); it('returns undefined for a page that is not in the flow', () => { - expect(getOnboardingStepCounter(SCREENS.ONBOARDING.PURPOSE, {signupQualifier: 'vsb'})).toBeUndefined(); + expect(getOnboardingStepCounter(O.PURPOSE, {signupQualifier: 'vsb'})).toBeUndefined(); }); describe('every purpose/qualifier combination produces a defined flow', () => { @@ -581,8 +561,12 @@ describe('getOnboardingStepCounter', () => { }); describe('getPreviousOnboardingRoute', () => { - it('returns undefined when employees is the first onboarding step', () => { - expect(getPreviousOnboardingRoute(SCREENS.ONBOARDING.EMPLOYEES, {signupQualifier: 'vsb'})).toBeUndefined(); + it('returns employees before interested features for VSB users', () => { + expect(getPreviousOnboardingRoute(O.INTERESTED_FEATURES, {signupQualifier: 'vsb'})).toBe(ROUTES.ONBOARDING_EMPLOYEES.getRoute()); + }); + + it('returns employees before interested features for VSB with accessible domain policies', () => { + expect(getPreviousOnboardingRoute(O.INTERESTED_FEATURES, {signupQualifier: 'vsb', hasAccessibleDomainPolicies: true})).toBe(ROUTES.ONBOARDING_EMPLOYEES.getRoute()); }); it('returns private domain for unvalidated VSB with accessible domain policies', () => { @@ -603,37 +587,36 @@ describe('getPreviousOnboardingRoute', () => { ).toBe(ROUTES.ONBOARDING_PERSONAL_DETAILS.getRoute()); }); - it('returns workspaces for public domain VSB with merge flow', () => { - expect(getPreviousOnboardingRoute(SCREENS.ONBOARDING.EMPLOYEES, {signupQualifier: 'vsb', isFromPublicDomain: true, isMergeAccountStepSkipped: false})).toBe( - ROUTES.ONBOARDING_WORKSPACES.getRoute(), + it('returns employees before interested features for public domain VSB with merge flow', () => { + expect(getPreviousOnboardingRoute(O.INTERESTED_FEATURES, {signupQualifier: 'vsb', isFromPublicDomain: true, isMergeAccountStepSkipped: false})).toBe( + ROUTES.ONBOARDING_EMPLOYEES.getRoute(), ); }); - it('returns work email validation for public domain VSB without merge skip', () => { - expect(getPreviousOnboardingRoute(SCREENS.ONBOARDING.EMPLOYEES, {signupQualifier: 'vsb', isFromPublicDomain: true})).toBe(ROUTES.ONBOARDING_WORK_EMAIL_VALIDATION.getRoute()); + it('returns employees before interested features for public domain VSB without merge skip', () => { + expect(getPreviousOnboardingRoute(O.INTERESTED_FEATURES, {signupQualifier: 'vsb', isFromPublicDomain: true})).toBe(ROUTES.ONBOARDING_EMPLOYEES.getRoute()); }); - it('returns undefined for public domain VSB when merge account step was skipped (employees is the first step)', () => { - // The skipped work email step is not a navigable previous route, so employees has no back destination. - expect(getPreviousOnboardingRoute(SCREENS.ONBOARDING.EMPLOYEES, {signupQualifier: 'vsb', isFromPublicDomain: true, isMergeAccountStepSkipped: true})).toBeUndefined(); + it('returns employees before interested features for public domain VSB when merge account step was skipped', () => { + expect(getPreviousOnboardingRoute(O.INTERESTED_FEATURES, {signupQualifier: 'vsb', isFromPublicDomain: true, isMergeAccountStepSkipped: true})).toBe( + ROUTES.ONBOARDING_EMPLOYEES.getRoute(), + ); }); - it('returns undefined for public domain VSB when account is validated (employees is the first step)', () => { - // The validated work email step is not a navigable previous route, so employees has no back destination. - expect( - getPreviousOnboardingRoute(SCREENS.ONBOARDING.EMPLOYEES, {signupQualifier: 'vsb', isFromPublicDomain: true, isAccountValidated: true, isMergeAccountStepSkipped: false}), - ).toBeUndefined(); + it('returns employees before interested features for public domain VSB when account is validated', () => { + expect(getPreviousOnboardingRoute(O.INTERESTED_FEATURES, {signupQualifier: 'vsb', isFromPublicDomain: true, isAccountValidated: true, isMergeAccountStepSkipped: false})).toBe( + ROUTES.ONBOARDING_EMPLOYEES.getRoute(), + ); }); it('returns purpose for individual manage team users', () => { - expect(getPreviousOnboardingRoute(SCREENS.ONBOARDING.EMPLOYEES, {signupQualifier: 'individual', purposeSelected: ONBOARDING_CHOICES.MANAGE_TEAM})).toBe( - ROUTES.ONBOARDING_PURPOSE.getRoute(), - ); + expect(getPreviousOnboardingRoute(O.EMPLOYEES, {signupQualifier: 'individual', purposeSelected: ONBOARDING_CHOICES.MANAGE_TEAM})).toBe(ROUTES.ONBOARDING_PURPOSE.getRoute()); }); it('passes backTo when resolving the previous onboarding route', () => { const backTo = ROUTES.ONBOARDING_PERSONAL_DETAILS.getRoute(); + expect(getPreviousOnboardingRoute(O.INTERESTED_FEATURES, {signupQualifier: 'vsb', hasAccessibleDomainPolicies: true}, backTo)).toBe(ROUTES.ONBOARDING_EMPLOYEES.getRoute(backTo)); expect(getPreviousOnboardingRoute(SCREENS.ONBOARDING.EMPLOYEES, {signupQualifier: 'vsb', hasAccessibleDomainPolicies: true}, backTo)).toBe( ROUTES.ONBOARDING_PRIVATE_DOMAIN.getRoute(backTo), ); diff --git a/tests/unit/navigateAfterOnboardingTest.ts b/tests/unit/navigateAfterOnboardingTest.ts index cb3769c5dfa9..73a19c0529fe 100644 --- a/tests/unit/navigateAfterOnboardingTest.ts +++ b/tests/unit/navigateAfterOnboardingTest.ts @@ -97,7 +97,7 @@ describe('navigateAfterOnboarding', () => { const testSession = {email: 'realaccount@gmail.com'}; navigateAfterOnboarding(false, true, '', {}, undefined, ONBOARDING_ADMINS_CHAT_REPORT_ID, (testSession?.email ?? '').includes('+')); - expect(navigate).toHaveBeenCalledWith(ROUTES.REPORT_WITH_ID.getRoute(ONBOARDING_ADMINS_CHAT_REPORT_ID)); + expect(navigate).toHaveBeenCalledWith(ROUTES.REPORT_WITH_ID.getRoute(ONBOARDING_ADMINS_CHAT_REPORT_ID), undefined); }); it('should navigate to home if onboardingAdminsChatReportID is not provided on larger screens and no report is topmost', () => { @@ -106,7 +106,7 @@ describe('navigateAfterOnboarding', () => { navigateAfterOnboarding(false, true, '', {}, undefined, undefined); // Without an admins chat report, we fall back to HOME to trigger guard evaluation instead of opening a report. expect(navigate).not.toHaveBeenCalledWith(ROUTES.REPORT_WITH_ID.getRoute(ONBOARDING_ADMINS_CHAT_REPORT_ID)); - expect(navigate).toHaveBeenCalledWith(ROUTES.HOME); + expect(navigate).toHaveBeenCalledWith(ROUTES.HOME, undefined); }); it('should preserve the topmost report if onboardingAdminsChatReportID is not provided on larger screens', () => { @@ -162,7 +162,7 @@ describe('navigateAfterOnboarding', () => { mockShouldOpenOnAdminRoom.mockReturnValue(true); navigateAfterOnboarding(true, true, '', {}, ONBOARDING_POLICY_ID, ONBOARDING_ADMINS_CHAT_REPORT_ID); - expect(navigate).toHaveBeenCalledWith(ROUTES.REPORT_WITH_ID.getRoute(REPORT_ID)); + expect(navigate).toHaveBeenCalledWith(ROUTES.REPORT_WITH_ID.getRoute(REPORT_ID), undefined); }); it('should pass reportNameValuePairs when looking up last accessed report', () => { @@ -183,12 +183,12 @@ describe('navigateAfterOnboarding', () => { const testSession = {email: 'test+account@gmail.com'}; navigateAfterOnboarding(true, true, '', {}, ONBOARDING_POLICY_ID, ONBOARDING_ADMINS_CHAT_REPORT_ID, (testSession?.email ?? '').includes('+')); - expect(navigate).toHaveBeenCalledWith(ROUTES.REPORT_WITH_ID.getRoute(REPORT_ID)); + expect(navigate).toHaveBeenCalledWith(ROUTES.REPORT_WITH_ID.getRoute(REPORT_ID), undefined); }); it('should navigate to the admin room when the inboxAdminsBespoke variant is assigned', () => { const navigate = jest.spyOn(Navigation, 'navigate'); - navigateAfterOnboarding(false, true, '', {}, undefined, ONBOARDING_ADMINS_CHAT_REPORT_ID, false, CONST.ONBOARDING_RHP_VARIANT.INBOX_ADMINS_BESPOKE); - expect(navigate).toHaveBeenCalledWith(ROUTES.REPORT_WITH_ID.getRoute(ONBOARDING_ADMINS_CHAT_REPORT_ID)); + navigateAfterOnboarding(false, true, '', {}, undefined, ONBOARDING_ADMINS_CHAT_REPORT_ID, false, {variantOverride: CONST.ONBOARDING_RHP_VARIANT.INBOX_ADMINS_BESPOKE}); + expect(navigate).toHaveBeenCalledWith(ROUTES.REPORT_WITH_ID.getRoute(ONBOARDING_ADMINS_CHAT_REPORT_ID), undefined); }); });