mirror of
https://github.com/The-Low-Code-Foundation/OpenNoodl.git
synced 2026-01-12 07:12:54 +01:00
Initial commit
Co-Authored-By: Eric Tuvesson <eric.tuvesson@gmail.com> Co-Authored-By: mikaeltellhed <2311083+mikaeltellhed@users.noreply.github.com> Co-Authored-By: kotte <14197736+mrtamagotchi@users.noreply.github.com> Co-Authored-By: Anders Larsson <64838990+anders-topp@users.noreply.github.com> Co-Authored-By: Johan <4934465+joolsus@users.noreply.github.com> Co-Authored-By: Tore Knudsen <18231882+torekndsn@users.noreply.github.com> Co-Authored-By: victoratndl <99176179+victoratndl@users.noreply.github.com>
This commit is contained in:
98
packages/noodl-runtime/test/editormodeleventshandler.test.js
Normal file
98
packages/noodl-runtime/test/editormodeleventshandler.test.js
Normal file
@@ -0,0 +1,98 @@
|
||||
const handleEvent = require('./editormodeleventshandler').handleEvent;
|
||||
const GraphModel = require('./models/graphmodel');
|
||||
const NodeContext = require('./nodecontext');
|
||||
|
||||
describe('Component ports update when on the componentPortsUpdated event', ()=>{
|
||||
let graphModel;
|
||||
let nodeContext;
|
||||
|
||||
beforeEach(async ()=>{
|
||||
nodeContext = new NodeContext();
|
||||
graphModel = new GraphModel();
|
||||
await graphModel.importComponentFromEditorData({
|
||||
id: 'component',
|
||||
name: 'testComponent',
|
||||
ports: [
|
||||
{ name: "testInput1", plug: "input", type: 'string'},
|
||||
{ name: "testInput2", plug: "input", type: 'string'},
|
||||
{ name: "testOutput1", plug: "output", type: 'string'},
|
||||
{ name: "testOutput2", plug: "output", type: 'string'}
|
||||
]
|
||||
});
|
||||
});
|
||||
|
||||
function updateAndMatchPorts(newInputPorts, newOutputPorts) {
|
||||
|
||||
handleEvent(nodeContext, graphModel, {
|
||||
type: 'componentPortsUpdated',
|
||||
componentName: 'testComponent',
|
||||
ports: newInputPorts.concat(newOutputPorts)
|
||||
});
|
||||
|
||||
const componentModel = graphModel.getComponentWithName('testComponent');
|
||||
const inputPorts = componentModel.getInputPorts();
|
||||
for(const port of newInputPorts) {
|
||||
expect(inputPorts.hasOwnProperty(port.name)).toBeTruthy();
|
||||
expect(inputPorts[port.name].type).toEqual(port.type);
|
||||
}
|
||||
expect(Object.keys(inputPorts).length).toBe(newInputPorts.length);
|
||||
|
||||
const outputPorts = componentModel.getOutputPorts();
|
||||
for(const port of newOutputPorts) {
|
||||
expect(outputPorts.hasOwnProperty(port.name)).toBeTruthy();
|
||||
expect(outputPorts[port.name].type).toEqual(port.type);
|
||||
}
|
||||
expect(Object.keys(outputPorts).length).toBe(newOutputPorts.length);
|
||||
}
|
||||
|
||||
test('Input ports are added', () => {
|
||||
updateAndMatchPorts([
|
||||
{ name: "testInput1", plug: "input", type: 'string'},
|
||||
{ name: "testInput2", plug: "input", type: 'string'},
|
||||
],
|
||||
[
|
||||
{name: "testOutput1", plug: "output", type: 'string'}
|
||||
]);
|
||||
});
|
||||
|
||||
test('Input ports are removed', () => {
|
||||
updateAndMatchPorts([],
|
||||
[
|
||||
{name: "testOutput1", plug: "output", type: 'string'}
|
||||
]);
|
||||
});
|
||||
|
||||
test('Input port types are updated', () => {
|
||||
updateAndMatchPorts([
|
||||
{ name: "testInput1", plug: "input", type: 'boolean'},
|
||||
{ name: "testInput2", plug: "input", type: {name:'number'}}
|
||||
],
|
||||
[]);
|
||||
});
|
||||
|
||||
test('Output ports are added', () => {
|
||||
updateAndMatchPorts([
|
||||
{ name: "testInput1", plug: "input", type: 'string'}
|
||||
],
|
||||
[
|
||||
{name: "testOutput1", plug: "output", type: 'string'},
|
||||
{name: "testOutput2", plug: "output", type: 'string'}
|
||||
]);
|
||||
});
|
||||
|
||||
test('Output ports are removed', () => {
|
||||
updateAndMatchPorts([
|
||||
{ name: "testInput1", plug: "input", type: 'string'}
|
||||
],
|
||||
[
|
||||
]);
|
||||
});
|
||||
|
||||
test('Output port types are updated', () => {
|
||||
updateAndMatchPorts([],
|
||||
[
|
||||
{ name: "testOutput1", plug: "output", type: 'number'},
|
||||
{ name: "testOutput2", plug: "output", type: {name:'boolean'}}
|
||||
]);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user