* fix(tauri): prevent Windows font loading crashes - Return native font files over binary Tauri IPC instead of JSON byte arrays - Resolve desktop script fallbacks without parsing large system fonts in JavaScript * fix(core): restore quality checks - Use the shared Vector primitive for render-bound offsets - Remove unsupported SLICE handling from SceneGraph rescaling - Drop an unused generated-text test binding * chore: address font fix review - Place the release note under the Fixed heading - Name fallback resolution options and use the shared Tauri constant
56 lines
2 KiB
TypeScript
56 lines
2 KiB
TypeScript
import { afterEach, describe, expect, test, vi } from 'bun:test'
|
|
|
|
import { fontManager } from '@open-pencil/core/text'
|
|
|
|
import { clearTauriMocks, mockTauriIPC } from '#tests/helpers/tauri/mocks'
|
|
|
|
afterEach(async () => {
|
|
await clearTauriMocks()
|
|
vi.restoreAllMocks()
|
|
})
|
|
|
|
describe('Tauri font helpers', () => {
|
|
test('lists system font families through mocked Tauri IPC', async () => {
|
|
await mockTauriIPC((cmd) => {
|
|
expect(cmd).toBe('list_system_fonts')
|
|
return [{ family: 'System UI', styles: ['Regular', 'Bold'] }]
|
|
})
|
|
|
|
vi.spyOn(fontManager, 'listFamilyOptions').mockResolvedValue([])
|
|
const { listFamilies, listFonts } = await import('@/app/editor/fonts')
|
|
|
|
await expect(listFamilies()).resolves.toEqual([{ family: 'System UI', source: 'local' }])
|
|
await expect(listFonts()).resolves.toEqual([
|
|
{ family: 'System UI', styles: ['Regular', 'Bold'] }
|
|
])
|
|
})
|
|
|
|
test('loads system font bytes and registers the face', async () => {
|
|
await mockTauriIPC((cmd, args) => {
|
|
expect(cmd).toBe('load_system_font')
|
|
expect(args).toEqual({ family: 'System UI', style: 'Bold Italic' })
|
|
return new Uint8Array([1, 2, 3, 4]).buffer
|
|
})
|
|
|
|
const { loadFont } = await import('@/app/editor/fonts')
|
|
const buffer = await loadFont('System UI', 'Bold Italic')
|
|
|
|
expect([...new Uint8Array(buffer ?? new ArrayBuffer(0))]).toEqual([1, 2, 3, 4])
|
|
expect(fontManager.isLoaded('System UI', 'Bold Italic')).toBe(true)
|
|
})
|
|
|
|
test('falls back to font manager loading when the system font command fails', async () => {
|
|
await mockTauriIPC((cmd) => {
|
|
expect(cmd).toBe('load_system_font')
|
|
throw new Error('missing system font')
|
|
})
|
|
const fallback = new Uint8Array([9, 8, 7]).buffer
|
|
const loadFontSpy = vi.spyOn(fontManager, 'loadFont').mockResolvedValue(fallback)
|
|
|
|
const { loadFont } = await import('@/app/editor/fonts')
|
|
|
|
await expect(loadFont('Missing Family', 'Regular')).resolves.toBe(fallback)
|
|
expect(loadFontSpy).toHaveBeenCalledWith('Missing Family', 'Regular', '')
|
|
})
|
|
})
|