Files
client-web/src/views/TenantAdministrationViews.test.mjs
T

97 lines
5.5 KiB
JavaScript
Raw Normal View History

2026-07-30 17:59:42 +08:00
import assert from 'node:assert/strict'
import fs from 'node:fs'
import test from 'node:test'
const routerSource = fs.readFileSync(new URL('../router/index.ts', import.meta.url), 'utf8')
const profileSource = fs.readFileSync(new URL('./CompanyProfileView.vue', import.meta.url), 'utf8')
const membersSource = fs.readFileSync(new URL('./MembersView.vue', import.meta.url), 'utf8')
const rolesSource = fs.readFileSync(new URL('./RolesView.vue', import.meta.url), 'utf8')
const permissionsSource = fs.readFileSync(new URL('./PermissionsView.vue', import.meta.url), 'utf8')
const storeSource = fs.readFileSync(new URL('../stores/tenantAdministration.ts', import.meta.url), 'utf8')
test('routes tenant administration modules to implemented views instead of the placeholder', () => {
assert.match(routerSource, /company\/profile'.*CompanyProfileView\.vue/)
assert.match(routerSource, /organization\/members'.*MembersView\.vue/)
assert.match(routerSource, /organization\/roles'.*RolesView\.vue/)
assert.match(routerSource, /organization\/permissions'.*PermissionsView\.vue/)
assert.doesNotMatch(routerSource, /ModuleView\.vue/)
})
test('implements company details, contact information and qualification workflow', () => {
assert.match(profileSource, /企业基本信息/)
assert.match(profileSource, /联系信息/)
assert.match(profileSource, /资质文件/)
assert.match(profileSource, /async function saveProfile\(\)/)
assert.match(profileSource, /function submitQualification\(\)/)
assert.match(profileSource, /validateQualificationFile/)
assert.match(profileSource, /function removeSelectedFile\(\)/)
assert.match(profileSource, /qualificationSubmitting/)
assert.match(profileSource, /class="mobile-qualification-list"/)
assert.match(profileSource, /downloadQualificationImage/)
assert.match(profileSource, /URL\.createObjectURL/)
assert.match(profileSource, /URL\.revokeObjectURL/)
2026-07-31 15:34:22 +08:00
assert.match(profileSource, /企业资料加载失败/)
assert.match(profileSource, /@click="loadCompanyContext"/)
assert.doesNotMatch(profileSource, /企业类型|注册资本|contactWechat|businessAddress/)
2026-07-30 17:59:42 +08:00
})
test('implements member list, role assignment, password reset and status control', () => {
assert.match(membersSource, /async function saveMember\(\)/)
assert.match(membersSource, /function resetPassword\(member: TenantMember\)/)
assert.match(membersSource, /function toggleStatus\(member: TenantMember\)/)
assert.match(membersSource, /v-model="form\.roleIds" multiple/)
assert.match(membersSource, /class="mobile-member-list"/)
assert.match(membersSource, /store\.loadMembers\(\)/)
assert.match(membersSource, /await store\.resetMemberPassword/)
assert.match(membersSource, /await store\.toggleMemberStatus/)
assert.match(membersSource, /v-model="form\.password"/)
2026-07-31 15:34:22 +08:00
assert.match(membersSource, /企业成员加载失败/)
assert.match(membersSource, /@click="loadMembers"/)
2026-07-30 17:59:42 +08:00
})
test('protects built-in roles and exposes role permission assignment', () => {
assert.match(rolesSource, /auth\.hasPermission\('company:role:write'\) && !role\.builtin/)
assert.match(rolesSource, /function assignPermissions\(role: TenantRole\)/)
assert.match(storeSource, /if \(role\.builtin\) throw new Error\('内置角色不能删除'\)/)
assert.match(storeSource, /if \(members\.value\.some\(\(member\) => member\.roleIds\.includes\(id\)\)\)/)
assert.match(rolesSource, /store\.loadRoles\(\)/)
2026-07-30 21:23:06 +08:00
assert.match(rolesSource, /auth\.hasPermission\('company:member:list'\).*store\.loadMembers\(\)/)
assert.match(rolesSource, /await Promise\.all\(requests\)/)
2026-07-30 17:59:42 +08:00
assert.match(rolesSource, /await store\.createRole/)
2026-07-31 13:43:16 +08:00
assert.match(rolesSource, /await store\.updateRole/)
assert.match(rolesSource, /await store\.toggleRoleStatus/)
assert.match(rolesSource, /await store\.deleteRole/)
2026-07-31 15:34:22 +08:00
assert.match(rolesSource, /企业角色加载失败/)
assert.match(rolesSource, /@click="loadRoles"/)
2026-07-30 17:59:42 +08:00
})
test('shows company audit status and applies button permissions', () => {
assert.match(profileSource, /companyApproved/)
assert.match(profileSource, /企业资料正在等待平台审核/)
assert.match(profileSource, /auth\.hasPermission\('company:profile:edit'\)/)
assert.match(membersSource, /auth\.hasPermission\('company:member:write'\)/)
assert.match(permissionsSource, /auth\.hasPermission\('company:permission:assign'\)/)
assert.match(storeSource, /auditStatus: 'PROFILE_REQUIRED'/)
assert.match(storeSource, /loadCompanyContext/)
})
test('implements grouped menu and action permission editing', () => {
assert.match(permissionsSource, /TENANT_PERMISSION_GROUPS/)
assert.match(permissionsSource, /function toggleGroup\(groupKey: string, checked: boolean\)/)
assert.match(permissionsSource, /function savePermissions\(\)/)
2026-07-30 21:23:06 +08:00
assert.match(permissionsSource, /系统内置角色,权限由平台统一维护,不允许修改/)
2026-07-30 17:59:42 +08:00
assert.match(permissionsSource, /全量替换/)
assert.match(permissionsSource, /await store\.setRolePermissions/)
2026-07-31 15:34:22 +08:00
assert.match(permissionsSource, /角色权限加载失败/)
assert.match(permissionsSource, /当前企业暂无可用角色/)
2026-07-30 17:59:42 +08:00
assert.doesNotMatch(permissionsSource, /当前只读展示权限资源/)
})
test('keeps tenant administration state scoped to the client store', () => {
assert.match(storeSource, /defineStore\('tenant-administration'/)
assert.match(storeSource, /function createMember/)
assert.match(storeSource, /function createRole/)
assert.match(storeSource, /function setRolePermissions/)
assert.doesNotMatch(storeSource, /tenantId\s*:/)
})