63 lines
2.1 KiB
JavaScript
63 lines
2.1 KiB
JavaScript
|
|
// The dashboard's `_measurement` templating var MUST equal the InfluxDB
|
||
|
|
// measurement name that outputUtils.formatMsg writes telemetry under, or every
|
||
|
|
// panel queries a non-existent series and renders blank.
|
||
|
|
//
|
||
|
|
// outputUtils convention (generalFunctions/src/helper/outputUtils.js):
|
||
|
|
// measurement = config.general.name || `${softwareType}_${config.general.id}`
|
||
|
|
//
|
||
|
|
// buildDashboard must mirror it exactly.
|
||
|
|
|
||
|
|
const test = require('node:test');
|
||
|
|
const assert = require('node:assert/strict');
|
||
|
|
|
||
|
|
const DashboardApi = require('../../src/specificClass');
|
||
|
|
|
||
|
|
function makeApi() {
|
||
|
|
return new DashboardApi({
|
||
|
|
general: { name: 'dapi', logging: { enabled: false, logLevel: 'error' } },
|
||
|
|
grafanaConnector: { protocol: 'http', host: 'localhost', port: 3000, bearerToken: '' },
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
function measurementVar(dash) {
|
||
|
|
return dash.dashboard.templating.list.find((v) => v.name === 'measurement').current.value;
|
||
|
|
}
|
||
|
|
|
||
|
|
test('measurement var uses general.name when set (matches outputUtils)', () => {
|
||
|
|
const api = makeApi();
|
||
|
|
const dash = api.buildDashboard({
|
||
|
|
nodeConfig: {
|
||
|
|
general: { id: '248ba213d44df5b9', name: 'pumpingStation' },
|
||
|
|
functionality: { softwareType: 'pumpingstation' },
|
||
|
|
},
|
||
|
|
positionVsParent: 'atequipment',
|
||
|
|
});
|
||
|
|
assert.equal(dash.measurementName, 'pumpingStation');
|
||
|
|
assert.equal(measurementVar(dash), 'pumpingStation');
|
||
|
|
});
|
||
|
|
|
||
|
|
test('measurement var falls back to <softwareType>_<id> when name is empty', () => {
|
||
|
|
const api = makeApi();
|
||
|
|
const dash = api.buildDashboard({
|
||
|
|
nodeConfig: {
|
||
|
|
general: { id: '693ebd559017d39f', name: '' },
|
||
|
|
functionality: { softwareType: 'rotatingmachine' },
|
||
|
|
},
|
||
|
|
positionVsParent: 'atequipment',
|
||
|
|
});
|
||
|
|
assert.equal(dash.measurementName, 'rotatingmachine_693ebd559017d39f');
|
||
|
|
assert.equal(measurementVar(dash), 'rotatingmachine_693ebd559017d39f');
|
||
|
|
});
|
||
|
|
|
||
|
|
test('fallback id segment is the node id, not the title', () => {
|
||
|
|
const api = makeApi();
|
||
|
|
const dash = api.buildDashboard({
|
||
|
|
nodeConfig: {
|
||
|
|
general: { id: 'abc123' },
|
||
|
|
functionality: { softwareType: 'measurement' },
|
||
|
|
},
|
||
|
|
positionVsParent: 'upstream',
|
||
|
|
});
|
||
|
|
assert.equal(dash.measurementName, 'measurement_abc123');
|
||
|
|
});
|