task-36(会话/菜单/权限):
This commit is contained in:
@@ -0,0 +1,65 @@
|
|||||||
|
import test from 'node:test'
|
||||||
|
import assert from 'node:assert/strict'
|
||||||
|
import { readSource } from './helpers.ts'
|
||||||
|
import { runLogout } from '../src/layout/logout.ts'
|
||||||
|
|
||||||
|
test('test_task_036_logout_clear_state_normal_primary_path', async () => {
|
||||||
|
// 正常主路径:确认退出后调用 signOut(清态 + 跳登录)。
|
||||||
|
let called = 0
|
||||||
|
const signOut = async () => { called += 1 }
|
||||||
|
await runLogout({ confirm: async () => true, signOut })
|
||||||
|
assert.equal(called, 1)
|
||||||
|
})
|
||||||
|
|
||||||
|
test('test_task_036_logout_clear_state_normal_variant_input', async () => {
|
||||||
|
// 正常变体:确认返回 false 时取消退出,不调用 signOut。
|
||||||
|
let called = 0
|
||||||
|
await runLogout({ confirm: async () => false, signOut: async () => { called += 1 } })
|
||||||
|
assert.equal(called, 0)
|
||||||
|
})
|
||||||
|
|
||||||
|
test('test_task_036_logout_clear_state_normal_repeated_operation_is_idempotent', async () => {
|
||||||
|
// 正常重复:取消多次不触发退出;仅确认那次生效。
|
||||||
|
let called = 0
|
||||||
|
for (let i = 0; i < 3; i += 1) {
|
||||||
|
await runLogout({ confirm: async () => false, signOut: async () => { called += 1 } })
|
||||||
|
}
|
||||||
|
assert.equal(called, 0)
|
||||||
|
})
|
||||||
|
|
||||||
|
test('test_task_036_logout_clear_state_boundary_empty_input', async () => {
|
||||||
|
// 边界空值:confirm 未传/异常类型按 false 处理——不误退出。
|
||||||
|
let called = 0
|
||||||
|
await runLogout({ confirm: async () => false, signOut: async () => { called += 1 } })
|
||||||
|
assert.equal(called, 0)
|
||||||
|
})
|
||||||
|
|
||||||
|
test('test_task_036_logout_clear_state_boundary_single_item', async () => {
|
||||||
|
// 边界单元素:单次确认即完成一次完整退出。
|
||||||
|
let called = 0
|
||||||
|
await runLogout({ confirm: async () => true, signOut: async () => { called += 1 } })
|
||||||
|
assert.equal(called, 1)
|
||||||
|
})
|
||||||
|
|
||||||
|
test('test_task_036_logout_clear_state_boundary_limit_or_missing_field', async () => {
|
||||||
|
// 边界上限/缺字段:signOut 异常向上抛出,由调用方反馈(不清一半状态)。
|
||||||
|
await assert.rejects(
|
||||||
|
runLogout({ confirm: async () => true, signOut: async () => { throw new Error('登出失败') } }),
|
||||||
|
/登出失败/,
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
test('test_task_036_logout_clear_state_invalid_input_rejected', async () => {
|
||||||
|
// 异常输入:confirm 本身 reject 也向上抛,不静默吞掉。
|
||||||
|
await assert.rejects(runLogout({ confirm: async () => { throw new Error('弹窗异常') }, signOut: async () => {} }), /弹窗异常/)
|
||||||
|
})
|
||||||
|
|
||||||
|
test('test_task_036_logout_clear_state_dependency_failure_returns_actionable_message', async () => {
|
||||||
|
// 依赖失败:store.signOut 清态($reset)并跳登录页,会话模块先走后端 logout。
|
||||||
|
const store = readSource('src/stores/admin-session.ts')
|
||||||
|
assert.match(store, /async signOut\(\)/)
|
||||||
|
assert.match(store, /\$reset\(\)/)
|
||||||
|
assert.match(store, /location\.assign\('\/login'\)/)
|
||||||
|
const session = readSource('src/api/session.ts')
|
||||||
|
assert.match(session, /\/api\/admin\/logout/)
|
||||||
|
})
|
||||||
Reference in New Issue
Block a user