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 { pillToneStyle, PILL_TONES, statusTone, type PillTone } from '../src/components/status-pill-model.ts'
|
|
import { copyFeedback } from '../src/components/copy-model.ts'
|
|
|
|
// module 13 task 247:行内工具组件化 —— 状态药丸/复制文本/掩码揭示,供视频/店铺数据/
|
|
// 数字人版本等页面复用;掩码复用店铺中心 secret-mask 语义。
|
|
|
|
test('test_task_247_pill_model_normal_primary_path', () => {
|
|
// 正常主路径:状态文本 → 语义 tone。
|
|
assert.equal(statusTone('SUCCESS'), 'success')
|
|
assert.equal(statusTone('FAILED'), 'danger')
|
|
assert.equal(statusTone('已发布'), 'success')
|
|
assert.equal(statusTone('失败'), 'danger')
|
|
})
|
|
|
|
test('test_task_247_pill_model_normal_variant_input', () => {
|
|
// 正常变体:运行/草稿等中间态落 warning;未知回落 info。
|
|
assert.equal(statusTone('RUNNING'), 'warning')
|
|
assert.equal(statusTone('草稿'), 'warning')
|
|
assert.equal(statusTone('something-unknown'), 'info')
|
|
})
|
|
|
|
test('test_task_247_pill_model_normal_repeated_operation_is_idempotent', () => {
|
|
assert.equal(statusTone('SUCCESS'), statusTone('success'))
|
|
assert.deepEqual(pillToneStyle('success'), pillToneStyle('success'))
|
|
})
|
|
|
|
test('test_task_247_pill_model_boundary_empty_input', () => {
|
|
// 边界空:空值/未知名不崩溃。
|
|
assert.equal(statusTone(''), 'info')
|
|
assert.equal(statusTone(undefined as unknown as string), 'info')
|
|
})
|
|
|
|
test('test_task_247_pill_model_boundary_single_item', () => {
|
|
// 边界单元素:每个 tone 都有可读配色(药丸文字/底色为 admin 三态色)。
|
|
for (const tone of Object.keys(PILL_TONES) as PillTone[]) {
|
|
const s = pillToneStyle(tone)
|
|
assert.match(s.text, /^#[0-9a-f]{6}$/)
|
|
assert.match(s.bg, /^#[0-9a-f]{6}$/)
|
|
}
|
|
assert.equal(pillToneStyle('success').text, '#4e806d')
|
|
assert.equal(pillToneStyle('danger').text, '#b35f6a')
|
|
})
|
|
|
|
test('test_task_247_pill_model_invalid_input_rejected', () => {
|
|
// 异常输入:非法 tone 回退 info,不抛错;三态主色与 admin 语义一致。
|
|
assert.equal(pillToneStyle('bogus' as PillTone).text, PILL_TONES.info.text)
|
|
assert.equal(PILL_TONES.warning.text, '#a8793e')
|
|
assert.equal(PILL_TONES.info.text, '#4f78a5')
|
|
})
|
|
|
|
test('test_task_247_copy_model_boundary_limit_or_missing_field', () => {
|
|
// 复制反馈:非空给「已复制 X」,空/失败给降级文案。
|
|
assert.equal(copyFeedback('B001'), '已复制 B001')
|
|
assert.equal(copyFeedback(' '), '复制失败,请手动选择')
|
|
assert.equal(copyFeedback(''), '复制失败,请手动选择')
|
|
})
|
|
|
|
test('test_task_247_components_dependency_failure_returns_actionable_message', () => {
|
|
// 依赖失败:组件真实存在且接入语义(药丸用 PILL_TONES、复制走 copyFeedback、掩码复用 secret-mask)。
|
|
assert.ok(readSource('src/components/StatusPill.vue').length > 0)
|
|
assert.ok(readSource('src/components/CopyText.vue').length > 0)
|
|
assert.ok(readSource('src/components/MaskReveal.vue').length > 0)
|
|
const copy = readSource('src/components/CopyText.vue')
|
|
assert.match(copy, /copyFeedback/)
|
|
assert.match(copy, /navigator\.clipboard/)
|
|
const mask = readSource('src/components/MaskReveal.vue')
|
|
assert.match(mask, /secret-mask|secretPlaceholder|SECRET_PLACEHOLDER/, '掩码应复用店铺 secret-mask 语义')
|
|
const pill = readSource('src/components/StatusPill.vue')
|
|
assert.match(pill, /pillToneStyle|PILL_TONES/, '药丸应使用统一配色模型')
|
|
})
|