import { describe, expect, it } from 'vitest' import { sortTransferTasks } from '../../../src/components/sftp/TransferPanel' import type { TransferTask } from '../../../shared/types/sftp.types' function task( id: string, status: TransferTask['status'] ): TransferTask { return { id, type: 'upload', fileName: id, filePath: `/${id}`, status, progress: status === 'transferring' ? 40 : 0, total: 100, transferred: status === 'transferring' ? 40 : 0, } } describe('sortTransferTasks', () => { it('puts transferring tasks first, then pending, then finished', () => { const ordered = sortTransferTasks([ task('done', 'completed'), task('wait', 'pending'), task('active', 'transferring'), task('fail', 'failed'), task('wait2', 'pending'), ]) expect(ordered.map((t) => t.id)).toEqual(['active', 'wait', 'wait2', 'fail', 'done']) }) it('keeps relative order within the same status', () => { const ordered = sortTransferTasks([ task('a', 'pending'), task('b', 'pending'), task('c', 'pending'), ]) expect(ordered.map((t) => t.id)).toEqual(['a', 'b', 'c']) }) })