cmvr-wms/ruoyi-ui-vue3/tests/runtime/purchase-amount-order.spec.js
lixiaolong cd86623061 feat(app): 添加服务器连接管理和到货操作功能
- 集成 ServerConnection 组件用于开发环境服务器切换
- 实现多服务器令牌隔离存储机制
- 添加 ArrivalOperation 屏幕处理到货和验收流程
- 支持待登记到货和待验收状态切换
- 优化库存操作界面的字段显示逻辑
- 增强 Excel 文件分片上传支持产品文件识别
- 添加 AI 助手会话滚动跟踪功能
- 实现开发服务器地址持久化存储
- 优化登录界面集成服务器连接组件
- 添加领用出库功能支持项目物资使用
- 改进盘点确认生效的操作流程
- 增强采购到货登记和验收的权限控制
- 优化移动端文件上传的断点续传机制
- 添加服务器切换时的数据清理保护机制
- 实现紧凑金额显示模式减少界面冗余
- 增强库存操作的数量验证和错误提示
- 优化 AI 助手的会话状态同步机制
2026-10-20 10:04:17 +08:00

46 lines
3.6 KiB
JavaScript

import {expect,it,vi} from 'vitest'
import {readFileSync} from 'node:fs'
import {parse} from '@vue/compiler-sfc'
import {baseParse} from '@vue/compiler-dom'
import {defineComponent,nextTick} from 'vue'
import {mount,flushPromises} from '@vue/test-utils'
import ElementPlus from 'element-plus'
import Sheet from '../../src/components/PurchaseSheet/index.vue'
vi.mock('@/utils/request',()=>({default:vi.fn()}))
vi.mock('@/store/modules/user',()=>({default:()=>({permissions:['*:*:*']})}))
vi.mock('@/store/modules/app',()=>({default:()=>({size:'default'})}))
it('real purchase columns, batch totals and footer keep actual amounts before quotes across display toggles',async()=>{
const template=parse(readFileSync('src/components/PurchaseSheet/index.vue','utf8')).descriptor.template.content
let grid,footer;const totals=[]
function visit(node){
if(node.tag==='template'&&node.props.some(p=>p.name==='for'&&p.exp?.content==='column in columns'))grid=node
if(node.tag==='div'&&node.props.some(p=>p.name==='class'&&p.value?.content==='sheet-footer'))footer=node.children.find(c=>c.type===1)
if(node.tag==='el-table-column'&&node.props.some(p=>p.name==='label'&&['实际总金额','报价合计'].includes(p.value?.content)))totals.push(node)
for(const child of node.children||[])visit(child)
}
visit(baseParse(template));expect(grid).toBeTruthy();expect(footer).toBeTruthy();expect(totals).toHaveLength(2)
const extract=node=>template.slice(node.loc.start.offset,node.loc.end.offset)
const host=defineComponent({template:`<div><el-table class="detail" :data="sheet.rows">${extract(grid)}</el-table><el-table class="batches" :data="sheet.rows">${totals.map(extract).join('')}</el-table><section class="summary">${extract(footer)}</section></div>`,
data:()=>({compactAmounts:false,extras:false,batchProject:{mixed:false},sheet:{rows:[{_key:'r',quantity:2,unit:'个',actualUnitPrice:3,finalUnitPrice:5,actualTotalAmount:6,totalAmount:10}]},cellOwner:{},editCell:null}),
computed:{columns(){return Sheet.computed.columns.call(this)},visibleRows(){return this.sheet.rows},actualTotal:()=>6,amount:()=>10,unpriced:()=>0},
methods:{selectColumn(){},originalIndex:()=>0,actualAmount:row=>row.quantity*row.actualUnitPrice,hasPrice:()=>true,money:value=>Number(value).toFixed(2)}})
const wrapper=mount(host,{global:{plugins:[ElementPlus],stubs:{PurchaseCell:true,BusinessIcon:true}}})
const headers=()=>wrapper.findAll('.detail thead th').map(h=>h.text())
const expected=['实际单价','实际金额','报价单价','报价金额']
await flushPromises();await nextTick()
expect(headers().filter(h=>expected.includes(h))).toEqual(expected)
for(const header of wrapper.findAll('.detail thead th').filter(h=>expected.includes(h.text())))expect(header.classes()).toContain('is-right')
expect(wrapper.findAll('.batches thead th').map(h=>h.text())).toEqual(['实际总金额','报价合计'])
expect(wrapper.get('.summary').text()).toMatch(/实际总金额 ¥ 6\.00.*报价总金额 ¥ 10\.00/)
expect(wrapper.get('.detail tbody').text()).toContain('6.00')
expect(wrapper.get('.detail tbody').text()).toContain('10.00')
await wrapper.setData({compactAmounts:true});await flushPromises();await nextTick()
expect(headers().filter(h=>expected.includes(h))).toEqual(['报价单价','报价金额'])
expect(wrapper.findAll('.batches thead th').map(h=>h.text())).toEqual(['报价合计'])
expect(wrapper.get('.summary').text()).not.toContain('实际总金额')
await wrapper.setData({compactAmounts:false});await flushPromises();await nextTick()
expect(headers().filter(h=>expected.includes(h))).toEqual(expected)
wrapper.unmount()
})