Files
go-sms-V2/web/tests/role-menu-matrix.spec.ts
Tory eda275944f Issue#4: 版本号+发布日志(侧栏红点/系统管理二级菜单/运营大白话Markdown)——①单一事实源=data/releases.ts(APP_VERSION=首条;package.json 0.1.0→1.5.0 同步,releases.spec 两侧一致断言防漂移;版本线 v1.0.0~v1.5.0 六版全运营大白话);②侧栏底脚版本chip(MainLayout sidebar-foot 折叠按钮旁,点击进发布日志;红点=本地未读 localStorage gosms_seen_ver≠当前版本即亮,CSS gosms-ver-blink 脉冲闪烁,首访亮/点击或进页 markSeen 即灭/发新版全员再亮;折叠态64px 短版本 1.5+红点 badge 绝对定位——实测 monospace 渲染偏宽 v1.5 溢出 foot 55px>47px 修正);③发布日志页 views/system/ReleaseLog.vue(defineOptions name=system-release 守门)+路由 /system/release 全角色(同 faq 口径用户拍板,icon=Memo);④迷你Markdown渲染器 utils/markdown.ts 零新依赖(标题/无序有序列表 1.与1、顿号中文习惯/粗体/行内代码哨兵保护 code内**不误判/围栏代码块/链接仅http(s) javascript伪协议不渲染;先全量HTML转义再解析,v-html 零注入);⑤守门=releases.spec +14(数据一致性4:单一事实源/降序/semver/日期标签;渲染器7:格式+转义+伪协议+哨兵;store3:首访亮/markSeen灭+刷新持久/新版再亮)+guard 菜单33→34显式更+role-menu-matrix 登记 system-release:ALL+verify-layout 23→31(chip可见/文本vN.N/首访红点/点击跳转/已读即灭/卡片≥3实为6/md列表渲染/回home);⑥门禁=eslint0/vue-tsc0/vitest 179(165+14)/build 全绿;Chrome 157 实机走查4步(红点1→点击进页→已读0+localStorage=1.5.0→折叠1.5)+样式级复核(动画名gosms-ver-blink/chip几何/暗亮双主题可见);口径诚实标注:红点=本地未读语义(换浏览器/清缓存重提示一次,无服务端同步)/移动端≤900随sidebar-foot既有隐藏/发布内容=仓库静态数据;发版SOP=releases.ts头部插一条+package.json同步,部署后全员红点亮起;验收单issue4-release-notes.md+CHANGELOG+memory-bank回填;Gitea#4完成评论待用户(token)
2026-11-18 10:58:18 +08:00

76 lines
3.6 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// role-menu-matrix.spec.ts S3·FE-6:五角色×全菜单权限矩阵走查(自动化快照)。
// 预期矩阵为**人工确认后的固化表**(非 routes.ts 同源推导)——任何人改动路由
// roles 都会在此暴露,走查语义=矩阵变更必须显式过目(与后端 casbin 五角色门对齐)。
// 语义基准:资金/通道/结算页=admin/ops;service=运营执行;group/customer=业务
// 与记录自助,不见平台资金信息(与后端 statsIsPlatform/ordersList/profit 平台门一致)。
import { describe, expect, it } from 'vitest'
import { accessibleRoutes } from '@/router/guard'
type Roles = 'admin' | 'ops' | 'service' | 'group' | 'customer'
const ALL: Roles[] = ['admin', 'ops', 'service', 'group', 'customer']
/** 预期矩阵:菜单 name → 允许角色(S3 固化,含 FE-D34 利润分析)。 */
const MATRIX: Record<string, Roles[]> = {
home: ALL,
notice: ['admin', 'ops', 'service', 'group'],
'account-list': ['admin', 'ops'],
audit: ['admin', 'ops', 'service'],
'sms-home': ALL, 'sms-batch': ALL, 'sms-personal': ALL, 'sms-timer': ALL,
'sms-result': ALL, 'sms-template': ALL, 'sms-downlink-detail': ALL,
video: ['admin', 'ops'], csp: ['admin', 'ops'], nullfilter: ['admin', 'ops'], shortlink: ['admin', 'ops'],
'record-down': ALL, 'record-up': ALL,
'record-repush': ['admin', 'ops', 'service'],
channel: ['admin', 'ops'], 'channel-upstream': ['admin', 'ops'], 'channel-group': ['admin', 'ops'],
policy: ['admin', 'ops'], 'policy-route': ['admin', 'ops'], 'policy-report': ['admin', 'ops'],
contacts: ALL,
'stats-user': ['admin', 'ops', 'service'], 'stats-channel': ['admin', 'ops'],
'stats-profit': ['admin', 'ops', 'service'], settle: ['admin', 'ops'],
'ops-callback': ['admin', 'ops'],
logs: ['admin', 'ops', 'service'], system: ['admin'], faq: ALL,
// Issue#4 发布日志:平台更新公告,面向全体用户(同 faq 口径,用户拍板)。
'system-release': ALL,
}
/** 实测:某角色经守卫过滤后的可见菜单集合。 */
function visibleMenus(role: Roles): Set<string> {
return new Set(
accessibleRoutes([role])
.flatMap((r) => r.children ?? [])
.filter((c) => c.meta?.menu)
.map((c) => String(c.name)),
)
}
describe('S3·FE-6 五角色×全菜单权限矩阵', () => {
const roles: Roles[] = ['admin', 'ops', 'service', 'group', 'customer']
it.each(roles)('角色 %s 可见菜单与矩阵一致', (role) => {
const visible = visibleMenus(role)
for (const [name, allow] of Object.entries(MATRIX)) {
const want = allow.includes(role)
expect(visible.has(name), `${role} × ${name}:期望${want ? '可见' : '不可见'}`).toBe(want)
}
})
it('矩阵覆盖全部菜单项(新增菜单未登记矩阵=本测试红,走查强制过目)', () => {
const adminVisible = visibleMenus('admin')
for (const name of adminVisible) expect(MATRIX[name], `菜单 ${name} 未登记矩阵`).toBeDefined()
expect(adminVisible.size).toBe(Object.keys(MATRIX).length)
})
it('资金与平台配置页对 group/customer 关闭(语义抽样:settle/stats-profit/channel/system)', () => {
for (const role of ['group', 'customer'] as Roles[]) {
const visible = visibleMenus(role)
for (const denied of ['settle', 'stats-profit', 'stats-channel', 'channel', 'channel-upstream', 'system', 'account-list', 'audit']) {
expect(visible.has(denied), `${role} 不应见 ${denied}`).toBe(false)
}
}
})
it('system 配置仅 admin', () => {
for (const role of ['ops', 'service', 'group', 'customer'] as Roles[]) {
expect(visibleMenus(role).has('system')).toBe(false)
}
})
})