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:
50
packages/noodl-runtime/test/nodecontext.test.js
Normal file
50
packages/noodl-runtime/test/nodecontext.test.js
Normal file
@@ -0,0 +1,50 @@
|
||||
const NodeContext = require('./nodecontext');
|
||||
const NodeDefinition = require('./nodedefinition');
|
||||
const ComponentInstance = require('./nodes/componentinstance');
|
||||
const { ComponentModel } = require('./models/componentmodel');
|
||||
|
||||
describe('NodeContext', ()=>{
|
||||
|
||||
test("can detect cyclic updates", async () => {
|
||||
const testNodeDefinition = NodeDefinition.defineNode({
|
||||
name: 'Test Node',
|
||||
category: 'test',
|
||||
initialize() {this._internal.count = 0;},
|
||||
inputs: {
|
||||
input: {
|
||||
set() {
|
||||
this._internal.count++;
|
||||
this.flagOutputDirty('output');
|
||||
}
|
||||
}
|
||||
},
|
||||
outputs: {
|
||||
output: {type: 'number', get() {return Math.random()}}
|
||||
},
|
||||
})
|
||||
|
||||
const context = new NodeContext();
|
||||
context.nodeRegister.register(testNodeDefinition);
|
||||
|
||||
const componentModel = await ComponentModel.createFromExportData({
|
||||
name: 'testComponent',
|
||||
id: '1',
|
||||
nodes: [
|
||||
{ id: '2', type: 'Test Node', parameters: {input: true}},
|
||||
{ id: '3', type: 'Test Node'}
|
||||
],
|
||||
connections: [
|
||||
{sourceId: '2', sourcePort: 'output', targetId: '3', targetPort: 'input'},
|
||||
{sourceId: '3', sourcePort: 'output', targetId: '2', targetPort: 'input'}
|
||||
]
|
||||
});
|
||||
|
||||
const componentInstance = new ComponentInstance(context);
|
||||
await componentInstance.setComponentModel(componentModel);
|
||||
|
||||
context.update();
|
||||
|
||||
expect(componentInstance.nodeScope.getNodeWithId('2')._internal.count).toBeGreaterThan(50);
|
||||
expect(componentInstance.nodeScope.getNodeWithId('3')._internal.count).toBeGreaterThan(50);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user