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

83 lines
4.6 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/)
})
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"/)
})
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\(\)/)
assert.match(rolesSource, /await store\.createRole/)
})
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\(\)/)
assert.match(permissionsSource, /内置角色,始终拥有全部客户工作台权限/)
assert.match(permissionsSource, /全量替换/)
assert.match(permissionsSource, /await store\.setRolePermissions/)
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*:/)
})