ui: the keyset selector is disabled and cleared while no preset is selected
A keyset only exists inside a card preset, but the SCP80/RAM/TAR keyset
selectors stayed enabled with no preset selected - showing either
"— no keyset —" or a stale "Keyset N — not defined in the preset" entry left
over from an earlier preset. spKeysetSync() now disables the selector and
reduces it to a "— select a card preset —" placeholder whenever its view has
no preset selected, and re-enables/populates it as soon as one is.
Clearing the preset dropdown ("— Select card —") also refreshed nothing:
cardsApply() returned before the sync, so the stale keyset list stayed; it now
syncs the selectors (and the preset warning) on the empty selection too.
The three selects get disabled:opacity-40 disabled:cursor-not-allowed (the
rules are already in the compiled style.css). Tests: keysets.test.js covers
the disabled/cleared state and the re-enable plus a cardsApply source guard;
cards_form.test.js and cards_counter.test.js gain tarPresetIdx in their
sandboxes. Help EN/RU and both AGENTS files; sw cache simple-v343.
This commit is contained in:
@@ -28,7 +28,7 @@ for (const fn of ['cardsTarValue', 'cardsApplyFields', 'cardsApply',
|
||||
'spKeysetOptionsHtml', 'cardsKeysetRowHtml', 'cardsKeysetRowsRender',
|
||||
'cardsKeysetAdd', 'cardsKeysetRemove', 'cardsKeysetKvnUpdate',
|
||||
'cardsKeysetsFromForm', 'spKeysetSync', 'spKeysetApply',
|
||||
'spKeysetChanged', 'ramKeysetChanged', 'ramPresetIdx', 'spKeysetGuard',
|
||||
'spKeysetChanged', 'ramKeysetChanged', 'ramPresetIdx', 'tarPresetIdx', 'spKeysetGuard',
|
||||
'ramKeysetGuard',
|
||||
]) {
|
||||
code += extractFunc(html, fn) + '\n';
|
||||
|
||||
@@ -34,7 +34,7 @@ for (const fn of ['cardsTarValue', 'cardsFormValues', 'cardsClearForm', 'cardsEd
|
||||
'spKeysetOptionsHtml', 'cardsKeysetRowHtml', 'cardsKeysetRowsRender',
|
||||
'cardsKeysetAdd', 'cardsKeysetRemove', 'cardsKeysetKvnUpdate',
|
||||
'cardsKeysetsFromForm', 'spKeysetSync', 'spKeysetApply', 'spKeysetChanged',
|
||||
'ramKeysetChanged', 'ramPresetIdx', 'spKeysetGuard', 'ramKeysetGuard']) {
|
||||
'ramKeysetChanged', 'ramPresetIdx', 'tarPresetIdx', 'spKeysetGuard', 'ramKeysetGuard']) {
|
||||
code += extractFunc(html, fn, ASYNC_FNS.indexOf(fn) >= 0) + '\n';
|
||||
}
|
||||
code = 'var _cardsKeysetCount = 0;\nglobalThis.spPresetWarningRender = function() {};\n' + code;
|
||||
|
||||
@@ -175,3 +175,45 @@ test('the RAM and TAR views rebuild their keyset lists when their preset is know
|
||||
// opening the TAR pill populates both its selectors
|
||||
assert.ok(html.includes("if (name === 'tar') { tarRender(); tarProbeRender(); }"));
|
||||
});
|
||||
|
||||
test('the keyset selector is disabled and cleared while no preset is selected', () => {
|
||||
const els = {
|
||||
'sp-keyset-sel': { value: '', innerHTML: '' },
|
||||
'ram-keyset-sel': { value: '', innerHTML: '' },
|
||||
'tar-keyset-sel': { value: '', innerHTML: '' },
|
||||
'sp-card-sel': { value: '' },
|
||||
'ram-card-sel': { value: '' },
|
||||
'tar-card-sel': { value: '' },
|
||||
'sp-kic-hex': { value: '' },
|
||||
'sp-kid-hex': { value: '' },
|
||||
};
|
||||
globalThis.document = { getElementById: id => els[id] || null };
|
||||
globalThis.cards = [];
|
||||
spKeysetSync();
|
||||
for (const id of ['sp-keyset-sel', 'ram-keyset-sel', 'tar-keyset-sel']) {
|
||||
assert.strictEqual(els[id].disabled, true, id + ' must be disabled');
|
||||
assert.match(els[id].innerHTML, /select a card preset/);
|
||||
assert.ok(!els[id].innerHTML.includes('not defined'), id);
|
||||
}
|
||||
// a selected preset enables the selector and lists its keysets
|
||||
globalThis.cards = [{ name: 'EP', keysets: [
|
||||
{ kic: '15', kid: '15', kicKey: 'AA', kidKey: 'BB', cntr: '0000000001' }] }];
|
||||
els['sp-card-sel'].value = '0';
|
||||
els['ram-card-sel'].value = '0';
|
||||
els['tar-card-sel'].value = '0';
|
||||
els['sp-kic-hex'].value = '15';
|
||||
els['sp-kid-hex'].value = '15';
|
||||
spKeysetSync();
|
||||
for (const id of ['sp-keyset-sel', 'ram-keyset-sel', 'tar-keyset-sel']) {
|
||||
assert.strictEqual(els[id].disabled, false, id + ' must be enabled');
|
||||
assert.match(els[id].innerHTML, /value="1" selected/);
|
||||
}
|
||||
});
|
||||
|
||||
test('clearing the preset selection clears the keyset selectors', () => {
|
||||
const at = html.indexOf('function cardsApply(');
|
||||
assert.ok(at > 0);
|
||||
const body = html.slice(at, at + 600);
|
||||
assert.ok(body.includes('spKeysetSync();'),
|
||||
'cardsApply must sync the keyset selectors when no preset is selected');
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user