ui: header preset indicators — ADM key glyph, SCP80/SCP81 completeness (v2.6.1)

- the ADM badge gains a trailing key glyph (ADM ✓ ⚿ / ADM ✗ ⚿) when the
  preset matching the equipped card's ICCID carries an ADM key; the four
  tooltip states cover key/no-key x verified/not-verified
- new gray SCP80/SCP81 markers after ADM, shown only when that preset has
  all SCP80 fields (KIc/KID, SPI1/SPI2, counter, KIc/KID keys) or the SCP81
  PSK pair filled in; hidden without a card session, a matching preset or
  the fields, never color-coded
- cardsScp80Complete/cardsScp81Complete/cardsAdmPresent/cardsMatchedPreset
  helpers; cardsRender reuses the SCP81 predicate
- tests: ADM four-state badge, marker show/hide, predicate whitespace
  handling, header markup order; help EN/RU updated; SW cache simple-v201
This commit is contained in:
2026-09-20 01:08:44 +03:00
parent cee59bd611
commit 97bc8f929d
9 changed files with 220 additions and 24 deletions
+71 -7
View File
@@ -24,7 +24,8 @@ function extractFunc(src, name) {
let code = 'var _pysimCardStateKey = null;\nvar _pysimCardSession = null;\n'
+ 'var _pysimServerAvailable = null;\nvar _pysimCardEquipped = false;\n'
+ 'var _pysimProactiveSeq = null;\nvar _pysimStkSig = null;\nvar _pysimAdmVerified = null;\n'
+ 'var _pysimHeaderIccid = undefined;\n'
+ 'var _pysimAdmKey = null;\n'
+ 'var _pysimHeaderIccid = undefined;\nvar _pysimHeaderScp80 = undefined;\nvar _pysimHeaderScp81 = undefined;\n'
+ 'var _cardsAutoIccid = null;\nvar _pysimCardIccid = null;\n';
code += extractFunc(html, 'pysimCardStateUpdate') + '\n';
code += extractFunc(html, 'pysimAvailabilityState') + '\n';
@@ -33,6 +34,12 @@ code += extractFunc(html, 'pysimProactiveSeqChanged') + '\n';
code += extractFunc(html, 'pysimStkStatusChanged') + '\n';
code += extractFunc(html, 'pysimUpdateAdmIndicator') + '\n';
code += extractFunc(html, 'pysimUpdateIccidIndicator') + '\n';
code += extractFunc(html, 'pysimUpdatePresetIndicator') + '\n';
code += extractFunc(html, 'pysimUpdatePresetIndicators') + '\n';
code += extractFunc(html, 'cardsMatchedPreset') + '\n';
code += extractFunc(html, 'cardsAdmPresent') + '\n';
code += extractFunc(html, 'cardsScp80Complete') + '\n';
code += extractFunc(html, 'cardsScp81Complete') + '\n';
code += extractFunc(html, 'pysimSetServerAvailable') + '\n';
code += '\nglobalThis.esc = s => s;\n';
code += 'globalThis.t = s => s;\n';
@@ -57,27 +64,36 @@ function setup() {
const el = { textContent: 'status line', innerHTML: '' };
const adm = fakeIndicator();
const iccidEl = fakeIndicator();
const scp80El = fakeIndicator();
const scp81El = fakeIndicator();
const calls = { connected: [], resets: [], refreshStatus: [], proactive: 0, autoIccid: [] };
_pysimCardStateKey = null;
_pysimCardSession = null;
_pysimProactiveSeq = null;
_pysimAdmVerified = null;
_pysimAdmKey = null;
_pysimHeaderIccid = undefined;
_pysimHeaderScp80 = undefined;
_pysimHeaderScp81 = undefined;
_pysimServerAvailable = null;
_cardsAutoIccid = null;
_pysimCardIccid = null;
globalThis.document = {
getElementById: id => id === 'state-indicator-adm' ? adm
: (id === 'state-indicator-iccid' ? iccidEl : el),
: (id === 'state-indicator-iccid' ? iccidEl
: (id === 'state-indicator-scp80' ? scp80El
: (id === 'state-indicator-scp81' ? scp81El : el))),
querySelectorAll: () => [],
};
globalThis.cards = [];
globalThis.cardsFindByIccid = () => -1;
globalThis.pysimSetConnected = v => calls.connected.push(v);
globalThis.pysimResetCardData = refresh => calls.resets.push(refresh);
globalThis.pysimApplyAvailability = () => {};
globalThis.isViewVisible = () => true;
globalThis.pysimProactiveLogRender = () => { calls.proactive++; };
globalThis.cardsAutoSelectByIccid = iccid => { calls.autoIccid.push(iccid); return -1; };
return { el, adm, iccidEl, calls };
return { el, adm, iccidEl, scp80El, scp81El, calls };
}
function status(extra) {
@@ -229,7 +245,7 @@ test('the header ADM badge shows verified / not verified / hidden', () => {
assert.strictEqual(adm.textContent, 'ADM ✓');
assert.ok(adm.classes.has('text-emerald-600'));
assert.ok(adm.classes.has('dark:text-emerald-400'));
assert.strictEqual(adm.title, 'ADM verified');
assert.strictEqual(adm.title, 'Verified — no ADM key in the card preset');
// an unchanged state must not rewrite the badge
adm.textContent = '';
pysimCardStateUpdate(status({ connected: true, adm_verified: true }));
@@ -239,7 +255,7 @@ test('the header ADM badge shows verified / not verified / hidden', () => {
assert.strictEqual(adm.textContent, 'ADM ✗');
assert.ok(adm.classes.has('text-red-500'));
assert.ok(!adm.classes.has('text-emerald-600'));
assert.strictEqual(adm.title, 'ADM not verified');
assert.strictEqual(adm.title, 'No ADM key in the card preset — not verified');
// no card session hides it
pysimCardStateUpdate(status({ connected: false }));
assert.ok(adm.classes.has('hidden'));
@@ -248,12 +264,60 @@ test('the header ADM badge shows verified / not verified / hidden', () => {
assert.deepStrictEqual(calls.connected, [true, false]);
});
test('losing the server hides the ADM badge', () => {
test('the ADM badge marks an ADM key in the matching preset', () => {
const { adm } = setup();
pysimCardStateUpdate(status({ connected: true, adm_verified: true }));
const st = extra => status(Object.assign({ connected: true, iccid: '89701450001700031958' }, extra));
globalThis.cards = [{ name: 'C', adm: '0011' }];
globalThis.cardsFindByIccid = () => 0;
pysimCardStateUpdate(st({ adm_verified: true }));
assert.strictEqual(adm.textContent, 'ADM ✓ ⚿');
assert.strictEqual(adm.title, 'ADM key in the card preset — verified');
// key present, verification lost (e.g. card reset)
pysimCardStateUpdate(st({ adm_verified: false }));
assert.strictEqual(adm.textContent, 'ADM ✗ ⚿');
assert.strictEqual(adm.title, 'ADM key in the card preset — not verified');
// verified manually, preset has no ADM -> no key glyph
globalThis.cards = [];
pysimCardStateUpdate(st({ adm_verified: true }));
assert.strictEqual(adm.textContent, 'ADM ✓');
assert.strictEqual(adm.title, 'Verified — no ADM key in the card preset');
// whitespace-only preset ADM counts as absent
globalThis.cards = [{ name: 'C', adm: ' ' }];
globalThis.cardsFindByIccid = () => 0;
pysimCardStateUpdate(st({ adm_verified: true }));
assert.strictEqual(adm.textContent, 'ADM ✓');
});
test('the header SCP80/SCP81 markers follow the matching preset', () => {
const { scp80El, scp81El } = setup();
globalThis.cards = [{ name: 'C', kic: '15', kid: '15', spi1: '16', spi2: '01',
cntr: '0000000001', kicKey: 'AA', kidKey: 'BB', pskIdentity: 'id', pskKey: 'KEY' }];
globalThis.cardsFindByIccid = () => 0;
pysimCardStateUpdate(status({ connected: true, card_session: 2, iccid: '89701450001700031958' }));
assert.strictEqual(scp80El.textContent, 'SCP80');
assert.strictEqual(scp81El.textContent, 'SCP81');
assert.ok(!scp80El.classes.has('hidden'));
assert.ok(!scp81El.classes.has('hidden'));
// disconnect hides them again
pysimCardStateUpdate(status({ connected: false, card_present: false, card_session: 3 }));
assert.ok(scp80El.classes.has('hidden'));
assert.ok(scp81El.classes.has('hidden'));
assert.strictEqual(scp80El.textContent, '');
});
test('losing the server hides the ADM badge and the preset markers', () => {
const { adm, scp80El, scp81El } = setup();
globalThis.cards = [{ name: 'C', adm: '0011', kic: '15', kid: '15', spi1: '16', spi2: '01',
cntr: '0000000001', kicKey: 'AA', kidKey: 'BB', pskIdentity: 'id', pskKey: 'KEY' }];
globalThis.cardsFindByIccid = () => 0;
pysimCardStateUpdate(status({ connected: true, adm_verified: true, iccid: '89701450001700031958' }));
assert.ok(!adm.classes.has('hidden'));
assert.ok(!scp80El.classes.has('hidden'));
assert.ok(!scp81El.classes.has('hidden'));
pysimSetServerAvailable(false);
assert.ok(adm.classes.has('hidden'));
assert.ok(scp80El.classes.has('hidden'));
assert.ok(scp81El.classes.has('hidden'));
});
test('the header indicator prints the equipped card ICCID', () => {
+21
View File
@@ -24,6 +24,7 @@ function extractFunc(src, name) {
let code = '';
for (const fn of ['cardsTarValue', 'cardsFormValues', 'cardsClearForm', 'cardsEdit',
'cardsAdd', 'cardsImport', 'cardsApply', 'ramApplyCard',
'cardsScp80Complete', 'cardsScp81Complete', 'cardsAdmPresent',
'spTarKeyForPack', 'spPresetTar', 'packToSp']) {
code += extractFunc(html, fn) + '\n';
}
@@ -85,6 +86,26 @@ test('cardsTarValue falls back to the per-target spec defaults', () => {
assert.strictEqual(cardsTarValue('nope', ''), '');
});
test('preset completeness predicates used by the header markers', () => {
const full = { kic: '15', kid: '15', spi1: '16', spi2: '01', cntr: '0000000001',
kicKey: 'AA', kidKey: 'BB', pskIdentity: 'id', pskKey: 'KEY', adm: '0011' };
assert.ok(cardsScp80Complete(full));
assert.ok(cardsScp81Complete(full));
assert.ok(cardsAdmPresent(full));
// every SCP80 field is required; whitespace counts as empty
for (const field of ['kic', 'kid', 'spi1', 'spi2', 'cntr', 'kicKey', 'kidKey']) {
const c = Object.assign({}, full);
c[field] = ' ';
assert.ok(!cardsScp80Complete(c), 'SCP80 marked complete with empty ' + field);
}
assert.ok(!cardsScp81Complete({ pskIdentity: 'id' }));
assert.ok(!cardsScp81Complete({ pskKey: 'KEY' }));
assert.ok(!cardsScp80Complete(null));
assert.ok(!cardsScp81Complete(null));
assert.ok(!cardsAdmPresent(null));
assert.ok(!cardsAdmPresent({ adm: ' ' }));
});
test('clearing the card form keeps the TAR spec defaults', () => {
const els = setup();
els['cards-tar'].value = 'AABBCC';
+48 -2
View File
@@ -21,13 +21,18 @@ function extractFunc(src, name) {
return src.slice(m.index, i + 1);
}
let code = 'var _pysimServerAvailable = null;\nvar _pysimCardEquipped = false;\nvar _pysimEquipping = false;\nvar _pysimCardIccid = null;\nvar _pysimHeaderIccid = undefined;\n';
let code = 'var _pysimServerAvailable = null;\nvar _pysimCardEquipped = false;\nvar _pysimEquipping = false;\nvar _pysimCardIccid = null;\nvar _pysimHeaderIccid = undefined;\nvar _pysimHeaderScp80 = undefined;\nvar _pysimHeaderScp81 = undefined;\n';
code += extractFunc(html, 'pysimAvailabilityState') + '\n';
code += extractFunc(html, 'pysimControlDisabled') + '\n';
code += extractFunc(html, 'pysimNeedsHint') + '\n';
code += extractFunc(html, 'pysimApplyAvailability') + '\n';
code += extractFunc(html, 'pysimUpdateStateIndicator') + '\n';
code += extractFunc(html, 'pysimUpdateIccidIndicator') + '\n';
code += extractFunc(html, 'pysimUpdatePresetIndicator') + '\n';
code += extractFunc(html, 'pysimUpdatePresetIndicators') + '\n';
code += extractFunc(html, 'cardsScp80Complete') + '\n';
code += extractFunc(html, 'cardsScp81Complete') + '\n';
code += extractFunc(html, 'cardsMatchedPreset') + '\n';
code += 'globalThis.t = s => s;\n';
eval(code);
@@ -53,6 +58,8 @@ function setup() {
'state-indicator-dot': fakeEl(),
'state-indicator-img': fakeEl(),
'state-indicator-iccid': fakeEl(),
'state-indicator-scp80': fakeEl(),
'state-indicator-scp81': fakeEl(),
};
els['state-indicator-img'].src = '';
globalThis.document = { getElementById: id => els[id] || null, querySelectorAll: () => [] };
@@ -61,6 +68,10 @@ function setup() {
_pysimEquipping = false;
_pysimCardIccid = null;
_pysimHeaderIccid = undefined;
_pysimHeaderScp80 = undefined;
_pysimHeaderScp81 = undefined;
globalThis.cards = [];
globalThis.cardsFindByIccid = () => -1;
return els;
}
@@ -145,9 +156,44 @@ test('header prints the equipped card ICCID next to the card image', () => {
pysimUpdateIccidIndicator(null);
assert.strictEqual(el.textContent, '');
assert.ok(el.classes.has('hidden'));
// markup order: image, ICCID, ADM badge
// markup order: image, ICCID, ADM badge, SCP80, SCP81
assert.ok(html.indexOf('id="state-indicator-img"') < html.indexOf('id="state-indicator-iccid"'));
assert.ok(html.indexOf('id="state-indicator-iccid"') < html.indexOf('id="state-indicator-adm"'));
assert.ok(html.indexOf('id="state-indicator-adm"') < html.indexOf('id="state-indicator-scp80"'));
assert.ok(html.indexOf('id="state-indicator-scp80"') < html.indexOf('id="state-indicator-scp81"'));
});
test('SCP80/SCP81 markers follow the matching preset completeness', () => {
const els = setup();
globalThis.cards = [{ name: 'C', kic: '15', kid: '15', spi1: '16', spi2: '01',
cntr: '0000000001', kicKey: 'AA', kidKey: 'BB', pskIdentity: 'id', pskKey: 'KEY' }];
globalThis.cardsFindByIccid = () => 0;
_pysimCardIccid = '89701450001700031958';
pysimUpdatePresetIndicators();
const e80 = els['state-indicator-scp80'];
const e81 = els['state-indicator-scp81'];
assert.strictEqual(e80.textContent, 'SCP80');
assert.strictEqual(e81.textContent, 'SCP81');
assert.ok(!e80.classes.has('hidden'));
assert.ok(!e81.classes.has('hidden'));
assert.strictEqual(e80.attrs.title, 'SCP80 preset complete');
assert.strictEqual(e81.attrs.title, 'SCP81 preset complete');
// SCP80 incomplete (missing key) -> only the SCP81 marker stays
globalThis.cards[0].kicKey = '';
pysimUpdatePresetIndicators();
assert.ok(e80.classes.has('hidden'));
assert.strictEqual(e80.textContent, '');
assert.strictEqual(e80.attrs.title, undefined);
assert.ok(!e81.classes.has('hidden'));
// no matching preset -> both hidden
globalThis.cardsFindByIccid = () => -1;
pysimUpdatePresetIndicators();
assert.ok(e81.classes.has('hidden'));
// explicit null ICCID (no card / server lost) hides them
globalThis.cardsFindByIccid = () => 0;
pysimUpdatePresetIndicators(null);
assert.ok(e80.classes.has('hidden'));
assert.ok(e81.classes.has('hidden'));
});
test('card-iccid controls need an equipped card with a readable ICCID', () => {