Add comprehensive smoke and feature tests for Gateway API
- Introduced LtdFeatureTests to validate BACnet and OPC UA point updates, trend logging, and alarm rule functionality. - Added OpcUaClientTests to ensure proper OPC UA client configuration, point value synchronization, and session management. - Created OpcUaFeatureTests to test OPC UA server capabilities, including browsing, reading, writing, and subscription notifications. - Implemented native_bacnet_test.py for isolated BACnet wire testing, covering discovery, read/write operations, and command processing. - Added ui-theme-tabs.test.cjs to verify theme switching, tab interactions, and protocol form accessibility in the UI.
This commit is contained in:
1 parent
d9165a60ff
commit
98c48d9d78
80 files changed
+11120
-315
No files matched your search
@@ -0,0 +1,86 @@
|
||||
const assert = require('node:assert/strict');
|
||||
const fs = require('node:fs');
|
||||
const path = require('node:path');
|
||||
const vm = require('node:vm');
|
||||
const { test } = require('node:test');
|
||||
|
||||
// No browser dependencies; exercise the same theme/tab functions as the shipped UI.
|
||||
function element(dataset = {}) {
|
||||
const classes = new Set();
|
||||
return { dataset, handlers: {}, attributes: {}, hidden: false,
|
||||
classList: { toggle(name, on) { on ? classes.add(name) : classes.delete(name); } },
|
||||
addEventListener(name, handler) { this.handlers[name] = handler; },
|
||||
setAttribute(name, value) { this.attributes[name] = value; },
|
||||
focus() { this.focused = true; }
|
||||
};
|
||||
}
|
||||
function harness() {
|
||||
const themes = ['light','dark','system'].map(theme => element({ theme }));
|
||||
const tabs = ['points','bacnet','opcua','modbus','knx','mqtt','serial','status'].map(pointsTab => element({ pointsTab }));
|
||||
const panels = tabs.map(tab => element({ pointsPanel: tab.dataset.pointsTab }));
|
||||
const storage = new Map();
|
||||
const document = { documentElement: element(), querySelector: () => null,
|
||||
querySelectorAll(selector) { return selector === 'button[data-theme]' ? themes : selector === '[data-points-tab]' ? tabs : selector === '[data-points-panel]' ? panels : []; }
|
||||
};
|
||||
const context = vm.createContext({ document, window: { matchMedia: () => ({ matches: true, addEventListener() {} }) },
|
||||
sessionStorage: { getItem() { return null; } }, localStorage: { getItem: key => storage.get(key), setItem: (key,value) => storage.set(key,value) }
|
||||
});
|
||||
const root = path.join(__dirname, '../src/Gateway.Api/wwwroot');
|
||||
const app = fs.readFileSync(path.join(root,'app.js'),'utf8');
|
||||
vm.runInContext(fs.readFileSync(path.join(root,'ltd.js'),'utf8'),context);
|
||||
vm.runInContext(fs.readFileSync(path.join(root,'gateway-status.js'),'utf8'),context);
|
||||
vm.runInContext(app.slice(0,app.lastIndexOf('boot().catch(')),context);
|
||||
return { context, document, themes, tabs, panels, storage, run: code => vm.runInContext(code,context) };
|
||||
}
|
||||
|
||||
test('theme updates every switch in place, persists preference, and does not rebuild forms', async () => {
|
||||
const h = harness();
|
||||
h.run("renderShell = () => { throw new Error('Theme must preserve forms'); }; api = async () => ({ theme: 'light', sidebarPinned: true });");
|
||||
await h.run("setTheme('light')");
|
||||
assert.equal(h.document.documentElement.dataset.theme,'light');
|
||||
assert.equal(h.storage.get('seiugw-theme'),'light');
|
||||
assert.equal(h.themes[0].attributes['aria-pressed'],'true');
|
||||
assert.equal(h.themes[1].attributes['aria-pressed'],'false');
|
||||
h.run("applyTheme('system')");
|
||||
assert.equal(h.document.documentElement.dataset.theme,'dark');
|
||||
assert.equal(h.themes[2].attributes['aria-pressed'],'true');
|
||||
});
|
||||
|
||||
test('tab clicks and arrow keys select exactly one retained panel', () => {
|
||||
const h = harness();
|
||||
h.run("renderView = () => { throw new Error('Tabs must preserve mounted forms'); }; bindPointTabs();");
|
||||
h.panels[3].draft = 'unsaved';
|
||||
h.tabs[3].handlers.click();
|
||||
assert.deepEqual(h.panels.filter(p => !p.hidden).map(p => p.dataset.pointsPanel),['modbus']);
|
||||
h.tabs[3].handlers.keydown({ key: 'ArrowRight', preventDefault() {} });
|
||||
assert.deepEqual(h.panels.filter(p => !p.hidden).map(p => p.dataset.pointsPanel),['knx']);
|
||||
assert.equal(h.tabs[4].focused,true);
|
||||
h.tabs[3].handlers.click();
|
||||
assert.equal(h.panels[3].draft,'unsaved');
|
||||
assert.equal(h.tabs.filter(tab => tab.tabIndex === 0).length,1);
|
||||
});
|
||||
|
||||
test('protocol forms and browser hosts belong to separate accessible panels', () => {
|
||||
const h = harness();
|
||||
h.run("state.configuration = { bacnet: {}, opcUa: {}, knx: {} }; state.pointsTab = 'bacnet';");
|
||||
const markup = h.run('viewProtocols()');
|
||||
const expected = { bacnet: ['bacnet-form','bacnet-browser'], opcua: ['opcua-form','opcua-browser'], modbus: ['modbus-server-form','modbus-import-form'], knx: ['knx-form'], serial: ['serial-port-form'] };
|
||||
const sections = [...markup.matchAll(/<section id="point-panel-([^"]+)"[\s\S]*?(?=<section id="point-panel-|$)/g)];
|
||||
assert.equal(sections.length,5);
|
||||
for (const [markup,id] of sections) {
|
||||
for (const form of expected[id]) assert.ok(markup.includes(`id="${form}"`),`${form} must be in ${id}`);
|
||||
assert.ok(markup.includes(`aria-labelledby="point-tab-${id}"`));
|
||||
assert.equal(/data-points-panel="[^"]+" hidden/.test(markup),id !== 'bacnet');
|
||||
}
|
||||
});
|
||||
|
||||
test('protocol tabs respect permissions, including MQTT-only accounts', () => {
|
||||
const h = harness();
|
||||
h.run("bodyOf = markup => markup; viewMqtt = () => '<div>MQTT test</div>'; state.user = { permissions: ['manage_integrations'] };");
|
||||
const markup = h.run('viewDataPoints()');
|
||||
assert.ok(markup.includes('point-tab-mqtt'));
|
||||
assert.ok(markup.includes('point-tab-status'));
|
||||
assert.ok(!markup.includes('point-tab-bacnet'));
|
||||
assert.ok(!markup.includes('point-tab-points'));
|
||||
assert.equal(h.run('state.pointsTab'),'mqtt');
|
||||
});
|
||||
Reference in new issue
Block a user