统一客户端采购与运输新增页样式及必填提示

This commit is contained in:
2026-10-29 14:15:27 +08:00
parent b977ccd89d
commit e3d94d06c9
5 changed files with 144 additions and 43 deletions
+31 -1
View File
@@ -1,11 +1,14 @@
import assert from 'node:assert/strict'
import test from 'node:test'
import { readFileSync } from 'node:fs'
import { createRequire } from 'node:module'
import { runInNewContext } from 'node:vm'
import ts from 'typescript'
import * as vue from 'vue'
import { parse, compileScript } from 'vue/compiler-sfc'
const { default: Schema } = createRequire(import.meta.resolve('element-plus'))('async-validator')
let nextKey = 0
const crypto = { randomUUID: () => `test-key-${++nextKey}` }
function moduleFrom(source, require = () => { throw new Error('unexpected import') }) {
@@ -86,9 +89,36 @@ function viewHarness({ createPage = false, detailPage = false, api = {}, storage
}
runInNewContext(ts.transpileModule(source, { compilerOptions: { target: ts.ScriptTarget.ES2022, module: ts.ModuleKind.CommonJS } }).outputText, context)
const state = context.exports.default.setup(props, { expose: () => {} })
state.formRef.value = {
validate: async () => { await new Schema(state.formRules).validate(state.form); return true },
clearValidate: () => {},
}
return { state, props, route, auth, pushes, storage, dispose: () => dispose.forEach(callback => callback()) }
}
test('procurement required fields validate individually and blank submissions never call the API', async () => {
const calls = []
const harness = viewHarness({ createPage: true, api: { createProcurement: async payload => { calls.push(payload); return { order: { orderNo: 'PO-VALID' } } } } })
try {
const fields = ['procurementDirection', 'productName', 'purchaseQuantity', 'budgetUnitPrice', 'currency', 'contactName', 'contactPhone', 'receivingAddress']
const source = readFileSync(new URL('./views/ProcurementView.vue', import.meta.url), 'utf8')
for (const field of fields) {
assert.match(source, new RegExp(`<el-form-item[^>]*prop="${field}"`))
const schema = new Schema({ [field]: harness.state.formRules[field] })
await assert.rejects(schema.validate({ [field]: '' }), error => Boolean(error.fields[field]))
}
await assert.rejects(new Schema(harness.state.formRules).validate({ ...draft(), productName: ' ' }))
await harness.state.submit()
assert.equal(calls.length, 0)
assert.equal(harness.state.submitting.value, false)
assert.equal(harness.state.submitError.value, '')
Object.assign(harness.state.form, draft(), { budgetUnitPrice: '0' })
await harness.state.submit()
assert.equal(calls.length, 1)
assert.equal(calls[0].budgetUnitPrice, 0)
} finally { harness.dispose() }
})
test('create summary follows the current form, preserves cents and clears with the draft', () => {
const harness = viewHarness({ createPage: true })
try {
@@ -166,7 +196,7 @@ test('submission double-click sends once and definitive validation rejection per
let reject, calls = 0
const harness = viewHarness({ createPage: true, api: { createProcurement: () => { calls++; return new Promise((_, failure) => { reject = failure }) } } })
try {
Object.assign(harness.state.form, draft()); const first = harness.state.submit(); await harness.state.submit(); assert.equal(calls, 1)
Object.assign(harness.state.form, draft()); const first = harness.state.submit(); await harness.state.submit(); await flush(); assert.equal(calls, 1)
reject(new ApiError('invalid', 'A0422')); await first
assert.equal(harness.state.submitting.value, false); assert.equal(harness.storage.size, 0)
} finally { harness.dispose() }