'use strict'; const test=require('node:test'),assert=require('node:assert/strict'),vm=require('node:vm'),fs=require('node:fs'),path=require('node:path'),C=require('../server/catalog.cjs'); const root=path.resolve(__dirname,'..'),NOW=Date.parse('2026-10-22T12:00:00Z'),langs=['en','pt','es','fr','ar','zh']; const esc=value=>String(value??'').replace(/[&<>"']/g,c=>({'&':'&','<':'<','>':'>','"':'"',"'":'''}[c])); function setup(){ const sandbox={window:{},Intl,Date};vm.createContext(sandbox); for(const file of ['copy-base.js','copy-pilot.js','copy-shared.js','copy-catalog.js','copy-rehearsal.js','copy-commerce.js','copy-search.js','copy-product.js','copy-sourcing.js','copy-global-search.js','search.js','catalog-ui.js','sourcing-ui.js','global-search-ui.js'])vm.runInContext(fs.readFileSync(path.join(root,'public',file),'utf8'),sandbox); sandbox.window.GlemoCommerce={isClosed:o=>o.commercial?.endsAt&&Date.parse(o.commercial.endsAt)'',countdown:()=>'',price:()=>'$1'}; return sandbox.window; } function context(w,lang,role='buyer'){return{lang,role,esc,t:key=>{assert.equal(typeof w.PilotCopy[lang][key],'string',lang+':'+key);return w.PilotCopy[lang][key];},icon:key=>'',assetImage:()=>'DEMO',category:value=>value,market:value=>value,money:value=>'$'+value/100,stateName:()=>'',assetRequests:[]};} test('global search is translated, labeled, escaped, and carries no purchase or participant data',()=>{ const w=setup();for(const lang of langs){for(const key of w.GlobalSearchCopyKeys)assert.equal(typeof w.PilotCopy[lang][key],'string');const html=w.GlemoGlobalSearchUI.bar('',context(w,lang));assert(html.includes('role="search"'));assert(html.includes('for="global-query"'));assert(html.includes('data-ui="global-voice-search"'));assert(!html.includes('{ const S=setup().GlemoSearch,offers=C.catalog().offers,options={now:NOW}; const result=S.explore(offers,'xcxcxcx',options);assert.equal(result.length,3);for(const o of result){assert(offers.includes(o));assert.equal(S.match(o,'xcxcxcx'),false);assert(!['reconciled','cancelled','expired','rejected'].includes(o.stage));} assert(S.explore(offers,'Dubai sem imóveis',options).every(o=>o.country==='AE'&&o.category!=='Real estate')); assert(S.explore(offers,'unknown',{...options,country:'SG',category:'Treasury'}).every(o=>o.country==='SG'&&o.category==='Treasury')); assert.equal(S.explore(offers,'unknown',{now:Date.parse('2027-01-01')}).some(o=>o.commercial?.endsAt),false); }); test('the exact no-result example has clearly labeled alternatives followed by a private sourcing form in every language',()=>{ const w=setup(),data=C.catalog(),filter={query:'xcxcxcx',country:'',category:'',benefit:'',searched:true}; for(const lang of langs){const c=context(w,lang),html=w.GlemoCatalogUI.list(data,filter,c)+w.GlemoSourcingUI.panel(filter,c);assert(html.includes('product-empty-compact'));assert(html.includes('data-explore-suggestions'));assert(!html.includes('data-related-suggestions'));assert.equal((html.match(/data-related-offer=/g)||[]).length,3);assert(html.includes(w.PilotCopy[lang].discoveryExploreNote));assert(html.indexOf('data-explore-suggestions'){ const w=setup(),filter={query:'real estate Dubai USD 30M',country:'',category:'',benefit:'',searched:true},html=w.GlemoCatalogUI.list(C.catalog(),filter,context(w,'en')); assert(html.includes('data-explore-suggestions'));assert(html.includes(w.PilotCopy.en.sourcingDifferentTicket));assert.equal((html.match(/data-related-offer=/g)||[]).length,3);assert(html.includes('class="case-card catalog-card')); });