mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-12-04 23:24:21 +00:00
140 lines
5.6 KiB
TypeScript
140 lines
5.6 KiB
TypeScript
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', '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', name: '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' })
|
|
const generate = dialog.getByRole('button', { name: 'Generate', exact: true })
|
|
const metadata = fileCard(page, fileName).getByTestId('file-card-metadata')
|
|
const selectLanguage = async (search: string, name: string) => {
|
|
await language.fill(search)
|
|
await expect(dialog.getByRole('option', { name })).toBeVisible()
|
|
await language.press('ArrowDown')
|
|
await expect(language).toHaveAttribute('aria-activedescendant', /.+/)
|
|
await language.press('Enter')
|
|
await expect(language).toHaveValue(name)
|
|
}
|
|
|
|
await expect(language).toHaveValue('Auto')
|
|
await selectLanguage('Chi', 'Chinese')
|
|
await generate.click()
|
|
await expect(dialog.getByRole('alert')).toBeVisible()
|
|
await expect(language).toHaveValue('Chinese')
|
|
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 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)
|
|
})
|