统一海外仓新增页样式与字段校验
This commit is contained in:
@@ -1,8 +1,39 @@
|
||||
import assert from 'node:assert/strict'
|
||||
import { readFileSync } from 'node:fs'
|
||||
import test from 'node:test'
|
||||
import { createRequire } from 'node:module'
|
||||
import ts from 'typescript'
|
||||
|
||||
const view = readFileSync(new URL('./WarehouseServiceView.vue', import.meta.url), 'utf8')
|
||||
const { default: Schema } = createRequire(import.meta.resolve('element-plus'))('async-validator')
|
||||
|
||||
test('新增废弃逐字段校验仓库、来源单和原因,备注不影响提交资格', async () => {
|
||||
const source = view.slice(view.indexOf('const disposalFormRules:'), view.indexOf('const labelingFormRef ='))
|
||||
const code = ts.transpileModule(source, { compilerOptions: { target: ts.ScriptTarget.ES2022 } }).outputText
|
||||
const rules = new Function(code + '\nreturn disposalFormRules')()
|
||||
const validator = new Schema(rules)
|
||||
await assert.rejects(validator.validate({ warehouse: '', sourceOrder: '', reason: '' }), error => {
|
||||
assert.deepEqual(Object.keys(error.fields).sort(), ['reason', 'sourceOrder', 'warehouse'])
|
||||
return true
|
||||
})
|
||||
const form = { warehouse: 'WH-A', sourceOrder: 'document:IN-A', reason: '其他', remark: '' }
|
||||
await validator.validate(form)
|
||||
await assert.rejects(validator.validate({ ...form, sourceOrder: '' }), error => Boolean(error.fields.sourceOrder))
|
||||
await assert.rejects(validator.validate({ ...form, reason: ' ' }), error => Boolean(error.fields.reason))
|
||||
})
|
||||
|
||||
test('新增废弃校验失败不进入库存提交判断,其他页面不调用废弃表单校验', async () => {
|
||||
const guard = view.match(/ if \(isDisposalCreate\.value && !await labelingFormRef[^\n]+/)[0]
|
||||
let validations = 0
|
||||
const submit = new Function('isDisposalCreate', 'labelingFormRef', 'return async () => {' + guard + '\nreturn "continue"\n}')
|
||||
const formRef = { value: { validate: async () => { validations++; throw new Error('required') } } }
|
||||
assert.equal(await submit({ value: true }, formRef)(), undefined)
|
||||
assert.equal(validations, 1)
|
||||
assert.equal(await submit({ value: false }, formRef)(), 'continue')
|
||||
assert.equal(validations, 1)
|
||||
formRef.value.validate = async () => true
|
||||
assert.equal(await submit({ value: true }, formRef)(), 'continue')
|
||||
})
|
||||
|
||||
test('货物废弃先选择海外操作仓,再加载并选择该仓入库单', () => {
|
||||
assert.match(view, /props\.service === 'disposal'.*操作仓.*v-model="form\.warehouse".*@change="selectDiscardWarehouse"/s)
|
||||
|
||||
Reference in New Issue
Block a user