mirror of
https://github.com/jkingsman/Remote-Terminal-for-MeshCore.git
synced 2026-03-28 17:43:05 +01:00
Back to main fanout screen on save
This commit is contained in:
@@ -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');
|
||||
|
||||
@@ -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 });
|
||||
|
||||
Reference in New Issue
Block a user