121 lines
4.5 KiB
TypeScript
121 lines
4.5 KiB
TypeScript
import { render, screen, waitFor } from '@testing-library/react'
|
|
import OrganizationWorkspace from './OrganizationWorkspace'
|
|
|
|
jest.mock('next-auth/react', () => ({
|
|
useSession: () => ({
|
|
data: { user: { role: 'SYSTEM_ADMIN', isSuperAdmin: false } },
|
|
status: 'authenticated',
|
|
}),
|
|
}))
|
|
|
|
jest.mock('next/navigation', () => ({
|
|
useRouter: () => ({ push: jest.fn() }),
|
|
}))
|
|
|
|
const organizationResponse = {
|
|
tree: [
|
|
{
|
|
id: 'company',
|
|
name: '江苏简尚品牌管理有限公司',
|
|
path: '江苏简尚品牌管理有限公司',
|
|
level: 0,
|
|
parentId: null,
|
|
count: 3,
|
|
children: [
|
|
{
|
|
id: 'brand-center',
|
|
name: '品牌中心',
|
|
path: '江苏简尚品牌管理有限公司/品牌中心',
|
|
level: 1,
|
|
parentId: 'company',
|
|
count: 2,
|
|
children: [
|
|
{
|
|
id: 'creative',
|
|
name: '品牌创意部',
|
|
path: '江苏简尚品牌管理有限公司/品牌中心/品牌创意部',
|
|
level: 2,
|
|
parentId: 'brand-center',
|
|
count: 1,
|
|
children: [],
|
|
},
|
|
],
|
|
},
|
|
{
|
|
id: 'support',
|
|
name: '业务支持',
|
|
path: '江苏简尚品牌管理有限公司/业务支持',
|
|
level: 1,
|
|
parentId: 'company',
|
|
count: 1,
|
|
children: [],
|
|
},
|
|
],
|
|
},
|
|
],
|
|
employees: [
|
|
{
|
|
employeeProfileId: 'profile-brand-1', userId: 'brand-1', username: 'brand-1', realName: '品牌甲', displayName: '品牌甲', jobNumber: 'BC001',
|
|
departmentPath: '江苏简尚品牌管理有限公司/品牌中心', departmentName: '品牌中心', positionTitle: '负责人',
|
|
positionLevel: 'M2', levelType: 'M', managerName: null, isLeadership: true, employmentState: 'ACTIVE', accountIsActive: true,
|
|
},
|
|
{
|
|
employeeProfileId: 'profile-brand-2', userId: 'brand-2', username: 'brand-2', realName: '品牌乙', displayName: '品牌乙', jobNumber: 'BC002',
|
|
departmentPath: '江苏简尚品牌管理有限公司/品牌中心/品牌创意部', departmentName: '品牌创意部', positionTitle: '设计师',
|
|
positionLevel: 'P2', levelType: 'P', managerName: '品牌甲', isLeadership: false, employmentState: 'ACTIVE', accountIsActive: true,
|
|
},
|
|
{
|
|
employeeProfileId: 'profile-support-1', userId: 'support-1', username: 'support-1', realName: '支持甲', displayName: '支持甲', jobNumber: 'SP001',
|
|
departmentPath: '江苏简尚品牌管理有限公司/业务支持', departmentName: '业务支持', positionTitle: '专员',
|
|
positionLevel: 'P1', levelType: 'P', managerName: null, isLeadership: false, employmentState: 'ACTIVE', accountIsActive: true,
|
|
},
|
|
],
|
|
unclassified: [],
|
|
unbound: [],
|
|
summary: {
|
|
totalEmployees: 3,
|
|
activeEmployees: 3,
|
|
inactiveEmployees: 0,
|
|
unboundCount: 0,
|
|
unclassifiedCount: 0,
|
|
visibleCount: 3,
|
|
scope: 'all',
|
|
},
|
|
}
|
|
|
|
describe('OrganizationWorkspace scoped view', () => {
|
|
beforeEach(() => {
|
|
global.fetch = jest.fn().mockResolvedValue({
|
|
ok: true,
|
|
json: async () => organizationResponse,
|
|
}) as jest.Mock
|
|
})
|
|
|
|
afterEach(() => {
|
|
jest.restoreAllMocks()
|
|
})
|
|
|
|
it('只显示品牌中心节点及其人员', async () => {
|
|
render(<OrganizationWorkspace embedded scopeRootName="品牌中心" heading="人员架构" />)
|
|
|
|
expect(await screen.findByRole('heading', { name: '人员架构' })).toBeInTheDocument()
|
|
expect(await screen.findByText('品牌中心组织架构')).toBeInTheDocument()
|
|
expect(screen.getByRole('button', { name: /品牌中心/ })).toBeInTheDocument()
|
|
expect(screen.queryByRole('button', { name: /业务支持/ })).not.toBeInTheDocument()
|
|
expect(screen.getByText((_, node) => node?.textContent === '共 2 人')).toBeInTheDocument()
|
|
expect((await screen.findAllByText('品牌甲')).length).toBeGreaterThan(0)
|
|
expect(screen.getByText('品牌乙')).toBeInTheDocument()
|
|
expect(screen.queryByText('支持甲')).not.toBeInTheDocument()
|
|
})
|
|
|
|
it('找不到品牌中心时显示明确同步提示且不回退到公司全量', async () => {
|
|
render(<OrganizationWorkspace embedded scopeRootName="不存在的中心" />)
|
|
|
|
expect(await screen.findByText('未找到“不存在的中心”组织节点')).toBeInTheDocument()
|
|
await waitFor(() => {
|
|
expect(screen.getByText(/请先完成公司组织架构同步/)).toBeInTheDocument()
|
|
})
|
|
expect(screen.queryByRole('button', { name: /江苏简尚品牌管理有限公司/ })).not.toBeInTheDocument()
|
|
})
|
|
})
|