Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/CONST/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1592,6 +1592,12 @@ const CONST = {
SPLIT_REPORT_ID: '-2',
// "Auto report" destination: the backend picks each expense's report (its owner's latest draft, or a new one).
AUTOMATIC_REPORT_ID: '-3',
// "Auto report" is hidden until the App can tell whether the backend will resolve a destination for every
// selected expense. The current guard only checks that each expense is on a managed card, which says nothing
// about whose card feed it is, so a selection holding another submitter's own-workspace card expense is offered
// the option and then rejected, leaving an error on the expense. Flip this back on once the guard also confirms
// every card belongs to a feed on a workspace the mover administers.
IS_AUTO_REPORT_ENABLED: false,
SECONDARY_ACTIONS: {
SUBMIT: 'submit',
APPROVE: 'approve',
Expand Down
1 change: 1 addition & 0 deletions src/hooks/useSearchBulkActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2869,6 +2869,7 @@ function useSearchBulkActions({queryJSON}: UseSearchBulkActionsParams) {
// the map/GPS rules on manual and odometer distance can only be checked against a known workspace
// An expense we cannot read fails all three, so it withholds the flow rather than risking a rejected move.
const canAutoReportAcrossSubmitters =
CONST.REPORT.IS_AUTO_REPORT_ENABLED &&
ownerAccountIDs.size > 1 &&
!hasUnknownOwner &&
selectedTransactionsKeys.every((id) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ function IOURequestEditReportCommon({
}, [isOffline, showConfirmModal, translate, autoReport]);

const autoReportOption = useMemo(() => {
if (!autoReport || !hasMultipleSubmitters) {
if (!CONST.REPORT.IS_AUTO_REPORT_ENABLED || !autoReport || !hasMultipleSubmitters) {
return undefined;
}

Expand Down
51 changes: 51 additions & 0 deletions tests/ui/IOURequestEditReportCommonTest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ const renderIOURequestEditReportCommon = ({
isPerDiemRequest = false,
selectReport = jest.fn(),
createReport,
hasMultipleSubmitters = false,
areAllManagedCardTransactions = false,
autoReport,
}: {
selectedReportID: string;
selectedPolicyID?: string;
Expand All @@ -58,6 +61,9 @@ const renderIOURequestEditReportCommon = ({
isPerDiemRequest?: boolean;
selectReport?: jest.Mock;
createReport?: jest.Mock;
hasMultipleSubmitters?: boolean;
areAllManagedCardTransactions?: boolean;
autoReport?: jest.Mock;
}) =>
render(
<NavigationContainer>
Expand All @@ -74,6 +80,9 @@ const renderIOURequestEditReportCommon = ({
createReport={createReport}
backTo=""
isPerDiemRequest={isPerDiemRequest}
hasMultipleSubmitters={hasMultipleSubmitters}
areAllManagedCardTransactions={areAllManagedCardTransactions}
autoReport={autoReport}
/>
</ComposeProviders>
</NavigationContainer>,
Expand Down Expand Up @@ -332,6 +341,48 @@ describe('IOURequestEditReportCommon', () => {
});
});

describe('Auto report', () => {
beforeAll(() => {
Onyx.init({
keys: ONYXKEYS,
initialKeyStates: {
[ONYXKEYS.SESSION]: {accountID: FAKE_ACCOUNT_ID, email: FAKE_EMAIL},
},
});
initOnyxDerivedValues();
return waitForBatchedUpdatesWithAct();
});

afterEach(async () => {
await act(async () => {
await Onyx.clear();
});
jest.clearAllMocks();
return waitForBatchedUpdatesWithAct();
});

it('does not offer "Auto report" while the option is disabled, even for a selection that satisfies every other guard', async () => {
// Given a mixed-submitter selection where every expense is on a managed card, which is the only selection
// the row was ever offered for
const autoReport = jest.fn();

// When the screen is rendered
renderIOURequestEditReportCommon({
selectedReportID: FAKE_REPORT_ID,
transactionIDs: [FAKE_TRANSACTION_ID],
hasMultipleSubmitters: true,
areAllManagedCardTransactions: true,
autoReport,
});
await waitForBatchedUpdatesWithAct();

// Then the row is not rendered, so the move it would have queued can never be started. The App cannot yet
// tell whether the backend will resolve a destination for another submitter's own-workspace card expense.
expect(screen.queryByText(translateLocal('iou.autoReport'))).toBeNull();
expect(autoReport).not.toHaveBeenCalled();
});
});

describe('NotFound', () => {
beforeAll(() => {
// Initialize Onyx with test configuration
Expand Down
Loading