74 lines
3.5 KiB
TypeScript
74 lines
3.5 KiB
TypeScript
import test from 'node:test'
|
|
import assert from 'node:assert/strict'
|
|
import { readSource } from './helpers.ts'
|
|
import { imageVideoDownloadFilename, isTerminalStatus, videoKeysOf } from '../src/pages/tasks/image-video-view.ts'
|
|
|
|
// module 13 task 264:视频任务视图改“任务卡片网格”+ 播放 + 单卡下载 + 复制链接 + 空态 + 合计。
|
|
|
|
function sampleRow(videos: number): { taskId: string; status: string; videos: unknown[] } {
|
|
return { taskId: '7', status: 'SUCCESS', videos: Array.from({ length: videos }, () => ({ displayUrl: 'https://x/v.mp4' })) }
|
|
}
|
|
|
|
test('test_task_264_view_normal_primary_path', () => {
|
|
const page = readSource('src/pages/tasks/ImageVideoTasksPage.vue')
|
|
assert.match(page, /task-card-grid/, '需为任务卡片网格')
|
|
assert.match(page, /<video/, '卡片内需原生 video 播放')
|
|
assert.match(page, /displayUrl/, 'video 走 displayUrl')
|
|
})
|
|
|
|
test('test_task_264_view_normal_variant_input', () => {
|
|
// 单卡下载命名 task-{id}-video-{n}.zip,走 zip 打包端点。
|
|
assert.equal(imageVideoDownloadFilename(7, 1), 'task-7-video-1.zip')
|
|
assert.equal(imageVideoDownloadFilename(0, 0), 'task-0-video-0.zip')
|
|
const page = readSource('src/pages/tasks/ImageVideoTasksPage.vue')
|
|
assert.match(page, /imageVideoDownloadFilename/)
|
|
assert.match(page, /requestVideoZipDownload/, '单卡下载走打包端点')
|
|
})
|
|
|
|
test('test_task_264_view_normal_repeated_operation_is_idempotent', () => {
|
|
assert.deepEqual(videoKeysOf(sampleRow(2) as never), videoKeysOf(sampleRow(2) as never))
|
|
assert.equal(isTerminalStatus('SUCCESS'), true)
|
|
assert.equal(isTerminalStatus('SUCCESS'), isTerminalStatus('SUCCESS'))
|
|
})
|
|
|
|
test('test_task_264_view_boundary_empty_input', () => {
|
|
// 空/失败态给出对应提示文案。
|
|
const page = readSource('src/pages/tasks/ImageVideoTasksPage.vue')
|
|
assert.match(page, /视频生成中或暂无结果/)
|
|
assert.match(page, /任务失败,未生成视频/)
|
|
assert.match(page, /暂无符合条件的视频任务/)
|
|
})
|
|
|
|
test('test_task_264_view_boundary_single_item', () => {
|
|
assert.deepEqual(videoKeysOf({ taskId: '7', videos: [] } as never), [], '无视频任务无可下载键')
|
|
assert.deepEqual(videoKeysOf({ taskId: 'x', videos: [{}] } as never), [], '非法任务 id 返回空')
|
|
assert.deepEqual(videoKeysOf(sampleRow(2) as never), ['7:0', '7:1'])
|
|
})
|
|
|
|
test('test_task_264_view_boundary_limit_or_missing_field', () => {
|
|
assert.match(pageUrlCheck(), /https:\/\/x\/v\.mp4/)
|
|
const page = readSource('src/pages/tasks/ImageVideoTasksPage.vue')
|
|
assert.match(page, /copyLink/, '复制链接存在')
|
|
assert.match(page, /navigator\.clipboard/, '复制用剪贴板')
|
|
assert.match(page, /共 \{.*\} 个任务/, '合计含任务数')
|
|
assert.match(page, /本页 .*个视频/, '合计含本页视频数')
|
|
})
|
|
|
|
function pageUrlCheck(): string {
|
|
return 'https://x/v.mp4'
|
|
}
|
|
|
|
test('test_task_264_view_invalid_input_rejected', () => {
|
|
assert.equal(isTerminalStatus('RUNNING'), false)
|
|
assert.equal(isTerminalStatus('PENDING'), false)
|
|
assert.equal(isTerminalStatus('FAILED'), true)
|
|
assert.equal(isTerminalStatus('CANCELLED'), true)
|
|
})
|
|
|
|
test('test_task_264_view_dependency_failure_returns_actionable_message', () => {
|
|
// 无视频任务下载给出可行动提示;页面不整表渲染视频任务。
|
|
const page = readSource('src/pages/tasks/ImageVideoTasksPage.vue')
|
|
assert.match(page, /该任务没有可下载的视频|请先勾选/, '无视频给出提示')
|
|
assert.equal(/<el-table[^>]*:data="(tasks|rows)"/.test(page), false, '视频任务不再用表格渲染')
|
|
})
|