test(176): cover RuleBuilder field-change operator/value reset

This commit is contained in:
2026-07-18 02:41:50 +02:00
parent ceb9069bae
commit 2763f65b35
@@ -49,4 +49,24 @@ describe('RuleBuilder', () => {
setup({ match: 'all', children: [{ field: 'type', operator: 'is', value: 'movie' }] });
expect(screen.getByRole('option', { name: 'episode' })).toBeInTheDocument();
});
it('resets operator and drops value/value2 when the field type changes', () => {
const onChange = vi.fn();
const fieldsWithNumber = [
{ name: 'genre', label: 'Genre', type: 'text' as const, group: 'General', values: [] },
{ name: 'minutes', label: 'Duration', type: 'number' as const, group: 'Technical', values: [] }
];
render(
<RuleBuilder
value={{ match: 'all', children: [{ field: 'minutes', operator: 'between', value: '10', value2: '90' }] }}
onChange={onChange}
fields={fieldsWithNumber}
/>
);
fireEvent.change(screen.getByLabelText('Field'), { target: { value: 'genre' } });
expect(onChange).toHaveBeenCalledWith({
match: 'all',
children: [{ field: 'genre', operator: 'is', value: '' }]
});
});
});