from test_est_rea_parity import run def test_quantity_totals_handles_large_estimate_and_ambiguous_targets(): result = run( "math", """(()=>{ const p=EstNative.empty(); p.tables.EstMainDat=Array.from({length:5000},(_,i)=>({PkID:i+1,Code:'C'+i,Level:0})); p.quantities=Array.from({length:5000},(_,i)=>({Code:'Q'+i,formula:'1',TargetKey:'id:'+(i+1)})); const totals=EstQuantity.totals(p,'manual'); p.tables.EstMainDat.push({PkID:1,Code:'other',Level:0}); let duplicate=false; try { EstQuantity.totals(p,'manual'); } catch(e) { duplicate=e.message.includes('중복'); } return {count:totals.size,first:totals.get(0),last:totals.get(4999),duplicate}; })()""", ) assert result == {"count": 5000, "first": 1, "last": 1, "duplicate": True} def test_quantity_target_options_are_loaded_when_focused(): result = run( "math", """(()=>{ const p=EstNative.empty(); p.tables.EstMainDat=[{PkID:1,Code:'A',Name:'첫 행'}, {PkID:2,Code:'B',Name:'둘째 행'},{PkID:3,Code:'C',Level:1}]; globalThis.EstApp={esc:v=>String(v),state:{project:p}}; const handlers={}; globalThis.document={addEventListener:(name,fn)=>handlers[name]=fn}; const html=EstQuantity.targetSelect(p,{TargetKey:'id:2',TargetCode:'B'},'manual',0); EstQuantity.install(); const select={dataset:{quantitySelect:'manual'},value:'id:2',innerHTML:''}; handlers.focusin({target:select}); return {initialOptions:(html.match(/