[优化] 代码优化

This commit is contained in:
ryan
2026-06-01 08:56:23 +08:00
parent 95d7045b4a
commit 77ad3ea7e3
6 changed files with 48 additions and 16 deletions
@@ -246,4 +246,46 @@ describe('WAF IP groups', () => {
expect(await screen.findByText(/IP组: edge blacklist/)).toBeInTheDocument();
});
it('defaults new rule entries to blacklist', async () => {
vi.stubGlobal(
'fetch',
vi.fn((input: RequestInfo | URL) => {
const url = String(input);
if (url.includes('/waf/rule-groups')) {
return Promise.resolve(
new Response(
JSON.stringify({
success: true,
message: '',
data: [buildRuleGroup()],
}),
),
);
}
if (url.includes('/waf/ip-groups') || url.includes('/proxy-routes/')) {
return Promise.resolve(
new Response(
JSON.stringify({ success: true, message: '', data: [] }),
),
);
}
return Promise.reject(new Error(`Unhandled fetch: ${url}`));
}),
);
renderWithProviders(<WAFPage />);
await userEvent.click(
await screen.findByRole('button', { name: /黑白名单/ }),
);
await userEvent.click(screen.getByRole('button', { name: /添加/ }));
expect(
await screen.findByRole('heading', { name: '添加黑名单规则' }),
).toBeInTheDocument();
});
});