import assert from 'node:assert/strict' import test from 'node:test' import { attachmentCount, dropsLockedPlate, keptPlates, missingCertLabel, productIdentity, referenceRowLocked, scopeExpands, statusChoices } from '../src/views/m/pl/plan-cert/cert-form-rules' test('an empty certificate names the first missing field and does not invent a unit', () => { assert.equal(missingCertLabel('purchase', { quantityUnit: '' }), '编号') assert.equal( missingCertLabel('purchase', { certNo: 'G1', productNameOnCert: '硫酸', totalQty: '1', quantityUnit: '', validUseText: '多次有效', buyerName: '甲', sellerName: '乙' }), '数量单位' ) assert.equal( missingCertLabel('transport', { certNo: 'Y1', productNameOnCert: '硫酸', totalQty: '1', quantityUnit: 'dun', validUseText: '多次有效', shipperName: '山峡' }), '' ) }) test('exactly one attachment is counted and status only moves to suspended, closed or void', () => { assert.equal(attachmentCount(' a.png, ,b.pdf '), 2) assert.equal(attachmentCount(''), 0) assert.deepEqual( statusChoices('active').map(([value]) => value), ['active', 'suspended', 'closed', 'void'] ) assert.deepEqual( statusChoices('closed').map(([value]) => value), ['closed'] ) assert.deepEqual( statusChoices('void').map(([value]) => value), ['void'] ) }) test('locked plates stay and a linked purchase reference cannot be edited', () => { assert.equal(dropsLockedPlate(['皖A'], ['皖B']), true) assert.deepEqual(keptPlates(['皖A'], ['皖B', '皖A']), ['皖A', '皖B']) assert.equal( referenceRowLocked(false, { id: 'ref-1', purchaseCertId: 'cert-1' }, ['ref-1']), true ) assert.equal(referenceRowLocked(false, { id: 'ref-2', purchaseCertId: null }, ['ref-1']), false) }) test('a void or closed certificate cannot gain a contract, a product, or a restored product', () => { assert.equal(scopeExpands('void', true, [], []), true) assert.equal(scopeExpands('closed', true, [], []), true) assert.equal( scopeExpands( 'void', false, [{ contractProductId: 'line-1', scopeStatus: 'inactive' }], [{ contractProductId: 'line-1', scopeStatus: 'active' }] ), true ) assert.equal( scopeExpands( 'active', false, [{ contractProductId: 'line-1', scopeStatus: 'active' }], [{ contractProductId: 'line-1', scopeStatus: 'inactive' }] ), false ) assert.equal(productIdentity([{ contractProductId: 'b' }, { contractProductId: 'a' }]), 'a\nb') })