mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-10-01 06:36:38 +08:00
db3f9b0c0a
- Removed summary cards from Managed Domains, Nodes, Proxy Routes, TLS Certificates, Users pages to streamline UI. - Updated Nodes and Proxy Routes pages to enhance action buttons and descriptions. - Added new runtime configuration options for rate limiting in Settings page, allowing for dynamic updates. - Updated documentation to reflect new runtime configurations and their effects. - Enhanced unit tests for DashboardOverview to include mock data for comprehensive coverage.
120 lines
3.3 KiB
TypeScript
120 lines
3.3 KiB
TypeScript
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
|
|
import { render, screen } from '@testing-library/react';
|
|
import { afterEach, describe, expect, it, vi } from 'vitest';
|
|
|
|
import { DashboardOverview } from '@/features/dashboard/components/dashboard-overview';
|
|
|
|
describe('DashboardOverview', () => {
|
|
afterEach(() => {
|
|
vi.unstubAllGlobals();
|
|
});
|
|
|
|
it('renders dashboard summary cards', async () => {
|
|
vi.stubGlobal(
|
|
'fetch',
|
|
vi.fn((input: RequestInfo | URL) => {
|
|
const url = String(input);
|
|
|
|
if (url.includes('/nodes/')) {
|
|
return Promise.resolve(
|
|
new Response(
|
|
JSON.stringify({
|
|
success: true,
|
|
message: '',
|
|
data: [{ id: 1, status: 'online', auto_update_enabled: true }],
|
|
}),
|
|
),
|
|
);
|
|
}
|
|
|
|
if (url.includes('/config-versions/')) {
|
|
return Promise.resolve(
|
|
new Response(
|
|
JSON.stringify({
|
|
success: true,
|
|
message: '',
|
|
data: [{ id: 1, version: '20260311-001', is_active: true, created_at: '2026-03-11T10:00:00Z' }],
|
|
}),
|
|
),
|
|
);
|
|
}
|
|
|
|
if (url.includes('/managed-domains/')) {
|
|
return Promise.resolve(
|
|
new Response(
|
|
JSON.stringify({
|
|
success: true,
|
|
message: '',
|
|
data: [{ id: 1, domain: '*.example.com', enabled: true, cert_id: 1 }],
|
|
}),
|
|
),
|
|
);
|
|
}
|
|
|
|
if (url.includes('/tls-certificates/')) {
|
|
return Promise.resolve(
|
|
new Response(
|
|
JSON.stringify({
|
|
success: true,
|
|
message: '',
|
|
data: [
|
|
{
|
|
id: 1,
|
|
name: 'example',
|
|
not_after: '2026-04-01T00:00:00Z',
|
|
updated_at: '2026-03-10T10:00:00Z',
|
|
},
|
|
],
|
|
}),
|
|
),
|
|
);
|
|
}
|
|
|
|
if (url.includes('/proxy-routes/')) {
|
|
return Promise.resolve(
|
|
new Response(
|
|
JSON.stringify({
|
|
success: true,
|
|
message: '',
|
|
data: [{ id: 1, enabled: true, enable_https: true, custom_headers: '[{"key":"X-Test","value":"1"}]' }],
|
|
}),
|
|
),
|
|
);
|
|
}
|
|
|
|
if (url.includes('/user/search')) {
|
|
return Promise.resolve(
|
|
new Response(
|
|
JSON.stringify({
|
|
success: true,
|
|
message: '',
|
|
data: [{ id: 1, role: 100, status: 1, username: 'root' }],
|
|
}),
|
|
),
|
|
);
|
|
}
|
|
|
|
return Promise.reject(new Error(`Unhandled fetch: ${url}`));
|
|
}),
|
|
);
|
|
|
|
const queryClient = new QueryClient({
|
|
defaultOptions: {
|
|
queries: {
|
|
retry: false,
|
|
},
|
|
},
|
|
});
|
|
|
|
render(
|
|
<QueryClientProvider client={queryClient}>
|
|
<DashboardOverview />
|
|
</QueryClientProvider>,
|
|
);
|
|
|
|
expect(screen.getByText('控制台仪表盘')).toBeInTheDocument();
|
|
expect(await screen.findByText('节点摘要')).toBeInTheDocument();
|
|
expect(await screen.findByText('用户概览')).toBeInTheDocument();
|
|
});
|
|
});
|