2026-10-16 15:30:10 +08:00
import test from 'node:test'
import assert from 'node:assert/strict'
import fs from 'node:fs'
2026-10-30 15:02:54 +08:00
import { supplierInquiryRows , supplierInquirySelection , quotationReady , quotationSummary , quotationUploadError } from '../../src/utils/supplier-quotation.js'
test ( 'selected inquiry IDs never expand into other same-product rows or invalid lines' , ( ) => {
const row = { id : 1 , productCode : 'A' , quantity : 2 } ; const all = [ row , { ... row , id : 2 , quantity : 8 } , { ... row , id : 3 , historical : true } , { ... row , id : 4 , receivedQuantity : 1 } , { ... row , id : 5 , purchaseStatus : 5 } ]
assert . deepEqual ( supplierInquirySelection ( [ all [ 1 ] ] ) , [ 2 ] ) ; assert . equal ( supplierInquiryRows ( [ all [ 1 ] ] ) [ 0 ] . quantity , 8 )
assert . deepEqual ( supplierInquirySelection ( all ) , [ 1 , 2 ] ) ; assert . deepEqual ( supplierInquirySelection ( [ ] ) , [ ] ) ; assert . deepEqual ( supplierInquirySelection ( [ row , row ] ) , [ 1 ] )
} )
2026-10-16 15:30:10 +08:00
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 ) )
} )
2026-10-30 15:02:54 +08:00
test ( 'supplier workflow uses readable identity columns, a real Excel export, a quote preview, export-column selection and explicit partial confirmation' , ( ) => {
2026-10-16 15:30:10 +08:00
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 , /规格型号/ )
2026-10-30 15:02:54 +08:00
assert . doesNotMatch ( dialog , /label="物品编码"/ ) ; assert . equal ( ( dialog . match ( /title="供应商询价与报价回填"/g ) || [ ] ) . length , 1 ) ; assert . match ( dialog , /title="选择询价单导出列"/ )
2026-10-16 15:30:10 +08:00
assert . match ( dialog , /summary\.errors>0 && !allowPartial/ ) ; assert . match ( dialog , /保存清单/ )
assert . ok ( dialog . indexOf ( 'label="供应商报价"' ) < dialog . indexOf ( 'label="原报价"' ) )
const parent = fs . readFileSync ( new URL ( '../../src/components/PurchaseSheet/index.vue' , import . meta . url ) , 'utf8' )
assert . match ( parent , /导出询价单/ ) ; assert . match ( parent , /回填供应商报价/ ) ; assert . doesNotMatch ( parent , /复制填写格式/ )
assert . match ( parent , /supplierName\(\)\{return this\.sheet\?\.batch\?\.supplierName/ )
} )