before functional changes by codex
This commit is contained in:
77
test/basic/input-routing.basic.test.js
Normal file
77
test/basic/input-routing.basic.test.js
Normal file
@@ -0,0 +1,77 @@
|
||||
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 supported topics to source methods/setters', () => {
|
||||
const inst = Object.create(NodeClass.prototype);
|
||||
const node = makeNodeStub();
|
||||
const calls = [];
|
||||
|
||||
const source = {
|
||||
updateState(timestamp) {
|
||||
calls.push(['clock', timestamp]);
|
||||
},
|
||||
childRegistrationUtils: {
|
||||
registerChild(childSource, position) {
|
||||
calls.push(['registerChild', childSource, position]);
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
Object.defineProperty(source, 'setInfluent', {
|
||||
set(v) {
|
||||
calls.push(['Fluent', v]);
|
||||
},
|
||||
});
|
||||
|
||||
Object.defineProperty(source, 'setOTR', {
|
||||
set(v) {
|
||||
calls.push(['OTR', v]);
|
||||
},
|
||||
});
|
||||
|
||||
Object.defineProperty(source, 'setTemperature', {
|
||||
set(v) {
|
||||
calls.push(['Temperature', v]);
|
||||
},
|
||||
});
|
||||
|
||||
Object.defineProperty(source, 'setDispersion', {
|
||||
set(v) {
|
||||
calls.push(['Dispersion', v]);
|
||||
},
|
||||
});
|
||||
|
||||
inst.node = node;
|
||||
inst.RED = makeREDStub({
|
||||
childA: {
|
||||
source: { id: 'child-source-A' },
|
||||
},
|
||||
});
|
||||
inst.source = source;
|
||||
|
||||
inst._attachInputHandler();
|
||||
|
||||
const onInput = node._handlers.input;
|
||||
const sent = [];
|
||||
let doneCount = 0;
|
||||
|
||||
onInput({ topic: 'clock', timestamp: 1000 }, (msg) => sent.push(msg), () => doneCount++);
|
||||
onInput({ topic: 'Fluent', payload: { inlet: 0, F: 10, C: [] } }, () => {}, () => doneCount++);
|
||||
onInput({ topic: 'OTR', payload: 3.5 }, () => {}, () => doneCount++);
|
||||
onInput({ topic: 'Temperature', payload: 18.2 }, () => {}, () => doneCount++);
|
||||
onInput({ topic: 'Dispersion', payload: 0.2 }, () => {}, () => doneCount++);
|
||||
onInput({ topic: 'registerChild', payload: 'childA', positionVsParent: 'upstream' }, () => {}, () => doneCount++);
|
||||
|
||||
assert.equal(doneCount, 6);
|
||||
assert.equal(sent.length, 1);
|
||||
assert.equal(Array.isArray(sent[0]), true);
|
||||
assert.deepEqual(calls[0], ['clock', 1000]);
|
||||
assert.equal(calls.some((x) => x[0] === 'Fluent'), true);
|
||||
assert.equal(calls.some((x) => x[0] === 'OTR'), true);
|
||||
assert.equal(calls.some((x) => x[0] === 'Temperature'), true);
|
||||
assert.equal(calls.some((x) => x[0] === 'Dispersion'), true);
|
||||
assert.deepEqual(calls.at(-1), ['registerChild', { id: 'child-source-A' }, 'upstream']);
|
||||
});
|
||||
Reference in New Issue
Block a user