Support custom BPQ Telnet prompts and banners, fix installer arguments

This commit is contained in:
alberto committed 2026-10-17 14:14:16 +02:00
1 parent 33d2cc4fbd
commit 2b00b1cbbd
14 files changed
+168 -44

No files matched your search

+4 -2
View File
@@ -3,9 +3,9 @@ import assert from 'node:assert/strict';
import vm from 'node:vm';
import {readFileSync} from 'node:fs';
const source=readFileSync(new URL('./public/i18n.js',import.meta.url),'utf8');
function client(languages=['it-IT'],saved=null){
function client(languages=['it-IT'],saved=null,defaultLanguage=null){
const storage=new Map(saved?[['bpq-language',saved]]:[]),events=[];
const context=vm.createContext({navigator:{languages},localStorage:{getItem:k=>storage.get(k),setItem:(k,v)=>storage.set(k,v)},document:{documentElement:{lang:''},readyState:'loading',body:null,addEventListener(){},querySelectorAll:()=>[],dispatchEvent:e=>events.push(e)},addEventListener(){},CustomEvent:class{constructor(type,options){Object.assign(this,{type,...options});}}});
const context=vm.createContext({BPQ_DEFAULT_LANGUAGE:defaultLanguage,navigator:{languages},localStorage:{getItem:k=>storage.get(k),setItem:(k,v)=>storage.set(k,v)},document:{documentElement:{lang:''},readyState:'loading',body:null,addEventListener(){},querySelectorAll:()=>[],dispatchEvent:e=>events.push(e)},addEventListener(){},CustomEvent:class{constructor(type,options){Object.assign(this,{type,...options});}}});
vm.runInContext(source,context);return {api:context.BPQI18n,document:context.document,storage,events};
}
test('first visit chooses a concrete saved language from the browser, with English fallback',()=>{
@@ -34,3 +34,5 @@ test('UI translations handle counters, statuses, decorative icons and dynamic va
});
test('legacy Auto preference migrates to a concrete language',()=>{const {api,storage}=client(['en-US'],'auto');assert.equal(api.preference,'en');assert.equal(storage.get('bpq-language'),'en');});
test('configured default language precedes browser detection, saved choice wins',()=>{assert.equal(client(['it-IT'],null,'en').api.language,'en');assert.equal(client(['en-US'],'it','en').api.language,'it');});