Skip to content

[$175] Reports - New report defaults to the default workspace instead of the selected workspace #107683

Todo

Description

@applause-bot

If you haven’t already, check out our contributing guidelines for onboarding. To join our Slack channel, fill out this form.


Version Number: 9.5.52-1
Reproducible in staging?: Yes
Reproducible in production?: Yes
If this was caught during regression testing, add the test name, ID and link from BrowserStack: #106464
Email or phone of affected tester (no customers): n/a
Issue reported by: Applause Internal Team
Bug source: Exploratory - Significant User Experience Deterioration
Device used: Mac 26.5.1 Safari/Chrome, iPhone 13 iOS 26.6
App Component: Money Requests

Action Performed:

  1. Navigate to https://staging.new.expensify.com
  2. Create two workspaces, each with at least two open reports
  3. Navigate to the non-default workspace
  4. Click the + button > Create expense > Manual
  5. Click the Report field.

Expected Result:

The new report should be created in the selected non-default workspace, since expense creation was initiated from that workspace

Actual Result:

Unable to create a new report in a non-default workspace during expense creation. The flow redirects to the default workspace.

Workaround:

Unknown

Platforms:

  • Android: App
  • Android: mWeb Chrome
  • iOS: App
  • iOS: mWeb Safari
  • iOS: mWeb Chrome
  • Windows: Chrome
  • MacOS: Chrome Safari

Screenshots/Videos

Bug7320932_1795308826400.Recording__3515.mp4

View all open jobs on GitHub

Applause Internal Information
Exported by: Chandana Kiran
Bug ID: 7320932

Upwork Automation - Do Not Edit
Issue OwnerCurrent Issue Owner: @ZhenjaHorbach

