Files
frontend-miniapp/tests/e2e/guide-performance.spec.ts
lyf 9ea1bfab71
Some checks failed
CI / verify (push) Has been cancelled
同步 sgs-frontend-mobile 源码
2026-07-27 11:26:01 +08:00

77 lines
2.9 KiB
TypeScript

import { expect, test } from '@playwright/test'
interface GuidePerformanceSummary {
operationCount: number
operations: Array<{
kind: string
name: string
p50Ms?: number
p95Ms?: number
}>
}
interface GuidePerformanceApi {
snapshot: () => Array<{ kind: string; name: string; outcome: string }>
summary: () => GuidePerformanceSummary
}
test('publishes model and POI label performance metrics in the H5 runtime', async ({ page }) => {
await page.goto('/')
await page.waitForURL(/tab=guide/, { timeout: 30_000 })
await expect.poll(async () => page.evaluate(() => (
(window as Window & { __GUIDE_3D_VISUAL_STABILITY__?: { isInitialModelReady: () => boolean } })
.__GUIDE_3D_VISUAL_STABILITY__?.isInitialModelReady() || false
)), { timeout: 180_000 }).toBe(true)
await expect.poll(async () => page.evaluate(() => {
const api = (window as Window & { __SGS_GUIDE_PERFORMANCE__?: GuidePerformanceApi })
.__SGS_GUIDE_PERFORMANCE__
return api?.snapshot().some((record) => (
record.kind === 'interaction' && record.name === 'poi-label-first-render' && record.outcome === 'success'
)) || false
}), { timeout: 30_000 }).toBe(true)
const summary = await page.evaluate(() => (
(window as Window & { __SGS_GUIDE_PERFORMANCE__?: GuidePerformanceApi })
.__SGS_GUIDE_PERFORMANCE__?.summary()
))
expect(summary).toBeTruthy()
console.log(`[guide-performance] ${JSON.stringify(summary)}`)
expect(summary!.operationCount).toBeGreaterThan(0)
expect(summary!.operations).toEqual(expect.arrayContaining([
expect.objectContaining({
kind: 'model'
}),
expect.objectContaining({
kind: 'interaction',
name: 'poi-label-first-render'
})
]))
await page.getByText('+', { exact: true }).click()
await expect(page.locator('.floor-switcher')).toBeVisible({ timeout: 30_000 })
const targetFloor = page.locator('.floor-item:not(.active)').first()
await expect(targetFloor).toBeVisible({ timeout: 30_000 })
const targetFloorLabel = await targetFloor.locator('.floor-label').innerText()
await targetFloor.click()
await expect(page.locator('.floor-item.active .floor-label')).toHaveText(targetFloorLabel, {
timeout: 120_000
})
await page.locator('.search-box').click()
await expect(page.locator('[data-testid="poi-result-list"] .result-row').first())
.toBeVisible({ timeout: 30_000 })
const interactionSummary = await page.evaluate(() => (
(window as Window & { __SGS_GUIDE_PERFORMANCE__?: GuidePerformanceApi })
.__SGS_GUIDE_PERFORMANCE__?.summary()
))
console.log(`[guide-performance-interactions] ${JSON.stringify(interactionSummary)}`)
expect(interactionSummary?.operations).toEqual(expect.arrayContaining([
expect.objectContaining({ kind: 'interaction', name: 'floor-switch', successCount: 1 }),
expect.objectContaining({ kind: 'interaction', name: 'poi-search-data', successCount: 1 })
]))
})