From cb9ebaadad670943a9a2eda465f665f657642f1f Mon Sep 17 00:00:00 2001 From: lucaronin Date: Wed, 29 Apr 2026 19:53:33 +0200 Subject: [PATCH] fix: keep manual selection after inbox organize --- src/App.test.tsx | 59 ++++++++++++++++++++++++++++++++++++++++++++++++ src/App.tsx | 2 +- 2 files changed, 60 insertions(+), 1 deletion(-) diff --git a/src/App.test.tsx b/src/App.test.tsx index c15d3fd8..474a486c 100644 --- a/src/App.test.tsx +++ b/src/App.test.tsx @@ -144,6 +144,7 @@ const mockCommandResults: Record = { get_all_content: mockAllContent, get_modified_files: [], get_note_content: mockAllContent['/vault/project/test.md'] || '', + save_note_content: null, reload_vault_entry: ({ path }: { path: string }) => mockEntries.find((entry) => entry.path === path) ?? null, sync_vault_asset_scope_for_window: null, get_file_history: [], @@ -279,6 +280,7 @@ function resetMockCommandResults() { get_all_content: mockAllContent, get_modified_files: [], get_note_content: mockAllContent['/vault/project/test.md'] || '', + save_note_content: null, reload_vault_entry: ({ path }: { path: string }) => mockEntries.find((entry) => entry.path === path) ?? null, sync_vault_asset_scope_for_window: null, get_file_history: [], @@ -1117,6 +1119,63 @@ describe('App', () => { }) }) + it('keeps the manually selected note after organizing finishes later', async () => { + configureNeighborhoodVault() + mockCommandResults.get_settings = { + auto_pull_interval_minutes: null, + auto_advance_inbox_after_organize: true, + telemetry_consent: true, + crash_reporting_enabled: null, + analytics_enabled: null, + anonymous_id: null, + release_channel: null, + } + + let resolveOrganizeSave!: () => void + const organizeSave = new Promise((resolve) => { + resolveOrganizeSave = resolve + }) + mockCommandResults.save_note_content = vi.fn(() => organizeSave) + + render() + + const noteListContainer = await screen.findByTestId('note-list-container') + await waitFor(() => { + expect(getHeaderForNoteList(noteListContainer)).toHaveTextContent('Inbox') + }) + + await act(async () => { + fireEvent.click(within(noteListContainer).getByText('Alpha')) + await Promise.resolve() + }) + + await waitFor(() => { + expect(screen.getByRole('button', { name: 'Set note as organized' })).toBeInTheDocument() + }) + + await act(async () => { + fireEvent.click(screen.getByRole('button', { name: 'Set note as organized' })) + await Promise.resolve() + }) + + await act(async () => { + fireEvent.click(within(noteListContainer).getByText('Gamma')) + await Promise.resolve() + }) + await waitFor(() => { + expect(window.__laputaTest?.activeTabPath).toBe('/vault/gamma.md') + }) + + await act(async () => { + resolveOrganizeSave() + await organizeSave + await Promise.resolve() + await Promise.resolve() + }) + + expect(window.__laputaTest?.activeTabPath).toBe('/vault/gamma.md') + }) + it('renders status bar', async () => { render() // StatusBar should be present diff --git a/src/App.tsx b/src/App.tsx index 0f298055..08eccaa5 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1391,7 +1391,7 @@ function App() { const organized = await entryActions.handleToggleOrganized(path) - if (organized && nextVisibleInboxEntry) { + if (organized && nextVisibleInboxEntry && notes.activeTabPathRef.current === path) { void notes.handleSelectNote(nextVisibleInboxEntry) } }, [effectiveSelection, entryActions, notes, settings.auto_advance_inbox_after_organize, vault.entries])