Activity

  1. applause-bot commented on Nov 22, 2026

    @applause-bot
    Author

    While Applause doesn't embed attachments for this bug, here are the links for quick view:
    https://platform.applause.com/services/links/v1/external/c17e224ea12389f0c4e8531a10537aff4d1e35e2e232feb46a251616af90c304

  2. added
    Daily
    Bug
    on Nov 22, 2026
  3. added
    External
    on Nov 22, 2026
  4. expensify-chore-bot commented on Nov 22, 2026

    @expensify-chore-bot

    Triggered auto assignment to Contributor-plus team member for initial proposal review - @abdulrahuman5196 (External)

  5. changed the title [-]Reports - New report defaults to the default workspace instead of the selected workspace[/-] [+][$175] Reports - New report defaults to the default workspace instead of the selected workspace[/+] on Nov 22, 2026
  6. expensify-chore-bot commented on Nov 22, 2026

    @expensify-chore-bot
  7. MelvinBot commented on Nov 22, 2026

    @MelvinBot
    Contributor

    🤖 Web test steps verification results: ❌ fail

    Reproduced from non-default Workspace B’s chat composer + menu: the expense starts in B, but selecting Create report switches it to default Workspace A. No expense was submitted.
    Expense workspace changed to default Workspace A after selecting Create report

    Step Status
    Navigate into Workspace B without changing the defaultWorkspace A remained the default; B’s expense chat contained two open report cards.
    ✅
    Open + → Create expense → ManualUsed B’s chat composer menu, not the global sidebar button. The form initially showed Workspace B.
    ✅
    Report picker preserves Workspace B contextExisting reports belonged to B, but Create report displayed Workspace A.
    Workspace B expense with B reports but Create report targeting default Workspace A
    ❌
    Selecting Create report retains Workspace BThe form switched to Workspace A. Persisted report ownership was not independently verified.
    Expense workspace changed to default Workspace A after selecting Create report
    ❌

    Proposal

    What is the root cause of that problem?

    The Report picker discards the expense’s workspace when the selected report belongs to the current user and the expense is not per diem. This causes Create report to fall back to the saved default workspace—even though the expense and existing-report options correctly identify the non-default workspace.

    Code evidence and alternative explanations

    The initial-context-loss hypothesis does not explain this reproduction: the manual form and existing-report options retained B until Create report was selected. The frontend fallback explains the observed switch without requiring a backend redirect.

    Scope: Verified on development web through the chat composer. The global sidebar + entry point was not verified; it should not be conflated with this flow. No introducing PR was established.

    What changes do you think we should make in order to solve the problem?

    Preserve the explicit workspace-chat destination when creating a new report for a non-global expense. Do not discard it solely because the selected report belongs to the current user.

    Keep global-create defaults, editing behavior, per-diem handling, other-owner handling, and workspace restrictions intact.

    Regression coverage

    With A default and B non-default, each containing two open reports:

    • Start a manual expense from B’s chat.
    • Verify existing reports and Create report target B.
    • Verify creation sends B’s policy ID.
    • Cover both dropdown and full-page pickers.
    • Retest global creation, per diem, other-owner expenses, and restricted workspaces.

    What alternative solutions did you explore? (Optional)

    Changing the saved default workspace would mask the bug rather than preserve the expense’s existing workspace context.

    Related issue: Consolidate the default-workspace eligibility rule across report and expense flows concerns overlapping fallback logic, but is not a confirmed duplicate.


    Next Steps for Contributor+ team:
    To accept: @MelvinBot implement this to create a draft PR.
    To refine: @MelvinBot <your feedback>
    To reject: Explain why you are rejecting Melvin's proposal.


    view run · view recording

  8. akzkid commented on Nov 22, 2026

    @akzkid

    Proposal

    Please re-state the problem that we are trying to solve in this issue.

    When I create an expense from a non-default workspace and pick Create report in the Report field, the new report goes to my default workspace instead of the workspace I started the expense in.

    What is the root cause of that problem?

    The report picker decides where Create report goes with usePolicyForMovingExpenses. It passes targetExpensePolicyID as the preferred workspace:

    const transactionPolicyID = transaction?.participants?.at(0)?.isPolicyExpenseChat ? transaction?.participants.at(0)?.policyID : undefined;
    // When moving an expense that belongs to another user, or when the selection includes per diem
    // transactions, use the policy of their report (or the transaction's policy as fallback) so the
    // selected workspace is preserved.
    // For the current user's own non-per-diem expenses, fall back to undefined to let the default workspace apply.
    const targetExpensePolicyID = ownerAccountID !== session?.accountID || isPerDiemTransaction ? (selectedReport?.policyID ?? transactionPolicyID) : undefined;
    // We need to fall back to transactionPolicyID because for a new workspace there is no report created yet
    // and if we choose this workspace as participant we want to create a new report in the chosen workspace
    const {policyForMovingExpensesID, shouldSelectPolicy} = usePolicyForMovingExpenses(
    isPerDiemTransaction,
    isTimeRequestUtil(transaction),
    targetExpensePolicyID,
    isUnreportedManagedCardTransaction,
    );

    targetExpensePolicyID is only set when the expense belongs to another user or is per diem. For my own regular expense it is always undefined, even when I'm creating the expense inside a specific workspace chat (transactionPolicyID, the workspace of the chat I started in, is already computed on L196 but not used here).

    With no expensePolicyID, usePolicyForMovingExpenses falls back to the active/default workspace:

    if (!resolvedPolicyID) {
    if (isPolicyValidForMovingExpenses(activePolicy, login, isPerDiemRequest, isTimeRequest)) {
    return {policyForMovingExpensesID: activePolicyID, policyForMovingExpenses: activePolicy, shouldSelectPolicy: false, shouldNavigateToUpgradePath: false, arePoliciesLoaded};
    }
    return {policyForMovingExpensesID: undefined, policyForMovingExpenses: undefined, shouldSelectPolicy: false, shouldNavigateToUpgradePath: arePoliciesLoaded, arePoliciesLoaded};
    }
    // If an expense policy ID is provided and valid, prefer it over the active policy
    if (validExpensePolicyID) {
    return {policyForMovingExpensesID: validExpensePolicyID, policyForMovingExpenses: resolvedPolicy, shouldSelectPolicy: false, shouldNavigateToUpgradePath: false, arePoliciesLoaded};
    }
    if (isPolicyValidForMovingExpenses(activePolicy, login, isPerDiemRequest, isTimeRequest)) {
    return {policyForMovingExpensesID: activePolicyID, policyForMovingExpenses: activePolicy, shouldSelectPolicy: false, shouldNavigateToUpgradePath: false, arePoliciesLoaded};
    }

    So policyForMovingExpenses is the default workspace, and createReportForPolicy builds the optimistic report on that policy (

    const createReportForPolicy = (shouldDismissEmptyReportsConfirmation?: boolean) => {
    if (!isPerDiemTransaction && !isUnreportedManagedCardTransaction && !policyForMovingExpenses?.id) {
    return;
    }
    const policyForNewReport = isPerDiemTransaction && perDiemOriginalPolicy ? perDiemOriginalPolicy : policyForMovingExpenses;
    const optimisticReport = createNewReport({
    ownerPersonalDetails,
    hasViolations,
    isASAPSubmitBetaEnabled,
    policy: policyForNewReport,
    isTrackIntentUser,
    getCurrencyDecimals,
    rules,
    shouldDismissEmptyReportsConfirmation,
    managedCardTransactionID: isUnreportedManagedCardTransaction ? transactionID : undefined,
    ). Then handleRegularReportSelection moves the draft expense onto that new report, so the expense also switches to the default workspace. The list already uses the chat's workspace when creating an expense (selectedPolicyID,
    selectedPolicyID = isFromGlobalCreate ? undefined : perDiemOriginalPolicy?.id;
    } else {
    // The route can hold a generated ID for a report that doesn't exist yet (the field shows "New report"), so fall back to the
    // workspace chat the expense is created in. Otherwise the list would offer reports from every workspace.
    selectedPolicyID = !isEditing && !isFromGlobalCreate ? (reportOrDraftReport?.policyID ?? transactionPolicyID) : undefined;
    }
    ), which is why the existing reports shown are from the right workspace but Create report isn't.

    The comment there says "fall back to undefined to let the default workspace apply". That makes sense when moving an existing expense, but not when the expense is being created from a chosen workspace chat.

    What changes do you think we should make in order to solve the problem?

    In useReportPickerActions, when we're creating an expense (action === CREATE) and its participant is a workspace chat, pass that workspace (transactionPolicyID) to usePolicyForMovingExpenses as the preferred policy. Keep the current behavior for editing/moving existing expenses (still default workspace) and for other users' and per diem expenses.

    usePolicyForMovingExpenses already checks that the preferred policy is valid (member, can create expenses, group policy, not pending delete, time tracking for time requests). If it isn't valid, it still falls back to the default workspace, so we don't add a new edge case.

    The empty-report confirmation and the restricted-action check already use policyForMovingExpenses, so they follow the right workspace automatically.

    What specific scenarios should we test?

    • Two workspaces, A default. From workspace B's chat: + > Create expense > Manual > Report > Create report. The report and the expense stay in B (web, iOS, Mac).
    • The same from workspace A still creates in A.
    • Editing an existing expense's report and choosing Create report keeps the current behavior.
    • Per diem, time and managed-card expenses are unchanged.
    • If I start in a workspace where I can't create expenses, it falls back to the default workspace as it does today.
    • Add a unit test in tests/ui/components/IOURequestStepReportNewReportTest.tsx covering a non-default workspace chat.

    What alternative solutions did you explore? (Optional)

    Using reportOrDraftReport?.policyID (the same source as selectedPolicyID) as the preferred policy for the create flow, so the list and Create report always use the same workspace.

    Contributor details

    Your Expensify account email: carp-digest@mail.grokbot.com
    Upwork Profile Link: https://www.upwork.com/freelancers/~01be5d412b545fdf18

  9. melvin-bot commented on Nov 22, 2026

    @melvin-bot

    ✅ Contributor details stored successfully. Thank you for contributing to Expensify!

  10. danlopes18-ctrl commented on Nov 22, 2026

    @danlopes18-ctrl

    Proposal

    What is the root cause of that problem?

    In src/pages/iou/request/step/IOURequestStepReport/hooks/useReportPickerActions.ts (lines 196–210), targetExpensePolicyID determines which workspace Create report targets (both for creating the report in createReportForPolicy at lines 261–279 and for displaying the workspace subtitle on the Create report row via transactionPolicyID: targetExpensePolicyID at line 328 → IOURequestEditReportCommon.tsx:169).

    Currently, line 201 only populates targetExpensePolicyID when ownerAccountID !== session?.accountID || isPerDiemTransaction, otherwise setting it to undefined:

    1. When a workspace has no open reports yet, selectedReport is undefined, so ownerAccountID is undefined and ownerAccountID !== session?.accountID accidentally evaluates to true, preserving transactionPolicyID.
    2. When the non-default workspace has open reports (as in the repro steps), selectedReport resolves to an open report owned by the current user (ownerAccountID === session?.accountID), so line 201 flips to false and discards the originating workspace (targetExpensePolicyID = undefined).
    3. Passing undefined to usePolicyForMovingExpenses (src/hooks/usePolicyForMovingExpenses.ts:135–142) skips the preferred validExpensePolicyID branch and falls back to activePolicy (the user's default workspace). Meanwhile, selectedPolicyID at line 315 explicitly preserves reportOrDraftReport?.policyID ?? transactionPolicyID when !isEditing && !isFromGlobalCreate, which is why the picker lists Workspace B's existing reports while Create report targets default Workspace A and moves the draft expense there.

    What changes do you think we should make in order to solve the problem?

    In src/pages/iou/request/step/IOURequestStepReport/hooks/useReportPickerActions.ts:

    1. Preserve the originating workspace during non-global expense creation:
      • Extend the targetExpensePolicyID condition at line 201 to also apply when creating a non-global expense (isCreateReport && !isFromGlobalCreate), resolving selectedReport?.policyID ?? reportOrDraftReport?.policyID ?? transactionPolicyID (aligned with selectedPolicyID at line 315 so both the existing-report list and Create report always use the same originating workspace, including when reportIDFromRoute is a generated ID or a workspace chat/report).
      • Keep !isFromGlobalCreate in the guard so Global Create (+ sidebar button, where selectedPolicyID is intentionally undefined to list reports across all workspaces and allow default/workspace-picker resolution via shouldSelectPolicy) is unaffected.
      • Keep isEditing, per-diem, time, managed-card, and other-owner flows untouched.
      • Because targetExpensePolicyID feeds both usePolicyForMovingExpenses (line 208) and listProps.transactionPolicyID (line 328 → IOURequestEditReportCommon.tsx:169), both the Create report row subtitle, restriction check (createReport), empty-report confirmation, and createReportForPolicy automatically target the originating non-default workspace across both the anchored dropdown and full-page report picker.
    2. Add regression unit tests in tests/ui/components/IOURequestStepReportNewReportTest.tsx:
      • With Workspace A as default (activePolicyID) and Workspace B non-default (both containing open reports), open the Report picker while creating a manual expense in Workspace B's chat (isFromGlobalCreate: false) and assert that Create report displays and creates the new report on Workspace B (policyID: B) rather than Workspace A.
      • Verify Global Create (isFromGlobalCreate: true) and editing an existing expense (action: EDIT) preserve their existing fallback behavior.

    What alternative solutions did you explore? (Optional)

    • Passing transactionPolicyID for all action === CREATE flows without checking !isFromGlobalCreate: Rejected because in Global Create (isFromGlobalCreate: true), selectedPolicyID is intentionally undefined so the picker spans all workspaces and Create report respects the default workspace / shouldSelectPolicy workspace selector flow.
    • Passing selectedPolicyID directly into usePolicyForMovingExpenses: Rejected because for editing another user's expense (isEditing === true and ownerAccountID !== session?.accountID), selectedPolicyID is undefined, whereas targetExpensePolicyID must still preserve selectedReport?.policyID ?? transactionPolicyID.
  11. TassioSales commented on Nov 22, 2026

    @TassioSales

    Contributor details:
    Your Expensify account email: tassiolucian.ljs@gmail.com
    Upwork Profile Link: https://www.upwork.com/freelancers/~0179cdc82689f205c7

    Proposal

    Please re-state the problem that we are trying to solve in this issue.

    When initiating expense creation from a non-default workspace (Workspace B) with existing open reports and tapping on the Report field, selecting Create report creates the new report in the default workspace (Workspace A) instead of retaining the selected originating workspace (Workspace B).

    What is the root cause of that problem?

    In src/pages/iou/request/step/IOURequestStepReport/hooks/useReportPickerActions.ts (lines 196–210 & 315–328):

    1. The Report picker correctly filters existing reports to Workspace B because line 315 preserves the originating policy:
    selectedPolicyID = !isEditing && !isFromGlobalCreate ? (reportOrDraftReport?.policyID ?? transactionPolicyID) : undefined;
    1. However, line 201 calculates targetExpensePolicyID:
    const targetExpensePolicyID = ownerAccountID !== session?.accountID || isPerDiemTransaction ? (selectedReport?.policyID ?? transactionPolicyID) : undefined;

    For a user's own manual expense in a non-default workspace with open reports, selectedReport resolves to the user's existing open report (ownerAccountID === session?.accountID), so ownerAccountID !== session?.accountID is false. Consequently, targetExpensePolicyID is set to undefined.

    1. targetExpensePolicyID is passed into usePolicyForMovingExpenses (line 208) and listProps.transactionPolicyID (line 328):
      When targetExpensePolicyID is undefined, usePolicyForMovingExpenses falls back to activePolicy (the user's saved default workspace, Workspace A).
    2. Therefore, the Create report action (and its subtitle) targets Workspace A instead of the active workspace (Workspace B) where expense creation was initiated.

    What changes do you think we should make in order to solve the problem?

    In src/pages/iou/request/step/IOURequestStepReport/hooks/useReportPickerActions.ts:

    Update targetExpensePolicyID (line 201) to preserve the originating policy during non-global expense creation (!isFromGlobalCreate && !isEditing / isCreateReport):

    const originatingPolicyID = selectedReport?.policyID ?? reportOrDraftReport?.policyID ?? transactionPolicyID;
    const targetExpensePolicyID =
        (!isFromGlobalCreate && !isEditing) || ownerAccountID !== session?.accountID || isPerDiemTransaction
            ? originatingPolicyID
            : undefined;

    This guarantees that:

    • Non-global expense creation initiated from a specific workspace chat or report retains that workspace for Create report.
    • Global Create (isFromGlobalCreate === true, via + in global LHN) continues to pass undefined, allowing standard default workspace resolution (shouldSelectPolicy).
    • Other-owner expenses and per-diem transactions continue to work as expected.
    • Both usePolicyForMovingExpenses and listProps.transactionPolicyID receive the consistent originating policyID.

    What alternative solutions did you explore? (Optional)

    • Unconditionally setting targetExpensePolicyID = originatingPolicyID: Suboptimal because global create (isFromGlobalCreate) intentionally needs undefined to allow workspace selection. Checking !isFromGlobalCreate ensures global create flows remain intact.
  12. mountiny commented on Nov 23, 2026

    @mountiny
    Contributor

    @ZhenjaHorbach can you take a look into this as its linked to your pr?

  13. ZhenjaHorbach commented on Nov 23, 2026

    @ZhenjaHorbach
    Contributor

    I will check!

  14. oqildev commented on Nov 23, 2026

    @oqildev
    Contributor

    @ZhenjaHorbach I reproduced this on web (video below) and with a unit test on main, and MelvinBot's root cause is right. The owner check comes from #87962, not #106464, and it never looks at action.

    If the fix only checks action === CREATE, submitting a tracked expense to a workspace still goes to the default one. Using the same condition as selectedPolicyID (!isEditing && !isFromGlobalCreate) fixes both cases. Global create and editing keep the default workspace, and 362/362 related tests pass.

    107683-repro-web.webm
    107683-repro-final
  15. ZhenjaHorbach commented on Nov 23, 2026

    @ZhenjaHorbach
    Contributor

    Yes
    This issue can also be reproduced in prod

  16. ZhenjaHorbach commented on Nov 25, 2026

    @ZhenjaHorbach
    Contributor

    @MelvinBot
    Create a PR with these changes

    diff --git a/src/pages/iou/request/step/IOURequestStepReport/hooks/useReportPickerActions.ts b/src/pages/iou/request/step/IOURequestStepReport/hooks/useReportPickerActions.ts
    index bbc20804b553..9a374c87019c 100644
    --- a/src/pages/iou/request/step/IOURequestStepReport/hooks/useReportPickerActions.ts
    +++ b/src/pages/iou/request/step/IOURequestStepReport/hooks/useReportPickerActions.ts
    @@ -195,11 +195,11 @@ function useReportPickerActions({
         const isUnreportedManagedCardTransaction = isUnreportedManagedCardTransactionUtil(transaction);
     
         const transactionPolicyID = transaction?.participants?.at(0)?.isPolicyExpenseChat ? transaction?.participants.at(0)?.policyID : undefined;
    -    // When moving an expense that belongs to another user, or when the selection includes per diem
    -    // transactions, use the policy of their report (or the transaction's policy as fallback) so the
    -    // selected workspace is preserved.
    -    // For the current user's own non-per-diem expenses, fall back to undefined to let the default workspace apply.
    -    const targetExpensePolicyID = ownerAccountID !== session?.accountID || isPerDiemTransaction ? (selectedReport?.policyID ?? transactionPolicyID) : undefined;
    +    // Keep the workspace of the expense when it belongs to another user, when it is a per diem expense, or when it is
    +    // being created from a workspace chat, so "Create report" opens the report in the same workspace as the listed reports.
    +    // Otherwise (editing the current user's own expense, or creating it from global create) let the default workspace apply.
    +    const shouldKeepExpenseWorkspace = ownerAccountID !== session?.accountID || isPerDiemTransaction || (!isEditing && !isFromGlobalCreate);
    +    const targetExpensePolicyID = shouldKeepExpenseWorkspace ? (selectedReport?.policyID ?? transactionPolicyID) : undefined;
     
         // We need to fall back to transactionPolicyID because for a new workspace there is no report created yet
         // and if we choose this workspace as participant we want to create a new report in the chosen workspace
    diff --git a/tests/unit/hooks/useReportPickerActionsTest.tsx b/tests/unit/hooks/useReportPickerActionsTest.tsx
    new file mode 100644
    index 000000000000..d57e8db101f2
    --- /dev/null
    +++ b/tests/unit/hooks/useReportPickerActionsTest.tsx
    @@ -0,0 +1,172 @@
    +import {renderHook, waitFor} from '@testing-library/react-native';
    +
    +import ActivePolicyProvider from '@components/ActivePolicyProvider';
    +import OnyxListItemProvider from '@components/OnyxListItemProvider';
    +
    +import useReportPickerActions from '@pages/iou/request/step/IOURequestStepReport/hooks/useReportPickerActions';
    +
    +import CONST from '@src/CONST';
    +import ONYXKEYS from '@src/ONYXKEYS';
    +import type {Transaction} from '@src/types/onyx';
    +
    +import type {ReactNode} from 'react';
    +
    +import React from 'react';
    +import Onyx from 'react-native-onyx';
    +
    +import createRandomPolicy from '../../utils/collections/policies';
    +import {createPolicyExpenseChat, createRandomReport} from '../../utils/collections/reports';
    +import waitForBatchedUpdates from '../../utils/waitForBatchedUpdates';
    +
    +jest.mock('@libs/Navigation/navigationRef', () => ({
    +    getCurrentRoute: jest.fn(() => ({name: 'Dynamic_Money_Request_Report', params: {}})),
    +    getState: jest.fn(() => ({})),
    +    isReady: jest.fn(() => false),
    +    addListener: jest.fn(() => jest.fn()),
    +}));
    +
    +jest.mock('@libs/Navigation/Navigation', () => ({
    +    navigate: jest.fn(),
    +    goBack: jest.fn(),
    +    navigationRef: {getCurrentRoute: jest.fn(() => ({name: 'Dynamic_Money_Request_Report', params: {}})), getState: jest.fn(() => ({}))},
    +    getActiveRoute: () => '',
    +    getActiveRouteWithoutParams: jest.fn(() => ''),
    +    isNavigationReady: jest.fn(() => Promise.resolve()),
    +}));
    +
    +jest.mock('@react-navigation/native', () => ({
    +    ...jest.requireActual<Record<string, unknown>>('@react-navigation/native'),
    +    useIsFocused: () => true,
    +    useNavigation: () => ({navigate: jest.fn(), addListener: jest.fn()}),
    +    useFocusEffect: jest.fn(),
    +    usePreventRemove: jest.fn(),
    +}));
    +
    +const ACCOUNT_ID = 1;
    +const ACCOUNT_LOGIN = 'test@user.com';
    +const DEFAULT_POLICY_ID = '1';
    +const SELECTED_POLICY_ID = '2';
    +const WORKSPACE_CHAT_ID = '20';
    +const OPEN_REPORT_ID = '30';
    +const TRANSACTION_ID = '1';
    +
    +function Wrapper({children}: {children: ReactNode}) {
    +    return (
    +        <OnyxListItemProvider>
    +            <ActivePolicyProvider>{children}</ActivePolicyProvider>
    +        </OnyxListItemProvider>
    +    );
    +}
    +
    +function buildPolicy(policyID: string) {
    +    return {
    +        ...createRandomPolicy(Number(policyID), CONST.POLICY.TYPE.TEAM),
    +        id: policyID,
    +        role: CONST.POLICY.ROLE.USER,
    +        pendingAction: null,
    +        employeeList: {[ACCOUNT_LOGIN]: {email: ACCOUNT_LOGIN, role: CONST.POLICY.ROLE.USER}},
    +    };
    +}
    +
    +function buildTransaction(isFromGlobalCreate: boolean): Transaction {
    +    return {
    +        transactionID: TRANSACTION_ID,
    +        amount: 0,
    +        currency: 'USD',
    +        created: '2025-08-29',
    +        merchant: '(none)',
    +        reportID: OPEN_REPORT_ID,
    +        isFromGlobalCreate,
    +        participants: [{accountID: 0, reportID: WORKSPACE_CHAT_ID, policyID: SELECTED_POLICY_ID, isPolicyExpenseChat: true, selected: true}],
    +    };
    +}
    +
    +/** The current user has an open report in the non-default workspace's chat, and another workspace is set as default */
    +async function givenOwnOpenReportInNonDefaultWorkspace() {
    +    await Onyx.merge(ONYXKEYS.SESSION, {accountID: ACCOUNT_ID, email: ACCOUNT_LOGIN});
    +    await Onyx.merge(`${ONYXKEYS.COLLECTION.POLICY}${DEFAULT_POLICY_ID}`, buildPolicy(DEFAULT_POLICY_ID));
    +    await Onyx.merge(`${ONYXKEYS.COLLECTION.POLICY}${SELECTED_POLICY_ID}`, buildPolicy(SELECTED_POLICY_ID));
    +    await Onyx.set(ONYXKEYS.NVP_ACTIVE_POLICY_ID, DEFAULT_POLICY_ID);
    +    await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${WORKSPACE_CHAT_ID}`, {
    +        ...createPolicyExpenseChat(Number(WORKSPACE_CHAT_ID), true),
    +        reportID: WORKSPACE_CHAT_ID,
    +        policyID: SELECTED_POLICY_ID,
    +        ownerAccountID: ACCOUNT_ID,
    +        iouReportID: OPEN_REPORT_ID,
    +    });
    +    await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${OPEN_REPORT_ID}`, {
    +        ...createRandomReport(Number(OPEN_REPORT_ID), undefined),
    +        reportID: OPEN_REPORT_ID,
    +        type: CONST.REPORT.TYPE.EXPENSE,
    +        stateNum: CONST.REPORT.STATE_NUM.OPEN,
    +        statusNum: CONST.REPORT.STATUS_NUM.OPEN,
    +        policyID: SELECTED_POLICY_ID,
    +        chatReportID: WORKSPACE_CHAT_ID,
    +        ownerAccountID: ACCOUNT_ID,
    +        managerID: ACCOUNT_ID,
    +    });
    +    await waitForBatchedUpdates();
    +}
    +
    +function renderReportPickerActions(action: typeof CONST.IOU.ACTION.CREATE | typeof CONST.IOU.ACTION.EDIT, transaction: Transaction) {
    +    return renderHook(
    +        () =>
    +            useReportPickerActions({
    +                transaction,
    +                transactionID: TRANSACTION_ID,
    +                action,
    +                iouType: CONST.IOU.TYPE.SUBMIT,
    +                reportIDFromRoute: OPEN_REPORT_ID,
    +                goBack: jest.fn(),
    +            }),
    +        {wrapper: Wrapper},
    +    );
    +}
    +
    +describe('useReportPickerActions', () => {
    +    beforeAll(() => {
    +        Onyx.init({keys: ONYXKEYS});
    +    });
    +
    +    beforeEach(async () => {
    +        await Onyx.clear();
    +        await waitForBatchedUpdates();
    +    });
    +
    +    it('creates the new report in the workspace the expense is created in, not in the default workspace', async () => {
    +        // Given the user creates an expense from the chat of a non-default workspace that already has their open report
    +        await givenOwnOpenReportInNonDefaultWorkspace();
    +
    +        // When the Report field opens the report picker
    +        const {result} = renderReportPickerActions(CONST.IOU.ACTION.CREATE, buildTransaction(false));
    +        await waitForBatchedUpdates();
    +
    +        // Then "Create report" targets that workspace, because the listed reports also come from it (issue #107683)
    +        await waitFor(() => expect(result.current.listProps.transactionPolicyID).toBe(SELECTED_POLICY_ID));
    +        expect(result.current.listProps.selectedPolicyID).toBe(SELECTED_POLICY_ID);
    +    });
    +
    +    it('lets the default workspace apply when the expense is created from global create', async () => {
    +        // Given the user starts the expense from global create, which doesn't tie it to a workspace
    +        await givenOwnOpenReportInNonDefaultWorkspace();
    +
    +        // When the Report field opens the report picker
    +        const {result} = renderReportPickerActions(CONST.IOU.ACTION.CREATE, buildTransaction(true));
    +        await waitForBatchedUpdates();
    +
    +        // Then no workspace is forced, so "Create report" falls back to the default workspace
    +        expect(result.current.listProps.transactionPolicyID).toBeUndefined();
    +    });
    +
    +    it('lets the default workspace apply when the user moves their own expense', async () => {
    +        // Given the user edits the report of their own existing expense
    +        await givenOwnOpenReportInNonDefaultWorkspace();
    +
    +        // When the report picker opens for editing
    +        const {result} = renderReportPickerActions(CONST.IOU.ACTION.EDIT, buildTransaction(false));
    +        await waitForBatchedUpdates();
    +
    +        // Then no workspace is forced, so moving to a new report keeps using the default workspace
    +        expect(result.current.listProps.transactionPolicyID).toBeUndefined();
    +    });
    +});
    
  17. MelvinBot commented on Nov 25, 2026

    @MelvinBot
    Contributor

    🤖 Web test steps verification results: ❌ fail

    Created draft Preserve expense workspace when creating a report from workspace chat, assigned to ZhenjaHorbach, with your exact changes; all 20 targeted tests and static checks passed. Browser verification was blocked by a blank development app and suspended session after retry.
    Development app displaying a blank page

    Step Status
    Open development web appThe page was blank; session state was unavailable.
    Development app displaying a blank page
    ❌
    Verify workspace selection, Create report, global creation, and own-expense editingNot tested: the blank app prevented fixture setup and navigation.
    ❌

    view run · no recording available

  18. added
    Reviewing
    Weekly
    and removed
    Daily
    on Nov 30, 2026
  19. expensify-chore-bot commented on Dec 1, 2026

    @expensify-chore-bot

    Triggered auto assignment to @Gonals, see https://stackoverflow.com/c/expensify/questions/7972 for more details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

BugExternalReviewingWeekly

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions