feat(admin-ui): catalog FK chips на cards (← N использ.)
This commit is contained in:
@@ -10,7 +10,9 @@ import {
|
||||
parseScopeFilter,
|
||||
matchesQuery,
|
||||
groupByBundle,
|
||||
uniqueRefBy,
|
||||
} from './dictionaries.index'
|
||||
import type { SchemaDependent } from '@/api/client'
|
||||
|
||||
const mkDict = (overrides: Partial<DictionaryDefinition>): DictionaryDefinition => ({
|
||||
id: 'id-' + (overrides.name ?? 'x'),
|
||||
@@ -131,3 +133,42 @@ describe('groupByBundle', () => {
|
||||
expect(out.has('default')).toBe(true)
|
||||
})
|
||||
})
|
||||
|
||||
describe('uniqueRefBy', () => {
|
||||
const mkDep = (sourceDict: string, sourceField = 'fk'): SchemaDependent => ({
|
||||
sourceDict,
|
||||
sourceDisplayName: `${sourceDict}-display`,
|
||||
sourceField,
|
||||
targetField: 'id',
|
||||
onClose: 'BLOCK',
|
||||
activeRecordsInSourceDict: 0,
|
||||
})
|
||||
|
||||
it('empty input returns empty array', () => {
|
||||
expect(uniqueRefBy([])).toEqual([])
|
||||
})
|
||||
|
||||
it('preserves single entry as-is', () => {
|
||||
const out = uniqueRefBy([mkDep('missions')])
|
||||
expect(out).toHaveLength(1)
|
||||
expect(out[0].sourceDict).toBe('missions')
|
||||
})
|
||||
|
||||
it('dedups by sourceDict — multiple fields → один chip', () => {
|
||||
const out = uniqueRefBy([
|
||||
mkDep('satellites', 'type_id'),
|
||||
mkDep('satellites', 'mission_id'),
|
||||
mkDep('missions', 'fk'),
|
||||
])
|
||||
expect(out.map((d) => d.sourceDict)).toEqual(['satellites', 'missions'])
|
||||
})
|
||||
|
||||
it('preserves first-occurrence displayName', () => {
|
||||
const out = uniqueRefBy([
|
||||
{ ...mkDep('x'), sourceDisplayName: 'First' },
|
||||
{ ...mkDep('x'), sourceDisplayName: 'Second' },
|
||||
])
|
||||
expect(out).toHaveLength(1)
|
||||
expect(out[0].sourceDisplayName).toBe('First')
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user