53 lines
2.4 KiB
JavaScript
53 lines
2.4 KiB
JavaScript
// Run with: node scripts/test_flow_disable_ui.js
|
|
// Regression checks for Flow OFF hiding generated rules even with stale plan data.
|
|
const assert = require('node:assert/strict');
|
|
const fs = require('node:fs');
|
|
const vm = require('node:vm');
|
|
const path = require('node:path');
|
|
const root = path.resolve(__dirname, '..');
|
|
const host = { innerHTML: '' };
|
|
const section = { hidden: false };
|
|
const app = {
|
|
flows: [{ id: 'flow1', enabled: false, draft: false, name: 'Disabled heating' }],
|
|
automations: [], devices: [], groups: [], zones: [],
|
|
controlPlan: { zones: [], next_events: [], rules: [], emergency_stop_active: false },
|
|
};
|
|
const context = vm.createContext({
|
|
app,
|
|
$: selector => selector === '#controlPlan' ? host : selector === '#controlPlanSection' ? section : null,
|
|
tr: key => key,
|
|
esc: x => String(x),
|
|
fmtTemp: n => String(n),
|
|
houseModeLabel: x => x,
|
|
zoneRuntimeStatusLabel: () => '',
|
|
zonePresetLabel: x => x,
|
|
groupState: () => ({}),
|
|
modeLabel: x => x,
|
|
locale: () => 'pl-PL',
|
|
});
|
|
vm.runInContext(fs.readFileSync(path.join(root, 'web/js-dynamic/dashboard.js'), 'utf8'), context);
|
|
function rule(flowId, enabled = true, id = 'FLOW_RULE_MARKER') {
|
|
return { id, name: id, enabled, flow_id: flowId, trigger_kind: 'flow', action: {} };
|
|
}
|
|
const generated = rule('flow1');
|
|
const orphan = rule('missing-flow', true, 'ORPHAN_RULE_MARKER');
|
|
const local = rule(null, true, 'LOCAL_RULE_MARKER');
|
|
app.controlPlan.rules = [generated, orphan, local];
|
|
function visible(r) { return context.planRuleEffectivelyEnabled(r); }
|
|
assert.equal(visible(generated), false, 'disabled parent must block generated rule');
|
|
assert.equal(visible(orphan), false, 'missing parent must block generated rule');
|
|
assert.equal(visible(local), true, 'unrelated local automation remains available');
|
|
context.renderControlPlan();
|
|
assert.doesNotMatch(host.innerHTML, /FLOW_RULE_MARKER|ORPHAN_RULE_MARKER/);
|
|
assert.match(host.innerHTML, /LOCAL_RULE_MARKER/);
|
|
app.flows[0].enabled = true;
|
|
assert.equal(visible(generated), true);
|
|
context.renderControlPlan();
|
|
assert.match(host.innerHTML, /FLOW_RULE_MARKER/);
|
|
app.flows[0].draft = true;
|
|
assert.equal(visible(generated), false, 'draft Flow must never execute');
|
|
app.flows[0].draft = false;
|
|
app.flows[0].enabled = false;
|
|
assert.equal(visible(rule('flow1', false)), false, 'disabled compiled rule must remain disabled');
|
|
console.log('OK: 9 disabled Flow UI/regression checks');
|