docs(tests): explain input ownership and incremental query assertions
This commit is contained in:
@@ -51,6 +51,7 @@ test('scene query converts screen pixels once and returns nested display path at
|
||||
|
||||
// 预览A移到x=5000,显式previewIds补入候选并排除旧位置;registry/文档来源不匹配和退化zoom均拒绝。
|
||||
test('preview nodes outside committed grid remain hittable; stale provenance is rejected',()=>{
|
||||
// committed 网格仍在 x=0;只有显式提供 previewIds 才把网格外预览补入候选。
|
||||
const document=doc([node('A')]),p=draw(document,registry,'P',()=>({...document.elements.get('A').geometry,x:5000}));assert.equal(query(p,registry,{x:5050,y:50}).hits.length,0);assert.equal(query(p,registry,{x:5050,y:50},{},{previewIds:new Set(['A'])}).hits[0].target.id,'A');assert.equal(query(p,registry,{x:50,y:50},{},{previewIds:new Set(['A'])}).hits.length,0);
|
||||
assert.throws(()=>hitProjectedCanvas(p,createDocumentQueries(document,registry),createRegistry(builtinComponents()),'view',{space:'scene',point:{x:0,y:0},zoom:1}),/query_registry_changed/);assert.throws(()=>projectCanvas(document,'P',createRegistry(builtinComponents()),new Set(),()=>undefined,null,undefined,{queries:createDocumentQueries(document,registry)}),/query_registry_changed/);
|
||||
const other=doc([node('A')]);assert.throws(()=>hitProjectedCanvas(p,createDocumentQueries(other,registry),registry,'view',{space:'scene',point:{x:0,y:0},zoom:1}),/stale_query_snapshot/);assert.throws(()=>query(p,registry,{x:0,y:0},{zoom:Number.MIN_VALUE}),/invalid_hit_query/);
|
||||
@@ -70,6 +71,7 @@ test('bounded cubic refinement hits actual curve, rejects chord and preserves am
|
||||
test('connection query follows projected curve and collapsed endpoints, with explicit unavailable custom geometry',()=>{
|
||||
const path={type:'bezier-chain',knots:[],startControl:{x:0,y:200},endControl:{x:0,y:200}},document=doc([node('A'),node('B','P',{x:500}),edge('E','A','B','P',path)]),p=draw(document),from=compatConnector(p.nodes[0],undefined,'right'),to=compatConnector(p.nodes[1],undefined,'left'),point=cubicPoint(bezierChainSegments(from,to,path)[0],.5);
|
||||
for(const zoom of [.1,1,4]){const result=query(p,registry,point,{zoom,tolerancePx:6});assert.equal(result.complete,true);assert.equal(result.hits.find(hit=>hit.target.id==='E').certainty,'confirmed');}
|
||||
// 有限细分步骤耗尽时保留 possible 并标记不完整,不能把候选当作已确认结果。
|
||||
const budget=query(p,registry,point,{}, {},{maxCurveSteps:1});assert.equal(budget.complete,false);assert.equal(budget.hits.find(hit=>hit.target.id==='E').certainty,'possible');assert.ok(budget.diagnostics.some(item=>item.code==='geometry_query_budget'));
|
||||
const invalid=query(p,registry,point,{}, {edgeGeometry:()=>[[{x:NaN,y:0}]]});assert.equal(invalid.complete,false);assert.ok(invalid.diagnostics.some(item=>item.code==='invalid_geometry_response'));
|
||||
const collapsed=createDocument('project',[{id:'P',parent:null},{id:'S',parent:{canvasId:'P',entryElementId:'F'}}],[node('C'),node('F','P',{x:500},'frame',{presentation:{collapsed:true}}),node('A','S'),edge('E','C','A')]),c=draw(collapsed),f=compatConnector(c.nodes.find(n=>n.id==='C'),undefined,'right'),t=compatConnector(c.nodes.find(n=>n.id==='F'),undefined,'left'),at=cubicPoint(bezierChainSegments(f,t)[0],.5),hit=query(c,registry,at).hits.find(hit=>hit.target.id==='E');assert.deepEqual(hit.displayedEndpoints,{source:'C',target:'F'});assert.equal(hit.ownerCanvasId,'P');assert.equal(collapsed.elements.get('E').target.elementId,'A');
|
||||
@@ -84,6 +86,7 @@ test('measured native handles use outer edges and loose target fallback without
|
||||
// 自定义圆节点与粗线使用模型协议及服务锚点;缺锚点/非法线宽/handler抛错分别报告诊断,opaque path保持原样。
|
||||
test('registered custom renderers provide model hit shapes, measured anchors, display-space curves and stroke width',()=>{
|
||||
let context;
|
||||
// 模型协议给出圆形命中与 20 单位粗线;renderer catalog 只负责匹配组件,锚点由下方服务替身提供。
|
||||
const definition={id:'custom',dataVersion:1,structure:'node',features:[],validate:()=>true,geometry:{...rectangleGeometry,hit:({geometry:g,point,tolerance})=>Math.hypot(point.x-g.x-g.width/2,point.y-g.y-g.height/2)<=g.width/2+tolerance}},connection={id:'custom-edge',dataVersion:1,structure:'connection',features:[],validate:()=>true,geometry:{kind:'connection',version:1,strokeWidth:()=>20,segments:input=>{context=input;return[[input.source.point,{x:200,y:200},{x:300,y:200},input.target.point]];}}},r=createRegistry([...builtinComponents(),definition,connection]),catalog=createRendererCatalog([...builtinRendererDefinitions,{componentId:'custom',dataVersion:1,structure:'node',rendererId:'circle'},{componentId:'custom-edge',dataVersion:1,structure:'connection',rendererId:'custom-edge'}]),document=doc([node('A','P',{},'custom'),node('B','P',{x:400},'custom'),{...edge('E','A','B'),componentId:'custom-edge',path:{type:'opaque-custom',value:7}}]),p=projectCanvas(document,'P',r,new Set(),()=>undefined,null,catalog),anchors={anchor:(node,_handle,end)=>({point:{x:node.position.x+(end==='source'?100:0),y:50},normal:{x:end==='source'?1:-1,y:0}})};
|
||||
assert.equal(query(p,r,{x:1,y:1},{tolerancePx:0},anchors).hits.some(hit=>hit.target.id==='A'),false);
|
||||
const absent=query(p,r,{x:250,y:160},{tolerancePx:0});assert.ok(absent.diagnostics.some(item=>item.code==='geometry_anchor_unavailable'));
|
||||
|
||||
Reference in New Issue
Block a user