openpencil/tests/engine/app/shell/menu/file-batch.test.ts
Danila Poyarkov 211a4ea99c
fix(i18n): localize app notifications (#557)
- Add app-owned notification translations for every supported locale.\n- Localize common file, clipboard, collaboration, chat, vectorization, storage, recovery, and library toasts.\n- Preserve actionable runtime details inside localized messages.
2026-08-18 18:52:19 +03:00

46 lines
1.4 KiB
TypeScript

import { afterEach, describe, expect, mock, test } from 'bun:test'
import { localeSetting } from '@open-pencil/vue'
import { openDesignFileBatch } from '@/app/shell/menu/files'
import { toast } from '@/app/shell/ui'
afterEach(() => {
toast.toasts.value = []
localeSetting.set(undefined)
})
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 () => {
localeSetting.set('en')
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: 'Could not open “broken.fig”: Invalid FIG container',
variant: 'error'
})
})
})