From 94546f90a4fb2dd9e1f86a88f32c21489e40916d Mon Sep 17 00:00:00 2001 From: Jack Kingsman Date: Fri, 6 Mar 2026 18:20:53 -0800 Subject: [PATCH] Back to main fanout screen on save --- .../settings/SettingsFanoutSection.tsx | 10 ++++-- frontend/src/test/fanoutSection.test.tsx | 31 +++++++++++++++++++ 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/frontend/src/components/settings/SettingsFanoutSection.tsx b/frontend/src/components/settings/SettingsFanoutSection.tsx index 1631d44..2b26a8d 100644 --- a/frontend/src/components/settings/SettingsFanoutSection.tsx +++ b/frontend/src/components/settings/SettingsFanoutSection.tsx @@ -1050,9 +1050,15 @@ export function SettingsFanoutSection({ }; if (enabled !== undefined) update.enabled = enabled; await api.updateFanoutConfig(editingId, update); - await loadConfigs(); - if (onHealthRefresh) await onHealthRefresh(); setEditingId(null); + await loadConfigs(); + if (onHealthRefresh) { + try { + await onHealthRefresh(); + } catch (err) { + console.error('Failed to refresh health after saving fanout config:', err); + } + } toast.success(enabled ? 'Integration saved and enabled' : 'Integration saved'); } catch (err) { toast.error(err instanceof Error ? err.message : 'Failed to save'); diff --git a/frontend/src/test/fanoutSection.test.tsx b/frontend/src/test/fanoutSection.test.tsx index 0a2ac39..e88ecd6 100644 --- a/frontend/src/test/fanoutSection.test.tsx +++ b/frontend/src/test/fanoutSection.test.tsx @@ -54,6 +54,18 @@ function renderSection(overrides?: { health?: HealthStatus }) { ); } +function renderSectionWithRefresh( + onHealthRefresh: () => Promise, + overrides?: { health?: HealthStatus } +) { + return render( + + ); +} + beforeEach(() => { vi.clearAllMocks(); mockedApi.getFanoutConfigs.mockResolvedValue([]); @@ -117,6 +129,25 @@ describe('SettingsFanoutSection', () => { }); }); + it('save as enabled returns to list even if health refresh fails', async () => { + mockedApi.getFanoutConfigs.mockResolvedValue([webhookConfig]); + mockedApi.updateFanoutConfig.mockResolvedValue({ ...webhookConfig, enabled: true }); + const failingRefresh = vi.fn(async () => { + throw new Error('refresh failed'); + }); + + renderSectionWithRefresh(failingRefresh); + await waitFor(() => expect(screen.getByText('Test Hook')).toBeInTheDocument()); + + fireEvent.click(screen.getByRole('button', { name: 'Edit' })); + await waitFor(() => expect(screen.getByText('← Back to list')).toBeInTheDocument()); + + fireEvent.click(screen.getByRole('button', { name: 'Save as Enabled' })); + + await waitFor(() => expect(screen.queryByText('← Back to list')).not.toBeInTheDocument()); + expect(screen.getByText('Test Hook')).toBeInTheDocument(); + }); + it('calls toggle enabled on checkbox click', async () => { mockedApi.getFanoutConfigs.mockResolvedValue([webhookConfig]); mockedApi.updateFanoutConfig.mockResolvedValue({ ...webhookConfig, enabled: false });