45 lines
5.5 KiB
JavaScript
45 lines
5.5 KiB
JavaScript
'use strict';
|
|
const test=require('node:test');const assert=require('node:assert/strict');
|
|
const {loadPlaywright,browserOptions}=require('../src/runtime.cjs');
|
|
const {hydrateReadonlyDocument,flattenTables}=require('../src/bpm-readonly-form.cjs');
|
|
const child='OFR_WY_ProductRequirementInfo_Remark',master='OFR_WY_Applicant';
|
|
const html=`<form><table dynamicarea="0,1" xdatasource="TableName:${child};Filter:TaskID->${master}.TaskID_Original" datamap="Remark->${child}.Remark"><tbody><tr><td><textarea xdatabind="${child}.Remark"></textarea></td></tr></tbody></table></form>`;
|
|
const table=(TableName,Rows)=>({TableName,Rows,FormTable:true});
|
|
async function fixture(t){const browser=await loadPlaywright().chromium.launch(browserOptions());t.after(()=>browser.close());const context=await browser.newContext({javaScriptEnabled:false}),page=await context.newPage();await context.route('**/*',route=>route.abort());return async(tables,{fieldsOnly=false,markup=html}={})=>{await page.setContent(markup);return page.evaluate(hydrateReadonlyDocument,{tables,fieldsOnly});};}
|
|
|
|
test('persisted current-task rows are displayed without applying the unrelated lookup Original filter',{timeout:30000},async t=>{
|
|
const hydrate=await fixture(t),rows=Array.from({length:9},(_,index)=>({TaskID:111,Remark:'CURRENT-'+index})),tables=[table(master,[{TaskID:111,TaskID_Original:999}]),table(child,rows)],result=await hydrate(tables);
|
|
assert.equal(result.blocker,undefined);assert.equal((result.snapshot.html.match(/<tr/g)||[]).length,9);for(const row of rows)assert.match(result.snapshot.html,new RegExp(row.Remark));assert.equal(flattenTables(tables).fields[child+'[8].Remark'],'CURRENT-8');
|
|
});
|
|
|
|
test('a rendered multirow child with mixed or missing TaskID is blocked instead of silently filtered',{timeout:30000},async t=>{
|
|
const hydrate=await fixture(t),parent=table(master,[{TaskID:111,TaskID_Original:999}]);
|
|
for(const rows of [[{TaskID:111,Remark:'CURRENT'},{TaskID:999,Remark:'UNRELATED'}],[{TaskID:111,Remark:'CURRENT'},{Remark:'MISSING TASK'}],[{TaskID:111,Remark:'CURRENT'},{TaskID:null,Remark:'NULL TASK'}]]){const tables=[parent,table(child,rows)],result=await hydrate(tables);assert.match(result.blocker,/TaskID|作用域|主表/);const raw=flattenTables(tables);assert.equal(raw.fields[child+'[1].Remark'],rows[1].Remark);const fieldsOnly=await hydrate(tables,{fieldsOnly:true});assert.equal(fieldsOnly.blocker,undefined);assert.equal(fieldsOnly.snapshot,null);}
|
|
});
|
|
|
|
test('multirow TaskID association requires one explicit scalar current Applicant TaskID',{timeout:30000},async t=>{
|
|
const hydrate=await fixture(t),detail=table(child,[{TaskID:111,Remark:'ONE'},{TaskID:111,Remark:'TWO'}]);
|
|
for(const tables of [[detail],[table(master,[{TaskID_Original:111}]),detail],[table(master,[{TaskID:[111]}]),detail],[table(master,[{TaskID:111},{TaskID:111}]),detail],[table(master,[{TaskID:111}]),table('Other_Applicant',[{TaskID:111}]),detail]])assert.match((await hydrate(tables)).blocker,/TaskID|作用域|主表/);
|
|
});
|
|
|
|
test('numeric and string representations of the same explicit TaskID preserve current detail rows',{timeout:30000},async t=>{
|
|
const hydrate=await fixture(t),result=await hydrate([table(master,[{TaskID:'111',TaskID_Original:'999'}]),table(child,[{TaskID:111,Remark:'ONE'},{TaskID:'111',Remark:'TWO'}])]);assert.equal(result.blocker,undefined);assert.match(result.snapshot.html,/ONE.*TWO/s);
|
|
});
|
|
|
|
test('scope validation also applies to already expanded undeclared detail rows',{timeout:30000},async t=>{
|
|
const hydrate=await fixture(t),markup=`<form><table><tr><td><input xdatabind="${child}.Remark"></td></tr><tr><td><input xdatabind="${child}.Remark"></td></tr></table></form>`,result=await hydrate([table(master,[{TaskID:111}]),table(child,[{TaskID:111,Remark:'CURRENT'},{TaskID:999,Remark:'UNRELATED'}])],{markup});assert.match(result.blocker,/TaskID|作用域|主表/);
|
|
});
|
|
|
|
test('one wrong-task child row cannot bypass the current master guard',{timeout:30000},async t=>{
|
|
const hydrate=await fixture(t),tables=[table(master,[{TaskID:111,TaskID_Original:999}]),table(child,[{TaskID:999,Remark:'EXTERNAL SINGLE ROW'}])],result=await hydrate(tables);assert.match(result.blocker,/TaskID|作用域|主表/);assert.equal(flattenTables(tables).fields[child+'.Remark'],'EXTERNAL SINGLE ROW');const fieldsOnly=await hydrate(tables,{fieldsOnly:true});assert.equal(fieldsOnly.blocker,undefined);assert.equal(fieldsOnly.snapshot,null);
|
|
});
|
|
|
|
test('single current child empty child and unrelated no-TaskID lookup remain usable',{timeout:30000},async t=>{
|
|
const hydrate=await fixture(t),markup='<form><input xdatabind="'+master+'.TaskID">'+html.replace(/^<form>|<\/form>$/g,'')+'<span xdatabind="UnrelatedLookup.Name"></span></form>',lookup=table('UnrelatedLookup',[{Name:'STATIC LOOKUP'}]),parent=table(master,[{TaskID:111,TaskID_Original:999}]);
|
|
for(const rows of [[{TaskID:111,Remark:'CURRENT SINGLE ROW'}],[]]){const result=await hydrate([parent,table(child,rows),lookup],{markup});assert.equal(result.blocker,undefined);assert.match(result.snapshot.html,/111/);assert.match(result.snapshot.html,/STATIC LOOKUP/);if(rows.length)assert.match(result.snapshot.html,/CURRENT SINGLE ROW/);}
|
|
});
|
|
|
|
test('one wrong-task ordinary bound table is blocked even without a dynamicarea marker',{timeout:30000},async t=>{
|
|
const hydrate=await fixture(t),markup='<form><input xdatabind="OFR_WY_BInfo.CustomerName"></form>',tables=[table(master,[{TaskID:111}]),table('OFR_WY_BInfo',[{TaskID:999,CustomerName:'EXTERNAL CUSTOMER'}])];assert.match((await hydrate(tables,{markup})).blocker,/TaskID|作用域|主表/);
|
|
});
|