Back to main fanout screen on save

This commit is contained in:
Jack Kingsman
2026-03-06 18:20:53 -08:00
parent f82cadb4e1
commit 94546f90a4
2 changed files with 39 additions and 2 deletions

View File

@@ -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');

View File

@@ -54,6 +54,18 @@ function renderSection(overrides?: { health?: HealthStatus }) {
);
}
function renderSectionWithRefresh(
onHealthRefresh: () => Promise<void>,
overrides?: { health?: HealthStatus }
) {
return render(
<SettingsFanoutSection
health={overrides?.health ?? baseHealth}
onHealthRefresh={onHealthRefresh}
/>
);
}
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 });