Files
frontend-miniapp/tests/e2e/explain-hall-page.spec.ts
lyf 5a711377b0
Some checks failed
CI / verify (push) Has been cancelled
优化讲解展厅与对象列表视觉
2026-07-18 01:16:30 +08:00

68 lines
3.1 KiB
TypeScript

import { expect, test } from '@playwright/test'
const stops = Array.from({ length: 21 }, (_, index) => ({
stopId: `stop-${index + 1}`,
name: `讲解对象${index + 1}`,
imageStatus: index === 0 ? 'READY' : 'MISSING',
coverImageUrl: index === 0 ? '/one.jpg' : undefined,
audioStatus: index === 0 ? 'READY' : 'MISSING',
hasAudio: index === 0,
hasTextRecord: index !== 0,
playTargetType: 'STOP' as const,
playTargetId: `target-${index + 1}`
}))
test('hall goes directly to paged guide objects without outline requests', async ({ page }) => {
const requests: string[] = []
await page.route('**/app-api/gis/guide/catalog/**', async (route) => {
const url = route.request().url()
requests.push(url)
if (url.includes('/catalog/halls?')) {
await route.fulfill({ json: { code: 0, data: [{ id: 'hall-1', name: '恐龙厅', floorId: 'L1', stopCount: 21 }] } })
return
}
if (url.includes('/halls/hall-1/stops/page')) {
const pageNo = new URL(url).searchParams.get('pageNo')
await route.fulfill({ json: { code: 0, data: { total: 21, list: pageNo === '1' ? stops.slice(0, 20) : stops.slice(20) } } })
return
}
await route.fulfill({ status: 404, json: { code: 404, msg: 'unexpected request' } })
})
await page.goto('/#/pages/explain/list')
await page.getByText('恐龙厅', { exact: true }).click()
await expect(page).toHaveURL(/guide-stop-list\?hallId=hall-1/)
await expect(page.getByText('讲解对象1', { exact: true })).toBeVisible()
const cards = page.locator('.stop-card')
await expect(cards).toHaveCount(20)
for (const width of [375, 390, 430]) {
await page.setViewportSize({ width, height: 844 })
const layout = await page.locator('.stop-list').evaluate((list) => {
const cards = Array.from(list.querySelectorAll<HTMLElement>('.stop-card'))
const listRect = list.getBoundingClientRect()
const firstRect = cards[0].getBoundingClientRect()
const secondRect = cards[1].getBoundingClientRect()
return {
clientWidth: list.clientWidth,
scrollWidth: list.scrollWidth,
listWidth: listRect.width,
first: { x: firstRect.x, width: firstRect.width, bottom: firstRect.bottom },
second: { x: secondRect.x, y: secondRect.y }
}
})
expect(layout.scrollWidth).toBeLessThanOrEqual(layout.clientWidth)
expect(layout.first.x).toBeCloseTo(layout.second.x, 0)
expect(layout.first.width).toBeCloseTo(layout.listWidth, 0)
expect(layout.second.y).toBeGreaterThan(layout.first.bottom)
}
await expect(page.getByRole('textbox')).toHaveCount(0)
await expect(page.locator('.filter-chip')).toHaveCount(0)
await page.locator('.explain-scroll').hover()
await page.mouse.wheel(0, 10000)
await expect(page.getByText('讲解对象21', { exact: true })).toBeVisible()
await page.getByText('讲解对象1', { exact: true }).click()
await expect(page).toHaveURL(/pages\/exhibit\/detail\?.*targetType=STOP.*targetId=target-1/)
expect(requests.some((url) => url.includes('/outlines'))).toBe(false)
expect(requests.filter((url) => url.includes('/stops/page')).map((url) => new URL(url).searchParams.get('pageNo'))).toEqual(['1', '2'])
})