50e70c43ab
empty-state 定义标题/引导文案与 shouldShowEmptyMenu 纯判定(Boolean 化防 undefined); AdminLayout 侧边栏与内容区(根路由)共用空态,加载中不闪现,未初始化不误报。
58 lines
2.6 KiB
TypeScript
58 lines
2.6 KiB
TypeScript
import test from 'node:test'
|
|
import assert from 'node:assert/strict'
|
|
import { readSource } from './helpers.ts'
|
|
import {
|
|
EMPTY_MENU_DESCRIPTION,
|
|
EMPTY_MENU_TITLE,
|
|
shouldShowEmptyMenu,
|
|
} from '../src/layout/empty-state.ts'
|
|
|
|
test('test_task_011_empty_menu_state_normal_primary_path', () => {
|
|
// 正常主路径:初始化完成且没有任何菜单 -> 展示空态。
|
|
assert.equal(shouldShowEmptyMenu(false, false, true), true)
|
|
})
|
|
|
|
test('test_task_011_empty_menu_state_normal_variant_input', () => {
|
|
// 正常变体:有一个或多个菜单时即使没有加载也不展示空态。
|
|
assert.equal(shouldShowEmptyMenu(true, false, true), false)
|
|
assert.equal(shouldShowEmptyMenu(true, true, true), false)
|
|
})
|
|
|
|
test('test_task_011_empty_menu_state_normal_repeated_operation_is_idempotent', () => {
|
|
// 正常重复:判定幂等。
|
|
assert.equal(shouldShowEmptyMenu(false, false, true), shouldShowEmptyMenu(false, false, true))
|
|
assert.equal(shouldShowEmptyMenu(true, false, true), shouldShowEmptyMenu(true, false, true))
|
|
})
|
|
|
|
test('test_task_011_empty_menu_state_boundary_empty_input', () => {
|
|
// 边界空值:会话未初始化时不展示空态(避免误报)。
|
|
assert.equal(shouldShowEmptyMenu(false, false, false), false)
|
|
assert.equal(shouldShowEmptyMenu(false, true, false), false)
|
|
})
|
|
|
|
test('test_task_011_empty_menu_state_boundary_single_item', () => {
|
|
// 边界单元素:仅一个菜单即不算空。
|
|
assert.equal(shouldShowEmptyMenu(true, false, true), false)
|
|
})
|
|
|
|
test('test_task_011_empty_menu_state_boundary_limit_or_missing_field', () => {
|
|
// 边界上限/缺字段:加载中禁止闪现空态;初始化字段缺失按未就绪处理。
|
|
assert.equal(shouldShowEmptyMenu(false, true, true), false, '加载中不得闪现空态')
|
|
assert.equal(shouldShowEmptyMenu(false, false, undefined as unknown as boolean), false)
|
|
})
|
|
|
|
test('test_task_011_empty_menu_state_invalid_input_rejected', () => {
|
|
// 异常输入:布尔语义混乱(未初始化却已加载完)也不展示。
|
|
assert.equal(shouldShowEmptyMenu(false, true, undefined as unknown as boolean), false)
|
|
})
|
|
|
|
test('test_task_011_empty_menu_state_dependency_failure_returns_actionable_message', () => {
|
|
// 依赖失败:壳层消费空态判定与文案常量,内容级空态在根路由呈现。
|
|
assert.ok(EMPTY_MENU_TITLE.length > 0)
|
|
assert.ok(EMPTY_MENU_DESCRIPTION.length > EMPTY_MENU_TITLE.length)
|
|
const layout = readSource('src/layout/AdminLayout.vue')
|
|
assert.match(layout, /shouldShowEmptyMenu/)
|
|
assert.match(layout, /EMPTY_MENU_DESCRIPTION/)
|
|
assert.match(layout, /route\.path === '\/'/, '内容级空态限定根路由')
|
|
})
|