basics-tab-direct-tag.test.tsx 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import { screen } from '@testing-library/react';
  2. import { describe, expect, it, vi } from 'vitest';
  3. import BasicsTab from '@/pages/xray/basics/BasicsTab';
  4. import type { XraySettingsValue } from '@/hooks/useXraySetting';
  5. import { renderWithProviders } from './test-utils';
  6. function renderBasics(outbounds: Record<string, unknown>[]) {
  7. renderWithProviders(
  8. <BasicsTab
  9. templateSettings={{ outbounds } as unknown as XraySettingsValue}
  10. setTemplateSettings={vi.fn()}
  11. outboundTestUrl=""
  12. onChangeOutboundTestUrl={vi.fn()}
  13. onResetDefault={vi.fn()}
  14. />,
  15. );
  16. return {
  17. strategy: screen.getByRole('combobox', { name: 'Freedom Protocol Strategy' }),
  18. happyEyeballs: screen.getByRole('switch', { name: 'Freedom Happy Eyeballs (IPv4/IPv6)' }),
  19. };
  20. }
  21. // Both setters drop the edit when a non-freedom outbound holds "direct", so
  22. // the controls must say so instead of snapping back silently.
  23. describe('BasicsTab with the direct tag held by a foreign outbound', () => {
  24. it('disables the freedom controls', () => {
  25. const { strategy, happyEyeballs } = renderBasics([
  26. { protocol: 'socks', tag: 'direct', settings: { servers: [] } },
  27. ]);
  28. expect(strategy).toHaveProperty('disabled', true);
  29. expect(happyEyeballs).toHaveProperty('disabled', true);
  30. });
  31. it('keeps them enabled when freedom holds the tag, whatever its spelling', () => {
  32. const { strategy, happyEyeballs } = renderBasics([
  33. { protocol: 'Freedom', tag: 'direct', settings: {} },
  34. ]);
  35. expect(strategy).toHaveProperty('disabled', false);
  36. expect(happyEyeballs).toHaveProperty('disabled', false);
  37. });
  38. });