Files
WebApp/src/app/conectar/schema-form.spec.ts
T

53 lines
1.9 KiB
TypeScript

import { nodeSchema } from './schema-form';
const PIPELINE = {
$defs: {
Position: { type: 'object', properties: { x: { type: 'number' } } },
Condition: { type: 'object', properties: { column: { type: 'string' } } },
Route: {
type: 'object',
additionalProperties: false,
required: ['id', 'when'],
properties: {
id: { type: 'string' },
kind: { const: 'route' },
inputs: { type: 'array' },
position: { anyOf: [{ $ref: '#/$defs/Position' }, { type: 'null' }] },
when: { type: 'array', items: { $ref: '#/$defs/Condition' } },
resource: { anyOf: [{ type: 'string' }, { type: 'null' }], title: 'Resource' },
values: { type: 'object', additionalProperties: { type: 'string' }, title: 'Values' },
on: {
type: 'array',
items: { type: 'array', prefixItems: [{ type: 'string' }, { type: 'string' }] },
},
extra: { type: 'object', title: 'Extra' },
source: { type: 'string', advanced: true },
},
},
},
} as never;
describe('node forms from the pipeline schema', () => {
const schema = nodeSchema(PIPELINE, 'route') as any;
it('leaves out what the canvas edits', () => {
expect(Object.keys(schema.properties)).toEqual(['when', 'resource', 'values', 'on']);
expect(schema.required).toEqual(['when']);
});
it('inlines references and drops null from optional values', () => {
expect(schema.properties.when.items.properties.column.type).toBe('string');
expect(schema.properties.resource.type).toBe('string');
});
it('edits maps of texts and pairs as rows', () => {
expect(schema.properties.values.widget.formlyConfig.type).toBe('map');
expect(schema.properties.on.widget.formlyConfig.type).toBe('pairs');
});
it('leaves JSON-only values and advanced fields to the "Avanzado" tab', () => {
expect(schema.properties.extra).toBeUndefined();
expect(schema.properties.source).toBeUndefined();
});
});