mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-12-04 15:14:10 +00:00
fix(video): transcribe archived videos and show progress (#560)
This commit is contained in:
@@ -76,7 +76,7 @@ apps/web/e2e/
|
||||
| Owner creates a project with a cover image | `tests/project/create-project.spec.ts` |
|
||||
| Owner opens project cards in new tabs with middle-click and modifier-click | `tests/project/open-in-new-tab.spec.ts` |
|
||||
| Owner opens a folder card and a file row in new tabs from the context menu | `tests/project/open-in-new-tab.spec.ts` |
|
||||
| Owner opens transcript generation from a video context menu, selects a language, and sees completion | `tests/project/generate-transcripts.spec.ts` |
|
||||
| Owner generates a transcript from an archived video's context menu, sees progress in card and list metadata across a refresh, and reuses the project status across folders | `tests/project/generate-transcripts.spec.ts` |
|
||||
| Owner uploads a file or an unsupported file via the "Upload File" context menu action | `tests/project/upload-file.spec.ts` |
|
||||
| Owner deletes a file, finds it in recently deleted, and restores it | `tests/project/delete-restore.spec.ts` |
|
||||
| Owner deletes a folder and still sees its contents preview and countdown in recently deleted | `tests/project/delete-restore.spec.ts` |
|
||||
|
||||
@@ -1,17 +1,28 @@
|
||||
import { expect, test } from '../../fixtures'
|
||||
import { seedFolder } from '../../helpers/assets'
|
||||
import { fileCard } from '../../helpers/files'
|
||||
import type { TranscriptJobStatus } from '@shumai/dtos'
|
||||
|
||||
test.use({ fileOptions: { mediaType: 'video' } })
|
||||
|
||||
test('selects a transcription language from the video context menu and tracks the job', async ({
|
||||
test('starts a transcript for an archived video and tracks it in the file metadata', async ({
|
||||
file,
|
||||
prisma,
|
||||
}) => {
|
||||
const { page, projectId, fileId, fileName } = file
|
||||
let status: TranscriptJobStatus = { taskId: 'previous-transcript', status: 'completed' }
|
||||
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', 'en']
|
||||
let submissions = 0
|
||||
let rejectSubmission = true
|
||||
let statusRequests = 0
|
||||
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: true } })
|
||||
@@ -27,14 +38,18 @@ test('selects a transcription language from the video context menu and tracks th
|
||||
},
|
||||
}),
|
||||
)
|
||||
await page.route(`**/api/files/${fileId}/transcription-status`, (route) =>
|
||||
route.fulfill({ json: status }),
|
||||
)
|
||||
await page.route(`**/api/files/${fileId}/transcripts`, async (route) => {
|
||||
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 } })
|
||||
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
|
||||
@@ -48,14 +63,21 @@ test('selects a transcription language from the video context menu and tracks th
|
||||
await prisma.asset.update({ where: { id: fileId }, data: { status: 'processing' } })
|
||||
const [signupInfo] = await Promise.all([
|
||||
page.waitForResponse('**/api/signup-info'),
|
||||
page.goto(`/projects/${projectId}`),
|
||||
page.goto(projectPath),
|
||||
])
|
||||
expect(await signupInfo.json()).toMatchObject({ transcriptionEnabled: true })
|
||||
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()
|
||||
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(fileCard(page, fileName)).toBeVisible()
|
||||
expect(statusRequests).toBe(idleRequests)
|
||||
const openDialog = async () => {
|
||||
await fileCard(page, fileName).click({ button: 'right' })
|
||||
await action.click()
|
||||
@@ -64,24 +86,40 @@ test('selects a transcription language from the video context menu and tracks th
|
||||
const dialog = page.getByRole('dialog', { name: 'Generate Transcripts' })
|
||||
const language = dialog.getByRole('combobox', { name: 'Language' })
|
||||
const generate = dialog.getByRole('button', { name: 'Generate', exact: true })
|
||||
await expect(dialog.getByRole('status')).toHaveText('Transcript generated.')
|
||||
const metadata = fileCard(page, fileName).getByTestId('file-card-metadata')
|
||||
await expect(language).toHaveValue('Auto')
|
||||
await language.fill('Chi')
|
||||
await dialog.getByRole('option', { name: 'Chinese' }).click()
|
||||
await expect(language).toHaveValue('Chinese')
|
||||
await generate.click()
|
||||
await expect(dialog.getByRole('status')).toHaveText('Generating transcript…')
|
||||
await dialog.getByRole('button', { name: 'Close', exact: true }).click()
|
||||
await expect(dialog.getByRole('alert')).toBeVisible()
|
||||
await expect(language).toHaveValue('Chinese')
|
||||
await generate.click()
|
||||
await expect(dialog).toBeHidden()
|
||||
status = { taskId: status.taskId, status: 'completed' }
|
||||
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 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()
|
||||
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)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user