20 lines
3.3 KiB
JavaScript
20 lines
3.3 KiB
JavaScript
'use strict';
|
|
const test=require('node:test'),assert=require('node:assert/strict'),fs=require('node:fs/promises'),os=require('node:os'),path=require('node:path');
|
|
const {startTestDashboard,login}=require('../fixtures/dashboard-runtime.cjs'),{loadPlaywright,browserOptions}=require('../../src/platform/browser.cjs');
|
|
test('real captured sample uses server evidence id and uncertain batch verification carries version and idempotency',async t=>{
|
|
const dir=await fs.mkdtemp(path.join(os.tmpdir(),'execution-contract-ui-')),runtime=await startTestDashboard({stateDir:dir}),browser=await loadPlaywright().chromium.launch(browserOptions());t.after(async()=>{await browser.close();await runtime.close();await fs.rm(dir,{recursive:true,force:true});});const page=await browser.newPage();page.setDefaultTimeout(5000);const writes=[];
|
|
let captured=false;await page.route('**/api/order-rules/fields',route=>route.fulfill({json:{samples:captured?[{id:'capture-1',processName:'备损订单更改评审',processVersion:'1.4',sample:{demo:false,processName:'备损订单更改评审',processVersion:'1.4',fields:{'OFR_BS_Applicant.OrderNum':'REAL-1'},title:'订单号:REAL-1'},fields:[{path:'OFR_BS_Applicant.OrderNum',label:'订单号',value:'REAL-1'}]}]:[],adapters:[]}}));
|
|
await page.route('**/api/order-rules/preview',route=>{writes.push(route.request().postDataJSON());return route.fulfill({json:{valid:true,issues:[]}});});
|
|
await page.goto('http://127.0.0.1:'+runtime.server.address().port+'/#order-rules');await login(page);await page.locator('#order-rule-refresh').waitFor();captured=true;await page.locator('#order-rule-refresh').click();await page.locator('[data-rule-id="bs-change"]').click();await page.getByLabel('表单样本',{exact:true}).selectOption('capture:capture-1');assert.equal(await page.locator('#order-rule-sample').getAttribute('readonly'),'');await page.getByRole('button',{name:'校验已保存规则',exact:true}).click();await page.locator('#order-rule-preview-result .alert-success').waitFor();assert.deepEqual(writes[0],{sampleId:'capture-1'});
|
|
const snapshot=runtime.orderRules.snapshot();snapshot.batches=[{id:'unknown-1',version:7,status:'unknown',subject:'待核验批次',to:['orders@example.test'],orderIds:[],text:'冻结内容'}];await page.route('**/api/order-rules',route=>route.fulfill({json:snapshot}));await page.route('**/api/order-rules/batches/unknown-1/resolve',route=>{writes.push(route.request().postDataJSON());return route.fulfill({json:{status:'failed'}});});await openRuleRoute(page,'notification-history');await page.getByLabel('核验依据',{exact:true}).fill('已核实SMTP服务器未接受');await page.getByRole('button',{name:'保存核验结论',exact:true}).click();await page.getByText('核验结论已保存。',{exact:true}).waitFor();assert.equal(writes[1].version,7);assert.ok(writes[1].idempotencyKey);assert.equal(writes[1].note,'已核实SMTP服务器未接受');
|
|
});
|
|
|
|
async function openRuleRoute(page,hash){
|
|
if(!await page.locator('a[href="#'+hash+'"]').count()){
|
|
const business=['order-rules','rule-fields'].includes(hash);
|
|
await page.locator('a[href="#'+(business?'business-settings':'order-notifications')+'"]').first().click();
|
|
if(hash==='notification-settings')await page.locator('a[href="#schedule"]').first().click();
|
|
}
|
|
await page.locator('a[href="#'+hash+'"]').first().click();
|
|
}
|