Files
crawler-plugin/admin-frontend-vue/tests/task-259.test.ts
T

81 lines
3.8 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import test from 'node:test'
import assert from 'node:assert/strict'
import { readSource } from './helpers.ts'
import { historyPanelTypeLabel } from '../src/pages/records/history-type.ts'
import { parseHistoryUserOptions } from '../src/pages/records/history-user-option.ts'
import { buildPreviewDescriptor } from '../src/pages/records/history-preview.ts'
import type { HistoryRecordItem } from '../src/pages/records/history-dto.ts'
// module 13 task 259:生成记录页对齐 admin panel-history(指定用户下拉 + 起止时间、类型中文、缩略图预览、空态)。
test('test_task_259_history_normal_primary_path', () => {
// 正常主路径:类型映射覆盖常见 panel_type。
assert.equal(historyPanelTypeLabel('textToImage'), '反推词')
assert.equal(historyPanelTypeLabel('productMainImage'), '产品主图')
assert.equal(historyPanelTypeLabel('imageEdit'), '图片编辑')
})
test('test_task_259_history_normal_variant_input', () => {
// 正常变体:未知/空类型回退原文或占位。
assert.equal(historyPanelTypeLabel('someNew'), 'someNew')
assert.equal(historyPanelTypeLabel(''), '—')
assert.equal(historyPanelTypeLabel(null), '—')
})
test('test_task_259_history_normal_repeated_operation_is_idempotent', () => {
assert.equal(historyPanelTypeLabel('buyerShow'), '买家秀')
assert.equal(historyPanelTypeLabel('buyerShow'), '买家秀')
})
test('test_task_259_history_boundary_empty_input', () => {
// 边界:用户下拉解析过滤无 id/非法项。
const parsed = parseHistoryUserOptions({
success: true,
data: { items: [{ id: 1, username: 'admin' }, { id: 2, username: 'bob' }, { username: 'no-id' }, null] },
})
assert.deepEqual(parsed, [
{ id: 1, username: 'admin' },
{ id: 2, username: 'bob' },
])
assert.deepEqual(parseHistoryUserOptions({ success: true, data: { items: [] } }), [])
})
test('test_task_259_history_boundary_single_item', () => {
// 边界:预览描述单条去重与限数。
const item: HistoryRecordItem = {
id: 1,
userId: 1,
username: 'u',
createdAt: '',
panelType: 'x',
originalUrls: [],
resultUrls: ['http://a/1.png', 'http://a/1.png', 'http://a/2.png'],
longImageUrl: 'http://a/long.png',
}
assert.deepEqual(buildPreviewDescriptor(item, 2).images, ['http://a/1.png', 'http://a/2.png'])
})
test('test_task_259_history_boundary_limit_or_missing_field', () => {
const page = readSource('src/pages/records/RecordsHistoryPage.vue')
assert.match(page, /指定用户/, '筛选需有“指定用户”标签(admin 语义)')
assert.match(page, /type="datetime-local"/, '自绘复刻用原生日历控件(对齐 admin datetime-local')
assert.match(page, /historyPanelTypeLabel|panelTypeLabel/, '类型列需走中文映射')
assert.match(page, /formatDateTime/, '时间统一格式化')
})
test('test_task_259_history_invalid_input_rejected', () => {
const page = readSource('src/pages/records/RecordsHistoryPage.vue')
assert.match(page, /historyEmptyText/, '空态文案来自 history-feedback')
const feedback = readSource('src/pages/records/history-feedback.ts')
assert.match(feedback, /暂无/, 'history-feedback 提供“暂无”空态文案')
assert.match(page, /buildPreviewDescriptor|preview/, '需有结果预览能力')
})
test('test_task_259_history_dependency_failure_returns_actionable_message', () => {
// 依赖失败:用户下拉由 API 适配加载(不内联裸 fetch 拼 /api/admin/users 在页面)。
const page = readSource('src/pages/records/RecordsHistoryPage.vue')
assert.match(page, /fetchHistoryUserOptions|fetchUserList|loadUserOptions/, '用户选项应经适配函数加载')
const api = readSource('src/pages/records/history-api.ts')
assert.match(api, /\/api\/admin\/users/, '适配层请求用户列表')
})