Initial commit to release
This commit is contained in:
109
packages/workflow/test/Helpers.ts
Normal file
109
packages/workflow/test/Helpers.ts
Normal file
@@ -0,0 +1,109 @@
|
||||
import {
|
||||
INodeType,
|
||||
INodeTypes,
|
||||
INodeTypesObject,
|
||||
} from '../src';
|
||||
|
||||
class NodeTypesClass implements INodeTypes {
|
||||
|
||||
nodeTypes: INodeTypesObject = {
|
||||
'test.set': {
|
||||
description: {
|
||||
displayName: 'Set',
|
||||
name: 'set',
|
||||
group: ['input'],
|
||||
version: 1,
|
||||
description: 'Sets a value',
|
||||
defaults: {
|
||||
name: 'Set',
|
||||
color: '#0000FF',
|
||||
},
|
||||
inputs: ['main'],
|
||||
outputs: ['main'],
|
||||
properties: [
|
||||
{
|
||||
displayName: 'Value1',
|
||||
name: 'value1',
|
||||
type: 'string',
|
||||
default: 'default-value1',
|
||||
},
|
||||
{
|
||||
displayName: 'Value2',
|
||||
name: 'value2',
|
||||
type: 'string',
|
||||
default: 'default-value2',
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
'test.setMulti': {
|
||||
description: {
|
||||
displayName: 'Set Multi',
|
||||
name: 'setMulti',
|
||||
group: ['input'],
|
||||
version: 1,
|
||||
description: 'Sets multiple values',
|
||||
defaults: {
|
||||
name: 'Set Multi',
|
||||
color: '#0000FF',
|
||||
},
|
||||
inputs: ['main'],
|
||||
outputs: ['main'],
|
||||
properties: [
|
||||
{
|
||||
displayName: 'Values',
|
||||
name: 'values',
|
||||
type: 'fixedCollection',
|
||||
typeOptions: {
|
||||
multipleValues: true,
|
||||
},
|
||||
default: {},
|
||||
options: [
|
||||
{
|
||||
name: 'string',
|
||||
displayName: 'String',
|
||||
values: [
|
||||
{
|
||||
displayName: 'Name',
|
||||
name: 'name',
|
||||
type: 'string',
|
||||
default: 'propertyName',
|
||||
placeholder: 'Name of the property to write data to.',
|
||||
},
|
||||
{
|
||||
displayName: 'Value',
|
||||
name: 'value',
|
||||
type: 'string',
|
||||
default: '',
|
||||
placeholder: 'The string value to write in the property.',
|
||||
},
|
||||
]
|
||||
},
|
||||
],
|
||||
},
|
||||
]
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
async init(nodeTypes: INodeTypesObject): Promise<void> { }
|
||||
|
||||
getAll(): INodeType[] {
|
||||
return Object.values(this.nodeTypes);
|
||||
}
|
||||
|
||||
getByName(nodeType: string): INodeType {
|
||||
return this.nodeTypes[nodeType];
|
||||
}
|
||||
}
|
||||
|
||||
let nodeTypesInstance: NodeTypesClass | undefined;
|
||||
|
||||
export function NodeTypes(): NodeTypesClass {
|
||||
if (nodeTypesInstance === undefined) {
|
||||
nodeTypesInstance = new NodeTypesClass();
|
||||
nodeTypesInstance.init({});
|
||||
}
|
||||
|
||||
return nodeTypesInstance;
|
||||
}
|
||||
2240
packages/workflow/test/NodeHelpers.test.ts
Normal file
2240
packages/workflow/test/NodeHelpers.test.ts
Normal file
File diff suppressed because it is too large
Load Diff
169
packages/workflow/test/ObservableObject.test.ts
Normal file
169
packages/workflow/test/ObservableObject.test.ts
Normal file
@@ -0,0 +1,169 @@
|
||||
import {
|
||||
IDataObject,
|
||||
ObservableObject,
|
||||
} from '../src';
|
||||
|
||||
|
||||
describe('ObservableObject', () => {
|
||||
|
||||
test('should recognize that item on parent level got added (init empty)', () => {
|
||||
const testObject = ObservableObject.create({});
|
||||
expect(testObject.__dataChanged).toBeFalsy();
|
||||
testObject.a = {};
|
||||
expect(testObject.__dataChanged).toBeTruthy();
|
||||
|
||||
// Make sure that "__dataChanged" does not returned as a key
|
||||
expect(Object.keys(testObject)).toEqual(['a']);
|
||||
});
|
||||
|
||||
test('should not recognize that item on parent level changed if it is empty object and option "ignoreEmptyOnFirstChild" === true (init empty)', () => {
|
||||
const testObject = ObservableObject.create({}, undefined, { ignoreEmptyOnFirstChild: true });
|
||||
expect(testObject.__dataChanged).toBeFalsy();
|
||||
testObject.a = {};
|
||||
expect(testObject.__dataChanged).toBeFalsy();
|
||||
expect(testObject.a).toEqual({});
|
||||
});
|
||||
|
||||
test('should recognize that item on parent level changed if it is not empty object and option "ignoreEmptyOnFirstChild" === true (init empty)', () => {
|
||||
const testObject = ObservableObject.create({}, undefined, { ignoreEmptyOnFirstChild: true });
|
||||
expect(testObject.__dataChanged).toBeFalsy();
|
||||
testObject.a = { b: 2 };
|
||||
expect(testObject.__dataChanged).toBeTruthy();
|
||||
expect(testObject.a).toEqual({ b: 2 });
|
||||
});
|
||||
|
||||
test('should not recognize that item on parent level changed if it is empty array and option "ignoreEmptyOnFirstChild" === true (init empty)', () => {
|
||||
const testObject = ObservableObject.create({}, undefined, { ignoreEmptyOnFirstChild: true });
|
||||
expect(testObject.__dataChanged).toBeFalsy();
|
||||
testObject.a = [];
|
||||
expect(testObject.__dataChanged).toBeFalsy();
|
||||
expect(testObject.a).toEqual([]);
|
||||
});
|
||||
|
||||
test('should recognize that item on parent level changed if it is not empty []] and option "ignoreEmptyOnFirstChild" === true (init empty)', () => {
|
||||
const testObject = ObservableObject.create({}, undefined, { ignoreEmptyOnFirstChild: true });
|
||||
expect(testObject.__dataChanged).toBeFalsy();
|
||||
testObject.a = [1, 2];
|
||||
expect(testObject.__dataChanged).toBeTruthy();
|
||||
expect(testObject.a).toEqual([1, 2]);
|
||||
});
|
||||
|
||||
test('should recognize that item on parent level changed (init data exists)', () => {
|
||||
const testObject = ObservableObject.create({ a: 1 });
|
||||
expect(testObject.__dataChanged).toBeFalsy();
|
||||
expect(testObject.a).toEqual(1);
|
||||
testObject.a = 2;
|
||||
expect(testObject.__dataChanged).toBeTruthy();
|
||||
expect(testObject.a).toEqual(2);
|
||||
});
|
||||
|
||||
test('should recognize that array on parent level changed (init data exists)', () => {
|
||||
const testObject = ObservableObject.create({ a: [1, 2] });
|
||||
expect(testObject.__dataChanged).toBeFalsy();
|
||||
expect(testObject.a).toEqual([1, 2]);
|
||||
(testObject.a as number[]).push(3);
|
||||
expect(testObject.__dataChanged).toBeTruthy();
|
||||
expect(testObject.a).toEqual([1, 2, 3]);
|
||||
});
|
||||
|
||||
test('should recognize that item on first child level changed (init data exists)', () => {
|
||||
const testObject = ObservableObject.create({ a: { b: 1 } });
|
||||
expect(testObject.__dataChanged).toBeFalsy();
|
||||
expect((testObject.a! as IDataObject).b).toEqual(1);
|
||||
(testObject.a! as IDataObject).b = 2;
|
||||
expect(testObject.__dataChanged).toBeTruthy();
|
||||
expect((testObject.a! as IDataObject).b).toEqual(2);
|
||||
});
|
||||
|
||||
test('should recognize that item on first child level changed if it is now empty and option "ignoreEmptyOnFirstChild" === true (init data exists)', () => {
|
||||
const testObject = ObservableObject.create({ a: { b: 1 } }, undefined, { ignoreEmptyOnFirstChild: true });
|
||||
expect(testObject.__dataChanged).toBeFalsy();
|
||||
expect((testObject.a! as IDataObject).b).toEqual(1);
|
||||
testObject.a = {};
|
||||
expect(testObject.__dataChanged).toBeTruthy();
|
||||
expect(testObject.a).toEqual({});
|
||||
});
|
||||
|
||||
test('should recognize that item on first child level changed if it is now empty and option "ignoreEmptyOnFirstChild" === false (init data exists)', () => {
|
||||
const testObject = ObservableObject.create({ a: { b: 1 } }, undefined, { ignoreEmptyOnFirstChild: false });
|
||||
expect(testObject.__dataChanged).toBeFalsy();
|
||||
expect((testObject.a! as IDataObject).b).toEqual(1);
|
||||
testObject.a = {};
|
||||
expect(testObject.__dataChanged).toBeTruthy();
|
||||
expect(testObject.a).toEqual({});
|
||||
});
|
||||
|
||||
test('should recognize that array on first child level changed (init data exists)', () => {
|
||||
const testObject = ObservableObject.create({ a: { b: [1, 2] } });
|
||||
expect(testObject.__dataChanged).toBeFalsy();
|
||||
expect((testObject.a! as IDataObject).b).toEqual([1, 2]);
|
||||
((testObject.a! as IDataObject).b as number[]).push(3);
|
||||
expect(testObject.__dataChanged).toBeTruthy();
|
||||
expect((testObject.a! as IDataObject).b).toEqual([1, 2, 3]);
|
||||
});
|
||||
|
||||
test('should recognize that item on second child level changed (init data exists)', () => {
|
||||
const testObject = ObservableObject.create({ a: { b: { c: 1 } } });
|
||||
expect(testObject.__dataChanged).toBeFalsy();
|
||||
expect((testObject.a! as IDataObject).b).toEqual({c: 1});
|
||||
expect(((testObject.a! as IDataObject).b! as IDataObject).c).toEqual(1);
|
||||
((testObject.a! as IDataObject).b! as IDataObject).c = 2;
|
||||
expect(testObject.__dataChanged).toBeTruthy();
|
||||
expect((testObject.a! as IDataObject).b).toEqual({ c: 2 });
|
||||
});
|
||||
|
||||
test('should recognize that item on parent level got deleted (init data exists)', () => {
|
||||
const testObject = ObservableObject.create({ a: 1 });
|
||||
expect(testObject.__dataChanged).toBeFalsy();
|
||||
expect(testObject.a!).toEqual(1);
|
||||
delete testObject.a;
|
||||
expect(testObject.__dataChanged).toBeTruthy();
|
||||
expect(testObject.a!).toEqual(undefined);
|
||||
expect(testObject).toEqual({});
|
||||
});
|
||||
|
||||
test('should recognize that item on parent level got deleted even with and option "ignoreEmptyOnFirstChild" === true (init data exists)', () => {
|
||||
const testObject = ObservableObject.create({ a: 1 }, undefined, { ignoreEmptyOnFirstChild: true });
|
||||
expect(testObject.__dataChanged).toBeFalsy();
|
||||
expect(testObject.a!).toEqual(1);
|
||||
delete testObject.a;
|
||||
expect(testObject.__dataChanged).toBeTruthy();
|
||||
expect(testObject.a!).toEqual(undefined);
|
||||
expect(testObject).toEqual({});
|
||||
});
|
||||
|
||||
test('should recognize that item on second child level got deleted (init data exists)', () => {
|
||||
const testObject = ObservableObject.create({ a: { b: { c: 1 } } });
|
||||
expect(testObject.__dataChanged).toBeFalsy();
|
||||
expect((testObject.a! as IDataObject).b).toEqual({ c: 1 });
|
||||
delete (testObject.a! as IDataObject).b;
|
||||
expect(testObject.__dataChanged).toBeTruthy();
|
||||
expect((testObject.a! as IDataObject).b).toEqual(undefined);
|
||||
expect(testObject).toEqual({ a: {} });
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// test('xxxxxx', () => {
|
||||
// const testObject = ObservableObject.create({ a: { } }, undefined, { ignoreEmptyOnFirstChild: true });
|
||||
// expect(testObject.__dataChanged).toBeFalsy();
|
||||
// expect(testObject).toEqual({ a: { b: { c: 1 } } });
|
||||
// ((testObject.a! as DataObject).b as DataObject).c = 2;
|
||||
// // expect((testObject.a! as DataObject).b).toEqual({ c: 1 });
|
||||
// expect(testObject.__dataChanged).toBeTruthy();
|
||||
|
||||
// // expect(testObject.a).toEqual({});
|
||||
|
||||
|
||||
|
||||
// // expect((testObject.a! as DataObject).b).toEqual({ c: 1 });
|
||||
// // expect(((testObject.a! as DataObject).b! as DataObject).c).toEqual(1);
|
||||
// // ((testObject.a! as DataObject).b! as DataObject).c = 2;
|
||||
// // expect((testObject.a! as DataObject).b).toEqual({ c: 2 });
|
||||
// });
|
||||
|
||||
});
|
||||
1245
packages/workflow/test/Workflow.test.ts
Normal file
1245
packages/workflow/test/Workflow.test.ts
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user