feat(tests): enhance test coverage and error handling across various components

- Added a test case in CrowdSecConfig to show improved error message when preset is not cached.
- Introduced a new test suite for the Dashboard component, verifying counts and health status.
- Updated SMTPSettings tests to utilize a shared render function and added tests for backend validation errors.
- Modified Security.audit tests to improve input handling and removed redundant export failure test.
- Refactored Security tests to remove export functionality and ensure correct rendering of components.
- Enhanced UsersPage tests with new scenarios for updating user permissions and manual invite link flow.
- Created a new utility for rendering components with a QueryClient and MemoryRouter for better test isolation.
- Updated go-test-coverage script to improve error handling and coverage reporting.
This commit is contained in:
GitHub Actions
2025-12-11 00:26:07 +00:00
parent ca4cfc4e65
commit e299aa6b52
81 changed files with 8960 additions and 450 deletions

View File

@@ -0,0 +1,34 @@
import { QueryClient, QueryClientProvider, QueryClientConfig } from '@tanstack/react-query'
import { ReactNode } from 'react'
import { MemoryRouter, MemoryRouterProps } from 'react-router-dom'
import { render } from '@testing-library/react'
const defaultConfig: QueryClientConfig = {
defaultOptions: {
queries: { retry: false, refetchOnWindowFocus: false },
mutations: { retry: false },
},
}
export const createTestQueryClient = (config: QueryClientConfig = defaultConfig) => new QueryClient(config)
interface RenderOptions {
client?: QueryClient
routeEntries?: MemoryRouterProps['initialEntries']
}
export const renderWithQueryClient = (ui: ReactNode, options: RenderOptions = {}) => {
const queryClient = options.client ?? createTestQueryClient()
const routeEntries = options.routeEntries ?? ['/']
const wrapper = ({ children }: { children: ReactNode }) => (
<QueryClientProvider client={queryClient}>
<MemoryRouter initialEntries={routeEntries}>{children}</MemoryRouter>
</QueryClientProvider>
)
return {
queryClient,
...render(<>{ui}</>, { wrapper }),
}
}