110 lines
3.0 KiB
JavaScript
110 lines
3.0 KiB
JavaScript
const test = require('node:test');
|
|
const assert = require('node:assert/strict');
|
|
|
|
const NodeClass = require('../../src/nodeClass');
|
|
const { makeNodeStub } = require('../helpers/factories');
|
|
|
|
function makeUiConfig(overrides = {}) {
|
|
return {
|
|
unit: 'm3/h',
|
|
enableLog: true,
|
|
logLevel: 'debug',
|
|
supplier: 'hidrostal',
|
|
category: 'machine',
|
|
assetType: 'pump',
|
|
model: 'hidrostal-H05K-S03R',
|
|
curvePressureUnit: 'mbar',
|
|
curveFlowUnit: 'm3/h',
|
|
curvePowerUnit: 'kW',
|
|
curveControlUnit: '%',
|
|
positionVsParent: 'atEquipment',
|
|
speed: 1,
|
|
movementMode: 'staticspeed',
|
|
startup: 0,
|
|
warmup: 0,
|
|
shutdown: 0,
|
|
cooldown: 0,
|
|
...overrides,
|
|
};
|
|
}
|
|
|
|
test('_loadConfig maps legacy editor fields for asset identity', () => {
|
|
const inst = Object.create(NodeClass.prototype);
|
|
inst.node = makeNodeStub();
|
|
inst.name = 'rotatingMachine';
|
|
|
|
inst._loadConfig(
|
|
makeUiConfig({
|
|
uuid: 'uuid-from-editor',
|
|
assetTagNumber: 'TAG-123',
|
|
}),
|
|
inst.node
|
|
);
|
|
|
|
assert.equal(inst.config.asset.uuid, 'uuid-from-editor');
|
|
assert.equal(inst.config.asset.tagCode, 'TAG-123');
|
|
assert.equal(inst.config.asset.tagNumber, 'TAG-123');
|
|
});
|
|
|
|
test('_loadConfig prefers explicit assetUuid/assetTagCode when present', () => {
|
|
const inst = Object.create(NodeClass.prototype);
|
|
inst.node = makeNodeStub();
|
|
inst.name = 'rotatingMachine';
|
|
|
|
inst._loadConfig(
|
|
makeUiConfig({
|
|
uuid: 'legacy-uuid',
|
|
assetUuid: 'explicit-uuid',
|
|
assetTagNumber: 'legacy-tag',
|
|
assetTagCode: 'explicit-tag',
|
|
}),
|
|
inst.node
|
|
);
|
|
|
|
assert.equal(inst.config.asset.uuid, 'explicit-uuid');
|
|
assert.equal(inst.config.asset.tagCode, 'explicit-tag');
|
|
});
|
|
|
|
test('_loadConfig builds explicit curveUnits and falls back for invalid flow unit', () => {
|
|
const inst = Object.create(NodeClass.prototype);
|
|
inst.node = makeNodeStub();
|
|
inst.name = 'rotatingMachine';
|
|
|
|
inst._loadConfig(
|
|
makeUiConfig({
|
|
unit: 'not-a-unit',
|
|
curvePressureUnit: 'mbar',
|
|
curveFlowUnit: 'm3/h',
|
|
curvePowerUnit: 'kW',
|
|
curveControlUnit: '%',
|
|
}),
|
|
inst.node
|
|
);
|
|
|
|
assert.equal(inst.config.general.unit, 'm3/h');
|
|
assert.equal(inst.config.asset.unit, 'm3/h');
|
|
assert.equal(inst.config.asset.curveUnits.pressure, 'mbar');
|
|
assert.equal(inst.config.asset.curveUnits.flow, 'm3/h');
|
|
assert.equal(inst.config.asset.curveUnits.power, 'kW');
|
|
assert.equal(inst.config.asset.curveUnits.control, '%');
|
|
assert.ok(inst.node._warns.length >= 1);
|
|
});
|
|
|
|
test('_setupSpecificClass propagates logging settings into state config', () => {
|
|
const inst = Object.create(NodeClass.prototype);
|
|
inst.node = makeNodeStub();
|
|
inst.name = 'rotatingMachine';
|
|
const uiConfig = makeUiConfig({
|
|
enableLog: true,
|
|
logLevel: 'warn',
|
|
uuid: 'uuid-test',
|
|
assetTagNumber: 'TAG-9',
|
|
});
|
|
|
|
inst._loadConfig(uiConfig, inst.node);
|
|
inst._setupSpecificClass(uiConfig);
|
|
|
|
assert.equal(inst.source.state.config.general.logging.enabled, true);
|
|
assert.equal(inst.source.state.config.general.logging.logLevel, 'warn');
|
|
});
|