Files
fluxscape/packages/noodl-runtime/test/nodecontext.test.js
Michael Cartner b9c60b07dc 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>
2024-01-26 11:52:55 +01:00

50 lines
1.8 KiB
JavaScript

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);
});
});