-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: all list variants (field, fields and types)
- Loading branch information
Showing
1 changed file
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import type { CmsField, CmsFieldBase, CmsFieldList } from 'decap-cms-core'; | ||
import z from 'zod'; | ||
|
||
import { transformListField } from './field-list.transform.js'; | ||
|
||
describe('field-list.transform', () => { | ||
it('allows parsing with field based schema', () => { | ||
const field = { | ||
name: 'foo', | ||
widget: 'list', | ||
field: { name: 'foo', widget: 'text' } as CmsField, | ||
} as CmsFieldBase & CmsFieldList; | ||
const { runtime } = transformListField(field, z); | ||
const result = ['foo', 'bar', 'baz']; | ||
expect(() => runtime.parse(result)).not.toThrow(); | ||
}); | ||
|
||
it('allows parsing with fields based schema', () => { | ||
const field = { | ||
name: 'foo', | ||
widget: 'list', | ||
fields: [ | ||
{ name: 'foo', widget: 'text' } as CmsField, | ||
{ name: 'bar', widget: 'number' } as CmsField, | ||
], | ||
} as CmsFieldBase & CmsFieldList; | ||
const { runtime } = transformListField(field, z); | ||
const result = [{ foo: 'foo', bar: 123 }]; | ||
expect(() => runtime.parse(result)).not.toThrow(); | ||
}); | ||
|
||
it('allows parsing with type based schema', () => { | ||
const field = { | ||
name: 'foo', | ||
widget: 'list', | ||
types: [ | ||
{ | ||
name: 'foo', | ||
fields: [ | ||
{ name: 'foo', widget: 'text' } as CmsField, | ||
{ name: 'bar', widget: 'number' } as CmsField, | ||
], | ||
}, | ||
], | ||
} as CmsFieldBase & CmsFieldList; | ||
const { runtime } = transformListField(field, z); | ||
const result = [{ type: 'foo', foo: 'foo', bar: 123 }]; | ||
expect(() => runtime.parse(result)).not.toThrow(); | ||
}); | ||
}); |