Skip to content
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,12 @@ function MoneyRequestReportTransactionList({
if (focusedRoute?.name !== SCREENS.RIGHT_MODAL.SEARCH_REPORT) {
return;
}
// Don't overwrite active transaction IDs when navigating from the duplicate review,
// as Review.tsx sets its own order via onPreviewPressed.
const backTo = (focusedRoute.params as Record<string, string> | undefined)?.backTo;
if (backTo?.replaceAll(/\?.*/g, '').endsWith('/duplicates/review')) {
return;
}
setActiveTransactionIDs(visualOrderTransactionIDs);
}, [visualOrderTransactionIDs]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ function useActiveTransactionIDsEffect(visualOrderTransactionIDs: string[]) {
if (focusedRoute?.name !== SCREENS.RIGHT_MODAL.SEARCH_REPORT) {
return;
}
const backTo = (focusedRoute.params as Record<string, string> | undefined)?.backTo;
if (backTo?.replaceAll(/\?.*/g, '').endsWith('/duplicates/review')) {
return;
}
setActiveTransactionIDs(visualOrderTransactionIDs);
}, [visualOrderTransactionIDs]);

Expand Down Expand Up @@ -173,6 +177,40 @@ describe('MoneyRequestReportTransactionList - Active Transaction IDs Effect', ()
expect(mockClearActiveTransactionIDs).not.toHaveBeenCalled();
});

it('should NOT call setActiveTransactionIDs when backTo includes duplicates review', () => {
// Given the focused route is SEARCH_REPORT with backTo pointing to a duplicate review
mockFindFocusedRoute.mockReturnValue({
name: SCREENS.RIGHT_MODAL.SEARCH_REPORT,
key: 'test-key',
params: {backTo: '/r/123/duplicates/review'},
});

const transactionIDs = ['trans1', 'trans2'];

// When the hook is rendered
renderHook(() => useActiveTransactionIDsEffect(transactionIDs));

// Then setActiveTransactionIDs should NOT be called because the IDs were already set by Review.tsx
expect(mockSetActiveTransactionIDs).not.toHaveBeenCalled();
});

it('should NOT call setActiveTransactionIDs when backTo includes duplicates review with query params', () => {
// Given the focused route is SEARCH_REPORT with backTo including query params after duplicates/review
mockFindFocusedRoute.mockReturnValue({
name: SCREENS.RIGHT_MODAL.SEARCH_REPORT,
key: 'test-key',
params: {backTo: '/r/456/duplicates/review?someParam=value'},
});

const transactionIDs = ['trans1', 'trans2'];

// When the hook is rendered
renderHook(() => useActiveTransactionIDsEffect(transactionIDs));

// Then setActiveTransactionIDs should NOT be called
expect(mockSetActiveTransactionIDs).not.toHaveBeenCalled();
});

it('should handle empty transaction IDs array', () => {
// Given the focused route is SEARCH_REPORT
mockFindFocusedRoute.mockReturnValue({name: SCREENS.RIGHT_MODAL.SEARCH_REPORT, key: 'test-key'});
Expand Down
Loading