import { describe, it, expect, afterEach } from 'vitest'
import { get } from 'svelte/store'
import { navContext } from './navContext.js'

describe('navContext', () => {
  afterEach(() => {
    navContext.set(null)
  })

  it('is a writable store with initial value null', () => {
    expect(get(navContext)).toBe(null)
  })

  it('updates when set is called', () => {
    navContext.set('my-decks')
    expect(get(navContext)).toBe('my-decks')
    navContext.set('community')
    expect(get(navContext)).toBe('community')
    navContext.set(null)
    expect(get(navContext)).toBe(null)
  })

  it('updates when update is called', () => {
    navContext.set('community')
    navContext.update((v) => (v === 'community' ? 'my-decks' : v))
    expect(get(navContext)).toBe('my-decks')
    navContext.set(null)
  })
})
