import test from 'node:test' import assert from 'node:assert/strict' import fs from 'node:fs' import {supplierInquiryRows,quotationReady,quotationSummary,quotationUploadError} from '../../src/utils/supplier-quotation.js' test('supplier inquiry merges only eligible same-item rows across projects without modifying original data',()=>{ const row={productCode:'A',materialName:'垫片',materialParams:'M4',materialBrand:'品牌',unit:'包',quantity:0.1,projectId:1} const source=[row,{...row,quantity:0.2,projectId:2},{...row,receivedQuantity:1},{...row,historical:true},{...row,purchaseStatus:5},{...row,productCode:'B',materialParams:'M5',quantity:2}] const groups=supplierInquiryRows(source);assert.equal(groups.length,2);assert.equal(groups[0].quantity,0.3);assert.equal(groups[0].rowCount,2);assert.equal(groups[1].spec,'M5');assert.equal(source[0].quantity,0.1) }) test('blank, invalid and unmatchable prices cannot be applied while a real zero price can',()=>{ const valid={unitPrice:0,rowIds:[1,2],error:null},skip={...valid,unitPrice:null,skipped:true},bad={...valid,error:'错误'} assert.equal(quotationReady(valid),true);for(const row of [skip,bad,{...valid,rowIds:[]},...[undefined,'',' ',false,-1,'abc'].map(unitPrice=>({...valid,unitPrice}))])assert.equal(quotationReady(row),false) assert.deepEqual(quotationSummary([valid,skip,bad]),{ready:1,errors:1,skipped:1}) }) test('quote upload validates type and size and accepts ordinary Excel files',()=>{ for(const name of ['报价.xlsx','报价.XLS'])assert.equal(quotationUploadError({name,size:1024}),'') for(const file of [{name:'报价.pdf',size:1},{name:'报价.xlsx',size:0},{name:'报价.xlsx',size:10485761}])assert.ok(quotationUploadError(file)) }) test('supplier workflow uses readable identity columns, a real Excel export, a single preview and explicit partial confirmation',()=>{ const dialog=fs.readFileSync(new URL('../../src/components/PurchaseSheet/SupplierQuotation.vue',import.meta.url),'utf8') assert.match(dialog,/inquiry-export/);assert.match(dialog,/上传供应商报价/);assert.match(dialog,/物品名称/);assert.match(dialog,/规格型号/) assert.doesNotMatch(dialog,/label="物品编码"/);assert.equal((dialog.match(/0 && !allowPartial/);assert.match(dialog,/保存清单/) assert.ok(dialog.indexOf('label="供应商报价"')