Files
prompt-optimizer/tests/e2e/helpers/common.ts
linshen 90b957c983 feat(image): deliver multi-image generation workflow
- add multi-image request types, routing, favorites integration, and desktop bridges
- support multimodal streaming prompt optimization with ordered image inputs
- enable Seedream multi-image generation and redesign the multi-image workspace
- add coverage for routing, persistence, workspace guards, and end-to-end flows
2026-04-06 14:13:28 +08:00

69 lines
2.5 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.
import { expect, type Page } from '@playwright/test'
/**
* 等待应用加载完成
*/
export async function waitForAppReady(page: Page): Promise<void> {
await expect(page.locator('.loading-container')).toHaveCount(0, { timeout: 15000 })
await expect(page.locator('#app, [id="app"], main')).toBeAttached()
}
/**
* 导航到指定模式
* @description 先访问根路径等待应用初始化,再导航到目标路由
*/
export async function navigateToMode(
page: Page,
mode: 'basic' | 'pro' | 'image',
subMode: string
): Promise<void> {
// 模拟真实用户:从 / 进入,由 RootBootstrapRoute 决定初始工作区,
// 然后通过顶部 CoreNav 切换到目标模式/子模式。
await page.goto('/', { waitUntil: 'domcontentloaded' })
await waitForAppReady(page)
// RootBootstrapRoute 会把 / 重定向到某个 workspace等到 workspace 出现即可。
await expect(page.locator('[data-testid="workspace"]').first()).toBeVisible({ timeout: 20000 })
await switchModeViaUI(page, mode, subMode)
// ✅ 验证 URL 正确
await expect(page).toHaveURL(new RegExp(`\\/#\\/${mode}\\/${subMode}$`), { timeout: 20000 })
}
export async function switchModeViaUI(
page: Page,
mode: 'basic' | 'pro' | 'image',
subMode: string
): Promise<void> {
// 功能模式basic/pro/image
const functionModeSelector = page.getByTestId('function-mode-selector')
await expect(functionModeSelector).toBeVisible({ timeout: 20000 })
// 不依赖按钮文案i18n 会变),直接按 data-testid 点击
await functionModeSelector.getByTestId(`function-mode-${mode}`).click()
// 子模式basic: system/user, pro: multi/variable, image: text2image/image2image
// image 子模式使用按钮组,不是 radio-group分别处理。
if (mode === 'image') {
const coreNav = page.getByTestId('core-nav')
const idMap: Record<string, string> = {
text2image: 'image-sub-mode-text2image',
image2image: 'image-sub-mode-image2image',
multiimage: 'image-sub-mode-multiimage',
}
const id = idMap[subMode]
if (!id) {
throw new Error(`Unsupported image sub mode for e2e navigation: ${subMode}`)
}
await coreNav.getByTestId(id).click()
return
}
const subModeSelector = page.getByTestId('optimization-mode-selector')
await expect(subModeSelector).toBeVisible({ timeout: 20000 })
// 不依赖按钮文案i18n 会变),直接按 data-testid 点击
await subModeSelector.getByTestId(`sub-mode-${subMode}`).click()
}