test: set up Vitest with 61 frontend tests
Add Vitest + testing-library/react + jsdom for frontend testing. Tests cover: cn() utility (6), usePermissions hook (27), useTreeValidation hook (22), and userPreferencesStore (6). CI updated to run frontend tests. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
45
frontend/src/store/userPreferencesStore.test.ts
Normal file
45
frontend/src/store/userPreferencesStore.test.ts
Normal file
@@ -0,0 +1,45 @@
|
||||
import { describe, it, expect, beforeEach } from 'vitest'
|
||||
import { useUserPreferencesStore } from './userPreferencesStore'
|
||||
|
||||
describe('userPreferencesStore', () => {
|
||||
beforeEach(() => {
|
||||
// Reset store to defaults
|
||||
useUserPreferencesStore.setState({
|
||||
defaultExportFormat: 'markdown',
|
||||
treeLibraryView: 'grid',
|
||||
treeLibrarySortBy: 'usage_count',
|
||||
})
|
||||
})
|
||||
|
||||
it('has correct defaults', () => {
|
||||
const state = useUserPreferencesStore.getState()
|
||||
expect(state.defaultExportFormat).toBe('markdown')
|
||||
expect(state.treeLibraryView).toBe('grid')
|
||||
expect(state.treeLibrarySortBy).toBe('usage_count')
|
||||
})
|
||||
|
||||
it('sets export format', () => {
|
||||
useUserPreferencesStore.getState().setDefaultExportFormat('html')
|
||||
expect(useUserPreferencesStore.getState().defaultExportFormat).toBe('html')
|
||||
})
|
||||
|
||||
it('sets tree library view', () => {
|
||||
useUserPreferencesStore.getState().setTreeLibraryView('list')
|
||||
expect(useUserPreferencesStore.getState().treeLibraryView).toBe('list')
|
||||
})
|
||||
|
||||
it('sets tree library view to table', () => {
|
||||
useUserPreferencesStore.getState().setTreeLibraryView('table')
|
||||
expect(useUserPreferencesStore.getState().treeLibraryView).toBe('table')
|
||||
})
|
||||
|
||||
it('sets sort by', () => {
|
||||
useUserPreferencesStore.getState().setTreeLibrarySortBy('name')
|
||||
expect(useUserPreferencesStore.getState().treeLibrarySortBy).toBe('name')
|
||||
})
|
||||
|
||||
it('sets sort by to created_at', () => {
|
||||
useUserPreferencesStore.getState().setTreeLibrarySortBy('created_at')
|
||||
expect(useUserPreferencesStore.getState().treeLibrarySortBy).toBe('created_at')
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user