cmvr-wms/mobile-app/tests/blackbox-followup.test.mjs

38 lines
2.8 KiB
JavaScript
Raw Normal View History

import test from 'node:test';
import assert from 'node:assert/strict';
import {draftStatus,draftFieldText,referenceText,sheetSelectionError,draftOutcome,draftReviewCount} from '../src/core/assistant-display.ts';
test('nested internal price preview counts every business item for mobile confirmation limits',()=>{
assert.equal(draftReviewCount({rows:[{_referencePricePreview:Array.from({length:34},()=>({}))}]}),34);
assert.equal(draftReviewCount({rows:[{},{}]}),2);
const rows=Array.from({length:34},()=>({}));
assert.deepEqual(draftOutcome({action:'purchase.referencePrice',rows:[{_referencePricePreview:rows}],results:[{status:'SUCCEEDED',data:{changed:13,rows}}]}),{succeeded:13,skipped:21,failed:0,labels:[]});
});
test('skipped quote rows are identified without claiming a successful correction',()=>{
const draft={rows:[{_rowId:'a'},{_rowId:'b',_sourceText:'水冷一体管,4×29.2元'}],results:[{rowId:'a',status:'SUCCEEDED',data:{}},{rowId:'b',status:'SUCCEEDED',data:{skipped:true}}]};
assert.deepEqual(draftOutcome(draft),{succeeded:1,skipped:1,failed:0,labels:['水冷一体管,4×29.2元']});
});
import {modules,recordDisplay} from '../src/core/modules.ts';
test('draft statuses and field options use distinct business definitions',()=>{
assert.equal(draftStatus('CANCELLED'),'已取消');assert.equal(draftStatus('WAIT_CONFIRM'),'待确认');
assert.equal(draftFieldText({status:0},{key:'status',options:[{value:'0',label:'正常'}]}),'正常');
assert.equal(draftFieldText({status:0},{key:'status',options:[{value:'0',label:'待验收'}]}),'待验收');
assert.equal(draftFieldText({unit:'个',_labels:{unit:'个'}},{key:'unit'}),'个');
});
test('unmatched reference becomes readable identity, not raw JSON or an arbitrary ID',()=>{
assert.equal(referenceText({keyword:'螺丝',spec:'M6',brand:'测试牌'}),'螺丝 / M6 / 测试牌');
assert.match(referenceText({id:99}),/尚未匹配/);assert.equal(referenceText(null),'—');
});
test('Excel validity reflects current selection rather than the prior error',()=>{
const file={name:'分表.xlsx',type:'excel',selectedSheetIndexes:[1,2],sheets:[{index:0,rowCount:101},{index:1,rowCount:50},{index:2,rowCount:51}]};
assert.match(sheetSelectionError([file]),/101/);
assert.equal(sheetSelectionError([{...file,selectedSheetIndexes:[1]}]),'');
assert.match(sheetSelectionError([{...file,selectedSheetIndexes:[]}]),/请选择/);
});
test('purchase cards expose the same state enum as the real procurement page',()=>{
const purchase=modules.find(m=>m.key==='purchase');
assert.equal(purchase.fields[0][0],'purchaseStatus');
for(const [state,label] of Object.entries({0:'待采购',1:'已下单',2:'采购中',3:'部分到货',4:'已到齐',5:'已取消'}))assert.equal(recordDisplay(purchase,'purchaseStatus',state),label);
});