mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-07-16 09:36:07 +00:00
5f7c2424ef
The rule form rebuilt the rule from a fixed literal of only the fields it edits, and RoutingTab replaces the rule wholesale on confirm. Fields the form never exposes — localPort, localIP, process, ruleTag, webhook — are in the rule schema and can arrive via the advanced JSON editor or Import Rules; opening such a rule in the form and saving silently dropped them. Carry over every key of the original rule the form does not manage before applying the form-derived fields, so an edit only touches what it surfaces.
34 lines
1.2 KiB
TypeScript
34 lines
1.2 KiB
TypeScript
import { describe, it, expect, vi } from 'vitest';
|
|
import { fireEvent, screen } from '@testing-library/react';
|
|
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
|
|
|
|
import RuleFormModal from '@/pages/xray/routing/RuleFormModal';
|
|
|
|
import { renderWithProviders } from './test-utils';
|
|
|
|
describe('RuleFormModal edit preserves unsurfaced fields', () => {
|
|
it('keeps a field the form does not surface (ruleTag) when saving an edit', () => {
|
|
const onConfirm = vi.fn();
|
|
const queryClient = new QueryClient({ defaultOptions: { queries: { retry: false } } });
|
|
|
|
renderWithProviders(
|
|
<QueryClientProvider client={queryClient}>
|
|
<RuleFormModal
|
|
open
|
|
rule={{ type: 'field', outboundTag: 'block', ruleTag: 'my-tag', enabled: true }}
|
|
inboundTags={[]}
|
|
outboundTags={['block']}
|
|
balancerTags={[]}
|
|
onClose={vi.fn()}
|
|
onConfirm={onConfirm}
|
|
/>
|
|
</QueryClientProvider>,
|
|
);
|
|
|
|
fireEvent.click(screen.getByRole('button', { name: 'Save Changes' }));
|
|
|
|
expect(onConfirm).toHaveBeenCalledTimes(1);
|
|
expect(onConfirm.mock.calls[0][0]).toMatchObject({ ruleTag: 'my-tag' });
|
|
});
|
|
});
|