51 lines
1.9 KiB
JavaScript
51 lines
1.9 KiB
JavaScript
|
|
'use strict';
|
||
|
|
|
||
|
|
const test = require('node:test');
|
||
|
|
const assert = require('node:assert/strict');
|
||
|
|
|
||
|
|
const DashboardApi = require('../../src/specificClass.js');
|
||
|
|
|
||
|
|
// softwareType (as reported at runtime, lowercased) -> the template that must resolve.
|
||
|
|
const CASES = [
|
||
|
|
['rotatingmachine', 'machine.json'],
|
||
|
|
['machinegroupcontrol', 'machineGroup.json'],
|
||
|
|
['pumpingstation', 'pumpingStation.json'],
|
||
|
|
['valvegroupcontrol', 'valveGroupControl.json'],
|
||
|
|
['diffuser', 'aeration.json'],
|
||
|
|
['measurement', 'measurement.json'],
|
||
|
|
['reactor', 'reactor.json'],
|
||
|
|
['settler', 'settler.json'],
|
||
|
|
['valve', 'valve.json'],
|
||
|
|
['monster', 'monster.json'],
|
||
|
|
];
|
||
|
|
|
||
|
|
for (const [softwareType, file] of CASES) {
|
||
|
|
test(`softwareType '${softwareType}' resolves to ${file}`, () => {
|
||
|
|
const api = new DashboardApi({});
|
||
|
|
const resolved = api._templateFileForSoftwareType(softwareType);
|
||
|
|
assert.ok(resolved, `expected a template path for ${softwareType}`);
|
||
|
|
assert.ok(resolved.endsWith(file), `expected ${file}, got ${resolved}`);
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
test('resolution is case-insensitive (camelCase softwareType still resolves)', () => {
|
||
|
|
const api = new DashboardApi({});
|
||
|
|
assert.ok(api._templateFileForSoftwareType('rotatingMachine').endsWith('machine.json'));
|
||
|
|
assert.ok(api._templateFileForSoftwareType('machineGroupControl').endsWith('machineGroup.json'));
|
||
|
|
});
|
||
|
|
|
||
|
|
test('rotatingmachine now builds a dashboard (was: no template found)', () => {
|
||
|
|
const api = new DashboardApi({});
|
||
|
|
const built = api.buildDashboard({
|
||
|
|
nodeConfig: { general: { id: 'rm-1', name: 'Pump A' }, functionality: { softwareType: 'rotatingmachine' } },
|
||
|
|
positionVsParent: 'downstream',
|
||
|
|
});
|
||
|
|
assert.ok(built, 'expected a built dashboard, not null');
|
||
|
|
assert.equal(built.softwareType, 'rotatingmachine');
|
||
|
|
});
|
||
|
|
|
||
|
|
test('unknown softwareType still returns null (no template)', () => {
|
||
|
|
const api = new DashboardApi({});
|
||
|
|
assert.equal(api._templateFileForSoftwareType('totally-unknown-type'), null);
|
||
|
|
});
|