This commit is contained in:
2026-08-17 19:52:04 +08:00
parent d618683467
commit ee4cd35927
42 changed files with 702 additions and 226 deletions
+6 -7
View File
@@ -3,7 +3,7 @@ import { readFileSync } from 'node:fs'
import { resolve } from 'node:path'
import { flushPromises, shallowMount } from '@vue/test-utils'
import { beforeEach, describe, expect, it, vi } from 'vitest'
import { createPlatformRole, listPlatformInternalUsers, listPlatformPermissions, listPlatformRoles, type PlatformRoleResource } from '@/modules/iam/api/platformIam'
import { createPlatformRole, listPlatformPermissions, listPlatformRoles, type PlatformRoleResource } from '@/modules/iam/api/platformIam'
import { useAuthStore } from '@/core/auth/auth'
import RolesView from './RolesView.vue'
@@ -11,7 +11,6 @@ const rolesSource = readFileSync(resolve(process.cwd(), 'src/modules/iam/pages/R
vi.mock('@/modules/iam/api/platformIam', () => ({
createPlatformRole: vi.fn(),
listPlatformInternalUsers: vi.fn(),
listPlatformPermissions: vi.fn(),
listPlatformRoles: vi.fn(),
updatePlatformRole: vi.fn(),
@@ -29,6 +28,7 @@ const platformRole: PlatformRoleResource = {
roleType: 'SYSTEM',
status: 'ACTIVE',
description: '企业资料与入驻审核',
memberCount: 3,
}
function mountView(pinia = createPinia()) {
@@ -86,9 +86,7 @@ describe('RolesView', () => {
setActivePinia(createPinia())
vi.mocked(listPlatformRoles).mockReset()
vi.mocked(listPlatformPermissions).mockReset()
vi.mocked(listPlatformInternalUsers).mockReset()
vi.mocked(listPlatformPermissions).mockResolvedValue([])
vi.mocked(listPlatformInternalUsers).mockResolvedValue([])
vi.mocked(createPlatformRole).mockReset()
})
@@ -98,8 +96,8 @@ describe('RolesView', () => {
expect(wrapper.get('[data-testid="permission-tree"]').attributes('data-check-strictly')).toBe('true')
})
it('keeps the role code available but hidden from the default list layout', () => {
expect(rolesSource).toContain("{ key: 'roleCode', prop: 'code', label: '角色编码', minWidth: 180, showOverflowTooltip: true, defaultVisible: false }")
it('shows the role code in the default list layout', () => {
expect(rolesSource).toContain("{ key: 'roleCode', prop: 'code', label: '角色编码', minWidth: 180, showOverflowTooltip: true }")
expect(rolesSource).toContain('<el-form-item label="角色编码"')
expect(rolesSource).not.toContain('<small>{{ (row as Role).code }}</small>')
expect(rolesSource).toContain('aria-label="平台角色列表"')
@@ -126,7 +124,8 @@ describe('RolesView', () => {
await flushPromises()
expect(listPlatformRoles).toHaveBeenCalledTimes(1)
expect(listPlatformInternalUsers).toHaveBeenCalledTimes(1)
expect(rolesSource).toContain('userCount: role.memberCount')
expect(rolesSource).not.toContain('listPlatformInternalUsers')
expect(wrapper.get('[data-testid="row-count"]').text()).toBe('1')
expect(wrapper.text()).not.toContain('角色负责聚合菜单、操作和数据范围,内部用户可分配多个角色')
expect(wrapper.find('[data-testid="permission-tree"]').exists()).toBe(false)