Files
simple/frontend/tests/poll_ui.test.js
T
catarrh 25f001a778 feat: card-driven STATUS polling and the Poll Interval Negotiation event (v3.5.9)
- EVENT_NAMES (server + PWA) corrected against TS 102 223 v18.3.0 8.25:
  0x14 is "Access technology change (multiple)" (not Change of UICC
  Access), 0x19 Profile container, 0x1A Void, 0x1B Secured profile
  container, 0x1C Poll interval negotiation, 0x20-0x22 reserved.  Values
  the CAT spec leaves "Reserved for 3GPP" now carry the concrete TS 31.111
  event name + clause (0x11 (I-)WLAN access status, 0x12 Network
  rejection, 0x15 CSG cell selection, 0x17 IMS registration, 0x18 Incoming
  IMS data, 0x1D Data connection status change, 0x1E CAG cell selection,
  0x1F Slices status change).
- Poll Interval Negotiation (0x1C) in the Phone tab: the form proposes a
  Duration (unit + interval) and the UICC's answer (TS 102 223 8.97
  accepted / rejected / modified + optional Duration) is decoded and
  shown; a "modified" duration becomes the background poll interval.  The
  form appears when the card subscribed to the event, like every other.
- Polling emulation is card-driven: a POLL INTERVAL adopts its Duration
  (minutes/seconds/tenths -> 1..255 s, logged) for the background poll,
  is echoed in the TERMINAL RESPONSE (6.8.4) and clears a POLLING OFF
  suspension; POLLING OFF (6.4.14) suspends proactive polling until a new
  POLL INTERVAL - the manual Send STATUS button and presence detection are
  unaffected.  /api/poll-status and /api/poll-toggle report card_disabled
  (+ a warning when enabling while suspended); the PWA shows it in amber.
- Tests: tests/test_poll.py +7, test_proactive_names.py +3, frontend
  event_forms +2 and poll_ui (4).  Help EN/RU, docs/api.md, AGENTS.

573 frontend / 439 Python green; version 3.5.9; sw cache simple-v262.
2026-09-26 12:56:18 +03:00

63 lines
2.1 KiB
JavaScript

const { test } = require('node:test');
const assert = require('node:assert');
const fs = require('node:fs');
const path = require('node:path');
const html = fs.readFileSync(path.join(__dirname, '..', 'index.html'), 'utf8');
function extractFunc(src, name, asyncFn) {
const re = new RegExp('function\\s+' + name + '\\s*\\([^)]*\\)\\s*\\{');
const m = re.exec(src);
if (!m) throw new Error('function ' + name + ' not found');
let i = m.index + m[0].length - 1;
let depth = 0;
for (; i < src.length; i++) {
if (src[i] === '{') depth++;
else if (src[i] === '}') {
depth--;
if (depth === 0) break;
}
}
return (asyncFn ? 'async ' : '') + src.slice(m.index, i + 1);
}
eval(extractFunc(html, 'pysimUpdatePollUI'));
globalThis.t = s => s;
function setup() {
const els = {
'pli-pause-btn': { textContent: '', classList: { add: () => {}, remove: () => {} } },
'pli-poll-stat': { textContent: '', className: 'text-xs text-gray-400' },
};
globalThis.document = { getElementById: id => els[id] || null };
return els;
}
test('pysimUpdatePollUI shows the interval while polling is on', () => {
const els = setup();
pysimUpdatePollUI(true, 30);
assert.strictEqual(els['pli-pause-btn'].textContent, 'ON');
assert.strictEqual(els['pli-poll-stat'].textContent, '(30s)');
assert.ok(!els['pli-poll-stat'].className.includes('amber'));
});
test('pysimUpdatePollUI shows the card-disabled state in amber', () => {
const els = setup();
pysimUpdatePollUI(true, 30, true);
assert.ok(els['pli-poll-stat'].textContent.includes('POLLING OFF'), els['pli-poll-stat'].textContent);
assert.ok(els['pli-poll-stat'].className.includes('text-amber-600'));
});
test('pysimUpdatePollUI shows a server warning', () => {
const els = setup();
pysimUpdatePollUI(true, 30, false, 'card disabled proactive polling');
assert.strictEqual(els['pli-poll-stat'].textContent, 'card disabled proactive polling');
});
test('pysimUpdatePollUI clears the status line when off', () => {
const els = setup();
pysimUpdatePollUI(false, 30);
assert.strictEqual(els['pli-pause-btn'].textContent, 'OFF');
assert.strictEqual(els['pli-poll-stat'].textContent, '');
});