attach-clients-modal.test.tsx 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import { describe, expect, it } from 'vitest';
  2. import { screen } from '@testing-library/react';
  3. import AttachClientsModal from '@/pages/inbounds/clients/AttachClientsModal';
  4. import { DBInbound } from '@/models/dbinbound';
  5. import { renderWithProviders } from './test-utils';
  6. function sourceInbound() {
  7. return new DBInbound({
  8. id: 7,
  9. port: 443,
  10. listen: '',
  11. protocol: 'vless',
  12. remark: 'edge',
  13. enable: true,
  14. settings: JSON.stringify({
  15. clients: [
  16. { id: 'uuid-1', email: 'alice@test' },
  17. { id: 'uuid-2', email: 'bob@test' },
  18. ],
  19. decryption: 'none',
  20. }),
  21. streamSettings: JSON.stringify({ network: 'tcp', security: 'none' }),
  22. sniffing: '',
  23. });
  24. }
  25. describe('AttachClientsModal', () => {
  26. it('lists the source clients, selected, when first mounted already open', async () => {
  27. renderWithProviders(
  28. <AttachClientsModal open source={sourceInbound()} dbInbounds={[]} onClose={() => {}} />,
  29. );
  30. expect(await screen.findByText('alice@test')).toBeTruthy();
  31. expect(screen.getByText('bob@test')).toBeTruthy();
  32. const boxes = screen.getAllByRole('checkbox') as HTMLInputElement[];
  33. const rowBoxes = boxes.slice(1);
  34. expect(rowBoxes).toHaveLength(2);
  35. expect(rowBoxes.every((b) => b.checked)).toBe(true);
  36. });
  37. });