cmvr-wms/ruoyi-ui-vue3/tests/unit/purchase-sheet-identity.test.mjs
lixiaolong a82258561b feat(auth): 添加认证cookie名称配置并优化表单布局
- 在 .env.production 中新增 VITE_AUTH_COOKIE_NAME 配置项用于设置认证cookie名称
- 将 AcceptanceException.vue 中的表单标签宽度从固定90px改为自动适配
- 在 ActionDialog.vue 中将多个表单项标记为必填项并调整标签宽度为自动适配
- 重构 ActionHistory.vue 中的按钮布局结构并添加表格列样式类名
- 更新 api-contract-audit.cjs 添加生产任务和BOM相关接口的契约测试
- 修改 auth.js 使用动态认证cookie键名替换硬编码的Admin-Token
- 调整系统角色授权用户页面的表单布局和表格样式类名
- 优化 ReceiptDialog Batch 组件的对话框尺寸、表单验证和分页功能
2026-10-16 15:30:10 +08:00

122 lines
5.0 KiB
JavaScript

import test from 'node:test'
import assert from 'node:assert/strict'
import { createRowIdentityEditor, pasteRectangle } from '../../src/utils/purchase-sheet.js'
const item = { id: 9, productCode: 'WP9', productName: '电机', brand: 'A', spec: 'M4', unit: '个', category: '机械件' }
function fixture(items = []) {
const pending = [], rows = new Set()
const editor = createRowIdentityEditor({
getItems: () => items,
loadName: name => new Promise(resolve => pending.push({ name, resolve })),
isCurrentRow: row => rows.has(row),
onDetach: row => { row.loanId = null }
})
return { editor, pending, rows, items }
}
function draft() {
return { materialName: '新物品', materialParams: '已填型号', materialBrand: '', quantity: 3, unit: '件', category: '设备', finalUnitPrice: '12.345678', purchaseLink: 'https://example.com/item', projectId: 1, expenseCategoryId: 2, remark: '保留说明' }
}
test('entering or clearing a new item brand preserves the specification, quote and all other draft fields', () => {
const { editor } = fixture(), row = draft(), before = { ...row }
row.materialBrand = '新品牌'
editor.brandChanged(row)
assert.deepEqual(row, { ...before, materialBrand: '新品牌', productId: null, productCode: null, loanId: null })
row.materialBrand = ''
editor.brandChanged(row)
assert.equal(row.materialParams, before.materialParams)
assert.equal(row.finalUnitPrice, before.finalUnitPrice)
editor.specChanged(row, '新型号')
assert.equal(row.materialBrand, '')
assert.equal(row.purchaseLink, before.purchaseLink)
assert.equal(row.unit, before.unit)
assert.equal(row.category, before.category)
})
test('free text only links a complete exact identity; a sole existing variant cannot replace a typed model', () => {
const { editor } = fixture([item]), row = { ...draft(), materialName: '电机', materialBrand: 'A' }
editor.brandChanged(row)
assert.equal(row.productId, null)
assert.equal(row.materialParams, '已填型号')
editor.specChanged(row, 'M4')
assert.equal(row.productId, null)
assert.equal(row.finalUnitPrice, '12.345678')
assert.equal(row.unit, '件')
assert.equal(row.category, '设备')
row.unit = '个'
row.category = '机械件'
editor.brandChanged(row)
assert.equal(row.productId, item.id)
})
test('an explicit archive option replaces archive fields while keeping the entered quote and purchase details', async () => {
const { editor } = fixture([item]), row = draft()
await editor.nameChanged(row, '@item:9')
assert.equal(row.productId, 9)
assert.equal(row.materialParams, 'M4')
assert.equal(row.unit, '个')
assert.equal(row.finalUnitPrice, '12.345678')
assert.equal(row.projectId, 1)
assert.equal(row.purchaseLink, 'https://example.com/item')
assert.equal(row.quantity, 3)
})
test('a delayed name match cannot overwrite a brand, specification or quote entered while loading', async () => {
const f = fixture(), row = draft()
f.rows.add(row)
const response = f.editor.nameChanged(row, '电机')
row.materialBrand = '自定义品牌'
f.editor.brandChanged(row)
f.editor.specChanged(row, '自定义型号')
row.finalUnitPrice = 0
f.items.push(item)
f.pending[0].resolve()
await response
assert.equal(row.materialBrand, '自定义品牌')
assert.equal(row.materialParams, '自定义型号')
assert.equal(row.finalUnitPrice, 0)
assert.equal(row.productId, null)
})
test('out of order A to B to A name responses and a removed row never apply stale matches', async () => {
const f = fixture(), row = { materialBrand: 'A', materialParams: 'M4' }
f.rows.add(row)
const first = f.editor.nameChanged(row, '电机')
const second = f.editor.nameChanged(row, '控制器')
const latest = f.editor.nameChanged(row, '电机')
f.items.push(item)
f.pending[0].resolve()
await first
assert.equal(row.productId, null)
f.pending[1].resolve()
await second
assert.equal(row.productId, null)
f.rows.delete(row)
f.pending[2].resolve()
await latest
assert.equal(row.productId, null)
})
test('an unchanged delayed exact match fills only missing archive metadata and preserves zero quote', async () => {
const f = fixture(), row = { materialBrand: 'A', materialParams: 'M4', finalUnitPrice: 0, quantity: 2 }
f.rows.add(row)
const result = f.editor.nameChanged(row, '电机')
f.items.push(item)
f.pending[0].resolve()
await result
assert.equal(row.productId, 9)
assert.equal(row.unit, '个')
assert.equal(row.category, '机械件')
assert.equal(row.finalUnitPrice, 0)
assert.equal(row.quantity, 2)
})
test('pasting an identity into a draft preserves its quote and purchase link', () => {
const row = { ...draft(), _key: 'one' }
const result = pasteRectangle([row], '品牌A\t型号B', 0, 0, ['materialBrand', 'materialParams'], { readonly: () => false, items: [], units: ['件'] })
assert.equal(result[0].materialParams, '型号B')
assert.equal(result[0].finalUnitPrice, row.finalUnitPrice)
assert.equal(result[0].purchaseLink, row.purchaseLink)
assert.equal(row.materialBrand, '')
})