library-picturebook-activity/lesingle-creation-frontend/e2e/admin/navigation.spec.ts
En 98e9ad1d28 feat(前端): 测试环境登录框支持自动填充测试账号
通过 VITE_AUTO_FILL_TEST 环境变量控制,在 .env.test 中启用,
使测试环境构建后登录框也能自动填充测试账号,方便测试人员使用。

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-11 17:03:22 +08:00

79 lines
2.8 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { test, expect } from '../fixtures/admin.fixture'
/**
* 侧边栏导航和路由守卫测试
*/
test.describe('侧边栏导航', () => {
test('N-01 侧边栏菜单渲染', async ({ adminPage }) => {
const page = adminPage
// 验证侧边栏 Logo 区域
await expect(page.locator('.logo-title-main')).toHaveText('乐绘世界')
// 验证菜单项存在Ant Design 菜单项)
const menuItems = page.locator('.ant-menu-item, .ant-menu-submenu')
const count = await menuItems.count()
expect(count).toBeGreaterThan(0)
})
test('N-02 菜单点击导航 - 工作台', async ({ adminPage }) => {
const page = adminPage
// 点击工作台菜单
await page.locator('.ant-menu-item').filter({ hasText: '工作台' }).first().click()
// 验证 URL 包含 dashboard
await page.waitForURL(/dashboard|workbench/, { timeout: 10_000 })
// 验证页面内容加载tenant-dashboard 和 welcome-banner 同时存在,需要指定其中一个)
await expect(page.locator('.tenant-dashboard')).toBeVisible({ timeout: 10_000 })
})
test('N-03 菜单点击导航 - 活动管理子菜单', async ({ adminPage }) => {
const page = adminPage
// 展开活动管理子菜单
const submenu = page.locator('.ant-menu-submenu').filter({ hasText: '活动管理' }).first()
await submenu.click()
// 等待子菜单展开
await page.waitForTimeout(500)
// 点击活动列表
const activityList = submenu.locator('.ant-menu-item').filter({ hasText: '活动列表' }).first()
await activityList.click()
// 验证跳转到活动列表页面
await page.waitForURL(/contests\/list/, { timeout: 10_000 })
await expect(page.locator('.contests-page')).toBeVisible({ timeout: 10_000 })
})
test('N-04 浏览器刷新保持状态', async ({ adminPage }) => {
const page = adminPage
// 确保在某个管理页面
await page.waitForURL(/gdlib/, { timeout: 5000 })
// 验证刷新前 Cookie 中有 token使用 document.cookie 检测)
const cookieStrBefore = await page.evaluate(() => document.cookie)
expect(cookieStrBefore).toContain('token=')
// 刷新页面
await page.reload({ waitUntil: 'networkidle' })
// 等待页面加载完成(路由守卫可能需要重新获取用户信息)
await page.waitForTimeout(3000)
// 验证 Cookie 中仍有 token
const cookieStrAfter = await page.evaluate(() => document.cookie)
expect(cookieStrAfter).toContain('token=')
// 验证页面已渲染(管理端或登录页二选一)
const hasSider = await page.locator('.custom-sider').isVisible({ timeout: 5_000 }).catch(() => false)
const hasLogin = await page.locator('.login-container').isVisible({ timeout: 3_000 }).catch(() => false)
// 至少应该渲染了某个页面
expect(hasSider || hasLogin).toBe(true)
})
})