Files
crawler-plugin/admin-frontend-vue/tests/task-12.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

72 lines
3.0 KiB
TypeScript

import test from 'node:test'
import assert from 'node:assert/strict'
import { existsSync } from 'node:fs'
import { join } from 'node:path'
import { readSource, occurrences } from './helpers.ts'
import { adminPages } from '../src/router/routes.ts'
const ROUTER = 'src/router/index.ts'
const NOT_FOUND = 'src/pages/error/NotFoundPage.vue'
test('test_task_012_route_error_page_normal_primary_path', () => {
// 正常主路径:未知路径注册到路由级错误页兜底。
const router = readSource(ROUTER)
assert.match(router, /path:\s*':pathMatch\(\.\*\)\*'/)
assert.match(router, /NotFoundPage/)
assert.match(router, /页面不存在/)
})
test('test_task_012_route_error_page_normal_variant_input', () => {
// 正常变体:错误页在 AdminLayout children 内,保留壳层 chrome。
const router = readSource(ROUTER)
const catchAllIndex = router.indexOf(':pathMatch(.*)*')
const registryIndex = router.indexOf('adminRouteRecords.map')
assert.ok(catchAllIndex > registryIndex, 'catch-all 应在业务路由之后注册')
assert.match(router, /path: '\/',/)
})
test('test_task_012_route_error_page_normal_repeated_operation_is_idempotent', () => {
// 正常重复:错误页注册不重复追加。
const first = readSource(ROUTER)
assert.equal(occurrences(first, ':pathMatch(.*)*'), 1)
})
test('test_task_012_route_error_page_boundary_empty_input', () => {
// 边界空值:错误页文件存在,且不进入业务路由注册表。
assert.equal(existsSync(join(process.cwd(), NOT_FOUND)), true)
assert.equal(adminPages.length, 16, '错误页不应计入业务路由')
})
test('test_task_012_route_error_page_boundary_single_item', () => {
// 边界单元素:错误页是单一 Vue 页面组件。
const source = readSource(NOT_FOUND)
assert.equal(occurrences(source, '<template>'), 1)
assert.match(source, /el-result/)
})
test('test_task_012_route_error_page_boundary_limit_or_missing_field', () => {
// 边界上限:catch-all 不参与菜单权限门禁(无 menuKey)。
const router = readSource(ROUTER)
const tail = router.slice(router.indexOf('component: NotFoundPage'))
assert.equal(tail.slice(0, 80).includes('menuKey'), false, '错误页不应带菜单 key')
})
test('test_task_012_route_error_page_invalid_input_rejected', () => {
// 异常输入:深层未知路径也能被通配兜底,且提供返回首页动作。
const router = readSource(ROUTER)
assert.match(router, /:pathMatch\(\.\*\)\*/, '通配需覆盖多段未知路径')
const page = readSource(NOT_FOUND)
assert.match(page, /router\.replace\('\/'\)/)
})
test('test_task_012_route_error_page_dependency_failure_returns_actionable_message', () => {
// 依赖失败:标题/样式/返回动作齐全,加载失败有明确入口。
const page = readSource(NOT_FOUND)
assert.match(page, /返回首页/)
assert.match(page, /404/)
const css = readSource('src/styles/main.css')
assert.match(css, /\.not-found/)
const router = readSource(ROUTER)
assert.match(router, /meta: \{ title: '页面不存在' \}/)
})