import { expect, it } from 'vitest' import { archiveItemEligibility, itemPresentationState, itemNextStep, pendingArchiveItems, nextPendingItem, reviewWaitDays } from '@/views/archive/archive-workflow' import { summary } from '@/views/archive/archive-model' const file = { id: 1, item_key: 'technical', title: '技术方案', required: 1, applicable: 1, state: 'MISSING', documents: [{ current_file_id: 'a' }] } it('uploaded legacy records are presented as maintenance while confirmation stays explicit', () => { expect(itemPresentationState(file)).toBe('PARTIAL') expect(file.state).toBe('MISSING') expect(itemNextStep(file)).toContain('待本人确认齐全') expect(itemNextStep({ ...file, state: 'DONE' })).toContain('项目是否归档请查看顶部归档状态') expect(itemPresentationState({ ...file, documents: [] })).toBe('MISSING') expect(itemPresentationState({ ...file, applicable: 0 })).toBe('NA') expect(archiveItemEligibility({ ...file, documents: [{ current_file_id: null }] }).allowed).toBe(false) expect(archiveItemEligibility({ ...file, expected_count: 2 }).reason).toContain('还需补充 1 份') }) it('cost completeness is separate from saving, unsaved edits and explicit confirmation', () => { const cost = { ...file, item_key: 'costAnalysis', documents: [] } expect(archiveItemEligibility(cost, {}).allowed).toBe(false) expect(archiveItemEligibility(cost, { data: {}, complete: false }).reason).toContain('补齐') expect(archiveItemEligibility(cost, { complete: true }, true).allowed).toBe(false) expect(archiveItemEligibility(cost, { complete: true }).allowed).toBe(true) expect(itemPresentationState(cost, { data: {}, complete: true })).toBe('PARTIAL') expect(itemPresentationState({ ...cost, has_cost_saved: 1 })).toBe('PARTIAL') expect(archiveItemEligibility({ ...cost, state: 'DONE' }, { complete: true }).allowed).toBe(false) }) it('next pending navigation prioritizes required issues, skips inapplicable items and never loops onto the same item', () => { const items = [{ ...file, id: 0, item_key: 'optional', required: 0 }, file, { ...file, id: 2, item_key: 'costAnalysis' }, { ...file, id: 3, item_key: 'na', applicable: 0 }] expect(pendingArchiveItems(items).map(item => item.item_key)).toEqual(['technical', 'costAnalysis', 'optional']) expect(nextPendingItem(items, '').item_key).toBe('technical') expect(nextPendingItem(items, 'technical').item_key).toBe('costAnalysis') expect(nextPendingItem([file], 'technical')).toBeNull() const totals = summary(items) expect(totals).toMatchObject({ required: 2, optional: 1, optionalDone: 0, na: 1 }) }) it('waiting days never invent a date or a negative wait', () => { const now = Date.parse('2026-10-23T00:00:00Z') expect(reviewWaitDays('2026-10-20T00:00:00Z', now)).toBe(3) expect(reviewWaitDays('2026-11-20T00:00:00Z', now)).toBe(0) expect(reviewWaitDays(null, now)).toBeNull() expect(reviewWaitDays('invalid', now)).toBeNull() })