import { describe, it, expect } from 'vitest' import { nextTick } from 'vue' import { useApproval } from '@/composables/useApproval' describe('useApproval', () => { it('initial state is reset', () => { const approval = useApproval() expect(approval.form.action).toBe('pass') expect(approval.form.comment).toBe('') expect(approval.submitting.value).toBe(false) expect(approval.batchMode.value).toBe(false) expect(approval.nextNodes.value).toEqual([]) }) it('buildActionData includes targetNodeId and attachmentUrls', async () => { const approval = useApproval() approval.form.action = 'pass' approval.form.comment = '同意' approval.form.targetNodeId = 'node_2' approval.attachmentList.value = [ { response: '/uploads/a.pdf' }, { url: '/uploads/b.pdf' } ] await nextTick() const data = approval.buildActionData() expect(data.action).toBe('pass') expect(data.comment).toBe('同意') expect(data.targetNodeId).toBe('node_2') expect(data.attachmentUrls).toContain('/uploads/a.pdf') expect(data.attachmentUrls).toContain('/uploads/b.pdf') }) it('reset clears form and attachments', () => { const approval = useApproval() approval.form.action = 'reject' approval.form.comment = '拒绝' approval.attachmentList.value = [{ response: '/uploads/a.pdf' }] approval.reset() expect(approval.form.action).toBe('pass') expect(approval.form.comment).toBe('') expect(approval.attachmentList.value).toHaveLength(0) }) })