feat: built-in type read-only view,s chema list, states, spec files
This commit is contained in:
1 parent
3c67cd2314
commit
f514146fed
24 files changed
+1220
-88
No files matched your search
@@ -0,0 +1,56 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import type { BuiltinField } from '@/composables/useContentTypes'
|
||||
import { fieldIcon, fieldRules, fieldTypeLabel } from '@/lib/schemaFields'
|
||||
|
||||
function field(overrides: Partial<BuiltinField>): BuiltinField {
|
||||
return {
|
||||
key: 'f',
|
||||
label: 'F',
|
||||
type: 'text',
|
||||
required: false,
|
||||
unique: false,
|
||||
default: null,
|
||||
min: null,
|
||||
max: null,
|
||||
options: null,
|
||||
...overrides,
|
||||
}
|
||||
}
|
||||
|
||||
describe('field types', () => {
|
||||
it.each([
|
||||
['text', 'Text', 'i-lucide-type'],
|
||||
['richtext', 'Rich text', 'i-lucide-pilcrow'],
|
||||
['number', 'Number', 'i-lucide-hash'],
|
||||
['boolean', 'Yes or no', 'i-lucide-toggle-left'],
|
||||
['date', 'Date', 'i-lucide-calendar'],
|
||||
['select', 'Choice', 'i-lucide-list'],
|
||||
])('%s reads %s with %s', (type, label, icon) => {
|
||||
expect(fieldTypeLabel(type)).toBe(label)
|
||||
expect(fieldIcon(type)).toBe(icon)
|
||||
})
|
||||
})
|
||||
|
||||
describe('field rules', () => {
|
||||
it.each([
|
||||
[{ type: 'text', required: true, max: 200 }, 'Required · up to 200 characters'],
|
||||
[{ type: 'text', required: true, unique: true }, 'Required · unique'],
|
||||
[{ type: 'richtext', max: 10000 }, 'Up to 10,000 characters'],
|
||||
[{ type: 'boolean', default: false }, 'Off by default'],
|
||||
[{ type: 'boolean', default: true }, 'On by default'],
|
||||
[{ type: 'date' }, ''],
|
||||
[{ type: 'text', min: 3, max: 80 }, '3 to 80 characters'],
|
||||
[{ type: 'text', min: 3 }, 'At least 3 characters'],
|
||||
[{ type: 'number', min: 1, max: 5000 }, 'Between 1 and 5000'],
|
||||
[{ type: 'number', min: 1 }, 'At least 1'],
|
||||
[{ type: 'number', max: 5000 }, 'At most 5000'],
|
||||
[{ type: 'select', options: ['a', 'b', 'c'] }, '3 choices'],
|
||||
[{ type: 'text', default: 'Draft' }, 'Default: Draft'],
|
||||
])('%j reads %s', (settings, rules) => {
|
||||
expect(fieldRules(field(settings as Partial<BuiltinField>))).toBe(rules)
|
||||
})
|
||||
|
||||
it('reads a missing setting as absent', () => {
|
||||
expect(fieldRules({ key: 'k', label: 'K', type: 'date' } as BuiltinField)).toBe('')
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user