window.addEventListener('load', async () => { const assert=(ok,message)=>{if(!ok)throw new Error(message);}; const wait=async check=>{for(let i=0;i<180;i++){if(check())return;await new Promise(r=>setTimeout(r,25));}throw new Error('City link fixture timed out');}; const click=element=>element.dispatchEvent(new MouseEvent('click',{bubbles:true,cancelable:true})); try { const start=location.href, historyLength=history.length; const data=await(await fetch('/_/api/v1/city/map')).json(); const q=data.quartiers.find(q=>q.name==='life'),s=q.streets.find(s=>s.name==='home'),p=s.spots.find(p=>p.name==='alpha'); const params=new URLSearchParams(location.search),level=['spot','street','quartier'].find(k=>params.has(k)); await wait(()=>document.querySelector('[data-city-locality-search]').elements.locality.value===(level||'domain')); const form=document.querySelector('[data-city-locality-search]'); if(level){ const target={quartier:q,street:s,spot:p}[level]; await wait(()=>document.querySelector('[data-city-inspector]').dataset.cityUuid===target.uuid); assert(form.elements.locality_id.value==='uuid:'+target.uuid,'Initial locality must be an explicit UUID'); assert(document.querySelector('.city-detail-link').getAttribute('href')===target.detail_href,'Deep link inspector opened wrong node'); } const jump=(type,id)=>click(document.querySelector(`[data-city-jump="${type}"][data-city-id="${id}"]`)); jump('quartier',q.uuid); await wait(()=>document.querySelector('.city-street-tile')); const road=document.querySelector(`.city-street-tile[data-city-uuid="${s.uuid}"]`); road.dispatchEvent(new MouseEvent('contextmenu',{bubbles:true,cancelable:true,clientX:100,clientY:100})); assert(document.querySelector('.city-context-menu a').getAttribute('href')==='/v/city/s/life/home','Context menu lost parent qualifier'); jump('street',s.uuid); assert(document.querySelector('.city-detail-link').getAttribute('href')==='/v/city/s/life/home','Inspector lost parent qualifier'); assert(form.elements.locality_id.value==='uuid:'+s.uuid,'Search selector is not an explicit UUID'); const search=await fetch('/v/search?q=page&'+new URLSearchParams(new FormData(form))); assert(search.ok,'Locality search failed'); for(const quartier of data.quartiers){ const street=quartier.streets[0]; assert(street.detail_href===`/v/city/s/${quartier.name}/home`,'Repeated Street not parent qualified'); const response=await fetch(street.detail_href),body=await response.text(); assert(response.ok&&body.includes(street.uuid),'Detail resolved a different Street'); } assert((await fetch('/v/city/s/home')).status===404,'Ambiguous legacy name selected an arbitrary Street'); jump('spot',p.uuid); await wait(()=>document.querySelector('.city-estate-detail .city-map-page-link')); for(const a of document.querySelectorAll('.city-map-page-link,[data-city-inspector] li a')){ const href=new URL(a.getAttribute('href'),location.href); assert(!href.hash&&!href.search,'Literal Page path interpreted as query/fragment'); assert(decodeURIComponent(href.pathname)==='/life/home/alpha/page?#%','Page path bytes were lost'); } assert(location.href===start&&history.length===historyLength,'Map navigation changed browser history'); document.body.dataset.vimReady='true'; }catch(error){const box=document.createElement('div');box.id='error';box.textContent=error.stack||error.message;document.body.append(box);} });