import { expect, test } from '../../fixtures' import { seedFolder } from '../../helpers/assets' import { fileCard } from '../../helpers/files' test.use({ fileOptions: { mediaType: 'video' } }) test('starts a transcript for an archived video and tracks it in the file metadata', async ({ file, prisma, }) => { const { page, projectId, rootFolderId, fileId, fileName } = file const projectPath = `/projects/${projectId}` const statusPath = `/api${projectPath}/transcription-status` const folder = await seedFolder(prisma, projectId, rootFolderId, 'Other folder') const expectedLanguages = ['zh-Hans', 'zh-Hant', 'en'] let submissions = 0 let rejectSubmission = true let statusRequests = 0 let transcriptionEnabled = false page.on('request', (request) => { if (new URL(request.url()).pathname === statusPath) { expect(request.method()).toBe('GET') expect(request.postData()).toBeNull() statusRequests++ } }) await page.route('**/api/signup-info', async (route) => { const response = await route.fetch() await route.fulfill({ json: { ...(await response.json()), transcriptionEnabled } }) }) await page.route('**/api/transcription/languages', (route) => route.fulfill({ json: { model: 'whisper-tiny', languages: [ { code: 'en', name: 'English' }, { code: 'zh-Hans', name: 'Simplified Chinese' }, { code: 'zh-Hant', name: 'Traditional Chinese' }, ], }, }), ) await page.route(`**/api/files/${fileId}/transcripts`, async (route) => { expect(route.request().postDataJSON()).toEqual({ language: expectedLanguages[submissions] }) if (rejectSubmission) { rejectSubmission = false await route.fulfill({ status: 503 }) return } const task = await prisma.workflowTask.create({ data: { projectId, assetId: fileId, type: 'ai_transcription', status: 'processing' }, }) submissions++ await route.fulfill({ status: 202, json: { kind: 'queued', taskId: task.id } }) }) await expect .poll(() => prisma.asset.findUnique({ where: { id: fileId }, select: { status: true, media: true }, }), ) .toMatchObject({ status: 'processed', media: { proxyType: 'video' } }) await prisma.asset.update({ where: { id: fileId }, data: { status: 'processing' } }) await page.goto(projectPath) const action = page.getByRole('menuitem', { name: 'Generate Transcripts' }) await fileCard(page, fileName).click({ button: 'right' }) await expect(page.getByRole('menu')).toBeVisible() await expect(action).toHaveCount(0) transcriptionEnabled = true const [signupInfo] = await Promise.all([ page.waitForResponse('**/api/signup-info'), page.goto(projectPath), ]) expect(await signupInfo.json()).toMatchObject({ transcriptionEnabled: true }) await fileCard(page, fileName).click({ button: 'right' }) await expect(action).toBeDisabled() await prisma.asset.update({ where: { id: fileId }, data: { status: 'archived' } }) const [idleStatus] = await Promise.all([page.waitForResponse(`**${statusPath}`), page.reload()]) expect(await idleStatus.json()).toEqual({ assetIds: [] }) const idleRequests = statusRequests await fileCard(page, folder.name).dblclick() await expect(page).toHaveURL(`${projectPath}/folders/${folder.id}`) await page.goBack() await expect(page).toHaveURL(projectPath) await expect(fileCard(page, fileName).getByTestId('file-card-archived-badge')).toBeVisible() expect(statusRequests).toBe(idleRequests) const openDialog = async () => { await fileCard(page, fileName).click({ button: 'right' }) await expect(action).toBeEnabled() await action.click() } await openDialog() const dialog = page.getByRole('dialog', { name: 'Generate Transcripts' }) const language = dialog.getByRole('combobox', { name: 'Language', exact: true }) const generate = dialog.getByRole('button', { name: 'Generate', exact: true }) const metadata = fileCard(page, fileName).getByTestId('file-card-metadata') const searchBox = dialog.getByRole('combobox', { name: 'Search languages' }) const dialogHeight = () => dialog.evaluate((element) => element.clientHeight) await expect(language).toBeEnabled() const closedHeight = await dialogHeight() await language.press('ArrowDown') await expect(dialog.getByRole('option', { name: 'English' })).toBeVisible() expect(await dialogHeight()).toBe(closedHeight) await expect(searchBox).toBeFocused() await searchBox.fill('unmatched query') await expect(dialog.getByText('No matching languages.')).toBeVisible() expect(await dialogHeight()).toBe(closedHeight) await searchBox.press('Escape') await expect(searchBox).toBeHidden() await expect(language).toBeFocused() await expect(language).toHaveText('Auto') const selectLanguage = async (search: string, name: string) => { await language.click() await expect(searchBox).toHaveValue('') await searchBox.fill(search) await expect(dialog.getByRole('option')).toHaveCount(1) await expect(dialog.getByRole('option', { name })).toBeVisible() await searchBox.press('ArrowDown') await expect(searchBox).toHaveAttribute('aria-activedescendant', /.+/) await searchBox.press('Enter') await expect(searchBox).toBeHidden() await expect(language).toHaveText(name) } await selectLanguage('Simplified', 'Chinese (Simplified)') await generate.click() await expect(dialog.getByRole('alert')).toBeVisible() await expect(language).toHaveText('Chinese (Simplified)') await generate.click() await expect(dialog).toBeHidden() await expect(metadata).toHaveText('Transcribing…') await page.reload() await expect(metadata).toHaveText('Transcribing…') await page.getByRole('button', { name: 'List View' }).click() const dateCell = fileCard(page, fileName).getByTestId('file-list-item-date') await expect(dateCell).toHaveText('Transcribing…') const activeTranscript = { assetId: fileId, type: 'ai_transcription', status: 'processing', } as const await prisma.workflowTask.updateMany({ where: activeTranscript, data: { status: 'completed' } }) await expect(dateCell).toHaveText(/\d/) const modifiedDate = await dateCell.innerText() await openDialog() await selectLanguage('Traditional', 'Chinese (Traditional)') await generate.click() await expect(dialog).toBeHidden() await expect(dateCell).toHaveText('Transcribing…') await prisma.workflowTask.updateMany({ where: activeTranscript, data: { status: 'completed' } }) await expect(dateCell).toHaveText(modifiedDate) await openDialog() await expect(generate).toBeEnabled() await selectLanguage('Eng', 'English') await generate.click() await expect(dialog).toBeHidden() await expect(dateCell).toHaveText('Transcribing…') await prisma.workflowTask.updateMany({ where: activeTranscript, data: { status: 'failed' } }) await expect(dateCell).toHaveText(modifiedDate) await expect(page.getByText('Transcript generation failed.', { exact: true })).toHaveCount(0) })