import {afterEach,expect,it,vi} from 'vitest' import {shallowMount} from '@vue/test-utils' import {readFileSync} from 'node:fs' import {resolve} from 'node:path' import {parse} from '@vue/compiler-sfc' import Borrow from '../../src/components/ProjectLoans/BatchBorrow.vue' import Receipt from '../../src/components/ReceiptDialog/Batch.vue' vi.mock('@/utils/request',()=>({default:vi.fn()})) vi.mock('@/utils/use-compact-layout',()=>({useCompactLayout:()=>({compact:false})})) const mounted=[] afterEach(()=>{for(const w of mounted.splice(0))w.unmount()}) const globals={stubs:{ElDialog:{template:'
'},ElTable:{template:'
'},ElTableColumn:true,ElForm:{template:'
'},ElFormItem:{template:'
'},ElButton:{props:['disabled'],template:''},DialogWorkspace:{template:'
'}}} function render(component,data){const w=shallowMount(component,{data:()=>({visible:true,...data}),global:globals});mounted.push(w);return w} it('borrow review separates basic information from all shortcuts and preserves amount and area edits',async()=>{ const rows=[{key:'a',stockNum:8,quantity:1,toAreaId:2},{key:'b',stockNum:6,quantity:1,toAreaId:2}] const w=render(Borrow,{stage:'review',rows,uniformArea:3,areas:[{id:3,areaName:'新库区'}]}) expect(w.find('.batch-dialog-form').attributes('label-position')).toBe('top') expect(w.find('.batch-dialog-form').findAll('button')).toHaveLength(0) expect(w.find('.batch-dialog-toolbar__actions').text()).toContain('应用库区') const buttons=w.findAll('button');await buttons.find(b=>b.text()==='应用库区').trigger('click');expect(w.vm.rows.map(r=>r.toAreaId)).toEqual([3,3]) await buttons.find(b=>b.text()==='按可用数量填写').trigger('click');expect(w.vm.rows.map(r=>r.quantity)).toEqual([8,6]) expect(w.emitted('changed')).toBeUndefined();expect(w.vm.workspaceHeight).toContain('318px') await w.setData({rows:[...w.vm.rows,{key:'c',stockNum:9,quantity:1,payload:{key:'frozen'}}]}) expect(w.findAll('button').some(b=>b.text()==='按可用数量填写')).toBe(false) }) it('receipt shortcuts stay outside the form and keep selection and acceptance rules',async()=>{ const w=render(Receipt,{mode:'arrival',rows:[{id:1,chosen:true,maximum:8,quantity:0},{id:2,chosen:false,maximum:6,quantity:0},{id:3,chosen:true,maximum:3,quantity:2,arrivalIdCreated:33}]}) expect(w.find('.batch-dialog-form').attributes('label-position')).toBe('top');expect(w.find('.batch-dialog-form').findAll('button')).toHaveLength(0) await w.findAll('button').find(b=>b.text()==='本次全部到齐').trigger('click');expect(w.vm.rows.map(r=>r.quantity)).toEqual([8,0,2]) expect(w.emitted('changed')).toBeUndefined();await w.setData({mode:'acceptance'});expect(w.findAll('button').some(b=>b.text()==='本次全部到齐')).toBe(false) }) it('all updated batch dialogs opt into shared styles without altering submission controls',()=>{ for(const file of ['ProjectLoans/BatchBorrow.vue','ProjectLoans/BatchReturn.vue','ReceiptDialog/Batch.vue','ReceiptDialog/PurchaseBulkEdit.vue','Production/BatchActions.vue']){ const source=readFileSync(resolve(process.cwd(),'src/components',file),'utf8'),sfc=parse(source) expect(sfc.errors).toHaveLength(0);expect(source).toContain('class="batch-dialog');expect(source).toContain('batch-dialog-form');expect(source).toContain('label-position="top"');expect(source).toContain(':loading="saving"');expect(source).toContain(':disabled="saving'); } })