2026-12-03 16:30:53 +08:00
|
|
|
|
import type { Locator } from '@playwright/test'
|
2026-12-03 11:19:22 +08:00
|
|
|
|
import { expect, test } from '../../fixtures'
|
|
|
|
|
|
|
|
|
|
|
|
test.use({ fileOptions: { mediaType: 'video' } })
|
|
|
|
|
|
|
|
|
|
|
|
test('reads, searches and follows a saved transcript in the video player', async ({
|
|
|
|
|
|
file,
|
|
|
|
|
|
prisma,
|
|
|
|
|
|
}) => {
|
|
|
|
|
|
const { page, projectId, fileId } = file
|
2026-12-03 16:00:41 +08:00
|
|
|
|
await page.setViewportSize({ width: 1280, height: 720 })
|
2026-12-03 11:19:22 +08:00
|
|
|
|
await expect
|
|
|
|
|
|
.poll(() =>
|
|
|
|
|
|
prisma.asset.findUnique({
|
|
|
|
|
|
where: { id: fileId },
|
|
|
|
|
|
select: { status: true, media: true },
|
|
|
|
|
|
}),
|
|
|
|
|
|
)
|
|
|
|
|
|
.toMatchObject({ status: 'processed', media: { proxyType: 'video' } })
|
|
|
|
|
|
|
|
|
|
|
|
await prisma.assetTranscript.create({
|
|
|
|
|
|
data: {
|
|
|
|
|
|
assetId: fileId,
|
|
|
|
|
|
language: 'en',
|
|
|
|
|
|
model: 'whisper-tiny',
|
|
|
|
|
|
workflowTaskId: 'english-test',
|
|
|
|
|
|
segments: {
|
|
|
|
|
|
create: [
|
|
|
|
|
|
{ position: 0, startMs: 0, endMs: 180, text: 'Signal. signal.' },
|
|
|
|
|
|
...Array.from({ length: 28 }, (_, index) => ({
|
|
|
|
|
|
position: index + 1,
|
|
|
|
|
|
startMs: 300 + index * 12,
|
|
|
|
|
|
endMs: 312 + index * 12,
|
|
|
|
|
|
text: `Intervening segment ${index + 1}`,
|
|
|
|
|
|
})),
|
|
|
|
|
|
{ position: 29, startMs: 720, endMs: 980, text: 'Final signal.' },
|
2026-12-03 15:25:28 +08:00
|
|
|
|
{ position: 30, startMs: 995, endMs: 1000, text: 'Closing word.' },
|
2026-12-03 11:19:22 +08:00
|
|
|
|
],
|
|
|
|
|
|
},
|
|
|
|
|
|
},
|
|
|
|
|
|
})
|
|
|
|
|
|
await prisma.assetTranscript.create({
|
|
|
|
|
|
data: {
|
|
|
|
|
|
assetId: fileId,
|
|
|
|
|
|
language: 'zh',
|
|
|
|
|
|
model: 'whisper-tiny',
|
|
|
|
|
|
workflowTaskId: 'chinese-test',
|
|
|
|
|
|
segments: { create: { position: 0, startMs: 0, endMs: 700, text: '你好。' } },
|
|
|
|
|
|
},
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
await page.goto(`/projects/${projectId}/files/${fileId}`)
|
|
|
|
|
|
const toggle = page.getByRole('button', { name: 'Show transcript' })
|
|
|
|
|
|
const navigator = page.getByRole('link', { name: 'Preview', exact: true })
|
|
|
|
|
|
await expect(navigator).toBeVisible()
|
|
|
|
|
|
await toggle.click()
|
|
|
|
|
|
const panel = page.getByRole('complementary', { name: 'Transcript' })
|
2026-12-03 16:30:53 +08:00
|
|
|
|
const divider = page.getByRole('separator', { name: 'Resize transcript' })
|
2026-12-03 11:19:22 +08:00
|
|
|
|
const first = panel.getByRole('button', { name: /Signal\. signal\./ })
|
|
|
|
|
|
const last = panel.getByRole('button', { name: /Final signal\./ })
|
|
|
|
|
|
const video = page.locator('video').first()
|
|
|
|
|
|
const sync = panel.getByRole('button', { name: 'Sync to playback' })
|
|
|
|
|
|
await expect(navigator).toBeHidden()
|
2026-12-03 16:00:41 +08:00
|
|
|
|
await expect(panel).toHaveCSS('width', '384px')
|
2026-12-03 11:19:22 +08:00
|
|
|
|
await expect(toggle).toHaveAttribute('aria-expanded', 'true')
|
2026-12-03 16:00:41 +08:00
|
|
|
|
await expect(toggle).toHaveCSS('cursor', 'pointer')
|
2026-12-03 11:19:22 +08:00
|
|
|
|
await expect(first).toHaveAttribute('aria-current', 'true')
|
2026-12-03 16:00:41 +08:00
|
|
|
|
await expect(first.getByText('Signal. signal.', { exact: true })).toHaveCSS('font-weight', '700')
|
|
|
|
|
|
await expect(first).toHaveCSS('background-color', 'rgba(0, 0, 0, 0)')
|
2026-12-03 11:19:22 +08:00
|
|
|
|
await expect(first).toContainText('00:00.000 – 00:00.180')
|
|
|
|
|
|
|
2026-12-03 16:30:53 +08:00
|
|
|
|
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()
|
|
|
|
|
|
|
2026-12-03 11:19:22 +08:00
|
|
|
|
await panel.getByRole('button', { name: 'Search transcript' }).click()
|
|
|
|
|
|
const search = panel.getByRole('searchbox', { name: 'Search transcript' })
|
|
|
|
|
|
await expect(search).toBeFocused()
|
|
|
|
|
|
await search.fill('SIGNAL.')
|
|
|
|
|
|
await expect(panel.getByText('1 / 3')).toBeVisible()
|
2026-12-03 16:00:41 +08:00
|
|
|
|
const match = panel.locator('[data-current-match]')
|
|
|
|
|
|
await expect(match).toHaveCSS('padding-left', '1px')
|
|
|
|
|
|
await expect(match).toHaveCSS('padding-right', '1px')
|
2026-12-03 11:19:22 +08:00
|
|
|
|
await panel.getByRole('button', { name: 'Next match' }).click()
|
|
|
|
|
|
await expect(panel.getByText('2 / 3')).toBeVisible()
|
|
|
|
|
|
await search.press('Enter')
|
|
|
|
|
|
await expect(panel.getByText('3 / 3')).toBeVisible()
|
|
|
|
|
|
await expect(last).toBeInViewport()
|
|
|
|
|
|
await expect(first).toHaveAttribute('aria-current', 'true')
|
|
|
|
|
|
await last.click()
|
|
|
|
|
|
await expect(last).toHaveAttribute('aria-current', 'true')
|
|
|
|
|
|
await expect
|
|
|
|
|
|
.poll(() => video.evaluate((element) => (element as HTMLVideoElement).currentTime))
|
|
|
|
|
|
.toBeCloseTo(0.72, 1)
|
|
|
|
|
|
await expect(video).toHaveJSProperty('paused', true)
|
|
|
|
|
|
await panel.getByRole('button', { name: 'Next match' }).click()
|
|
|
|
|
|
await expect(panel.getByText('1 / 3')).toBeVisible()
|
|
|
|
|
|
await panel.getByRole('button', { name: 'Previous match' }).click()
|
|
|
|
|
|
await expect(panel.getByText('3 / 3')).toBeVisible()
|
|
|
|
|
|
await search.fill('unmatched')
|
|
|
|
|
|
await expect(panel.getByText('0 / 0')).toBeVisible()
|
|
|
|
|
|
await search.press('Escape')
|
|
|
|
|
|
await expect(search).toBeHidden()
|
|
|
|
|
|
await sync.click()
|
|
|
|
|
|
await expect(sync).toBeHidden()
|
|
|
|
|
|
|
|
|
|
|
|
await viewport.hover()
|
|
|
|
|
|
await page.mouse.wheel(0, -2500)
|
|
|
|
|
|
await expect(sync).toBeVisible()
|
|
|
|
|
|
await expect(last).not.toBeInViewport()
|
|
|
|
|
|
await expect(last).toHaveAttribute('aria-current', 'true')
|
|
|
|
|
|
await sync.click()
|
|
|
|
|
|
await expect(last).toBeInViewport()
|
|
|
|
|
|
await expect(sync).toBeHidden()
|
|
|
|
|
|
|
|
|
|
|
|
await video.evaluate((element) => {
|
|
|
|
|
|
const media = element as HTMLVideoElement
|
|
|
|
|
|
media.currentTime = 0.22
|
|
|
|
|
|
})
|
|
|
|
|
|
await expect(panel.locator('[aria-current=true]')).toHaveCount(0)
|
|
|
|
|
|
await video.evaluate((element) => {
|
|
|
|
|
|
const media = element as HTMLVideoElement
|
|
|
|
|
|
media.currentTime = 0
|
|
|
|
|
|
})
|
|
|
|
|
|
await expect(first).toHaveAttribute('aria-current', 'true')
|
|
|
|
|
|
await expect(first).toBeInViewport()
|
|
|
|
|
|
await video.evaluate(async (element) => {
|
|
|
|
|
|
const media = element as HTMLVideoElement
|
|
|
|
|
|
media.playbackRate = 0.5
|
|
|
|
|
|
await media.play()
|
|
|
|
|
|
})
|
|
|
|
|
|
await expect(last).toBeInViewport()
|
|
|
|
|
|
await expect(sync).toBeHidden()
|
|
|
|
|
|
await expect(video).toHaveJSProperty('ended', true)
|
|
|
|
|
|
await last.press('Enter')
|
|
|
|
|
|
await expect(last).toHaveAttribute('aria-current', 'true')
|
|
|
|
|
|
await expect(video).toHaveJSProperty('paused', true)
|
|
|
|
|
|
|
2026-12-03 15:25:28 +08:00
|
|
|
|
const closingWord = panel.getByRole('button', { name: /Closing word\./ })
|
|
|
|
|
|
await closingWord.click()
|
|
|
|
|
|
await expect
|
|
|
|
|
|
.poll(() =>
|
|
|
|
|
|
video.evaluate((element) => {
|
|
|
|
|
|
const media = element as HTMLVideoElement
|
|
|
|
|
|
return { seeking: media.seeking, timeMs: Math.round(media.currentTime * 1000) }
|
|
|
|
|
|
}),
|
|
|
|
|
|
)
|
|
|
|
|
|
.toEqual({ seeking: false, timeMs: 995 })
|
|
|
|
|
|
await expect(closingWord).toHaveAttribute('aria-current', 'true')
|
|
|
|
|
|
await expect(video).toHaveJSProperty('paused', true)
|
|
|
|
|
|
|
2026-12-03 11:19:22 +08:00
|
|
|
|
await panel.getByRole('combobox', { name: 'Language' }).selectOption('zh')
|
|
|
|
|
|
await expect(panel.getByText('你好。')).toBeVisible()
|
|
|
|
|
|
await expect(last).toHaveCount(0)
|
2026-12-03 16:30:53 +08:00
|
|
|
|
await dragDivider(divider, 64)
|
|
|
|
|
|
await expect(panel).toHaveCSS('width', '448px')
|
2026-12-03 11:19:22 +08:00
|
|
|
|
await panel.getByRole('button', { name: 'Close transcript' }).click()
|
|
|
|
|
|
await expect(panel).toBeHidden()
|
|
|
|
|
|
await expect(navigator).toBeVisible()
|
|
|
|
|
|
await expect(toggle).toBeFocused()
|
2026-12-03 16:30:53 +08:00
|
|
|
|
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()
|
2026-12-03 11:19:22 +08:00
|
|
|
|
|
|
|
|
|
|
await page.setViewportSize({ width: 390, height: 844 })
|
|
|
|
|
|
const comments = page.getByTestId('mobile-bottom-sheet')
|
|
|
|
|
|
await expect(comments).toBeVisible()
|
|
|
|
|
|
await toggle.click()
|
|
|
|
|
|
await expect(panel).toBeVisible()
|
|
|
|
|
|
await expect(video).toBeVisible()
|
|
|
|
|
|
await expect(comments).toBeHidden()
|
|
|
|
|
|
await panel.getByRole('button', { name: 'Close transcript' }).click()
|
|
|
|
|
|
await expect(comments).toBeVisible()
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
test('uses the displayed video version and hides the toggle for versions without a transcript', async ({
|
|
|
|
|
|
file,
|
|
|
|
|
|
prisma,
|
|
|
|
|
|
}) => {
|
|
|
|
|
|
const { page, projectId, fileId, rootFolderId } = file
|
|
|
|
|
|
await expect
|
|
|
|
|
|
.poll(() =>
|
|
|
|
|
|
prisma.asset.findUnique({
|
|
|
|
|
|
where: { id: fileId },
|
|
|
|
|
|
select: { status: true, media: true },
|
|
|
|
|
|
}),
|
|
|
|
|
|
)
|
|
|
|
|
|
.toMatchObject({ status: 'processed', media: { proxyType: 'video' } })
|
|
|
|
|
|
const latest = await prisma.asset.findUniqueOrThrow({ where: { id: fileId } })
|
|
|
|
|
|
if (!latest.media) throw new Error('Expected processed video media')
|
|
|
|
|
|
const stack = await prisma.asset.create({
|
|
|
|
|
|
data: {
|
|
|
|
|
|
projectId,
|
|
|
|
|
|
parentId: rootFolderId,
|
|
|
|
|
|
name: latest.name,
|
|
|
|
|
|
type: 'version_stack',
|
|
|
|
|
|
status: 'processed',
|
|
|
|
|
|
fileCount: 2,
|
|
|
|
|
|
},
|
|
|
|
|
|
})
|
|
|
|
|
|
await prisma.asset.update({
|
|
|
|
|
|
where: { id: fileId },
|
|
|
|
|
|
data: { parentId: stack.id, sortIndex: 'a0' },
|
|
|
|
|
|
})
|
|
|
|
|
|
const old = await prisma.asset.create({
|
|
|
|
|
|
data: {
|
|
|
|
|
|
projectId,
|
|
|
|
|
|
parentId: stack.id,
|
|
|
|
|
|
name: 'Earlier video.mp4',
|
|
|
|
|
|
type: 'file',
|
|
|
|
|
|
status: 'processed',
|
|
|
|
|
|
mediaType: latest.mediaType,
|
|
|
|
|
|
storageKeyId: latest.storageKeyId,
|
|
|
|
|
|
media: latest.media,
|
|
|
|
|
|
sizeByte: latest.sizeByte,
|
|
|
|
|
|
sortIndex: 'a1',
|
|
|
|
|
|
},
|
|
|
|
|
|
})
|
|
|
|
|
|
await prisma.assetTranscript.create({
|
|
|
|
|
|
data: {
|
|
|
|
|
|
assetId: fileId,
|
|
|
|
|
|
language: 'en',
|
|
|
|
|
|
model: 'whisper-tiny',
|
|
|
|
|
|
workflowTaskId: 'latest-version-test',
|
|
|
|
|
|
segments: {
|
|
|
|
|
|
create: { position: 0, startMs: 0, endMs: 950, text: 'Latest version text' },
|
|
|
|
|
|
},
|
|
|
|
|
|
},
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
const stackUrl = `/projects/${projectId}/files/${stack.id}`
|
|
|
|
|
|
await page.goto(stackUrl)
|
|
|
|
|
|
const toggle = page.getByRole('button', { name: 'Show transcript' })
|
|
|
|
|
|
await toggle.click()
|
|
|
|
|
|
const panel = page.getByRole('complementary', { name: 'Transcript' })
|
|
|
|
|
|
await expect(panel.getByText('Latest version text')).toBeVisible()
|
|
|
|
|
|
|
|
|
|
|
|
const [languages] = await Promise.all([
|
|
|
|
|
|
page.waitForResponse(`**/api/files/${old.id}/transcripts`),
|
|
|
|
|
|
page.goto(`${stackUrl}?version=${old.id}`),
|
|
|
|
|
|
])
|
|
|
|
|
|
expect(await languages.json()).toEqual({ languages: [] })
|
|
|
|
|
|
await expect(panel).toBeHidden()
|
|
|
|
|
|
await expect(toggle).toBeHidden()
|
|
|
|
|
|
})
|