Files
crawler-plugin/admin-frontend-vue/tests/task-36.test.ts
T
huangzd1997 4c88964473 task-283(后台迁移收尾/发布): admin-vue 后台工程入库 + Flask 后台整体退役
- 新后台 admin-frontend-vue 整工程入库(base=/admin-vue/、History 路由、Nginx 静态托管方案与 verify-dist 校验)
- Java AdminConsoleController 改为入口重定向: /admin|/admin.html、/login|/login.html -> /admin-vue/; 删除 classpath:static 旧 admin.html/login.html 单页与 admin.js 副本
- Flask 后台整体退役: 删除 admin_api/auth/main 蓝图、web_source 页面、static 脚本与 admin 相关测试; app.py 收敛为仅注册 version_bp(/api/version、/api/version/latest, 供桌面端更新检查)
- AdminApiGuardFilterTest 豁免样例路径 /admin.html -> /admin-vue/
2026-09-06 10:41:47 +08:00

67 lines
2.9 KiB
TypeScript

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\(joinAdminPath\('login'\)\)/)
const session = readSource('src/api/session.ts')
assert.match(session, /\/logout/, '登出走 auth 模块根端点 POST /logout')
assert.equal(session.includes('/api/admin/logout'), false, '不应指向不存在的 /api/admin/logout')
})