cmvr-wms/ruoyi-ui-vue3/tests/unit/assistant-quotation-review.test.mjs
lixiaolong 5cee6482f8 feat(assistant): 优化业务助手功能和移动应用配置
- 实现业务确认单条目的移出和恢复功能
- 添加报价匹配明细中的跳过处理选项
- 重构移动应用的环境配置使用默认开发配置
- 更新移动应用Android版本号策略
- 替换到货操作组件为独立的操作组件
- 添加安装配置检查脚本
- 增强测试覆盖包括条目移出恢复和报价跳过场景
2026-10-20 15:35:58 +08:00

38 lines
3.5 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import test from 'node:test'
import assert from 'node:assert/strict'
import { assistantQuotationReviewRows, assistantQuotationReviewState, assistantQuotationSkipChange } from '../../src/utils/assistant-quotation-review.js'
import { assistantApplyDraftChanges } from '../../src/utils/assistant-draft-edit.js'
import { assistantRowsSignature } from '../../src/utils/business-assistant.js'
const fields = [{ key: 'id', ref: 'purchase' }, { key: 'finalUnitPrice', type: 'decimal' }, { key: 'skipCorrection', type: 'boolean' }]
const draft = { action: 'purchase.correctPrice', status: 'WAIT_CONFIRM', version: 1, ready: false, results: [] }
const source = () => [{ _rowId: 'matched', id: 10, finalUnitPrice: 88, _quotePreview: [{ line: 1, name: '水泵', unitPrice: 88, newAmount: 176 }] },
{ _rowId: 'missing', id: { keyword: '水冷一体管', spec: '白色带线1.5米' }, finalUnitPrice: 29.2, _sourceRow: 24, _sourceText: '原PDF第24项 4×29.2', _errors: ['采购明细未匹配'], _quotePreview: [{ line: 24, name: '水冷一体管', unitPrice: 29.2, newAmount: null, sourceText: '原PDF第24项 4×29.2', error: '采购明细未匹配' }] }]
const context = { draft, fields, editable: true }
test('skip is an explicit editable field on the original row; PDF rows, identity, price and other matches stay intact', () => {
const rows = source(), original = structuredClone(rows), preview = assistantQuotationReviewRows(rows, context)
const event = assistantQuotationSkipChange(preview[1])
assert.deepEqual(event, { rowId: 'missing', key: 'skipCorrection', value: true })
const changed = assistantApplyDraftChanges(rows, event, { action: draft.action, fields, draft })
assert.equal(changed.length, 2); assert.equal(changed[0], rows[0]); assert.equal(changed[1].skipCorrection, true)
for (const key of ['id', 'finalUnitPrice', '_sourceRow', '_sourceText', '_quotePreview']) assert.deepEqual(changed[1][key], original[1][key])
assert.deepEqual(rows, original)
assert.notEqual(assistantRowsSignature(changed), assistantRowsSignature(rows), 'the old ready/confirmation signature must become stale')
const selected = assistantQuotationReviewRows(changed, context)[1]
assert.deepEqual(assistantQuotationReviewState(selected), { skipped: true, pending: true, error: false, text: '已选择跳过,请重新校验预览' })
assert.equal(assistantQuotationSkipChange(selected).value, false)
})
test('previewed skips and restored rows are shown honestly; no skip is inferred from a lookup error', () => {
const missing = assistantQuotationReviewRows(source(), context)[1]
assert.equal(missing._skipSelected, false); assert.equal(assistantQuotationReviewState(missing).error, true)
assert.equal(assistantQuotationReviewState({ ...missing, skipped: true, _skipSelected: true }).text, '本次跳过,不修改采购')
assert.equal(assistantQuotationReviewState({ ...missing, skipped: true, _skipSelected: false }).text, '已恢复处理,请重新校验预览')
})
test('history, succeeded, unauthorized and missing-schema rows never expose skip edits', () => {
for (const options of [{ ...context, editable: false }, { ...context, fields: [] }, { ...context, fields: [{ key: 'skipCorrection', readonly: true }] },
{ ...context, draft: { ...draft, action: 'purchase.importQuote' } }, { ...context, draft: { ...draft, results: [{ rowId: 'missing', status: 'SUCCEEDED' }] } }]) {
const row = assistantQuotationReviewRows(source(), options)[1]
assert.equal(row._canSkip, false); assert.equal(assistantQuotationSkipChange(row), null)
}
})