Files
zkxw/web-admin/tests/project-management.test.ts
T
zlwuandCursor a598b17ab9 fix(web-admin): 项目业务类型下拉去掉中试服务可选 (#162)
新建不可选中试;旧项目已含 pilot_service 时编辑仍展示该选项。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-20 15:15:54 +08:00

106 lines
3.3 KiB
TypeScript

import assert from 'node:assert/strict'
import test from 'node:test'
import {
buildDrillFilters,
assignmentSnapshot,
joinChildNames,
projectBizTypeSelectLabels
} 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' })
})
test('project biz type select hides pilot by default but keeps it when already selected', () => {
const labels = {
presign: '预签约',
cell_storage: '细胞存储',
research_donation: '科研捐赠',
pilot_service: '中试服务',
basic_experiment: '临床科研'
}
const fresh = projectBizTypeSelectLabels(labels, [])
assert.equal(fresh.pilot_service, undefined)
assert.equal(fresh.presign, undefined)
assert.equal(fresh.cell_storage, '细胞存储')
assert.equal(fresh.basic_experiment, '临床科研')
const legacy = projectBizTypeSelectLabels(labels, ['cell_storage', 'pilot_service'])
assert.equal(legacy.pilot_service, '中试服务')
assert.equal(legacy.cell_storage, '细胞存储')
})