import { render, screen } from '@testing-library/react' import userEvent from '@testing-library/user-event' import UserPermissionsDashboard from './UserPermissionsDashboard' jest.mock('next-auth/react', () => ({ useSession: () => ({ status: 'authenticated', data: { user: { isSuperAdmin: true, name: '本地超级管理员' } }, }), })) jest.mock('./DepartmentShell', () => ({ __esModule: true, default: ({ children }: { children: React.ReactNode }) =>
{children}
, })) describe('UserPermissionsDashboard', () => { beforeEach(() => { global.fetch = jest.fn().mockImplementation(async (input: RequestInfo) => { const url = String(input) if (url.includes('/api/organization/user-permissions?q=')) { return { ok: true, json: async () => ({ groups: [ { slug: 'operations', name: '运营' }, { slug: 'visual', name: '视觉' }, ], people: [ { userId: 'u-1', username: 'jiuqianqi', displayName: '九千七', jobNumber: 'JS0001', departmentPath: '江苏简尚品牌管理有限公司/运营中心A/事业一部/品类十九部', departmentName: '品类十九部', departmentGroups: [ { slug: 'operations', name: '运营', attachedPath: '江苏简尚品牌管理有限公司/运营中心A', source: 'inherit', }, ], personalGroups: [{ slug: 'visual', name: '视觉' }], }, ], }), } } return { ok: true, json: async () => ({ ok: true }) } }) as jest.Mock }) it('搜人后能看到部门组和加餐组', async () => { render() expect(screen.getByRole('heading', { level: 1, name: '按人看权限' })).toBeInTheDocument() await userEvent.type(screen.getByLabelText('搜索人员'), '九千七') expect(await screen.findByRole('heading', { level: 2, name: '九千七' })).toBeInTheDocument() expect(screen.getByText('部门带来的组')).toBeInTheDocument() expect(screen.getByText('随 运营中心A')).toBeInTheDocument() expect(screen.getByText('个人加的组')).toBeInTheDocument() expect(screen.getByText('视觉')).toBeInTheDocument() expect(screen.getAllByText('运营').length).toBeGreaterThan(0) }) })