import { renderToStaticMarkup } from 'react-dom/server';
import { describe, expect, it, vi } from 'vitest';
import { AuthPanel } from './AuthPanel';

const baseProps = {
  authMode: 'login' as const,
  externalToken: '',
  loginForm: { account: '', password: '' },
  registerForm: { username: '', email: '', password: '', displayName: '', invitationCode: '' },
  state: 'idle' as const,
  onAuthModeChange: vi.fn(),
  onExternalTokenChange: vi.fn(),
  onLoginChange: vi.fn(),
  onRegisterChange: vi.fn(),
  onSubmitExternalToken: vi.fn(),
  onSubmitLogin: vi.fn(),
  onSubmitRegister: vi.fn(),
  onOIDCLogin: vi.fn(),
};

describe('AuthPanel', () => {
  it('shows one unified authentication entry when OIDC is enabled', () => {
    const html = renderToStaticMarkup(<AuthPanel {...baseProps} oidcEnabled />);

    expect(html).toContain('使用统一认证登录');
    expect(html).not.toContain('使用平台账号登录');
    expect(html).not.toContain('使用租户账号登录');
    expect(html).not.toContain('用户名或邮箱');
    expect(html).not.toContain('注册账号');
    expect(html).not.toContain('外部 Token');
  });

  it('keeps the existing local login options when OIDC is disabled', () => {
    const html = renderToStaticMarkup(<AuthPanel {...baseProps} oidcEnabled={false} />);

    expect(html).toContain('账号登录');
    expect(html).toContain('注册账号');
    expect(html).toContain('外部 Token');
    expect(html).toContain('用户名或邮箱');
  });
});
