Files
3x-ui/frontend/src/test/dns-server-port-field.test.tsx
T
Sanaei c392f367e1 fix(dns): stop offering a port field that DoH entries discard
Xray ignores port for DoH/DoHL/DoQL, so valuesToWire deliberately stores none
for an encrypted address and a non-standard port has to go inside the URL. The
form kept offering the field anyway, pre-filled with the 53 from its own
defaults: a port typed there was dropped on save and redrawn as 53 on reopen,
which reads as the panel losing the value.

Render the port field only where it is actually stored. DoT keeps it, since
tls:// is not an encrypted-address scheme for this purpose.

Closes #6403
2026-09-09 00:47:18 +02:00

48 lines
1.4 KiB
TypeScript

import { describe, expect, it } from 'vitest';
import { fireEvent, screen } from '@testing-library/react';
import DnsServerModal from '@/pages/xray/dns/DnsServerModal';
import { renderWithProviders } from './test-utils';
describe('DnsServerModal port field', () => {
it('hides the port for an encrypted address, whose port lives in the URL', () => {
renderWithProviders(
<DnsServerModal
open
server="https://dns.example.com/dns-query"
isEdit
onClose={() => {}}
onConfirm={() => {}}
/>,
);
expect(screen.queryByLabelText('Port')).toBeNull();
});
it('offers the port for a plain address and for DoT', () => {
renderWithProviders(
<DnsServerModal
open
server="tls://dns.example.com"
isEdit
onClose={() => {}}
onConfirm={() => {}}
/>,
);
expect(screen.getByLabelText('Port')).toBeTruthy();
});
it('drops the port field as soon as the address becomes a DoH URL', () => {
renderWithProviders(
<DnsServerModal open server="1.1.1.1" isEdit onClose={() => {}} onConfirm={() => {}} />,
);
expect(screen.getByLabelText('Port')).toBeTruthy();
fireEvent.change(screen.getByLabelText('Address'), {
target: { value: 'https://dns.example.com/dns-query' },
});
expect(screen.queryByLabelText('Port')).toBeNull();
});
});