feat(ui/alerts): silence + notification query hooks

This commit is contained in:
hsiegeln
2026-04-20 13:16:57 +02:00
parent c6c3dd9cfe
commit 51bc796bec
3 changed files with 194 additions and 0 deletions

View File

@@ -0,0 +1,39 @@
import { describe, it, expect, beforeEach, vi } from 'vitest';
import { renderHook, waitFor } from '@testing-library/react';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import type { ReactNode } from 'react';
import { useEnvironmentStore } from '../environment-store';
vi.mock('../client', () => ({
api: { GET: vi.fn(), POST: vi.fn(), PUT: vi.fn(), DELETE: vi.fn() },
}));
import { api as apiClient } from '../client';
import { useAlertSilences } from './alertSilences';
function wrapper({ children }: { children: ReactNode }) {
const qc = new QueryClient({
defaultOptions: {
queries: { retry: false },
mutations: { retry: false },
},
});
return <QueryClientProvider client={qc}>{children}</QueryClientProvider>;
}
describe('useAlertSilences', () => {
beforeEach(() => {
vi.clearAllMocks();
useEnvironmentStore.setState({ environment: 'dev' });
});
it('fetches silences for selected env', async () => {
(apiClient.GET as any).mockResolvedValue({ data: [], error: null });
const { result } = renderHook(() => useAlertSilences(), { wrapper });
await waitFor(() => expect(result.current.isSuccess).toBe(true));
expect(apiClient.GET).toHaveBeenCalledWith(
'/environments/{envSlug}/alerts/silences',
{ params: { path: { envSlug: 'dev' } } },
);
});
});