Files
chorus/admin-ui/tests/unit/admin/system-management.spec.js
T

40 lines
1.6 KiB
JavaScript

import fs from 'fs'
import path from 'path'
const read = relativePath => fs.readFileSync(path.resolve(__dirname, `../../../${relativePath}`), 'utf8')
describe('Chorus system management pages', () => {
test.each([
['sys-menu', '菜单结构'],
['sys-api', '接口清单'],
['sys-login-log', '登录日志']
])('%s is explicitly read-only and exposes no write action', (view, heading) => {
const source = read(`src/views/admin/${view}/index.vue`)
expect(source).toContain(`<h2>${heading}</h2>`)
expect(source).toContain('>只读</el-tag>')
expect(source).not.toMatch(/handle(Add|Update|Delete)/)
expect(source).not.toMatch(/新增|编辑|删除[^。]/)
})
test('read-only API modules only issue GET requests', () => {
for (const api of ['sys-menu', 'sys-api', 'sys-login-log']) {
const source = read(`src/api/admin/${api}.js`)
expect(source).not.toMatch(/method: '(post|put|delete)'/)
}
})
test('administrator page omits legacy organization and contact dependencies', () => {
const source = read('src/views/admin/sys-user/index.vue')
expect(source).toContain('<h2>管理员账号</h2>')
expect(source).toContain('当前账号')
expect(source).not.toMatch(/部门|岗位|手机号|邮箱|sys-dept|sys-post/)
})
test('role page presents the built-in role protection boundary', () => {
const source = read('src/views/admin/sys-role/index.vue')
expect(source).toContain("const PROTECTED_ROLE_KEY = 'chorus_operator'")
expect(source).toContain('内置保护')
expect(source).not.toMatch(/数据权限|sys-dept/)
})
})