import { test, expect } from '@playwright/test'

test.describe('登录签名测试', () => {
  test('登录功能应该正常工作', async ({ page }) => {
    page.on('console', msg => {
      console.log('BROWSER CONSOLE:', msg.type(), msg.text())
    })
    
    page.on('pageerror', error => {
      console.error('PAGE ERROR:', error.message)
    })
    
    page.on('requestfailed', request => {
      console.error('REQUEST FAILED:', request.url(), request.failure()?.errorText)
    })
    
    await page.goto('/login')
    
    await page.fill('input[placeholder="请输入用户名"]', 'admin')
    await page.fill('input[placeholder="请输入密码"]', 'admin123')
    
    await page.click('button:has-text("登录")')
    
    await page.waitForURL('**/dashboard', { timeout: 10000 })
    
    console.log('Current URL after login:', page.url())
    
    const token = await page.evaluate(() => localStorage.getItem('token'))
    console.log('Token in localStorage:', token ? 'exists' : 'not found')
    
    expect(page.url()).toContain('/dashboard')
    expect(token).toBeTruthy()
  })
})
