25 lines
1.5 KiB
TypeScript
25 lines
1.5 KiB
TypeScript
import { render, screen } from '@testing-library/react'
|
|
import OrganizationStructureDashboard from './OrganizationStructureDashboard'
|
|
|
|
let role = 'SYSTEM_ADMIN'
|
|
jest.mock('next-auth/react', () => ({ useSession: () => ({ status: 'authenticated', data: { user: { role } } }) }))
|
|
jest.mock('./DepartmentShell', () => ({ __esModule: true, default: ({ children }: { children: React.ReactNode }) => <div>{children}</div> }))
|
|
jest.mock('@/components/organization/OrganizationWorkspace', () => ({
|
|
__esModule: true, default: ({ scopeRootName }: { scopeRootName?: string }) => <div data-testid="organization-workspace" data-scope={scopeRootName || 'company'} />,
|
|
}))
|
|
|
|
beforeEach(() => { role = 'SYSTEM_ADMIN' })
|
|
test('品牌中心与全公司使用同一真实组件并明确切换范围', () => {
|
|
const { rerender } = render(<OrganizationStructureDashboard />)
|
|
expect(screen.getByTestId('organization-workspace')).toHaveAttribute('data-scope', '品牌中心')
|
|
rerender(<OrganizationStructureDashboard scope="company" />)
|
|
expect(screen.getByTestId('organization-workspace')).toHaveAttribute('data-scope', 'company')
|
|
expect(screen.getByRole('link', { name: '全公司' })).toHaveAttribute('aria-current', 'page')
|
|
})
|
|
test('普通成员不能挂载全公司组织工作面', () => {
|
|
role = 'USER'
|
|
render(<OrganizationStructureDashboard scope="company" />)
|
|
expect(screen.getByRole('heading', { name: '暂无组织架构查看权限' })).toBeInTheDocument()
|
|
expect(screen.queryByTestId('organization-workspace')).not.toBeInTheDocument()
|
|
})
|