122 lines
16 KiB
JavaScript
122 lines
16 KiB
JavaScript
'use strict';
|
|
// Compatibility component tests; native production navigation is covered in tests/order-rules and tests/app.
|
|
const test=require('node:test');const assert=require('node:assert/strict');const fs=require('node:fs/promises');const http=require('node:http');const path=require('node:path');
|
|
const {loadPlaywright,browserOptions}=require('../src/runtime.cjs');
|
|
const rule={id:'r1',version:1,enabled:true,processName:'海外运营订单评审',nodeName:'订单专员(生效)',productLine:'海外运营',templateId:'tpl-1',pdfTemplateId:'bpm-snapshot-v1',notificationType:'order',batchMode:'product_line',recipientGroupId:'海外运营',adapters:{V13:{orderNo:'OrderNum',brief:{source:'arrival',path:'subject'}}},published:false};
|
|
const arrival={connectionId:'conn-1',source:'portal-v4',taskId:'test-task-1',processName:'海外运营订单评审',activityName:'订单专员(生效)',subject:'订单说明'};
|
|
const order={versionKey:'version-1',orderNo:'TEST-001',businessVersion:'B1',tid:'tid-1',pid:'pid-1',source:'portal-v4',taskId:'test-task-1',ruleId:'r1',productLine:'海外运营',processName:'海外运营订单评审',nodeName:'订单专员(生效)',status:'archive_error',sources:{orderNo:{path:'detail.OrderNum',value:'TEST-001'}},steps:{detail:{status:'success'},pdf:{status:'success'},archive:{status:'error',error:'共享不可用'},notification:{status:'pending'}},pdf:{jobId:'pdf-1'},error:'共享不可用'};
|
|
async function fixture(t,role='admin'){
|
|
const state={rules:[structuredClone(rule)],orders:[structuredClone(order)],batches:[{id:'batch-1',status:'unknown',templateId:'tpl-1',templateVersion:3,orderVersionKeys:['version-1'],to:['test@example.test'],cc:['copy@example.test'],subject:'测试主题',text:'订单说明',error:'结果需要核验'}],arrivals:[arrival],blockedArrivals:[],calls:[],checkValid:true,slowCheck:false};
|
|
const server=http.createServer(async(req,res)=>{try{let file=req.url==='/'?'tests/fixtures/order-workflow-component.html':req.url.startsWith('/vendor/')?null:'web'+req.url;if(file&& !file.includes('..')){const value=await fs.readFile(path.resolve(__dirname,'..',file));res.setHeader('content-type',file.endsWith('.js')?'text/javascript':'text/html');res.end(value);}else{res.statusCode=404;res.end();}}catch{res.statusCode=404;res.end();}});
|
|
await new Promise(r=>server.listen(0,'127.0.0.1',r));const browser=await loadPlaywright().chromium.launch(browserOptions()),page=await browser.newPage();
|
|
t.after(async()=>{await browser.close();await new Promise(r=>server.close(r));});
|
|
await page.route('**/api/**',async route=>{
|
|
const request=route.request(),url=new URL(request.url()),body=request.postDataJSON();state.calls.push({path:url.pathname,body});let data;
|
|
if(url.pathname==='/api/bootstrap/status')data={required:false};else if(url.pathname==='/api/me')data={user:{id:'u-'+role,username:role,role}};
|
|
else if(url.pathname==='/api/order-workflow/rules'&&request.method()==='GET')data={rules:state.rules};
|
|
else if(url.pathname==='/api/order-workflow/options')data={templates:[{id:'tpl-1',subject:'海外模板',version:3,status:'active'}],groups:[{productLine:'海外运营',to:['test@example.test'],cc:[]}],connections:[{id:'conn-1',name:'测试连接'}],adapters:{V13:rule.adapters.V13}};
|
|
else if(url.pathname==='/api/order-workflow')data={orders:state.orders,batches:state.batches,arrivals:state.arrivals,blockedArrivals:state.blockedArrivals,settings:{enabled:false,sendEnabled:false}};
|
|
else if(url.pathname==='/api/order-workflow/rules'&&request.method()==='POST'){data={...body,version:(body.version||0)+1};state.rules=[data];}
|
|
else if(url.pathname.endsWith('/check')){if(state.slowCheck)await new Promise(r=>setTimeout(r,350));data={valid:state.checkValid,issues:state.checkValid?[]:['缺少业务版本'],checkId:'check-1',sample:{processName:rule.processName,nodeName:rule.nodeName,processVersion:'V13',fields:{OrderNum:'TEST-001'},tid:'tid-1',pid:'pid-1'}};}
|
|
else if(url.pathname.endsWith('/publish')){data={...state.rules[0],published:true,version:state.rules[0].version+1};state.rules=[data];}
|
|
else if(url.pathname==='/api/order-workflow/order/version-1')data=state.orders[0];
|
|
else if(url.pathname.endsWith('/retry')){data={ok:true};}
|
|
else if(url.pathname.endsWith('/resolve')){data={ok:true};state.batches[0].status='resolved_sent';}
|
|
else data={};
|
|
await route.fulfill({status:200,contentType:'application/json',body:JSON.stringify(data)});
|
|
});
|
|
return {page,state,base:'http://127.0.0.1:'+server.address().port};
|
|
}
|
|
|
|
test('classification page saves a draft, checks a real arrival and publishes only a successful unchanged check',{timeout:30000},async t=>{
|
|
const {page,state,base}=await fixture(t);await page.goto(base+'/#order-rules');
|
|
await page.getByRole('heading',{name:'分类规则',exact:true}).waitFor({timeout:3000});
|
|
await page.getByRole('button',{name:'编辑规则',exact:true}).click();
|
|
assert.equal(await page.locator('#rule-adapter-details').getAttribute('open'),null);
|
|
await page.getByLabel('产品线 / 产业',{exact:true}).fill('海外运营');
|
|
await page.getByRole('button',{name:'保存草稿',exact:true}).click();
|
|
await page.getByText('草稿已保存,需重新检查样本后发布。',{exact:true}).waitFor();
|
|
assert.equal(await page.getByRole('button',{name:'发布规则',exact:true}).isDisabled(),true);
|
|
await page.getByLabel('真实 BPM 到达记录',{exact:true}).selectOption('0');
|
|
state.slowCheck=true;await page.getByRole('button',{name:'检查只读样本',exact:true}).click();
|
|
assert.equal(await page.getByRole('button',{name:'检查只读样本',exact:true}).isDisabled(),true);
|
|
await page.getByText('样本检查通过,可以发布当前草稿。',{exact:true}).waitFor();
|
|
await page.getByRole('button',{name:'发布规则',exact:true}).click();
|
|
await page.getByText('规则已发布。',{exact:true}).waitFor();
|
|
assert.equal(state.calls.filter(c=>c.path.endsWith('/check')).length,1);
|
|
assert.deepEqual(state.calls.find(c=>c.path.endsWith('/publish')).body,{version:2,checkId:'check-1'});
|
|
});
|
|
|
|
test('viewer sees order field evidence and frozen batch recipients but has no write actions or duplicate page tabs',{timeout:30000},async t=>{
|
|
const {page,state,base}=await fixture(t,'viewer');await page.goto(base+'/#order-center');
|
|
await page.getByRole('heading',{name:'订单任务',exact:true}).waitFor({timeout:3000});
|
|
assert.equal(await page.locator('#content a[href="#mail-batches"]').count(),0);
|
|
await page.getByRole('button',{name:'查看详情',exact:true}).click();await page.getByText('detail.OrderNum',{exact:true}).waitFor();
|
|
assert.equal(await page.getByRole('button',{name:'重试失败步骤',exact:true}).count(),0);
|
|
await page.locator('aside a[href="#mail-batches"]').click();await page.getByRole('heading',{name:'邮件批次',exact:true,level:2}).waitFor();
|
|
await page.getByText('test@example.test',{exact:true}).waitFor();await page.getByText('copy@example.test',{exact:true}).waitFor();await page.getByText('tpl-1 · v3',{exact:true}).waitFor();
|
|
assert.equal(await page.getByRole('button',{name:'保存核验结果',exact:true}).count(),0);
|
|
await page.locator('aside a[href="#rules"]').click();await page.getByRole('heading',{name:'分类规则',exact:true}).waitFor();assert.equal(await page.getByRole('button',{name:'新增分类规则',exact:true}).count(),0);
|
|
assert.equal(state.calls.filter(c=>c.body).length,0);
|
|
});
|
|
|
|
test('admin must record unknown batch evidence and business strings render as text',{timeout:30000},async t=>{
|
|
const {page,state,base}=await fixture(t);state.batches[0].subject='<img src=x onerror=alert(1)>';await page.goto(base+'/#mail-batches');await page.getByRole('heading',{name:'邮件批次',exact:true,level:2}).waitFor({timeout:3000});
|
|
assert.equal(await page.locator('#content img').count(),0);await page.getByRole('button',{name:'保存核验结果',exact:true}).click();assert.equal(state.calls.some(c=>c.path.endsWith('/resolve')),false);
|
|
await page.getByLabel('核验依据',{exact:true}).fill('已查询测试邮箱并确认收到');await page.getByRole('button',{name:'保存核验结果',exact:true}).click();await page.getByText('核验结果已保存。',{exact:true}).waitFor();
|
|
const calls=state.calls.filter(c=>c.path.endsWith('/resolve'));assert.equal(calls.length,1);assert.deepEqual(calls[0].body,{resolution:'sent',note:'已查询测试邮箱并确认收到'});
|
|
});
|
|
|
|
test('leaving a slow sample check prevents its response from replacing the order center',{timeout:30000},async t=>{
|
|
const {page,state,base}=await fixture(t);state.slowCheck=true;await page.goto(base+'/#rules');await page.getByRole('button',{name:'编辑规则',exact:true}).click({timeout:3000});await page.getByLabel('真实 BPM 到达记录',{exact:true}).selectOption('0');await page.getByRole('button',{name:'检查只读样本',exact:true}).click();await page.locator('aside a[href="#order-center"]').click();await page.getByRole('heading',{name:'订单任务',exact:true}).waitFor();await page.waitForTimeout(450);assert.equal(await page.getByText('样本检查通过,可以发布当前草稿。',{exact:true}).count(),0);
|
|
});
|
|
|
|
test('admin can provide an actual detail link when an older arrival has no stored link',{timeout:30000},async t=>{
|
|
const {page,state,base}=await fixture(t);await page.goto(base+'/#rules');await page.getByRole('button',{name:'编辑规则',exact:true}).click({timeout:3000});await page.getByLabel('真实 BPM 到达记录',{exact:true}).selectOption('0');
|
|
const detailUrl='https://bpm.skyworthdigital.com/YZSoft/Forms/XForm/TestV13.aspx?tid=101&pid=202';await page.getByLabel('BPM 详情链接(旧记录补充)',{exact:true}).fill(detailUrl,{timeout:1000});await page.getByRole('button',{name:'检查只读样本',exact:true}).click();await page.getByText('样本检查通过,可以发布当前草稿。',{exact:true}).waitFor();
|
|
assert.equal(state.calls.find(c=>c.path.endsWith('/check')).body.detailUrl,detailUrl);
|
|
});
|
|
|
|
test('a new classification can adopt process and node from an existing BPM arrival',{timeout:30000},async t=>{
|
|
const {page,base}=await fixture(t);await page.goto(base+'/#rules');await page.getByRole('button',{name:'新增分类规则',exact:true}).click({timeout:3000});await page.getByLabel('真实 BPM 到达记录',{exact:true}).selectOption('0');assert.equal(await page.getByLabel('流程名称',{exact:true}).inputValue(),rule.processName);assert.equal(await page.getByLabel('当前节点',{exact:true}).inputValue(),rule.nodeName);
|
|
});
|
|
|
|
test('changing the sample link during a slow check invalidates its response',{timeout:30000},async t=>{
|
|
const {page,state,base}=await fixture(t);state.slowCheck=true;await page.goto(base+'/#rules');await page.getByRole('button',{name:'编辑规则',exact:true}).click({timeout:3000});await page.getByLabel('真实 BPM 到达记录',{exact:true}).selectOption('0');await page.getByRole('button',{name:'检查只读样本',exact:true}).click();await page.getByLabel('BPM 详情链接(旧记录补充)',{exact:true}).fill('https://bpm.skyworthdigital.com/YZSoft/Forms/XForm/TestV13.aspx?tid=303&pid=404');await page.waitForTimeout(500);assert.equal(await page.getByRole('button',{name:'发布规则',exact:true}).isDisabled(),true);assert.equal(await page.getByText('样本检查通过,可以发布当前草稿。',{exact:true}).count(),0);
|
|
});
|
|
|
|
test('failed sample cannot publish and edits invalidate a successful sample check',{timeout:30000},async t=>{
|
|
const {page,state,base}=await fixture(t);await page.goto(base+'/#rules');await page.getByRole('button',{name:'编辑规则',exact:true}).click({timeout:3000});await page.getByLabel('真实 BPM 到达记录',{exact:true}).selectOption('0');state.checkValid=false;
|
|
await page.getByRole('button',{name:'检查只读样本',exact:true}).click();await page.getByText('缺少业务版本',{exact:true}).waitFor();assert.equal(await page.getByRole('button',{name:'发布规则',exact:true}).isDisabled(),true);
|
|
state.checkValid=true;await page.getByRole('button',{name:'检查只读样本',exact:true}).click();await page.getByText('样本检查通过,可以发布当前草稿。',{exact:true}).waitFor();await page.getByLabel('当前节点',{exact:true}).fill('其他节点');assert.equal(await page.getByRole('button',{name:'发布规则',exact:true}).isDisabled(),true);
|
|
});
|
|
|
|
test('operator can recover a blocked candidate before an order version exists',{timeout:30000},async t=>{
|
|
const {page,state,base}=await fixture(t,'operator');state.orders=[];state.blockedArrivals=[{...arrival,id:'candidate-1',status:'blocked',error:'缺少明确业务版本',code:'VERSION_MISSING'}];await page.goto(base+'/#order-center');await page.getByRole('heading',{name:'待确认的 BPM 到达记录',exact:true}).waitFor({timeout:3000});
|
|
await page.getByText('VERSION_MISSING',{exact:true}).waitFor();await page.getByText('缺少明确业务版本',{exact:true}).waitFor();await page.getByRole('button',{name:'重新采集候选记录',exact:true}).click();await page.getByText('候选记录重试已提交,请刷新查看结果。',{exact:true}).waitFor();assert.deepEqual(state.calls.find(c=>c.path==='/api/order-workflow/arrivals/candidate-1/retry').body,{});
|
|
});
|
|
|
|
test('viewer can inspect blocked candidates without a recovery action',{timeout:30000},async t=>{
|
|
const {page,state,base}=await fixture(t,'viewer');state.blockedArrivals=[{...arrival,id:'candidate-1',status:'blocked',error:'缺少字段',code:'MISSING_FIELD'}];await page.goto(base+'/#order-center');await page.getByText('MISSING_FIELD',{exact:true}).waitFor({timeout:3000});assert.equal(await page.getByRole('button',{name:'重新采集候选记录',exact:true}).count(),0);
|
|
});
|
|
|
|
test('notification failures are retryable but a blocked order needs manual correction',{timeout:30000},async t=>{
|
|
const {page,state,base}=await fixture(t,'operator');state.orders[0].status='notification_error';await page.goto(base+'/#order-center');await page.getByRole('button',{name:'查看详情',exact:true}).click({timeout:3000});await page.getByRole('button',{name:'重试失败步骤',exact:true}).click({timeout:1000});await page.getByText('重试已提交,请刷新查看步骤结果。',{exact:true}).waitFor();assert.equal(state.calls.filter(c=>c.path==='/api/order-workflow/orders/version-1/retry').length,1);
|
|
state.orders[0].status='blocked';await page.reload();await page.getByRole('button',{name:'查看详情',exact:true}).click();await page.getByText('detail.OrderNum',{exact:true}).waitFor();assert.equal(await page.getByRole('button',{name:'重试失败步骤',exact:true}).count(),0);
|
|
});
|
|
|
|
test('admin can restore an exhausted failed batch with a required recovery note',{timeout:30000},async t=>{
|
|
const {page,state,base}=await fixture(t);state.batches[0].status='failed';state.batches[0].error='SMTP 检查次数已耗尽';await page.goto(base+'/#mail-batches');await page.getByRole('button',{name:'保存核验结果',exact:true}).click({timeout:1500});assert.equal(state.calls.some(c=>c.path.endsWith('/resolve')),false);await page.getByLabel('核验结果',{exact:true}).selectOption('retry');await page.getByLabel('核验依据',{exact:true}).fill('已修复 SMTP 配置并完成连接检查');await page.getByRole('button',{name:'保存核验结果',exact:true}).click();await page.getByText('核验结果已保存。',{exact:true}).waitFor();assert.equal(state.calls.find(c=>c.path.endsWith('/resolve')).body.resolution,'retry');
|
|
});
|
|
|
|
test('old arrivals explain that an arbitrary detail link cannot establish the order identity',{timeout:30000},async t=>{
|
|
const {page,base}=await fixture(t);await page.goto(base+'/#rules');await page.getByRole('button',{name:'编辑规则',exact:true}).click({timeout:3000});await page.getByText('历史记录若未保存 tid/pid 或权威详情链接,请先重新扫描获取来源依据,不能用任意链接绑定订单。',{exact:true}).waitFor({timeout:1000});
|
|
});
|
|
|
|
|
|
test('operator can explicitly read real notification tasks without enabling processing or sending',{timeout:30000},async t=>{
|
|
const {page,state,base}=await fixture(t,'operator');await page.goto(base+'/#order-rules');await page.getByRole('heading',{name:'分类规则',exact:true}).waitFor({timeout:3000});
|
|
await page.getByLabel('通知任务来源连接',{exact:true}).selectOption('conn-1');await page.getByRole('button',{name:'读取通知任务',exact:true}).click();
|
|
await page.getByText('只读采集完成',{exact:false}).waitFor({timeout:3000});assert.equal(state.calls.some(call=>call.path==='/api/order-workflow/source-scan'&&call.body.connectionId==='conn-1'),true);assert.equal(state.calls.some(call=>call.path==='/api/order-workflow/settings'),false);
|
|
});
|