Files
prompt-optimizer/tests/e2e/workflows/route-initialization.spec.ts
linshen 204c5d9816 feat(ui): 提升可访问性并稳定 Pro Multi 流程
- 提升 UI 组件可访问性与导航交互一致性\n- 稳定 Pro Multi 消息优化流程,降低 E2E flake
2026-01-13 21:17:00 +08:00

115 lines
3.7 KiB
TypeScript
Raw Permalink 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.
/**
* 路由初始化测试 - 验证所有下拉框都有值
*
* 功能:
* - 验证各个路由初始化后,模型选择下拉框和提示词模板下拉框都有选项
* - 确保数据加载正常,避免空状态
*
* 测试范围:
* - Basic 模式basic-system, basic-user
* - Pro 模式pro-multi, pro-variable
* - Image 模式text2image, image2image
*/
import { test, expect } from '../fixtures'
import { navigateToMode } from '../helpers/common'
type RouteCase = {
name: string
mode: 'basic' | 'pro' | 'image'
subMode: string
hashPath: string
modelLabel: RegExp
templateLabel: RegExp
}
const ROUTES: RouteCase[] = [
{
name: 'basic-system',
mode: 'basic' as const,
subMode: 'system' as const,
hashPath: '/#/basic/system',
modelLabel: /优化模型|Optimization Model/i,
templateLabel: /优化提示词模板|Optimization Template/i,
},
{
name: 'basic-user',
mode: 'basic' as const,
subMode: 'user' as const,
hashPath: '/#/basic/user',
modelLabel: /优化模型|Optimization Model/i,
templateLabel: /优化提示词模板|Optimization Template/i,
},
{
name: 'pro-multi',
mode: 'pro' as const,
subMode: 'multi' as const,
hashPath: '/#/pro/multi',
modelLabel: /优化模型|Optimization Model/i,
templateLabel: /优化提示词模板|Optimization Template/i,
},
{
name: 'pro-variable',
mode: 'pro' as const,
subMode: 'variable' as const,
hashPath: '/#/pro/variable',
modelLabel: /优化模型|Optimization Model/i,
templateLabel: /优化提示词模板|Optimization Template/i,
},
{
name: 'image-text2image',
mode: 'image' as const,
subMode: 'text2image' as const,
hashPath: '/#/image/text2image',
modelLabel: /Text Model|文本模型|优化模型|Optimization Model/i,
templateLabel: /Optimization Template|优化.*模板/i,
},
{
name: 'image-image2image',
mode: 'image' as const,
subMode: 'image2image' as const,
hashPath: '/#/image/image2image',
modelLabel: /Text Model|文本模型|优化模型|Optimization Model/i,
templateLabel: /Optimization Template|优化.*模板/i,
},
]
/**
* 验证下拉框有选项
* @description 检查 Naive UI Select 组件是否渲染了选项
*/
async function expectSelectHasOptions(page: Parameters<typeof test>[0]['page'], label: RegExp): Promise<void> {
const labelNode = page.getByText(label).first()
await expect(labelNode).toBeVisible({ timeout: 15000 })
// 找到包含该 label 的最近选择器容器Naive UI NSelect 会渲染 .n-base-selection
const container = labelNode.locator(
'xpath=ancestor::*[.//div[contains(@class,"n-base-selection")]][1]'
)
const select = container.locator('.n-base-selection').first()
await expect(select).toBeVisible({ timeout: 15000 })
await select.click()
// 有选项时会渲染 .n-base-select-option空态会渲染 empty slot
const firstOption = page.locator('.n-base-select-option').first()
await expect(firstOption).toBeVisible({ timeout: 15000 })
const optionCount = await page.locator('.n-base-select-option').count()
expect(optionCount).toBeGreaterThan(0)
await page.keyboard.press('Escape')
}
test.describe('Route Initialization: 模型/模板下拉框有值', () => {
for (const route of ROUTES) {
test(route.name, async ({ page }) => {
// ✅ 使用 navigateToMode 导航(从 / 进入,再通过 UI 切换到目标工作区)
await navigateToMode(page, route.mode, route.subMode)
// ✅ 验证模型和模板下拉框都加载了选项
await expectSelectHasOptions(page, route.modelLabel)
await expectSelectHasOptions(page, route.templateLabel)
})
}
})