|
|
@@ -5,6 +5,7 @@ const mediaPaths = [
|
|
|
'/Users/samien/.hermes/profiles/yaoer/cache/images/国漫三视图.png',
|
|
|
]
|
|
|
const mediaNames = mediaPaths.map(path => path.split('/').at(-1)!)
|
|
|
+const mediaLabels = ['3D 半写实女性四视图', '国漫三视图']
|
|
|
|
|
|
async function signIn(request: APIRequestContext, origin: string) {
|
|
|
const bootstrap = await (await request.get('/api/app/bootstrap')).json()
|
|
|
@@ -25,7 +26,10 @@ async function signIn(request: APIRequestContext, origin: string) {
|
|
|
|
|
|
async function expectDecodedImage(image: Locator) {
|
|
|
await expect(image).toBeVisible()
|
|
|
- await expect.poll(() => image.evaluate(element => (element as HTMLImageElement).naturalWidth)).toBeGreaterThan(0)
|
|
|
+ await expect.poll(() => image.evaluate(element => {
|
|
|
+ const img = element instanceof HTMLImageElement ? element : element.querySelector('img')
|
|
|
+ return img?.naturalWidth ?? 0
|
|
|
+ })).toBeGreaterThan(0)
|
|
|
}
|
|
|
|
|
|
test('loads Hermes profile cache images through the Web server and switches their full-size previews', async ({ page, baseURL }, testInfo) => {
|
|
|
@@ -38,7 +42,7 @@ test('loads Hermes profile cache images through the Web server and switches thei
|
|
|
await page.goto('/chat/session-media?profile=yaoer')
|
|
|
await expect(page).toHaveTitle('瑶儿生成图片验收 · 夭夭 AI')
|
|
|
|
|
|
- for (const [index, name] of mediaNames.entries()) {
|
|
|
+ for (const [index, name] of mediaLabels.entries()) {
|
|
|
const image = page.getByRole('button', { name: `预览图片 ${name}`, exact: true })
|
|
|
await image.scrollIntoViewIfNeeded()
|
|
|
await expectDecodedImage(image)
|
|
|
@@ -50,23 +54,24 @@ test('loads Hermes profile cache images through the Web server and switches thei
|
|
|
expect(new URL(response.url()).searchParams.get('profile')).toBe('yaoer')
|
|
|
}
|
|
|
|
|
|
- await page.getByRole('button', { name: `预览图片 ${mediaNames[0]}`, exact: true }).click()
|
|
|
- const preview = page.locator('.image-preview-overlay')
|
|
|
+ await page.getByRole('button', { name: `预览图片 ${mediaLabels[0]}`, exact: true }).click()
|
|
|
+ const preview = page.getByRole('dialog')
|
|
|
await expect(preview).toHaveAccessibleName(`预览 ${mediaNames[0]}`)
|
|
|
await expectDecodedImage(preview.getByRole('img', { name: mediaNames[0], exact: true }))
|
|
|
- await expect(preview.locator('.image-preview-counter')).toHaveText('1 / 2')
|
|
|
+ await expect(preview.getByRole('button', { name: '下一张媒体' })).toBeVisible()
|
|
|
|
|
|
await preview.getByRole('button', { name: '下一张媒体' }).click()
|
|
|
await expect(preview).toHaveAccessibleName(`预览 ${mediaNames[1]}`)
|
|
|
const secondPreview = preview.getByRole('img', { name: mediaNames[1], exact: true })
|
|
|
await expectDecodedImage(secondPreview)
|
|
|
expect(new URL(await secondPreview.getAttribute('src') || '', baseURL).searchParams.get('path')).toBe(mediaPaths[1])
|
|
|
- await expect(preview.locator('.image-preview-counter')).toHaveText('2 / 2')
|
|
|
+ await expect(preview.getByRole('button', { name: '上一张媒体' })).toBeVisible()
|
|
|
+ await expect(preview.getByRole('button', { name: '下一张媒体' })).toBeHidden()
|
|
|
|
|
|
await page.keyboard.press('ArrowLeft')
|
|
|
await expect(preview).toHaveAccessibleName(`预览 ${mediaNames[0]}`)
|
|
|
await expectDecodedImage(preview.getByRole('img', { name: mediaNames[0], exact: true }))
|
|
|
- await expect(preview.locator('.image-preview-counter')).toHaveText('1 / 2')
|
|
|
+ await expect(preview.getByRole('button', { name: '下一张媒体' })).toBeVisible()
|
|
|
await page.screenshot({ path: testInfo.outputPath('hermes-profile-cache-preview.png') })
|
|
|
await page.keyboard.press('Escape')
|
|
|
await expect(preview).toBeHidden()
|
|
|
@@ -114,14 +119,13 @@ test('server permissions reject a previously readable image and retry succeeds a
|
|
|
await policy('folders')
|
|
|
try {
|
|
|
await page.goto('/chat/session-media?profile=yaoer')
|
|
|
- const failure=page.getByRole('alert').filter({hasText:mediaNames[0]})
|
|
|
- await expect(failure).toContainText('文件访问')
|
|
|
- await expect(failure.getByRole('button',{name:'重试',exact:true})).toBeVisible()
|
|
|
+ const failure=page.getByRole('button',{name:`${mediaLabels[0]} · 加载失败,点击重试`,exact:true})
|
|
|
+ await expect(failure).toBeVisible()
|
|
|
const denied=await page.request.get('/api/files/download',{params:{path:mediaPaths[0]!,profile:'yaoer',preview:'1'}})
|
|
|
expect(denied.status()).toBe(403)
|
|
|
await policy('all')
|
|
|
- await failure.getByRole('button',{name:'重试',exact:true}).click()
|
|
|
- await expectDecodedImage(page.getByRole('button',{name:`预览图片 ${mediaNames[0]}`,exact:true}))
|
|
|
+ await failure.click()
|
|
|
+ await expectDecodedImage(page.getByRole('button',{name:`预览图片 ${mediaLabels[0]}`,exact:true}))
|
|
|
await expect(failure).toHaveCount(0)
|
|
|
} finally {await policy('all')}
|
|
|
})
|