Files
OpenFlare/frontend/app/(main)/waf/rules/editor/components/node-properties.test.tsx
T
ryan a1a997bcda feat(waf): complete composable rule orchestration
Add the React Flow rule editor, ordered graph APIs and runtime DAG execution.\n\nPublish rules only on OpenResty reload and reconcile checksum-driven IP group snapshots in bounded shared memory.
2026-07-13 14:17:15 +08:00

35 lines
2.0 KiB
TypeScript

import {fireEvent, render, screen} from '@testing-library/react';
import {expect, it, vi} from 'vitest';
import type {WAFIPGroup, WAFRuleNode} from '@/lib/services/openflare';
import {NodeProperties} from './node-properties';
it('edits IP group config through a typed multi-select', async () => {
const node: WAFRuleNode = {id: 'match', type: 'ip_match', position: {x: 0, y: 0}, config: {ips: [], cidrs: [], ip_group_ids: []}};
const group = {id: 7, name: '办公室出口'} as WAFIPGroup;
const onChange = vi.fn();
render(<NodeProperties node={node} ipGroups={[group]} onChange={onChange}/>);
fireEvent.click(screen.getByRole('button', {name: 'IP 组'}));
fireEvent.click(await screen.findByText('办公室出口'));
expect(onChange).toHaveBeenCalledWith(expect.objectContaining({config: expect.objectContaining({ip_group_ids: [7]})}));
});
it('associates numeric property labels and constrains server ranges', () => {
const node: WAFRuleNode = {id: 'pow', type: 'pow', position: {x: 0, y: 0}, config: {algorithm: 'fast', difficulty: 4, session_ttl: 60, challenge_ttl: 30}};
render(<NodeProperties node={node} ipGroups={[]} onChange={vi.fn()}/>);
expect(screen.getByLabelText('难度')).toHaveAttribute('min', '1');
expect(screen.getByLabelText('难度')).toHaveAttribute('max', '16');
expect(screen.getByLabelText('会话 TTL(秒)')).toHaveAttribute('min', '60');
});
it('creates any normalized valid geography code', async () => {
const node: WAFRuleNode = {id: 'geo', type: 'geo_match', position: {x: 0, y: 0}, config: {countries: [], regions: []}};
const onChange = vi.fn();
render(<NodeProperties node={node} ipGroups={[]} onChange={onChange}/>);
fireEvent.click(screen.getByRole('button', {name: '国家代码'}));
fireEvent.change(await screen.findByPlaceholderText('输入代码并添加'), {target: {value: 'nz'}});
fireEvent.click(screen.getByRole('button', {name: '添加代码'}));
expect(onChange).toHaveBeenCalledWith(expect.objectContaining({config: expect.objectContaining({countries: ['NZ']})}));
});