import { describe, it, expect, vi, beforeEach } from 'vitest';
import { screen } from '@testing-library/react';

// 隔离网络：版本取数返回空列表，避免 act 警告与真实请求
vi.mock('../../src/api/usrApi', () => ({
  fetchCompanies: vi.fn().mockResolvedValue([]),
  login: vi.fn(),
}));

import LoginPage from '../../src/pages/usr/Login/LoginPage';
import { renderWithProviders } from './renderLogin';

describe('LoginPage 布局', () => {
  beforeEach(() => {
    localStorage.clear();
  });

  it('renders brand header / hero slogan / footer', () => {
    renderWithProviders(<LoginPage />);
    expect(screen.getByText('Antler ERP')).toBeInTheDocument();
    expect(screen.getByText('欢迎登录EBC平台')).toBeInTheDocument();
    expect(screen.getByText('企业业务能力平台')).toBeInTheDocument();
    expect(screen.getByText('ERP')).toBeInTheDocument();
    // 页脚版权 + 备案号
    expect(screen.getByText(/Antler Software/)).toBeInTheDocument();
    expect(screen.getByText(/沪ICP备14034791号-1/)).toBeInTheDocument();
  });

  it('renders login card title 用户登录', () => {
    renderWithProviders(<LoginPage />);
    expect(screen.getByText('用户登录')).toBeInTheDocument();
  });

  it('renders username/password/version fields and submit button 登 录', () => {
    renderWithProviders(<LoginPage />);
    const username = screen.getByPlaceholderText('请输入你的用户名');
    expect(username).toBeInTheDocument();
    const password = screen.getByPlaceholderText('请输入你的密码');
    expect(password).toBeInTheDocument();
    // BR3：密码掩码显示
    expect(password).toHaveAttribute('type', 'password');
    // 版本下拉 placeholder（idle 后为「请选择版本」，初始 loading 为「加载版本中…」）
    expect(
      screen.getByText((t) => t.includes('请选择版本') || t.includes('加载版本中')),
    ).toBeInTheDocument();
    // 提交按钮
    expect(screen.getByRole('button', { name: /登\s*录/ })).toBeInTheDocument();
  });
});
