admin.spec.ts 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. import { test, expect } from '@playwright/test'
  2. const ADMIN_USER = 'admin'
  3. const ADMIN_PASS = 'admin123'
  4. test.describe('数字能量学管理平台 E2E', () => {
  5. test('登录 → 仪表盘 → 用户 → 提现 → 配置 全流程', async ({ page }) => {
  6. // ===== 1. 登录页 =====
  7. await page.goto('/login')
  8. await expect(page.locator('.login-title')).toHaveText('数字能量学管理平台')
  9. // 输入登录信息
  10. await page.getByPlaceholder('用户名').fill(ADMIN_USER)
  11. await page.getByPlaceholder('密码').fill(ADMIN_PASS)
  12. await page.getByRole('button', { name: '登 录' }).click()
  13. // 等待跳转到仪表盘
  14. await page.waitForURL('**/dashboard')
  15. // 验证登录成功的 toast
  16. await expect(page.getByText('登录成功')).toBeVisible()
  17. // ===== 2. 仪表盘 =====
  18. // 等待加载完成(统计卡片出现)
  19. await page.waitForTimeout(1000)
  20. const statCards = page.locator('.stat-card')
  21. await expect(statCards.first()).toBeVisible()
  22. // 应有 4 张统计卡片
  23. await expect(statCards).toHaveCount(4)
  24. // 验证图表容器存在
  25. await expect(page.locator('.chart-row')).toBeVisible()
  26. // 验证最近订单表格存在
  27. await expect(page.locator('.recent-orders')).toBeVisible()
  28. // ===== 3. 用户管理 =====
  29. await page.click('text=用户管理')
  30. await page.waitForURL('**/users')
  31. await page.waitForTimeout(800)
  32. // 用户列表应有表格
  33. const userTable = page.locator('.el-table')
  34. await expect(userTable).toBeVisible()
  35. // ===== 4. 提现管理 =====
  36. await page.click('text=提现管理')
  37. await page.waitForURL('**/withdraw')
  38. await page.waitForTimeout(800)
  39. await expect(page.locator('.el-table')).toBeVisible()
  40. // ===== 5. 系统配置 =====
  41. await page.click('text=系统配置')
  42. await page.waitForURL('**/settings')
  43. await page.waitForTimeout(800)
  44. // 配置页面应有配置卡片
  45. await expect(page.locator('.config-card').first()).toBeVisible()
  46. // 应有 4 组配置卡片
  47. await expect(page.locator('.config-card')).toHaveCount(4)
  48. // ===== 6. 退出登录 =====
  49. // 侧边栏底部应有退出按钮
  50. const logoutBtn = page.locator('text=退出登录')
  51. if (await logoutBtn.isVisible()) {
  52. await logoutBtn.click()
  53. // 应跳回登录页
  54. await page.waitForURL('**/login')
  55. await expect(page.locator('.login-title')).toBeVisible()
  56. }
  57. })
  58. test('未登录访问受保护页面应跳转到登录页', async ({ page }) => {
  59. // 清除 localStorage 中的 token
  60. await page.goto('/dashboard')
  61. // 无 token,应被路由守卫拦截跳转到登录页
  62. await page.waitForURL('**/login')
  63. await expect(page.locator('.login-title')).toHaveText('数字能量学管理平台')
  64. })
  65. test('错误密码应显示提示', async ({ page }) => {
  66. await page.goto('/login')
  67. await page.getByPlaceholder('用户名').fill(ADMIN_USER)
  68. await page.getByPlaceholder('密码').fill('wrong_password')
  69. await page.getByRole('button', { name: '登 录' }).click()
  70. // 应显示错误消息(使用 Pinia action 中的错误处理或 ElMessage)
  71. // 页面应仍然在登录页
  72. await expect(page.locator('.login-title')).toBeVisible()
  73. })
  74. })