openpencil/tests/engine/app/shell/menu/file-batch.test.ts
Victor Wads 4e48420ac1
feat(app): open multiple files from the Open dialog (#552)
- Open multiple selected design files in separate tabs.\n- Support desktop, File System Access, and fallback pickers.\n- Continue opening later selections when one file fails.
2026-08-18 11:30:36 +03:00

42 lines
1.3 KiB
TypeScript

import { afterEach, describe, expect, mock, test } from 'bun:test'
import { openDesignFileBatch } from '@/app/shell/menu/files'
import { toast } from '@/app/shell/ui'
afterEach(() => {
toast.toasts.value = []
})
describe('openDesignFileBatch', () => {
test('opens selected files sequentially in selection order', async () => {
const opened: string[] = []
const openItem = mock(async (name: string) => {
opened.push(name)
})
await openDesignFileBatch(['first.fig', 'second.pen'], (name) => name, openItem)
expect(opened).toEqual(['first.fig', 'second.pen'])
expect(openItem).toHaveBeenCalledTimes(2)
})
test('reports one failed file and continues opening later selections', async () => {
const opened: string[] = []
const openItem = mock(async (name: string) => {
opened.push(name)
if (name === 'broken.fig') throw new Error('Invalid FIG container')
})
await expect(
openDesignFileBatch(['first.fig', 'broken.fig', 'last.pen'], (name) => name, openItem)
).resolves.toBeUndefined()
expect(opened).toEqual(['first.fig', 'broken.fig', 'last.pen'])
expect(toast.toasts.value).toHaveLength(1)
expect(toast.toasts.value[0]).toMatchObject({
message: 'Failed to open broken.fig: Invalid FIG container',
variant: 'error'
})
})
})