feat(cms): clarify sponsor ordering
This commit is contained in:
48
tests/int/partners-admin-ordering.int.spec.ts
Normal file
48
tests/int/partners-admin-ordering.int.spec.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
import type { Field, NumberField, NumberFieldSingleValidation } from 'payload'
|
||||
import { describe, expect, it } from 'vitest'
|
||||
|
||||
import { Partners } from '@/collections/Partners'
|
||||
|
||||
function partnerField(name: string): Field {
|
||||
const field = Partners.fields.find((candidate) => 'name' in candidate && candidate.name === name)
|
||||
if (!field) throw new Error(`Missing Partners field: ${name}`)
|
||||
return field
|
||||
}
|
||||
|
||||
describe('Partners admin ordering contract', () => {
|
||||
it('shows the title and ordering state needed for content operations', () => {
|
||||
expect(Partners.admin?.useAsTitle).toBe('name')
|
||||
expect(Partners.admin?.defaultColumns).toEqual([
|
||||
'name',
|
||||
'tier',
|
||||
'sortOrder',
|
||||
'_status',
|
||||
'active',
|
||||
'showOnHomepage',
|
||||
'updatedAt',
|
||||
])
|
||||
})
|
||||
|
||||
it('accepts only numeric tiers 1, 2, and 3', async () => {
|
||||
const tierField = partnerField('tier')
|
||||
|
||||
expect(tierField).toMatchObject({
|
||||
type: 'number',
|
||||
min: 1,
|
||||
max: 3,
|
||||
required: true,
|
||||
admin: { step: 1 },
|
||||
})
|
||||
|
||||
const validate = (tierField as NumberField).validate as NumberFieldSingleValidation | undefined
|
||||
expect(validate).toBeTypeOf('function')
|
||||
|
||||
for (const value of [1, 2, 3]) {
|
||||
expect(await validate?.(value, {} as never)).toBe(true)
|
||||
}
|
||||
|
||||
for (const value of [0, 1.5, 4, Number.NaN, null, undefined]) {
|
||||
expect(await validate?.(value, {} as never)).toBe('Tier must be one of 1, 2, or 3.')
|
||||
}
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user