innerWidth>760&&innerWidth<=1200;
function selectLink(id){UI.sel={type:'link',id};UI.confirm=null;if(isTablet()||isPhone())UI.leftOpen=false;$('panel').classList.remove('full');renderPanel();renderLeft();}
function selectCity(c){UI.sel={type:'city',id:c};UI.confirm=null;if(isTablet()||isPhone())UI.leftOpen=false;const P=$('panel');if(P)P.classList.remove('full');if(!S.pops[c])UI.tab='cust';renderPanel();}
diff --git a/src/game/93-ui/40-hud-and-panels.js b/src/game/93-ui/40-hud-and-panels.js
index 2f599cf..5070f9d 100644
--- a/src/game/93-ui/40-hud-and-panels.js
+++ b/src/game/93-ui/40-hud-and-panels.js
@@ -44,7 +44,7 @@ function renderLeft(){checkLayer();
if(!S.offers.length)h+=`${tr('hud_and_panels.no_open_offers_right_now_businesses')}
`;
for(const o of S.offers.slice().sort((a,b)=>a.exp-b.exp)){const has=bHas(o);
h+=`${esc(o.name)}
${esc(BIZ_T[o.type].l)} · ${CITY[o.city].name}${o.city2?' ⇄ '+CITY[o.city2].name:''} · ${bTerms(o)} · ${tr('ui.n_d_left',{n:o.exp-S.day})}${(o.reqs||[]).length?` · ${trn('hud_and_panels.n_special_requirement',o.reqs.length)}`:''}
${reqList(o)}
-
${has?btn(autoAcceptLabel(),'accept',{id:o.id},'green sm'):btn(tr('common.go_there'),'focusCity',{city:bCities(o).find(c=>!S.pops[c])},'ghost sm')}${btn(tr('common.decline'),'decline',{id:o.id},'ghost sm')}
${has?'':`
${tr('hud_and_panels.needs_a_pop_in_cities',{cities:bCities(o).filter(x=>!S.pops[x]).map(x=>CITY[x].name).join(', ')})}
`}
`;}
+ ${has?btn(autoAcceptLabel(o),'accept',{id:o.id},'green sm'):btn(tr('common.go_there'),'focusCity',{city:bCities(o).find(c=>!S.pops[c])},'ghost sm')}${btn(tr('common.decline'),'decline',{id:o.id},'ghost sm')}
${has?'':`${tr('hud_and_panels.needs_a_pop_in_cities',{cities:bCities(o).filter(x=>!S.pops[x]).map(x=>CITY[x].name).join(', ')})}
`}`;}
}else if(UI.left==='noc'){
h+=`${btn(tr('hud_and_panels.open_noc_dashboard'),'dash',{},'pink')}${btn(tr('common.connections'),'connOpen',{},'')}${btn(tr('common.traceroute'),'trace',{},'')}
`;
h+=`${tr('hud_and_panels.your_network_operations_center_every')}
`;
diff --git a/src/game/93-ui/70-link-panels.js b/src/game/93-ui/70-link-panels.js
index 5cba29a..3d15925 100644
--- a/src/game/93-ui/70-link-panels.js
+++ b/src/game/93-ui/70-link-panels.js
@@ -76,7 +76,7 @@ function dfPanel(l){
if(!bld){const sold=S.biz.filter(b=>b.link===l.id&&(b.type==='wwave'||b.type==='dfpair'||b.type==='pairs')),off=S.offers.find(o=>o.link===l.id),fc=freeCh(l);
h+=`${tr('link_panels.selling_spare_capacity')}
${tr('link_panels.other_carriers_rent_what_you_do')}
${tr('common.free_channels')}${fc} / ${chMax(l)}
${sold.map(b=>`${esc(b.name)}
${esc(b.what||BIZ_T[b.type].l)} · ${tr('common.price_mo',{price:fmt$(b.rate)})}
`).join('')}
- ${off?`${esc(off.name)}
${esc(off.what)} · ${tr('common.price_mo',{price:fmt$(off.rate)})} · ${tr('ui.n_d_left',{n:off.exp-S.day})}${off.broker?' · '+tr('link_panels.via_a_capacity_broker'):''}
${btn(autoAcceptLabel(),'accept',{id:off.id},'pink sm')}
`:fc>=1||pairFree(l)?`${btn(tr('link_panels.list_it_with_a_capacity_broker'),'advertise',{id:l.id},'sm')}
`:`${tr('link_panels.nothing_spare_to_sell_on_this')}
`}`;}
+ ${off?`${esc(off.name)}
${esc(off.what)} · ${tr('common.price_mo',{price:fmt$(off.rate)})} · ${tr('ui.n_d_left',{n:off.exp-S.day})}${off.broker?' · '+tr('link_panels.via_a_capacity_broker'):''}
${btn(autoAcceptLabel(off),'accept',{id:off.id},'pink sm')}
`:fc>=1||pairFree(l)?`${btn(tr('link_panels.list_it_with_a_capacity_broker'),'advertise',{id:l.id},'sm')}
`:`${tr('link_panels.nothing_spare_to_sell_on_this')}
`}`;}
h+=`${tr('common.optics')}
${tr('link_panels.each_channel_is_a_pair_of')}
`;
if(l.own&&l.sub)h+=subUpgradePanel(l);
for(const k of Object.keys(OPT)){const O=OPT[k],n=(l.ch||[]).filter(x=>x===k).length,why=chWhy(l,k);
@@ -93,7 +93,7 @@ function dfPanel(l){
}
function offersHere(c){
const os=S.offers.filter(o=>bCities(o).includes(c));if(!os.length)return '';
- return `${tr('common.offers_here')}
${os.map(o=>`${esc(o.name)}
${esc(BIZ_T[o.type].l)}${o.city2?` ${CITY[o.city].name} ⇄ ${CITY[o.city2].name}`:''} · ${bTerms(o)} · ${tr('ui.n_d_left',{n:o.exp-S.day})}
${R.reach<0.99&&!BIZ_T[o.type].l2?`
${tr('link_panels.they_need_the_full_internet_your',{pct:pct(R.reach)})}
`:''}${o.type==='scrub'&&!hasScrub()?`
${tr('link_panels.needs_your_own_scrubbing_center')}
`:''}${reqList(o)}${bHas(o)?'':`
${tr('link_panels.needs_a_pop_in_cities_too',{cities:bCities(o).filter(x=>!S.pops[x]).map(x=>CITY[x].name).join(', ')})}
`}
${bHas(o)?btn(autoAcceptLabel(),'accept',{id:o.id},'green sm'):''}${btn(tr('common.no'),'decline',{id:o.id},'ghost sm')}
`).join('')}`;
+ return `${tr('common.offers_here')}
${os.map(o=>`${esc(o.name)}
${esc(BIZ_T[o.type].l)}${o.city2?` ${CITY[o.city].name} ⇄ ${CITY[o.city2].name}`:''} · ${bTerms(o)} · ${tr('ui.n_d_left',{n:o.exp-S.day})}
${R.reach<0.99&&!BIZ_T[o.type].l2?`
${tr('link_panels.they_need_the_full_internet_your',{pct:pct(R.reach)})}
`:''}${o.type==='scrub'&&!hasScrub()?`
${tr('link_panels.needs_your_own_scrubbing_center')}
`:''}${reqList(o)}${bHas(o)?'':`
${tr('link_panels.needs_a_pop_in_cities_too',{cities:bCities(o).filter(x=>!S.pops[x]).map(x=>CITY[x].name).join(', ')})}
`}
${bHas(o)?btn(autoAcceptLabel(o),'accept',{id:o.id},'green sm'):''}${btn(tr('common.no'),'decline',{id:o.id},'ghost sm')}
`).join('')}`;
}
function linkPanel(id){
const l=S.links.find(x=>x.id===id);if(!l){UI.sel=null;return '';}
diff --git a/tests/automation.test.js b/tests/automation.test.js
index b613873..5ae9473 100644
--- a/tests/automation.test.js
+++ b/tests/automation.test.js
@@ -44,14 +44,16 @@ test('Accept buttons share a real-time countdown in Deals, city offers and fiber
assert.equal(dom.window.document.querySelectorAll('[data-auto-sales]').length, 0);
ev("ACT.autoToggle({k:'autoSales'});renderAutoCountdown()");
const counts = () => [...dom.window.document.querySelectorAll('[data-auto-sales]')];
- assert.ok(counts().length >= 2, 'Deals and the city panel both show it');
- assert.ok(counts().every(el => el.textContent === '(5)'));
+ const readyCounts = () => counts().filter(el => el.dataset.autoSales === 'ready');
+ assert.ok(readyCounts().length >= 2, 'Deals and the city panel both show it');
+ assert.ok(readyCounts().every(el => el.textContent === '(5)'));
+ assert.ok(counts().filter(el => el.dataset.autoSales === 'waiting').every(el => el.textContent === ''), 'unmet requirements have no countdown');
ev('testNow=2001;renderAutoCountdown()');
- assert.ok(counts().every(el => el.textContent === '(4)'));
+ assert.ok(readyCounts().every(el => el.textContent === '(4)'));
ev('testNow=3000;UI.speed=8;renderAutoCountdown()');
- assert.ok(counts().every(el => el.textContent === '(3)'));
+ assert.ok(readyCounts().every(el => el.textContent === '(3)'));
ev('UI.speed=0.5;renderAll();renderAutoCountdown()');
- assert.ok(counts().every(el => el.textContent === '(3)'), 'game speed and re-rendering leave the real-time clock alone');
+ assert.ok(readyCounts().every(el => el.textContent === '(3)'), 'game speed and re-rendering leave the real-time clock alone');
assert.match(dom.window.document.querySelector('#leftBody [data-act="accept"]').textContent, /Accept \(3\)/);
ev("ACT.buildPop({city:'ams'});S.links.push({id:'fiber',a:'fra',b:'ams',kind:'df',sys:'lite',ch:[],own:true,km:450,ready:0,cut:0,mo:1})");
offer(ev, 'broker', { type: 'wwave', city2: 'ams', link: 'fiber', slots: 1, what: 'One wave' });
@@ -62,13 +64,55 @@ test('Accept buttons share a real-time countdown in Deals, city offers and fiber
ev('testNow=6000;automationTick(testNow);renderAutoCountdown()');
assert.equal(ev("S.biz.some(b=>b.id==='ready')"), true);
assert.equal(ev("S.offers.some(o=>o.id==='waiting')"), true, 'the countdown does not bypass requirements');
- assert.ok(counts().every(el => el.textContent === '(5)'), 'the next check starts a fresh countdown');
+ offer(ev, 'next-ready');
+ ev('renderAll();renderAutoCountdown()');
+ assert.ok(counts().filter(el => el.dataset.autoSales === 'next-ready').every(el => el.textContent === '(5)'), 'the next check starts a fresh countdown');
ev("ACT.autoToggle({k:'autoSales'});renderAutoCountdown()");
assert.equal(counts().length, 0);
assert.deepEqual(errors, []);
dom.window.close();
});
+test('only ready offers get a countdown, including after requirements or capacity change', () => {
+ const { ev, dom, errors } = load();
+ setup(ev);
+ offer(ev, 'ready');
+ offer(ev, 'needs-generator', { reqs: ['gen'] });
+ offer(ev, 'too-big', { bw: 1000 });
+ offer(ev, 'expired', { exp: 0 });
+ ev("window.testNow=1000;performance.now=()=>testNow;ACT.leftTab({t:'deals'});ACT.autoToggle({k:'autoSales'});renderAutoCountdown()");
+ const count = id => dom.window.document.querySelector(`#leftBody [data-auto-sales="${id}"]`).textContent;
+ assert.equal(count('ready'), '(5)');
+ assert.equal(count('needs-generator'), '');
+ assert.equal(count('too-big'), '');
+ assert.equal(count('expired'), '');
+ ev('S.pops.fra.gen=true;after()');
+ assert.equal(count('needs-generator'), '(5)', 'becoming eligible shows the timer');
+ ev('S.pops.fra.gen=false;compute();renderAutoCountdown()');
+ assert.equal(count('needs-generator'), '', 'a requirement becoming false hides it immediately');
+ ev("S.offers.find(o=>o.id==='too-big').bw=2;after()");
+ assert.equal(count('too-big'), '(5)', 'actions invalidate the capacity preview');
+ ev('testNow=6000;automationTick(testNow);renderAutoCountdown()');
+ assert.equal(ev("S.offers.some(o=>o.id==='needs-generator')"), true, 'acceptance checks requirements again');
+ assert.deepEqual(errors, []);
+ dom.window.close();
+});
+
+test('readiness trials are shared between views and are not repeated for every redraw', () => {
+ const { ev, dom, errors } = load();
+ setup(ev);
+ offer(ev, 'ready');
+ ev("window.testNow=1000;performance.now=()=>testNow;ACT.leftTab({t:'deals'});UI.sel={type:'city',id:'fra'};UI.tab='cust';window.originalAutoOffer=autoOffer;window.trials=0;window.autoOffer=o=>{trials++;return originalAutoOffer(o)};ACT.autoToggle({k:'autoSales'})");
+ assert.equal(ev('trials'), 1);
+ ev('renderAll();compute();renderAll();renderAutoCountdown()');
+ assert.equal(ev('trials'), 1, 'ordinary routing refreshes reuse the preview');
+ ev('after()');
+ assert.equal(ev('trials'), 2, 'a real action refreshes readiness');
+ ev('window.autoOffer=originalAutoOffer');
+ assert.deepEqual(errors, []);
+ dom.window.close();
+});
+
test('auto-accept leaves unready and expired offers alone without failure notifications', () => {
const { ev, dom, errors } = load();
setup(ev);