2026-04-09 12:52:39 +08:00
|
|
|
|
import { test, expect } from '../fixtures/admin.fixture'
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 侧边栏导航和路由守卫测试
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
test.describe('侧边栏导航', () => {
|
|
|
|
|
|
test('N-01 侧边栏菜单渲染', async ({ adminPage }) => {
|
|
|
|
|
|
const page = adminPage
|
|
|
|
|
|
|
|
|
|
|
|
// 验证侧边栏 Logo 区域
|
2026-04-11 19:30:26 +08:00
|
|
|
|
await expect(page.locator('.logo-title-main')).toHaveText('智创未来')
|
2026-04-09 12:52:39 +08:00
|
|
|
|
|
|
|
|
|
|
// 验证菜单项存在(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)
|
|
|
|
|
|
})
|
|
|
|
|
|
})
|