feat: delete a custom type

This commit is contained in:
Florian Sylvain committed 2026-10-20 17:56:44 +02:00
1 parent 76e9e1220c
commit 5404291af2
25 files changed
+1768 -46

No files matched your search

@@ -0,0 +1,125 @@
import { describe, expect, it } from 'vitest'
import { resolveSchemaTypeView, type SchemaTypeInputs } from '@/lib/schemaTypeView'
const SETTLED: SchemaTypeInputs = {
listsForbidden: false,
listsLoading: false,
customFailed: false,
builtinFailed: false,
hasBuiltin: false,
hasCustom: false,
skeletonVisible: false,
countStatus: 'idle',
}
const resolve = (patch: Partial<SchemaTypeInputs>) =>
resolveSchemaTypeView({ ...SETTLED, ...patch })
describe('resolveSchemaTypeView', () => {
it.each([
['forbidden lists', { listsForbidden: true }],
['forbidden count', { countStatus: 'forbidden' }],
[
'forbidden over loading',
{ listsForbidden: true, listsLoading: true, skeletonVisible: true },
],
['forbidden over a custom type', { countStatus: 'forbidden', hasCustom: true }],
] as const)('is forbidden and bleeds for %s', (_, patch) => {
expect(resolve(patch)).toEqual({
view: 'forbidden',
editable: false,
loading: false,
bleed: true,
})
})
it.each([
['lists loading', { listsLoading: true }],
['count idle on a custom type', { hasCustom: true, countStatus: 'idle' }],
['count loading on a custom type', { hasCustom: true, countStatus: 'loading' }],
] as const)('shows the skeleton only once visible, %s', (_, patch) => {
expect(resolve({ ...patch, skeletonVisible: true })).toEqual({
view: 'skeleton',
editable: false,
loading: true,
bleed: false,
})
expect(resolve({ ...patch, skeletonVisible: false })).toEqual({
view: 'blank',
editable: false,
loading: true,
bleed: false,
})
})
it('does not wait for the count when there is no custom type', () => {
expect(resolve({ hasBuiltin: true, countStatus: 'loading' }).loading).toBe(false)
})
it('reports a failed custom list before anything else', () => {
expect(
resolve({
customFailed: true,
builtinFailed: true,
hasBuiltin: true,
hasCustom: true,
countStatus: 'failed',
}),
).toEqual({ view: 'listsFailed', editable: false, loading: false, bleed: false })
})
it('reports a failed built-in list after the custom one', () => {
expect(resolve({ builtinFailed: true, hasBuiltin: true, countStatus: 'failed' })).toEqual({
view: 'builtinListFailed',
editable: false,
loading: false,
bleed: false,
})
})
it('reports a failed count on a custom type', () => {
expect(resolve({ hasCustom: true, hasBuiltin: true, countStatus: 'failed' })).toEqual({
view: 'countFailed',
editable: false,
loading: false,
bleed: false,
})
})
it('is editable and bleeds for a custom type with a ready count', () => {
expect(resolve({ hasCustom: true, hasBuiltin: true, countStatus: 'ready' })).toEqual({
view: 'editable',
editable: true,
loading: false,
bleed: true,
})
})
it.each(['idle', 'ready', 'missing'] as const)(
'shows a built-in type without bleeding, count %s',
(countStatus) => {
expect(resolve({ hasBuiltin: true, countStatus })).toEqual({
view: 'builtin',
editable: false,
loading: false,
bleed: false,
})
},
)
it.each(['idle', 'missing', 'ready'] as const)(
'is not found and bleeds with no type at all, count %s',
(countStatus) => {
expect(resolve({ countStatus })).toEqual({
view: 'notFound',
editable: false,
loading: false,
bleed: true,
})
},
)
it('is not found for a custom type whose count went missing', () => {
expect(resolve({ hasCustom: true, countStatus: 'missing' }).view).toBe('notFound')
})
})