From 526cb5596bd8f2a68bb78e89bdcb7d27bdc50a4e Mon Sep 17 00:00:00 2001 From: lucaronin Date: Tue, 24 Feb 2026 10:30:53 +0100 Subject: [PATCH] test: add tests for string error display and double-click prevention Tauri invoke errors are strings (not Error instances). The new test verifies the frontend displays the actual backend error message. Also tests that the login button is disabled during the OAuth flow. Co-Authored-By: Claude Opus 4.6 --- src/components/SettingsPanel.test.tsx | 51 +++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/src/components/SettingsPanel.test.tsx b/src/components/SettingsPanel.test.tsx index 39cd7789..71aac1a7 100644 --- a/src/components/SettingsPanel.test.tsx +++ b/src/components/SettingsPanel.test.tsx @@ -291,5 +291,56 @@ describe('SettingsPanel', () => { ) expect(screen.getByText(/Connect your GitHub account/)).toBeInTheDocument() }) + + it('displays the actual backend error string when device flow start fails', async () => { + mockInvokeFn.mockImplementation(async (cmd: string) => { + if (cmd === 'github_device_flow_start') { + // Tauri invoke rejects with a plain string, not an Error instance + throw 'GitHub device flow not available. Ensure a GitHub App is registered.' + } + return null + }) + + render( + + ) + + fireEvent.click(screen.getByTestId('github-login')) + + await waitFor(() => { + expect(screen.getByTestId('github-error')).toHaveTextContent( + 'GitHub device flow not available. Ensure a GitHub App is registered.' + ) + }) + }) + + it('prevents double-click by disabling button during login flow', async () => { + let resolveStart: ((v: unknown) => void) | null = null + mockInvokeFn.mockImplementation(async (cmd: string) => { + if (cmd === 'github_device_flow_start') { + return new Promise(r => { resolveStart = r }) + } + return null + }) + + render( + + ) + + const loginBtn = screen.getByTestId('github-login') as HTMLButtonElement + fireEvent.click(loginBtn) + + // Button should be disabled while waiting + await waitFor(() => { + expect(loginBtn.disabled).toBe(true) + }) + + // Clean up + resolveStart?.({ + device_code: 'dc', user_code: 'UC-1234', + verification_uri: 'https://github.com/login/device', + expires_in: 900, interval: 5, + }) + }) }) })