mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-12-03 14:34:40 +00:00
228 lines
8.0 KiB
TypeScript
228 lines
8.0 KiB
TypeScript
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
|
||
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.' },
|
||
{ position: 30, startMs: 995, endMs: 1000, text: 'Closing word.' },
|
||
],
|
||
},
|
||
},
|
||
})
|
||
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' })
|
||
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()
|
||
await expect(toggle).toHaveAttribute('aria-expanded', 'true')
|
||
await expect(first).toHaveAttribute('aria-current', 'true')
|
||
await expect(first).toContainText('00:00.000 – 00:00.180')
|
||
|
||
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()
|
||
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()
|
||
|
||
const viewport = panel.locator('[data-slot=scroll-area-viewport]')
|
||
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)
|
||
|
||
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)
|
||
|
||
await panel.getByRole('combobox', { name: 'Language' }).selectOption('zh')
|
||
await expect(panel.getByText('你好。')).toBeVisible()
|
||
await expect(last).toHaveCount(0)
|
||
await panel.getByRole('button', { name: 'Close transcript' }).click()
|
||
await expect(panel).toBeHidden()
|
||
await expect(navigator).toBeVisible()
|
||
await expect(toggle).toBeFocused()
|
||
|
||
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()
|
||
})
|