Skip to content

Commit

Permalink
test: all list variants (field, fields and types)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidenke committed Oct 26, 2024
1 parent 65788ed commit c54b637
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions src/transformers/field-list.transform.spec.ts
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();
});
});

0 comments on commit c54b637

Please sign in to comment.