Start a link by typing the city it goes to (#343)
A POP's Infra tab gets Link to a city: it opens the city finder in link mode, which offers only cities a link from there could end in, and picking one (or Enter) opens the same link window as dragging between the two on the map. Much easier than finding a far-away city on a crowded phone screen. Fixes #343
This commit is contained in:
parent
c52e7c7747
commit
2b8bd1c402
12 changed files with 130 additions and 11 deletions
|
|
@ -8,6 +8,7 @@ All notable changes to this project are documented here. The project follows
|
|||
|
||||
- Alien waves you list on a fiber yourself now stay listed. With the capacity market selling for you, the broker used to cut your listing down to what its settings allowed the next day, or take it off altogether when the route's demand was below your minimum. Your own listing now stays put, and the broker adds what its settings allow on top (#340).
|
||||
- The Connections list in the NOC dashboard no longer stays blank when you sort it by load or show only NNI ports while a fabric port runs at 400G. A 400G fabric port is the fastest there is, so the list now offers it one more LAG member instead of a faster port that does not exist.
|
||||
- You can now start a link by typing where it goes: open one of your POPs, go to Infra and tap Link to a city, then type a city, country or exchange and pick it. You get the same link window as dragging between the two on the map, which is much easier on a crowded phone screen (#343).
|
||||
- The Connections tab of the NOC dashboard can now shrink connections as well as grow them. Next to the upgrades, transit ports, PNIs and exchange ports get a downgrade to the next smaller port and a button to drop one LAG member, and a PNI that is still on order can be chased from the list, just like from the POP panel (#336).
|
||||
|
||||
## [3.4.0] — 2026-11-10
|
||||
|
|
|
|||
|
|
@ -1035,6 +1035,7 @@
|
|||
"city_panel.ix_members_on_ix_n":"IX-Mitglieder am {ix}: {n}",
|
||||
"city_panel.ix_switch":"{ix}-Switch",
|
||||
"city_panel.launch_broadband_cost":"Breitband starten <small>{cost}</small>",
|
||||
"city_panel.link_to_a_city":"🔗 Link zu einer Stadt…",
|
||||
"city_panel.make_sacrificial_contains_floods_1_2":"Als Opfer-Link nutzen <small>hält Fluten auf · ½ Kapazität</small>",
|
||||
"city_panel.maxed_out_traffic_here_is_being":"Am Limit. Traffic wird hier verworfen.",
|
||||
"city_panel.model_level_lv":"{model} <small>Level {lv}</small>",
|
||||
|
|
@ -2230,7 +2231,9 @@
|
|||
"find.city_country_or_exchange":"Stadt, Land oder Austauschknoten",
|
||||
"find.find_a_city":"Stadt finden",
|
||||
"find.find_a_city_slash":"Stadt finden (/)",
|
||||
"find.link_from_city":"Neuer Link ab {city}",
|
||||
"find.no_city_matches_q":"Keine Stadt passt zu „{q}“.",
|
||||
"find.pick_where_the_link_goes":"Wähl, wohin der Link geht: genau wie das Ziehen von diesem POP zu der Stadt auf der Karte.",
|
||||
"find.press_slash_to_search_from":"Tipp: Drück irgendwo auf der Karte <b>/</b>, um zu suchen.",
|
||||
"find.type_a_city_a_country":"Gib eine Stadt, ein Land oder einen Austauschknoten ein.",
|
||||
"find.your_pop":"dein POP",
|
||||
|
|
|
|||
|
|
@ -1033,6 +1033,7 @@
|
|||
"city_panel.ix_members_on_ix_n":"Miembros del IX en {ix}: {n}",
|
||||
"city_panel.ix_switch":"Switch de {ix}",
|
||||
"city_panel.launch_broadband_cost":"Lanzar banda ancha <small>{cost}</small>",
|
||||
"city_panel.link_to_a_city":"🔗 Enlace a una ciudad…",
|
||||
"city_panel.make_sacrificial_contains_floods_1_2":"Hacer de sacrificio <small>contiene inundaciones · ½ de capacidad</small>",
|
||||
"city_panel.maxed_out_traffic_here_is_being":"Al límite. Aquí se está descartando tráfico.",
|
||||
"city_panel.model_level_lv":"{model} <small>nivel {lv}</small>",
|
||||
|
|
@ -2228,7 +2229,9 @@
|
|||
"find.city_country_or_exchange":"Ciudad, país o punto de intercambio",
|
||||
"find.find_a_city":"Buscar una ciudad",
|
||||
"find.find_a_city_slash":"Buscar una ciudad (/)",
|
||||
"find.link_from_city":"Nuevo enlace desde {city}",
|
||||
"find.no_city_matches_q":"Ninguna ciudad coincide con «{q}».",
|
||||
"find.pick_where_the_link_goes":"Elige adónde va el enlace: igual que arrastrar desde este POP hasta esa ciudad en el mapa.",
|
||||
"find.press_slash_to_search_from":"Consejo: pulsa <b>/</b> en cualquier parte del mapa para buscar.",
|
||||
"find.type_a_city_a_country":"Escribe una ciudad, un país o un punto de intercambio.",
|
||||
"find.your_pop":"tu POP",
|
||||
|
|
|
|||
|
|
@ -1033,6 +1033,7 @@
|
|||
"city_panel.ix_members_on_ix_n":"Membres de l’IX sur {ix} : {n}",
|
||||
"city_panel.ix_switch":"Switch {ix}",
|
||||
"city_panel.launch_broadband_cost":"Lancer le haut débit <small>{cost}</small>",
|
||||
"city_panel.link_to_a_city":"🔗 Lien vers une ville…",
|
||||
"city_panel.make_sacrificial_contains_floods_1_2":"Rendre sacrificiel <small>contient les floods · ½ capacité</small>",
|
||||
"city_panel.maxed_out_traffic_here_is_being":"Saturé. Du trafic est perdu ici.",
|
||||
"city_panel.model_level_lv":"{model} <small>niveau {lv}</small>",
|
||||
|
|
@ -2228,7 +2229,9 @@
|
|||
"find.city_country_or_exchange":"Ville, pays ou point d'échange",
|
||||
"find.find_a_city":"Trouver une ville",
|
||||
"find.find_a_city_slash":"Trouver une ville (/)",
|
||||
"find.link_from_city":"Nouveau lien depuis {city}",
|
||||
"find.no_city_matches_q":"Aucune ville ne correspond à « {q} ».",
|
||||
"find.pick_where_the_link_goes":"Choisissez où va le lien : comme si vous le tiriez de ce POP jusqu'à cette ville sur la carte.",
|
||||
"find.press_slash_to_search_from":"Astuce : appuyez sur <b>/</b> n'importe où sur la carte pour chercher.",
|
||||
"find.type_a_city_a_country":"Tapez une ville, un pays ou un point d'échange.",
|
||||
"find.your_pop":"votre POP",
|
||||
|
|
|
|||
|
|
@ -1033,6 +1033,7 @@
|
|||
"city_panel.ix_members_on_ix_n":"Membri IX su {ix}: {n}",
|
||||
"city_panel.ix_switch":"Switch di {ix}",
|
||||
"city_panel.launch_broadband_cost":"Lancia la banda larga <small>{cost}</small>",
|
||||
"city_panel.link_to_a_city":"🔗 Link verso una città…",
|
||||
"city_panel.make_sacrificial_contains_floods_1_2":"Rendi sacrificale <small>contiene i flood · ½ capacità</small>",
|
||||
"city_panel.maxed_out_traffic_here_is_being":"Al limite. Qui il traffico viene scartato.",
|
||||
"city_panel.model_level_lv":"{model} <small>livello {lv}</small>",
|
||||
|
|
@ -2228,7 +2229,9 @@
|
|||
"find.city_country_or_exchange":"Città, paese o exchange",
|
||||
"find.find_a_city":"Trova una città",
|
||||
"find.find_a_city_slash":"Trova una città (/)",
|
||||
"find.link_from_city":"Nuovo link da {city}",
|
||||
"find.no_city_matches_q":"Nessuna città corrisponde a “{q}”.",
|
||||
"find.pick_where_the_link_goes":"Scegli dove va il link: come trascinarlo da questo POP fino a quella città sulla mappa.",
|
||||
"find.press_slash_to_search_from":"Suggerimento: premi <b>/</b> ovunque sulla mappa per cercare.",
|
||||
"find.type_a_city_a_country":"Scrivi una città, un paese o un exchange.",
|
||||
"find.your_pop":"il tuo POP",
|
||||
|
|
|
|||
|
|
@ -1033,6 +1033,7 @@
|
|||
"city_panel.ix_members_on_ix_n":"Membros do IX em {ix}: {n}",
|
||||
"city_panel.ix_switch":"Switch do {ix}",
|
||||
"city_panel.launch_broadband_cost":"Lançar banda larga <small>{cost}</small>",
|
||||
"city_panel.link_to_a_city":"🔗 Link para uma cidade…",
|
||||
"city_panel.make_sacrificial_contains_floods_1_2":"Tornar sacrificial <small>contém floods · ½ capacidade</small>",
|
||||
"city_panel.maxed_out_traffic_here_is_being":"No limite. O tráfego aqui está sendo descartado.",
|
||||
"city_panel.model_level_lv":"{model} <small>nível {lv}</small>",
|
||||
|
|
@ -2228,7 +2229,9 @@
|
|||
"find.city_country_or_exchange":"Cidade, país ou exchange",
|
||||
"find.find_a_city":"Encontrar uma cidade",
|
||||
"find.find_a_city_slash":"Encontrar uma cidade (/)",
|
||||
"find.link_from_city":"Novo link a partir de {city}",
|
||||
"find.no_city_matches_q":"Nenhuma cidade corresponde a “{q}”.",
|
||||
"find.pick_where_the_link_goes":"Escolha para onde vai o link: o mesmo que arrastar deste POP até essa cidade no mapa.",
|
||||
"find.press_slash_to_search_from":"Dica: pressione <b>/</b> em qualquer lugar do mapa para pesquisar.",
|
||||
"find.type_a_city_a_country":"Digite uma cidade, um país ou um exchange.",
|
||||
"find.your_pop":"seu POP",
|
||||
|
|
|
|||
|
|
@ -537,6 +537,8 @@ const API_VIEW={
|
|||
linkCheck:{args:[['id','entityId']],doc:'Open the redundancy check for a link: what a single cut would drop, without changing anything.'},
|
||||
findOpen:{args:[],doc:'Open the city finder (the 🔍 in the top bar).'},
|
||||
findGo:{args:[['city','cityId']],doc:'Close the finder and jump to a city.'},
|
||||
findLink:{args:[['city','cityId']],doc:'Open the city finder to pick where a new link from this POP goes (the "Link to a city" button in its panel).'},
|
||||
linkTo:{args:[['a','cityId'],['b','cityId']],doc:'From the link finder: open the new-link window from POP a to city b, as dragging between them would.'},
|
||||
popStep:{args:[['d','integer']],doc:'Select and centre the previous (d<0) or next (d>0) of your POPs, by name: the [ and ] keys.'},
|
||||
offerStep:{args:[],doc:'Select the next open offer (soonest to expire first), centre its city and mark it under Offers here: the $ key.'},
|
||||
zoomStep:{args:[['d','integer']],doc:'Zoom the map out (d<0) or in (d>0) around its middle: the - and = keys.'},
|
||||
|
|
|
|||
|
|
@ -49,6 +49,9 @@ const ACT={
|
|||
logAll:()=>{UI.logAll=!UI.logAll;renderLeft();},
|
||||
findOpen:()=>findOpen(),
|
||||
findGo:({city})=>{if(!isCity(city))return;closeModal();$('dash').hidden=true;ACT.focusCity({city});},
|
||||
// A link from one of your POPs to a city you type instead of dragging to (#343): the same window the drag opens.
|
||||
findLink:({city})=>{if(!isCity(city)||!S.pops[city]||pzOn())return;findOpen(city);},
|
||||
linkTo:({a,b})=>{if(!isCity(a)||!isCity(b)||a===b||pzOn()||!linkFromOk(a)||!linkToOk(b))return;$('dash').hidden=true;sfx('click');openLinkModal(a,b);},
|
||||
focusCity:({city})=>{selectCity(city);const C=CITY[city];cam.x=C.x;cam.y=C.y;cam.z=Math.max(cam.z,1.2);if(innerWidth<760)UI.leftOpen=false;renderLeft();},
|
||||
popStep:({d})=>{const L=popOrder(),n=L.length;if(!n)return;const i=UI.sel&&UI.sel.type==='city'?L.indexOf(UI.sel.id):-1;$('dash').hidden=true;ACT.focusCity({city:L[i<0?(d>0?0:n-1):(i+(d>0?1:n-1))%n]});},
|
||||
// The offer stays marked in its city's Offers here until something else is selected, so two offers in one city each get a press.
|
||||
|
|
|
|||
|
|
@ -103,7 +103,7 @@ function cityPanel(c){
|
|||
else h+=`<div class="btns">${NNI.map((N,i)=>portShown(i)?btn(tr('city_panel.port_port_price_mo_197d',{port:N.n,price:fmt$(N.mo)}),'buyNni',{city:c,prov:f.id,tier:i},'sm',S.cash<N.mo||!portOk(c,i)):'').join('')}</div>`;
|
||||
h+=`</div></div>`;}
|
||||
h+=`</section>`;}
|
||||
h+=`<section><h3>${tr('city_panel.fiber_from_city',{city:C.name})}</h3><p class="lead">${tr('city_panel.drag_from_this_router_to_any')}</p>`;
|
||||
h+=`<section><h3>${tr('city_panel.fiber_from_city',{city:C.name})}</h3><p class="lead">${tr('city_panel.drag_from_this_router_to_any')}</p><div class="btns">${btn(tr('city_panel.link_to_a_city'),'findLink',{city:c},'sm')}</div>`;
|
||||
if(!ls.length)h+=`<p class="empty">${tr('common.no_links_yet')}</p>`;
|
||||
for(const l of ls){const o=l.a===c?l.b:l.a,u=capOf(l)?(R.load[l.id]||0)/capOf(l):0,cut=linkDown(l);
|
||||
h+=`<div class="row"><div class="grow"><div class="nm">→ ${CITY[o].name}${l.mult>1?' · '+tr('common.diverse'):''} ${cut?'<span class="tag restrictive">'+tr('common.cut')+'</span>':''}</div><div class="meta">${capName(l)} · ${l.km.toLocaleString()} km ${l.kind==='vxc'?tr('city_panel.virtual_circuit_via_fab',{fab:esc(FAB[l.prov].name)}):l.kind==='df'?(l.own?(l.sub&&l.cname?tr('city_panel.your_own_subsea_cable_name',{name:esc(l.cname)}):tr('common.own_dark_fiber')):tr('city_panel.dark_fiber_iru'))+(l.ready>S.day?` · ${tr('city_panel.ready_in_n_d',{n:l.ready-S.day})}`:''):l.sub?tr('common.subsea'):tr('common.terrestrial')} · ${tr('common.price_mo',{price:fmt$(l.mo)})}</div><div class="bar ${barCls(u)}"><i style="width:${u*100}%"></i></div></div>${btn(tr('common.open'),'selLink',{id:l.id},'ghost sm')}</div>`;}
|
||||
|
|
|
|||
|
|
@ -9,22 +9,26 @@ function findIndex(){if(FIND_IX)return FIND_IX;let dn=null,en=null;try{dn=new In
|
|||
const cn=(d,cc)=>{try{return d?d.of(cc)||'':'';}catch(e){return '';}};
|
||||
FIND_IX=Object.values(CITY).map(C=>{const land=cn(dn,C.cc)||C.cc||'';return {id:C.id,name:fold(C.name),land,ctry:fold(land+' '+cn(en,C.cc)+' '+(C.cc||'')),xtra:fold((C.ix||'')+' '+(C.dc||''))};});return FIND_IX;}
|
||||
// Best matches first: the name starts with it, a word of the name does, the name has it, then country, then exchange or DC.
|
||||
function findCities(q){q=fold(q);const mine=c=>S&&S.pops&&S.pops[c]?0:1;
|
||||
if(!q)return S&&S.pops?Object.keys(S.pops).filter(isCity).sort((a,b)=>CITY[a].name.localeCompare(CITY[b].name)).slice(0,FIND_N):[];
|
||||
const out=[];for(const e of findIndex()){const n=e.name;
|
||||
// With from (#343, a link from that POP), only cities a link could end in: not from itself, and only those the map shows.
|
||||
function findCities(q,from){q=fold(q);const mine=c=>S&&S.pops&&S.pops[c]?0:1,ok=c=>!from||(c!==from&&cityOn(c));
|
||||
if(!q)return S&&S.pops?Object.keys(S.pops).filter(c=>isCity(c)&&ok(c)).sort((a,b)=>CITY[a].name.localeCompare(CITY[b].name)).slice(0,FIND_N):[];
|
||||
const out=[];for(const e of findIndex()){const n=e.name;if(!ok(e.id))continue;
|
||||
const s=n.startsWith(q)?0:n.split(/[\s\-.'()]+/).some(w=>w.startsWith(q))?1:n.includes(q)?2:e.ctry.includes(q)?3:e.xtra.includes(q)?4:-1;
|
||||
if(s>=0)out.push([s,mine(e.id),-(CITY[e.id].P||0),e.id]);}
|
||||
return out.sort((a,b)=>a[0]-b[0]||a[1]-b[1]||a[2]-b[2]).slice(0,FIND_N).map(r=>r[3]);}
|
||||
function findRows(q){const ids=findCities(q),land=c=>(findIndex().find(e=>e.id===c)||{}).land||'';
|
||||
function findRows(q,from){const ids=findCities(q,from),land=c=>(findIndex().find(e=>e.id===c)||{}).land||'';
|
||||
if(!ids.length)return `<p class="meta" style="margin:10px 0">${q.trim()?tr('find.no_city_matches_q',{q:esc(q.trim())}):tr('find.type_a_city_a_country')}</p>`;
|
||||
return ids.map((c,i)=>{const C=CITY[c],p=S&&S.pops&&S.pops[c];
|
||||
return `<button class="row findrow${i?'':' on'}" data-act="findGo" data-args="${esc(JSON.stringify({city:c}))}"><span class="grow"><span class="nm">${p?'📍 ':''}${esc(C.name)}</span><span class="meta">${esc([land(c),C.ix].filter(Boolean).join(' · '))}${p?' · '+tr('find.your_pop'):''}</span></span><span aria-hidden="true">›</span></button>`;}).join('');}
|
||||
function findOpen(){if(!S||!UI.started)return;
|
||||
openModal(`<h2 style="font-size:24px;margin:0 0 10px">🔍 ${tr('find.find_a_city')}</h2><input class="t" id="findIn" type="search" enterkeyhint="go" autocomplete="off" autocapitalize="off" spellcheck="false" placeholder="${esc(tr('find.city_country_or_exchange'))}" aria-label="${esc(tr('find.find_a_city'))}" aria-controls="findList">
|
||||
<div id="findList" class="findlist" role="list">${findRows('')}</div>${isPhone()?'':`<p class="meta" style="margin:8px 0 0">${tr('find.press_slash_to_search_from')}</p>`}`,'find');
|
||||
return `<button class="row findrow${i?'':' on'}" data-act="${from?'linkTo':'findGo'}" data-args="${esc(JSON.stringify(from?{a:from,b:c}:{city:c}))}"><span class="grow"><span class="nm">${p?'📍 ':''}${esc(C.name)}</span><span class="meta">${esc([land(c),C.ix].filter(Boolean).join(' · '))}${p?' · '+tr('find.your_pop'):''}</span></span><span aria-hidden="true">›</span></button>`;}).join('');}
|
||||
/* The same box picks where a new link from one of your POPs goes (#343): on a crowded phone map, dragging from a POP
|
||||
to a city far away is fiddly, so you type the other end and get the link window the drag would have opened. */
|
||||
function findOpen(from){if(!S||!UI.started)return;from=from&&S.pops[from]?from:null;UI.findFrom=from;
|
||||
const title=from?tr('find.link_from_city',{city:CITY[from].name}):tr('find.find_a_city');
|
||||
openModal(`<h2 style="font-size:24px;margin:0 0 10px">${from?'🔗':'🔍'} ${esc(title)}</h2><input class="t" id="findIn" type="search" enterkeyhint="go" autocomplete="off" autocapitalize="off" spellcheck="false" placeholder="${esc(tr('find.city_country_or_exchange'))}" aria-label="${esc(title)}" aria-controls="findList">
|
||||
<div id="findList" class="findlist" role="list">${findRows('',from)}</div>${from?`<p class="meta" style="margin:8px 0 0">${tr('find.pick_where_the_link_goes')}</p>`:isPhone()?'':`<p class="meta" style="margin:8px 0 0">${tr('find.press_slash_to_search_from')}</p>`}`,'find');
|
||||
const el=$('findIn');if(el)el.focus();}
|
||||
document.addEventListener('input',e=>{if(e.target.id!=='findIn')return;const L=$('findList');if(L)L.innerHTML=findRows(e.target.value);});
|
||||
document.addEventListener('input',e=>{if(e.target.id!=='findIn')return;const L=$('findList');if(L)L.innerHTML=findRows(e.target.value,UI.findFrom);});
|
||||
document.addEventListener('keydown',e=>{
|
||||
if(e.target.id==='findIn'){if(e.key==='Escape'){closeModal();return;}if(e.key==='Enter'){e.preventDefault();const c=findCities(e.target.value)[0];if(c)ACT.findGo({city:c});}return;}
|
||||
if(e.target.id==='findIn'){if(e.key==='Escape'){closeModal();return;}if(e.key==='Enter'){e.preventDefault();const f=UI.findFrom,c=findCities(e.target.value,f)[0];if(c){if(f)ACT.linkTo({a:f,b:c});else ACT.findGo({city:c});}}return;}
|
||||
if(e.key!=='/'||e.ctrlKey||e.metaKey||e.altKey||(e.target.closest&&e.target.closest('input,textarea,select,[contenteditable]')))return;
|
||||
if(!S||!UI.started||!$('modal').hidden)return;e.preventDefault();findOpen();});
|
||||
|
|
|
|||
|
|
@ -1034,6 +1034,7 @@
|
|||
"city_panel.ix_members_on_ix_n":"IX members on {ix}: {n}",
|
||||
"city_panel.ix_switch":"{ix} switch",
|
||||
"city_panel.launch_broadband_cost":"Launch broadband <small>{cost}</small>",
|
||||
"city_panel.link_to_a_city":"🔗 Link to a city…",
|
||||
"city_panel.make_sacrificial_contains_floods_1_2":"Make sacrificial <small>contains floods · ½ capacity</small>",
|
||||
"city_panel.maxed_out_traffic_here_is_being":"Maxed out. Traffic here is being dropped.",
|
||||
"city_panel.model_level_lv":"{model} <small>level {lv}</small>",
|
||||
|
|
@ -2229,7 +2230,9 @@
|
|||
"find.city_country_or_exchange":"City, country or exchange",
|
||||
"find.find_a_city":"Find a city",
|
||||
"find.find_a_city_slash":"Find a city (/)",
|
||||
"find.link_from_city":"New link from {city}",
|
||||
"find.no_city_matches_q":"No city matches “{q}”.",
|
||||
"find.pick_where_the_link_goes":"Pick where the link goes: the same as dragging from this POP to that city on the map.",
|
||||
"find.press_slash_to_search_from":"Tip: press <b>/</b> anywhere on the map to search.",
|
||||
"find.type_a_city_a_country":"Type a city, a country or an exchange.",
|
||||
"find.your_pop":"your POP",
|
||||
|
|
|
|||
91
tests/city-picker.test.js
Normal file
91
tests/city-picker.test.js
Normal file
|
|
@ -0,0 +1,91 @@
|
|||
// #343: on a crowded phone map, dragging from a POP to a city far away is fiddly. A POP's panel can open the city
|
||||
// finder in link mode: type the other end, pick it, and get the same link window the drag would have opened.
|
||||
const test = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const { load } = require('./harness');
|
||||
const { lit } = require('../scripts/lib/js-literal');
|
||||
|
||||
const start = "ACT.start({});if(UI.pendGame)ACT.pitchSkip();S.nextFail=1e9;S.nextEvent=1e9;S.cash=1e9";
|
||||
const home = ev => ev("Object.keys(S.pops)[0]");
|
||||
|
||||
test('#343 a POP panel has a Link to a city button that opens the finder in link mode', () => {
|
||||
const { ev, dom, errors } = load();
|
||||
ev(start);
|
||||
const a = home(ev);
|
||||
ev(`UI.sel={type:'city',id:${lit(a)}};UI.tab='links';renderPanel()`);
|
||||
const doc = dom.window.document;
|
||||
const b = [...doc.querySelectorAll('#panelBody [data-act="findLink"]')];
|
||||
assert.equal(b.length, 1, 'one button in the fiber section');
|
||||
assert.match(b[0].textContent, /Link to a city/);
|
||||
b[0].click();
|
||||
assert.equal(ev("$('modal').hidden"), false);
|
||||
assert.equal(ev("$('modal').className"), 'find');
|
||||
assert.match(doc.getElementById('modalCard').textContent, new RegExp(`New link from ${ev(`CITY[${lit(a)}].name`)}`));
|
||||
// Rows open the link window, not the map jump.
|
||||
ev("$('findIn').value='sydney';$('findIn').dispatchEvent(new Event('input',{bubbles:true}))");
|
||||
const row = doc.querySelector('#findList .findrow');
|
||||
assert.equal(row.dataset.act, 'linkTo');
|
||||
assert.deepEqual(JSON.parse(row.dataset.args), { a, b: 'syd' });
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test('#343 picking a city opens the same link window as dragging there, and Enter picks the first match', () => {
|
||||
const { ev, dom, errors } = load();
|
||||
ev(start);
|
||||
const a = home(ev), doc = dom.window.document;
|
||||
const b = a === 'syd' ? 'tyo' : 'syd';
|
||||
ev(`ACT.findLink({city:${lit(a)}})`);
|
||||
ev(`$('findIn').value=CITY[${lit(b)}].name;$('findIn').dispatchEvent(new Event('input',{bubbles:true}))`);
|
||||
doc.querySelector('#findList .findrow').click();
|
||||
assert.deepEqual(JSON.parse(ev("JSON.stringify(UI.pending)")), { a, b });
|
||||
const viaPicker = doc.getElementById('modalCard').textContent;
|
||||
assert.match(viaPicker, new RegExp(`${ev(`CITY[${lit(a)}].name`)} → ${ev(`CITY[${lit(b)}].name`)}`));
|
||||
ev(`closeModal();openLinkModal(${lit(a)},${lit(b)})`);
|
||||
assert.equal(doc.getElementById('modalCard').textContent, viaPicker, 'exactly what the drag opens');
|
||||
// Typing without accents and pressing Enter.
|
||||
ev(`closeModal();ACT.findLink({city:${lit(a)}});$('findIn').value='SAO PAULO'`);
|
||||
doc.getElementById('findIn').dispatchEvent(new dom.window.KeyboardEvent('keydown', { key: 'Enter', bubbles: true }));
|
||||
assert.deepEqual(JSON.parse(ev("JSON.stringify(UI.pending)")), { a, b: 'sao' });
|
||||
// The plain finder still jumps the map.
|
||||
ev("closeModal();ACT.findOpen()");
|
||||
assert.equal(ev("UI.findFrom"), null);
|
||||
ev("$('findIn').value='sydney';$('findIn').dispatchEvent(new Event('input',{bubbles:true}))");
|
||||
assert.equal(doc.querySelector('#findList .findrow').dataset.act, 'findGo');
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test('#343 only cities a link could end in are offered: not the POP itself, not cities the map does not show', () => {
|
||||
const { ev, errors } = load();
|
||||
ev(start);
|
||||
const a = home(ev);
|
||||
assert.equal(ev(`findCities(${lit(ev(`CITY[${lit(a)}].name`))},${lit(a)}).includes(${lit(a)})`), false, 'not itself');
|
||||
assert.equal(ev("cityOn('aju')"), false, 'Aracaju is off the map');
|
||||
assert.equal(ev(`findCities('aracaju',${lit(a)}).includes('aju')`), false);
|
||||
assert.equal(ev("findCities('aracaju').includes('aju')"), true, 'the plain finder still finds it');
|
||||
// An empty box lists your other POPs.
|
||||
ev("ACT.buildPop({city:'syd'})");
|
||||
assert.deepEqual(ev(`findCities('',${lit(a)}).join()`).split(',').filter(Boolean), ev(`Object.keys(S.pops).filter(c=>c!==${lit(a)}).sort((x,y)=>CITY[x].name.localeCompare(CITY[y].name)).join()`).split(',').filter(Boolean));
|
||||
// Typed orders that make no sense do nothing.
|
||||
ev(`ACT.linkTo({a:${lit(a)},b:${lit(a)}})`);
|
||||
assert.equal(ev("$('modal').hidden"), true);
|
||||
ev("ACT.linkTo({a:'atlantis',b:'syd'})");
|
||||
assert.equal(ev("$('modal').hidden"), true);
|
||||
ev(`ACT.linkTo({a:${lit(a)},b:'aju'})`);
|
||||
assert.equal(ev("$('modal').hidden"), true, 'a city off the map takes no link');
|
||||
ev("ACT.findLink({city:'aju'})");
|
||||
assert.equal(ev("$('modal').hidden"), true, 'no finder from a city without a POP');
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test('#343 the link finder works on a phone, in German', () => {
|
||||
const { ev, dom, errors } = load({ lang: 'de' });
|
||||
ev(start + ";window.innerWidth=360");
|
||||
const a = home(ev);
|
||||
ev(`UI.sel={type:'city',id:${lit(a)}};UI.tab='links';renderPanel()`);
|
||||
const doc = dom.window.document;
|
||||
assert.match(doc.getElementById('panelBody').textContent, /Link zu einer Stadt/);
|
||||
ev(`ACT.findLink({city:${lit(a)}})`);
|
||||
assert.match(doc.getElementById('modalCard').textContent, /Neuer Link ab/);
|
||||
assert.ok(ev("findCities('deutschland'," + lit(a) + ").includes('fra')") || a === 'fra');
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue