Files
zkxw/web-admin/tests/project-management.test.ts
T
zlwuandCursor 1fd1100b8f feat(web-admin): 项目组列表展示成员与负责医院
在负责人列后追加成员、负责医院,复用列表接口已有子行名称并用顿号拼接。
关联 #44

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-05 14:33:02 +08:00

86 lines
2.6 KiB
TypeScript

import assert from 'node:assert/strict'
import test from 'node:test'
import {
buildDrillFilters,
assignmentSnapshot,
joinChildNames
} from '../src/utils/project-management'
test('drill preserves applied dates and selected project when a team is opened', () => {
assert.deepEqual(
buildDrillFilters(
{ groupBy: 'team', projectId: 'project-1', startDate: '2026-01-01', endDate: '2026-01-31' },
{ id: 'team-1' },
'cell_storage'
),
{
projectId: 'project-1',
teamId: 'team-1',
startDate: '2026-01-01',
endDate: '2026-01-31',
bizType: 'cell_storage',
unassigned: false
}
)
})
test('unassigned drill preserves active scope so detail counts match the filtered summary', () => {
assert.deepEqual(
buildDrillFilters(
{ groupBy: 'project', projectId: 'p', teamId: 't' },
{ id: 'unassigned' },
'research_donation'
),
{ projectId: 'p', teamId: 't', bizType: 'research_donation', unassigned: true }
)
})
test('assignment snapshot preserves nullable old ownership and excludes display-only data', () => {
assert.deepEqual(
assignmentSnapshot([
{ bizType: 'presign', id: 'a', projectId: null, projectName: 'old', secret: 'x' }
]),
[{ bizType: 'presign', id: 'a', projectId: null }]
)
})
test('management payload excludes readonly response fields and preserves child IDs', async () => {
const { managementPayload } = await import('../src/utils/project-management')
assert.deepEqual(
managementPayload('teams', {
id: 't',
teamName: 'Team',
leaderUserId: 'u',
leaderName: 'Name',
enabled: true,
remark: '',
members: [{ id: 'm', userId: 'u', name: 'Name' }],
regions: [],
hospitals: [],
createTime: 'today'
}),
{
teamName: 'Team',
leaderUserId: 'u',
enabled: true,
remark: '',
members: [{ id: 'm', userId: 'u' }],
regions: [],
hospitals: []
}
)
})
test('joinChildNames joins display names and skips blanks', () => {
assert.equal(joinChildNames([{ name: '甲' }, { name: '' }, { name: '乙' }, {}]), '甲、乙')
assert.equal(joinChildNames([]), '')
assert.equal(joinChildNames(undefined), '')
})
test('filter options use visible historical scope; create and reassignment remain strict', async () => {
const { projectOptionsParams } = await import('../src/utils/project-management')
assert.deepEqual(projectOptionsParams('cell_storage', true), {
bizType: 'cell_storage',
usage: 'filter'
})
assert.deepEqual(projectOptionsParams('cell_storage', false), { bizType: 'cell_storage' })
})