import { fireEvent, render, screen } from '@testing-library/react';
import { expect, test } from 'vitest';
import { PasswordInput } from './PasswordInput';

test('uses a localized Semi UI visibility control without losing the password value', () => {
  render(<PasswordInput aria-label="登录密码" visibilityLabel="登录密码" defaultValue="Secret!123" />);

  const input = screen.getByLabelText('登录密码');
  expect(input).toHaveAttribute('type', 'password');
  expect(input).toHaveValue('Secret!123');

  fireEvent.click(screen.getByRole('button', { name: '显示登录密码' }));
  expect(input).toHaveAttribute('type', 'text');
  expect(input).toHaveValue('Secret!123');
  expect(screen.getByRole('button', { name: '隐藏登录密码' })).toHaveAttribute('aria-pressed', 'true');

  fireEvent.click(screen.getByRole('button', { name: '隐藏登录密码' }));
  expect(input).toHaveAttribute('type', 'password');
});
