mirror of
https://github.com/n8n-io/n8n.git
synced 2024-11-15 00:54:06 -08:00
test
This commit is contained in:
parent
bd4df6dbb5
commit
878220d7b6
|
@ -1,5 +1,5 @@
|
|||
import jp from 'jsonpath';
|
||||
import { useDataSchema } from '@/composables/useDataSchema';
|
||||
import { useDataSchema, useFlattenSchema } from '@/composables/useDataSchema';
|
||||
import type { Schema } from '@/Interface';
|
||||
|
||||
describe('useDataSchema', () => {
|
||||
|
@ -525,3 +525,39 @@ describe('useDataSchema', () => {
|
|||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('useFlattenSchema', () => {
|
||||
it('flattens a schema', () => {
|
||||
const schema: Schema = {
|
||||
path: '',
|
||||
type: 'object',
|
||||
value: [
|
||||
{
|
||||
key: 'obj',
|
||||
path: '.obj',
|
||||
type: 'object',
|
||||
value: [
|
||||
{
|
||||
key: 'foo',
|
||||
path: '.obj.foo',
|
||||
type: 'object',
|
||||
value: [
|
||||
{
|
||||
key: 'nested',
|
||||
path: '.obj.foo.nested',
|
||||
type: 'string',
|
||||
value: 'bar',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
};
|
||||
expect(
|
||||
useFlattenSchema().flattSchema({
|
||||
schema,
|
||||
}).length,
|
||||
).toBe(3);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -12,7 +12,7 @@ import { generatePath, getMappedExpression } from '@/utils/mappingUtils';
|
|||
import { isObj } from '@/utils/typeGuards';
|
||||
import { useWorkflowsStore } from '@/stores/workflows.store';
|
||||
import { isPresent, shorten } from '@/utils/typesUtils';
|
||||
import { i18n } from '@/plugins/i18n';
|
||||
import { useI18n } from '@/composables/useI18n';
|
||||
import { checkExhaustive } from '@/utils/typeGuards';
|
||||
|
||||
export function useDataSchema() {
|
||||
|
@ -175,7 +175,7 @@ export type SchemaNode = {
|
|||
depth: number;
|
||||
connectedOutputIndexes: number[];
|
||||
itemsCount: number;
|
||||
schema: Schema | null;
|
||||
schema: Schema;
|
||||
};
|
||||
|
||||
export type RenderItem = {
|
||||
|
@ -321,16 +321,6 @@ export const useFlattenSchema = () => {
|
|||
}
|
||||
};
|
||||
|
||||
const flattSchemaNode = (schemaNode: SchemaNode) => {
|
||||
const { schema, node, depth } = schemaNode;
|
||||
|
||||
if (!schema) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return flattSchema({ schema, node, depth });
|
||||
};
|
||||
|
||||
const flattMultipleSchema = (nodes: SchemaNode[], additionalInfo: (node: INodeUi) => string) =>
|
||||
nodes.reduce<Renders[]>((acc, item, index) => {
|
||||
acc.push({
|
||||
|
@ -350,13 +340,13 @@ export const useFlattenSchema = () => {
|
|||
if (isDataEmpty(item.schema)) {
|
||||
acc.push({
|
||||
id: `empty-${index}`,
|
||||
value: i18n.baseText('dataMapping.schemaView.emptyData'),
|
||||
value: useI18n().baseText('dataMapping.schemaView.emptyData'),
|
||||
type: 'item',
|
||||
});
|
||||
return acc;
|
||||
}
|
||||
|
||||
acc.push(...flattSchemaNode(item));
|
||||
acc.push(...flattSchema(item));
|
||||
return acc;
|
||||
}, []);
|
||||
|
||||
|
|
Loading…
Reference in a new issue