docling-studio/frontend/src/features/feature-flags/useFeatureFlag.test.ts
Pier-Jean Malandrino 2e086cc4f3 Add feature flipping mechanism
Introduce a feature-flags module in the frontend that detects
the backend conversion engine via /health and exposes typed
feature flags. Chunking is enabled only in local engine mode.
2026-04-02 11:25:23 +02:00

28 lines
821 B
TypeScript

import { describe, it, expect, vi, beforeEach } from 'vitest'
import { setActivePinia, createPinia } from 'pinia'
import { useFeatureFlag } from './useFeatureFlag'
import { useFeatureFlagStore } from './store'
vi.mock('@/shared/api/http', () => ({ apiFetch: vi.fn() }))
describe('useFeatureFlag', () => {
beforeEach(() => {
setActivePinia(createPinia())
})
it('returns false before flags are loaded', () => {
const flag = useFeatureFlag('chunking')
expect(flag.value).toBe(false)
})
it('returns reactive value matching store state', () => {
const store = useFeatureFlagStore()
store.$patch({ loaded: true, engine: 'local' })
const flag = useFeatureFlag('chunking')
expect(flag.value).toBe(true)
store.$patch({ engine: 'remote' })
expect(flag.value).toBe(false)
})
})