Files
3x-ui/frontend/src/test/attach-clients-modal.test.tsx
T
Younes Beriane d4a7086c4e fix(inbounds): list clients in the detach/attach modals when they mount open (#6736)
* fix(inbounds): list clients in the detach modal when it mounts open

DetachClientsModal seeded its synced-source state with the open source,
so a modal first mounted with open and a source saw no change on its
first render and never read the client rows. The table stayed empty
until the modal was closed and reopened.

Seed the state with null so the first open render loads the rows, as
the reset-during-render check already expects. The test mounts the
modal already open and fails without this change.

Fixes #6733

* fix(inbounds): list clients in the attach modal when it mounts open

AttachClientsModal seeds its synced-source state the same way
DetachClientsModal did, so a modal first mounted with open and a source
saw no change on its first render and never read the client rows. The
table stayed empty, and nothing was pre-selected, until the modal was
closed and reopened.

Seed the state with null here too. The test mounts the attach modal
already open and fails without this change.

Refs #6733

---------

Co-authored-by: Sanaei <ho3ein.sanaei@gmail.com>
2026-10-05 15:27:56 +02:00

44 lines
1.3 KiB
TypeScript

import { describe, expect, it } from 'vitest';
import { screen } from '@testing-library/react';
import AttachClientsModal from '@/pages/inbounds/clients/AttachClientsModal';
import { DBInbound } from '@/models/dbinbound';
import { renderWithProviders } from './test-utils';
function sourceInbound() {
return new DBInbound({
id: 7,
port: 443,
listen: '',
protocol: 'vless',
remark: 'edge',
enable: true,
settings: JSON.stringify({
clients: [
{ id: 'uuid-1', email: 'alice@test' },
{ id: 'uuid-2', email: 'bob@test' },
],
decryption: 'none',
}),
streamSettings: JSON.stringify({ network: 'tcp', security: 'none' }),
sniffing: '',
});
}
describe('AttachClientsModal', () => {
it('lists the source clients, selected, when first mounted already open', async () => {
renderWithProviders(
<AttachClientsModal open source={sourceInbound()} dbInbounds={[]} onClose={() => {}} />,
);
expect(await screen.findByText('alice@test')).toBeTruthy();
expect(screen.getByText('bob@test')).toBeTruthy();
const boxes = screen.getAllByRole('checkbox') as HTMLInputElement[];
const rowBoxes = boxes.slice(1);
expect(rowBoxes).toHaveLength(2);
expect(rowBoxes.every((b) => b.checked)).toBe(true);
});
});