before functional changes by codex
This commit is contained in:
54
test/basic/nodeclass-routing.basic.test.js
Normal file
54
test/basic/nodeclass-routing.basic.test.js
Normal file
@@ -0,0 +1,54 @@
|
||||
const test = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
|
||||
const NodeClass = require('../../src/nodeClass');
|
||||
const { makeNodeStub, makeREDStub } = require('../helpers/factories');
|
||||
|
||||
test('_attachInputHandler routes known topics to source methods', () => {
|
||||
const inst = Object.create(NodeClass.prototype);
|
||||
const node = makeNodeStub();
|
||||
const calls = [];
|
||||
|
||||
inst.node = node;
|
||||
inst.RED = makeREDStub();
|
||||
inst.source = {
|
||||
toggleSimulation() { calls.push('simulator'); },
|
||||
toggleOutlierDetection() { calls.push('outlierDetection'); },
|
||||
calibrate() { calls.push('calibrate'); },
|
||||
set inputValue(v) { calls.push(['measurement', v]); },
|
||||
};
|
||||
|
||||
inst._attachInputHandler();
|
||||
const onInput = node._handlers.input;
|
||||
|
||||
onInput({ topic: 'simulator' }, () => {}, () => {});
|
||||
onInput({ topic: 'outlierDetection' }, () => {}, () => {});
|
||||
onInput({ topic: 'calibrate' }, () => {}, () => {});
|
||||
onInput({ topic: 'measurement', payload: 12.3 }, () => {}, () => {});
|
||||
|
||||
assert.deepEqual(calls[0], 'simulator');
|
||||
assert.deepEqual(calls[1], 'outlierDetection');
|
||||
assert.deepEqual(calls[2], 'calibrate');
|
||||
assert.deepEqual(calls[3], ['measurement', 12.3]);
|
||||
});
|
||||
|
||||
test('_registerChild emits delayed registerChild message on output 2', () => {
|
||||
const inst = Object.create(NodeClass.prototype);
|
||||
const node = makeNodeStub();
|
||||
|
||||
inst.node = node;
|
||||
inst.config = { functionality: { positionVsParent: 'upstream', distance: 5 } };
|
||||
|
||||
const originalSetTimeout = global.setTimeout;
|
||||
global.setTimeout = (fn) => { fn(); return 1; };
|
||||
try {
|
||||
inst._registerChild();
|
||||
} finally {
|
||||
global.setTimeout = originalSetTimeout;
|
||||
}
|
||||
|
||||
assert.equal(node._sent.length, 1);
|
||||
assert.equal(node._sent[0][2].topic, 'registerChild');
|
||||
assert.equal(node._sent[0][2].positionVsParent, 'upstream');
|
||||
assert.equal(node._sent[0][2].distance, 5);
|
||||
});
|
||||
Reference in New Issue
Block a user