52 lines
1.7 KiB
TypeScript
52 lines
1.7 KiB
TypeScript
import { render, screen } from '@testing-library/react'
|
|
import DataDefinitionsDashboard from './DataDefinitionsDashboard'
|
|
|
|
let sessionState = {
|
|
data: { user: { name: '本地超级管理员', role: 'SYSTEM_ADMIN' } },
|
|
status: 'authenticated',
|
|
}
|
|
|
|
jest.mock('next-auth/react', () => ({
|
|
useSession: () => sessionState,
|
|
signOut: jest.fn(),
|
|
}))
|
|
|
|
jest.mock('@/components/organization/OrganizationWorkspace', () => ({
|
|
__esModule: true,
|
|
default: ({ embedded }: { embedded?: boolean }) => (
|
|
<div data-testid="organization-workspace" data-embedded={embedded ? 'true' : 'false'}>
|
|
真实公司组织架构
|
|
</div>
|
|
),
|
|
}))
|
|
|
|
describe('DataDefinitionsDashboard', () => {
|
|
beforeEach(() => {
|
|
sessionState = {
|
|
data: { user: { name: '本地超级管理员', role: 'SYSTEM_ADMIN' } },
|
|
status: 'authenticated',
|
|
}
|
|
})
|
|
|
|
it('二级边栏直接显示公司组织架构并复用真实操作面', () => {
|
|
render(<DataDefinitionsDashboard />)
|
|
|
|
const navigation = screen.getByRole('navigation', { name: '数据口径二级导航' })
|
|
expect(navigation).not.toHaveTextContent('数据来源')
|
|
expect(screen.getByRole('link', { name: /公司组织架构/ })).toHaveAttribute('aria-current', 'page')
|
|
expect(screen.getByTestId('organization-workspace')).toHaveAttribute('data-embedded', 'true')
|
|
})
|
|
|
|
it('沿用组织架构原有管理员权限', () => {
|
|
sessionState = {
|
|
data: { user: { name: '普通成员', role: 'USER' } },
|
|
status: 'authenticated',
|
|
}
|
|
|
|
render(<DataDefinitionsDashboard />)
|
|
|
|
expect(screen.getByRole('heading', { name: '暂无组织架构查看权限' })).toBeInTheDocument()
|
|
expect(screen.queryByTestId('organization-workspace')).not.toBeInTheDocument()
|
|
})
|
|
})
|