2026-12-02 22:12:33 +08:00
|
|
|
import { expect, test } from '../../fixtures'
|
|
|
|
|
import { fileCard } from '../../helpers/files'
|
2026-12-03 16:00:41 +08:00
|
|
|
import type { TranscriptJobStatus } from '@shumai/dtos'
|
2026-12-02 22:12:33 +08:00
|
|
|
|
|
|
|
|
test.use({ fileOptions: { mediaType: 'video' } })
|
|
|
|
|
|
|
|
|
|
test('selects a transcription language from the video context menu and tracks the job', async ({
|
|
|
|
|
file,
|
|
|
|
|
prisma,
|
|
|
|
|
}) => {
|
|
|
|
|
const { page, projectId, fileId, fileName } = file
|
2026-12-03 16:00:41 +08:00
|
|
|
let status: TranscriptJobStatus = { taskId: 'previous-transcript', status: 'completed' }
|
|
|
|
|
const expectedLanguages = ['zh', 'en']
|
|
|
|
|
let submissions = 0
|
2026-12-02 22:12:33 +08:00
|
|
|
await page.route('**/api/signup-info', async (route) => {
|
|
|
|
|
const response = await route.fetch()
|
|
|
|
|
await route.fulfill({ json: { ...(await response.json()), transcriptionEnabled: true } })
|
|
|
|
|
})
|
|
|
|
|
await page.route('**/api/transcription/languages', (route) =>
|
|
|
|
|
route.fulfill({
|
|
|
|
|
json: {
|
|
|
|
|
model: 'whisper-tiny',
|
|
|
|
|
languages: [
|
|
|
|
|
{ code: 'en', name: 'English' },
|
|
|
|
|
{ code: 'zh', name: 'Chinese' },
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
}),
|
|
|
|
|
)
|
|
|
|
|
await page.route(`**/api/files/${fileId}/transcription-status`, (route) =>
|
2026-12-03 16:00:41 +08:00
|
|
|
route.fulfill({ json: status }),
|
2026-12-02 22:12:33 +08:00
|
|
|
)
|
|
|
|
|
await page.route(`**/api/files/${fileId}/transcripts`, async (route) => {
|
2026-12-03 16:00:41 +08:00
|
|
|
expect(route.request().postDataJSON()).toEqual({ language: expectedLanguages[submissions] })
|
|
|
|
|
const taskId = `transcript-task-${++submissions}`
|
|
|
|
|
status = { taskId, status: 'processing' }
|
|
|
|
|
await route.fulfill({ status: 202, json: { kind: 'queued', taskId } })
|
2026-12-02 22:12:33 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
await expect
|
|
|
|
|
.poll(() =>
|
|
|
|
|
prisma.asset.findUnique({
|
|
|
|
|
where: { id: fileId },
|
|
|
|
|
select: { status: true, media: true },
|
|
|
|
|
}),
|
|
|
|
|
)
|
|
|
|
|
.toMatchObject({ status: 'processed', media: { proxyType: 'video' } })
|
2026-12-03 21:05:40 +08:00
|
|
|
await prisma.asset.update({ where: { id: fileId }, data: { status: 'processing' } })
|
2026-12-02 22:12:33 +08:00
|
|
|
const [signupInfo] = await Promise.all([
|
|
|
|
|
page.waitForResponse('**/api/signup-info'),
|
|
|
|
|
page.goto(`/projects/${projectId}`),
|
|
|
|
|
])
|
|
|
|
|
expect(await signupInfo.json()).toMatchObject({ transcriptionEnabled: true })
|
2026-12-03 21:05:40 +08:00
|
|
|
const action = page.getByRole('menuitem', { name: 'Generate Transcripts' })
|
|
|
|
|
await fileCard(page, fileName).click({ button: 'right' })
|
|
|
|
|
await expect(action).toBeDisabled()
|
|
|
|
|
await prisma.asset.update({ where: { id: fileId }, data: { status: 'processed' } })
|
|
|
|
|
await page.reload()
|
2026-12-03 16:00:41 +08:00
|
|
|
const openDialog = async () => {
|
|
|
|
|
await fileCard(page, fileName).click({ button: 'right' })
|
2026-12-03 21:05:40 +08:00
|
|
|
await action.click()
|
2026-12-03 16:00:41 +08:00
|
|
|
}
|
|
|
|
|
await openDialog()
|
2026-12-02 22:12:33 +08:00
|
|
|
const dialog = page.getByRole('dialog', { name: 'Generate Transcripts' })
|
|
|
|
|
const language = dialog.getByRole('combobox', { name: 'Language' })
|
2026-12-03 16:00:41 +08:00
|
|
|
const generate = dialog.getByRole('button', { name: 'Generate', exact: true })
|
|
|
|
|
await expect(dialog.getByRole('status')).toHaveText('Transcript generated.')
|
2026-12-02 22:12:33 +08:00
|
|
|
await expect(language).toHaveValue('Auto')
|
|
|
|
|
await language.fill('Chi')
|
|
|
|
|
await dialog.getByRole('option', { name: 'Chinese' }).click()
|
|
|
|
|
await expect(language).toHaveValue('Chinese')
|
2026-12-03 16:00:41 +08:00
|
|
|
await generate.click()
|
|
|
|
|
await expect(dialog.getByRole('status')).toHaveText('Generating transcript…')
|
|
|
|
|
await dialog.getByRole('button', { name: 'Close', exact: true }).click()
|
|
|
|
|
await expect(dialog).toBeHidden()
|
|
|
|
|
status = { taskId: status.taskId, status: 'completed' }
|
|
|
|
|
|
|
|
|
|
await openDialog()
|
|
|
|
|
await expect(generate).toBeEnabled()
|
|
|
|
|
await language.fill('Eng')
|
|
|
|
|
await dialog.getByRole('option', { name: 'English' }).click()
|
|
|
|
|
await generate.click()
|
|
|
|
|
await expect(dialog.getByRole('status')).toHaveText('Generating transcript…')
|
|
|
|
|
status = { taskId: status.taskId, status: 'completed' }
|
|
|
|
|
await expect(dialog).toBeHidden()
|
|
|
|
|
await expect(page.getByText('Transcript generated.', { exact: true })).toBeVisible()
|
2026-12-02 22:12:33 +08:00
|
|
|
})
|