import test from 'node:test'; import assert from 'node:assert/strict'; import { DEFAULT_SETTINGS } from '../lib/defaults.js'; const { initializeMenuSettings }=await import('../options/menu-settings.js').catch(()=>({})); function fixture() { const fields=new Map();const document={activeElement:null,getElementById:id=>{ if(!fields.has(id))fields.set(id,{value:'',checked:false,hidden:false,textContent:'',addEventListener(type,fn){this[type]=fn;},setAttribute(name,value){this[name]=value;}}); return fields.get(id); }}; let changed=0; const controls=initializeMenuSettings({document,onChange:()=>changed++}); return {controls,document,field:document.getElementById,get changed(){return changed;}}; } test('dependent controls preserve hidden preferences and restore defaults',()=>{ assert.equal(typeof initializeMenuSettings,'function'); const f=fixture();f.controls.render(DEFAULT_SETTINGS); assert.equal(f.field('advanced-settings').hidden,true); f.field('contextMenuMode').value='advanced';f.field('contextMenuMode').input(); assert.equal(f.field('advanced-settings').hidden,false);assert.equal(f.field('translation-settings').hidden,true); f.field('showTranslate').checked=true;f.field('showTranslate').input(); assert.equal(f.field('translation-settings').hidden,false); f.field('translationMode').value='preferred';f.field('translationMode').input(); assert.equal(f.field('preferred-language-field').hidden,false); f.field('translationLanguage').value=' Spanish ';f.field('translationLanguage').input(); assert.equal(f.controls.collect().translationLanguage,'Spanish'); f.field('contextMenuMode').value='off';f.field('contextMenuMode').input(); assert.equal(f.controls.collect().translationLanguage,'Spanish'); f.controls.render(DEFAULT_SETTINGS);assert.equal(f.field('showTranslate').checked,false);assert.equal(f.field('translationLanguage').value,''); }); test('invalid language gives guidance and active edits survive storage echoes',()=>{ assert.equal(typeof initializeMenuSettings,'function'); const f=fixture();f.controls.render({...DEFAULT_SETTINGS,contextMenuMode:'advanced',showTranslate:true,translationMode:'preferred'}); assert.match(f.field('language-validation').textContent,/language/i); f.field('translationLanguage').value='😀'.repeat(100);f.field('translationLanguage').input();assert.equal(f.field('language-validation').textContent,''); f.field('translationLanguage').value='😀'.repeat(101);f.field('translationLanguage').input();assert.notEqual(f.field('language-validation').textContent,'');assert.equal(f.controls.collect().translationLanguage,''); f.document.activeElement=f.field('translationLanguage');f.controls.render(DEFAULT_SETTINGS);assert.equal([...f.field('translationLanguage').value].length,101); });