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')
  })
})
