This commit is contained in:
Mateusz Gruszczyński committed 2026-10-21 11:27:44 +02:00
1 parent bb5caa769f
commit a679eb5747
25 files changed
+484 -78

No files matched your search

@@ -0,0 +1,49 @@
// Focused UI checks for zone temperature origin and sensor-safety indicators.
// Run from the project root: node scripts/test_temperature_explanation_ui.js
'use strict';
const assert = require('node:assert/strict');
const fs = require('node:fs');
const vm = require('node:vm');
const dict = JSON.parse(fs.readFileSync('lang/pl.json', 'utf8')).translations;
const ctx = vm.createContext({
app: { zones: [], devices: [], groups: [] },
tr: (key, vars = {}) => String(dict[key] || key).replace(/\{(\w+)\}/g, (match, name) => vars[name] ?? match),
fmtTemp: value => value == null ? '--' : `${Number(value).toFixed(1)}°C`,
uiIcon: name => `<icon name="${name}"></icon>`,
esc: value => String(value ?? '').replace(/[&<>'"]/g, x => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', "'": '&#39;', '"': '&quot;' })[x]),
});
vm.runInContext(fs.readFileSync('web/js-dynamic/entities.js', 'utf8'), ctx);
const combined = {
sensor_source: 'combined',
control_temperature_source: 'combined',
device_temperature: 19,
external_temperature: 21,
external_sensor_weight: 0.8,
current_temperature: 20.6,
room_sensor_status: 'ok',
enabled: true,
};
const formula = ctx.zoneTemperatureExplanation(combined);
assert.match(formula, /GREE 19\.0°C × 20%/);
assert.match(formula, /pokój 21\.0°C × 80% = 20\.6°C/);
const help = ctx.zoneTemperatureHelp(combined);
assert.match(help, /<details/);
assert.match(help, /Skąd ta temperatura/);
assert.match(help, /aria-label=/);
assert.match(ctx.zoneTemperatureExplanation({ ...combined, control_temperature_source: 'external' }), /21\.0°C pochodzi z czujnika pokojowego/);
assert.match(ctx.zoneTemperatureExplanation({ ...combined, control_temperature_source: 'device' }), /19\.0°C pochodzi wyłącznie z GREE/);
const stale = {
...combined, control_temperature_source: 'device_fallback', room_sensor_status: 'stale',
external_temperature: null, current_temperature: 19, heating_sensor_guard_active: true,
};
assert.match(ctx.zoneTemperatureExplanation(stale), /nieaktualny/);
assert.match(ctx.zoneTemperatureHelp(stale), /nie uruchomi ani nie zwiększy grzania/);
assert.match(ctx.zoneHeatingGuardNotice(stale, { power: true, mode: 'heat' }), /ochrony sprężarki/);
assert.match(ctx.zoneHeatingGuardNotice(stale, { power: true, mode: 'auto' }), /ochrony sprężarki/);
assert.equal(ctx.zoneRuntimeStatusLabel(stale, 'heat', { power: true }), dict['zones.heatGuardActive']);
const mismatch = { ...stale, room_sensor_status: 'discrepancy', control_temperature_source: 'device_discrepancy_fallback', external_temperature: 23, max_sensor_difference: 3 };
assert.match(ctx.zoneTemperatureExplanation(mismatch), /więcej niż 3\.0°C/);
assert.equal(ctx.zoneHeatingGuardNotice({ ...combined, heating_sensor_guard_active: false }, null), '');
console.log('OK: weighted formula, control sources, stale/mismatch warning and automatic heat safeguard UI');