Files
crawler-plugin/frontend-vue/tests/appearance-patent-current-task-download.test.ts
T
huangzd1997 bc818eb3ea fix(frontend): 外观专利当前任务区补下载入口
结果文件已生成时「当前任务」卡片只有删除按钮、下载只挂在历史弹层,
用户误读成"失败了不能下载"。现与历史区共用同一 canDownload 判据
(只看文件不看任务状态),并加防回归用例钉住判据不得掺入状态。
2026-10-24 16:35:39 +08:00

65 lines
2.6 KiB
TypeScript

/**
* 「当前任务」那一行必须有下载入口的用例(2026-10-24 现网)。
*
* 症状:外观专利任务的结果文件已经生成(result_file_url 非空),用户在「当前任务」卡片上
* 仍然点不到下载——因为 `#item-actions` 里只挂了「删除」,下载只在 `#history-item-actions`。
* 用户因此以为"失败了不能下载",实际是这一格入口缺失(另一格是后端补检期间故意不出表,
* 那条判据见 result-build-failed-when-downloadable.test.ts,两件事别混)。
*
* 判据与历史区共用同一个 canDownload:只看文件到没到,不看任务状态。
*
* 跑法:`node --test tests/appearance-patent-current-task-download.test.ts`
*/
import { test } from 'node:test'
import assert from 'node:assert/strict'
import { readFileSync } from 'node:fs'
import { fileURLToPath } from 'node:url'
import { resolve, dirname } from 'node:path'
const here = dirname(fileURLToPath(import.meta.url))
const tabSource = readFileSync(
resolve(here, '../src/pages/brand/components/BrandAppearancePatentTab.vue'),
'utf-8',
)
function slot(name: string): string {
const match = tabSource.match(
new RegExp(`<template #${name}="\\{ item \\}">([\\s\\S]*?)</template>`),
)
assert.ok(match, `找不到 #${name} 插槽`)
return match[1]
}
test('当前任务区必须有下载按钮', () => {
const current = slot('item-actions')
assert.match(
current,
/v-if="canDownload\(itemSource\(item\)\)"[^>]*>\s*下载\s*<\/button>/,
'「当前任务」那一行要按 canDownload 出下载按钮,不能只有删除',
)
})
test('当前任务与历史区的下载判据必须是同一个', () => {
const current = slot('item-actions')
const history = slot('history-item-actions')
assert.equal(
/canDownload\(itemSource\(item\)\)/.test(current),
/canDownload\(itemSource\(item\)\)/.test(history),
'两处都得到判据;判据不一致等于同一枚任务在两个位置说法不同',
)
assert.match(current, /deleteTaskRecord\(itemSource\(item\)\)/, '删除按钮不能顺手丢掉')
})
test('下载判据只看文件,不看任务状态', () => {
const match = tabSource.match(/function canDownload\([\s\S]*?\n\}/)
assert.ok(match, '找不到 canDownload')
const body = match[0]
assert.match(body, /item\.resultId/, '没有结果行就不该给下载')
assert.match(body, /item\.fileReady \|\| item\.downloadUrl/, '文件到了才给下载')
assert.doesNotMatch(
body,
/taskStatus|fileStatus|FAILED/,
'判据里出现任务状态就是回归:失败态同样要能下载已生成的文件',
)
})