'use strict'; const test=require('node:test'),assert=require('node:assert/strict'); const {loadPlaywright,browserOptions}=require('../src/runtime.cjs'); const {hydrateReadonlyDocument}=require('../src/bpm-readonly-form.cjs'); async function fixture(t){const b=await loadPlaywright().chromium.launch(browserOptions());t.after(()=>b.close());const c=await b.newContext({javaScriptEnabled:false});await c.route('**/*',r=>r.abort());const p=await c.newPage();return async(html,tables,options={})=>{await p.setContent(html);return p.evaluate(hydrateReadonlyDocument,{tables,...options});};} const table=(name,rows)=>({TableName:name,FormTable:true,Rows:rows}); test('approved display policy removes absent display values without inventing backend evidence',async t=>{const run=await fixture(t),html='
',tables=[table('Main',[{OrderNum:'123'}])];assert.ok((await run(html,tables)).blocker);const r=await run(html,tables,{allowMissingDisplayFields:true});assert.equal(r.blocker,undefined);assert.match(r.snapshot.html,/123/);assert.doesNotMatch(r.snapshot.html,/STALE/);assert.equal(r.snapshot.warnings.filter(w=>w.includes('后端未提供')).length,2);assert.equal(Object.hasOwn(tables[0].Rows[0],'Legacy'),false);}); test('display policy never drops a partially present column or a compound backend value',async t=>{const run=await fixture(t),html='';for(const rows of [[{Value:'A'},{}],[{Value:{nested:'A'}}]])assert.ok((await run(html,[table('Items',rows)],{allowMissingDisplayFields:true})).blocker);}); test('validated instance id supports non-Applicant main tables while rejecting cross-instance data',async t=>{const run=await fixture(t),html='',tables=[table('Notification_All',[{TaskID:123,OrderNum:'ORDER'}]),table('Items',[{TaskID:123,Value:'VALUE'}])];const r=await run(html,tables,{expectedInstanceId:'123'});assert.equal(r.blocker,undefined);assert.match(r.snapshot.html,/VALUE/);tables[1].Rows[0].TaskID=999;assert.equal((await run(html,tables,{expectedInstanceId:'123'})).diagnostics.reason,'TASK_SCOPE_MISMATCH');}); test('lookup datasource does not override proven persisted row bindings',async t=>{const run=await fixture(t),html='';const r=await run(html,[table('Items',[{TaskID:123,Value:'PERSISTED'}])],{expectedInstanceId:'123'});assert.equal(r.blocker,undefined);assert.match(r.snapshot.html,/PERSISTED/);assert.ok(r.snapshot.warnings.some(w=>w.includes('数据源')));}); test('dynamic detail rows preserve a separate backend-bound summary footer',async t=>{const run=await fixture(t),html='',tables=[table('Items',[{Value:2},{Value:3}]),table('Summary',[{Total:5}])];const r=await run(html,tables);assert.equal(r.blocker,undefined);assert.match(r.snapshot.html,/>2<.*>3<.*>5{const run=await fixture(t),html='';const r=await run(html,[table('Items',[{Value:'A'},{Value:'B'}])],{allowMissingDisplayFields:true});assert.equal(r.blocker,undefined);assert.match(r.snapshot.html,/>A<.*>B{const run=await fixture(t),html='';const r=await run(html,[table('Items',[])],{allowMissingDisplayFields:true});assert.equal(r.blocker,undefined);assert.doesNotMatch(r.snapshot.html,/STALE/);}); test('display omissions also apply to optional template datamap columns without relaxing real row mappings',async t=>{const run=await fixture(t),html='';const r=await run(html,[table('Items',[{Value:'A'},{Value:'B'}])],{allowMissingDisplayFields:true});assert.equal(r.blocker,undefined);assert.doesNotMatch(r.snapshot.html,/STALE/);assert.match(r.snapshot.html,/>A<.*>B{const run=await fixture(t),html='';const r=await run(html,[table('Summary',[{Total:5}])],{allowMissingDisplayFields:true});assert.equal(r.blocker,undefined);assert.doesNotMatch(r.snapshot.html,/STALE/);assert.match(r.snapshot.html,/>5);});