cmvr-wms/ruoyi-ui-vue3/tests/runtime/supplier-inquiry-export.spec.js
lixiaolong 6b43b0104f feat(app): 优化移动端应用配置和功能实现
- 添加生产环境服务器地址配置支持内外网切换
- 实现采购列表只看我创建的功能开关
- 更新构建脚本中的默认生产环境API地址
- 优化采购单表格单元格编辑体验改用自动补全组件
- 调整应用更新检查逻辑增强生产环境兼容性
- 修复开发服务器切换时的一些验证问题
- 增强应用启动时的服务地址配置灵活性
2026-10-30 15:02:54 +08:00

39 lines
2.9 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 {afterEach,expect,it,vi} from 'vitest'
import {mount,flushPromises} from '@vue/test-utils'
import ElementPlus from 'element-plus'
import Quotation from '../../src/components/PurchaseSheet/SupplierQuotation.vue'
const api=vi.hoisted(()=>({request:vi.fn(),saveAs:vi.fn()}))
vi.mock('@/utils/request',()=>({default:api.request}))
vi.mock('file-saver',()=>({saveAs:api.saveAs}))
vi.mock('@/api/warehouse/purchase',()=>({previewSupplierQuotes:vi.fn()}))
vi.mock('@/utils/amount-display',()=>({amountDisplay:{enabled:false}}))
const mounted=[]
afterEach(()=>{mounted.splice(0).forEach(w=>w.unmount());vi.clearAllMocks();document.body.innerHTML=''})
function render(extra={}) {
const rows=[{id:1,productCode:'A',materialName:'垫片',quantity:2},{id:2,productCode:'A',materialName:'垫片',quantity:9}]
const w=mount(Quotation,{props:{sheet:{batch:{id:7,batchNo:'TEST'},version:'v1',rows},canExport:true,exportRows:[rows[0]],selectionActive:true,...extra},global:{plugins:[ElementPlus]}})
mounted.push(w);return w
}
const button=text=>[...document.querySelectorAll('button')].find(b=>b.textContent.trim()===text)
it('lets users uncheck quote unit price and posts only the selected saved row IDs',async()=>{
const w=render();w.vm.exportInquiry();await flushPromises()
expect(document.body.textContent).toContain('仅导出已勾选明细:1 条采购明细,按物品合并为 1 项')
const quote=[...document.querySelectorAll('.el-checkbox')].find(x=>x.textContent.trim()==='报价单价')
expect(quote.querySelector('input').disabled).toBe(false);quote.querySelector('input').click();await flushPromises()
api.request.mockRejectedValue(new Error('test response'))
button('导出询价单').click();await flushPromises()
expect(api.request).toHaveBeenCalledTimes(1)
const call=api.request.mock.calls[0][0];expect(call.data).toEqual({rowIds:[1]});expect(call.params.selectedColumns.split(',')).not.toContain('quoteUnitPrice');expect(call.params.version).toBe('v1')
})
it('captures the selection at dialog opening and never exports the full batch after selection changes',async()=>{
const w=render();w.vm.exportInquiry();await flushPromises();await w.setProps({exportRows:[{id:2,productCode:'A',quantity:9}]})
api.request.mockRejectedValue(new Error('test response'));button('导出询价单').click();await flushPromises()
expect(api.request.mock.calls[0][0].data.rowIds).toEqual([1])
})
it('does not export an empty selection or a stale sheet version',async()=>{
const w=render({exportRows:[]});w.vm.exportInquiry();await flushPromises();expect(api.request).not.toHaveBeenCalled();expect(button('导出询价单')).toBeUndefined()
await w.setProps({exportRows:[{id:1,productCode:'A',quantity:2}]});w.vm.exportInquiry();await flushPromises()
await w.setProps({sheet:{batch:{id:7},version:'v2',rows:[]}});button('导出询价单').click();await flushPromises();expect(api.request).not.toHaveBeenCalled()
})