peregrine/web/src/stores/settings/search.test.ts
pyr0ball 8bd1be7b16 feat(web): merge Vue SPA from feature/vue-spa; add ClassicUIButton + useFeatureFlag
- Import web/ directory (Vue 3 + Vite + UnoCSS SPA) from feature/vue-spa branch
- Add web/src/components/ClassicUIButton.vue: switch-back to Streamlit via
  cookie (prgn_ui=streamlit) + ?prgn_switch=streamlit query param bridge
- Add web/src/composables/useFeatureFlag.ts: reads prgn_demo_tier cookie for
  demo toolbar visual consistency (not an authoritative gate, see issue #8)
- Update .gitignore: add .superpowers/, pytest-output.txt, docs/superpowers/
2026-03-22 18:46:11 -07:00

42 lines
1.7 KiB
TypeScript

import { describe, it, expect, vi, beforeEach } from 'vitest'
import { setActivePinia, createPinia } from 'pinia'
import { useSearchStore } from './search'
vi.mock('../../composables/useApi', () => ({ useApiFetch: vi.fn() }))
import { useApiFetch } from '../../composables/useApi'
const mockFetch = vi.mocked(useApiFetch)
describe('useSearchStore', () => {
beforeEach(() => { setActivePinia(createPinia()); vi.clearAllMocks() })
it('defaults remote_preference to both', () => {
expect(useSearchStore().remote_preference).toBe('both')
})
it('load() sets fields from API', async () => {
mockFetch.mockResolvedValue({ data: {
remote_preference: 'remote', job_titles: ['Engineer'], locations: ['NYC'],
exclude_keywords: [], job_boards: [], custom_board_urls: [],
blocklist_companies: [], blocklist_industries: [], blocklist_locations: [],
}, error: null })
const store = useSearchStore()
await store.load()
expect(store.remote_preference).toBe('remote')
expect(store.job_titles).toContain('Engineer')
})
it('suggest() adds to titleSuggestions without persisting', async () => {
mockFetch.mockResolvedValue({ data: { suggestions: ['Staff Engineer'] }, error: null })
const store = useSearchStore()
await store.suggestTitles()
expect(store.titleSuggestions).toContain('Staff Engineer')
expect(store.job_titles).not.toContain('Staff Engineer')
})
it('save() calls PUT endpoint', async () => {
mockFetch.mockResolvedValue({ data: { ok: true }, error: null })
const store = useSearchStore()
await store.save()
expect(mockFetch).toHaveBeenCalledWith('/api/settings/search', expect.objectContaining({ method: 'PUT' }))
})
})