feat(video): resize transcripts and follow playback earlier

This commit is contained in:
yiling
2026-12-03 16:30:53 +08:00
parent 543862ff9b
commit ce4ae6e33e
10 changed files with 236 additions and 30 deletions
@@ -1,3 +1,4 @@
import type { Locator } from '@playwright/test'
import { expect, test } from '../../fixtures'
test.use({ fileOptions: { mediaType: 'video' } })
@@ -54,6 +55,7 @@ test('reads, searches and follows a saved transcript in the video player', async
await expect(navigator).toBeVisible()
await toggle.click()
const panel = page.getByRole('complementary', { name: 'Transcript' })
const divider = page.getByRole('separator', { name: 'Resize transcript' })
const first = panel.getByRole('button', { name: /Signal\. signal\./ })
const last = panel.getByRole('button', { name: /Final signal\./ })
const video = page.locator('video').first()
@@ -67,6 +69,56 @@ test('reads, searches and follows a saved transcript in the video player', async
await expect(first).toHaveCSS('background-color', 'rgba(0, 0, 0, 0)')
await expect(first).toContainText('00:00.000 – 00:00.180')
const dragDivider = async (handle: Locator, delta: number) => {
const box = await handle.boundingBox()
if (!box) throw new Error('Expected the divider to be visible')
const x = box.x + box.width / 2
const y = box.y + box.height / 2
await page.mouse.move(x, y)
await page.mouse.down()
await page.mouse.move(x + delta, y, { steps: 8 })
await page.mouse.up()
}
await dragDivider(divider, 256)
await expect(panel).toHaveCSS('width', '576px')
await dragDivider(divider, -384)
await expect(panel).toHaveCSS('width', '256px')
await divider.press('ArrowRight')
await expect(divider).toHaveAttribute('aria-valuenow', '21')
await divider.press('Home')
await expect(panel).toHaveCSS('width', '256px')
await dragDivider(divider, 128)
await expect(panel).toHaveCSS('width', '384px')
const viewport = panel.locator('[data-slot=scroll-area-viewport]')
const nearBottomId = await viewport.evaluate((element) => {
const view = element.getBoundingClientRect()
const nearBottom = Array.from(element.querySelectorAll('li[data-segment-id]')).find((row) => {
const { top, bottom } = row.getBoundingClientRect()
return top > view.top + view.height * 0.75 && bottom < view.bottom
})
return nearBottom?.getAttribute('data-segment-id')
})
if (!nearBottomId) throw new Error('Expected a visible segment in the bottom quarter')
const nearBottom = panel.locator(`[data-segment-id="${nearBottomId}"]`).getByRole('button')
await nearBottom.click()
await expect(nearBottom).toHaveAttribute('aria-current', 'true')
await expect
.poll(() =>
nearBottom.evaluate((element) => {
const view = element.closest('[data-slot=scroll-area-viewport]')!.getBoundingClientRect()
const row = element.getBoundingClientRect()
return (row.top + row.height / 2 - view.top) / view.height
}),
)
.toBeCloseTo(0.5, 1)
await video.evaluate((element) => {
const media = element as HTMLVideoElement
media.currentTime = 0
})
await expect(first).toHaveAttribute('aria-current', 'true')
await expect(first).toBeInViewport()
await panel.getByRole('button', { name: 'Search transcript' }).click()
const search = panel.getByRole('searchbox', { name: 'Search transcript' })
await expect(search).toBeFocused()
@@ -98,7 +150,6 @@ test('reads, searches and follows a saved transcript in the video player', async
await sync.click()
await expect(sync).toBeHidden()
const viewport = panel.locator('[data-slot=scroll-area-viewport]')
await viewport.hover()
await page.mouse.wheel(0, -2500)
await expect(sync).toBeVisible()
@@ -147,10 +198,27 @@ test('reads, searches and follows a saved transcript in the video player', async
await panel.getByRole('combobox', { name: 'Language' }).selectOption('zh')
await expect(panel.getByText('你好。')).toBeVisible()
await expect(last).toHaveCount(0)
await dragDivider(divider, 64)
await expect(panel).toHaveCSS('width', '448px')
await panel.getByRole('button', { name: 'Close transcript' }).click()
await expect(panel).toBeHidden()
await expect(navigator).toBeVisible()
await expect(toggle).toBeFocused()
await toggle.click()
await expect(panel).toHaveCSS('width', '448px')
const commentsDivider = page.locator('main [data-slot="resize-handle"]:not([role="separator"])')
await dragDivider(commentsDivider, -200)
await page.setViewportSize({ width: 840, height: 720 })
await expect
.poll(async () => Number(await divider.getAttribute('aria-valuemax')))
.toBeLessThan(20)
await divider.press('End')
await page.setViewportSize({ width: 1280, height: 720 })
await dragDivider(commentsDivider, 200)
await expect(panel).toHaveCSS('width', '448px')
await panel.getByRole('button', { name: 'Close transcript' }).click()
await page.setViewportSize({ width: 390, height: 844 })
const comments = page.getByTestId('mobile-bottom-sheet')