Files
property-match/src/stores/__tests__/toastStore.test.ts
T
Benjamin Sutter 58a0a05eff test: integration coverage for stores, services, MockAIService, and hooks
- Stores (29 tests): compareStore max-4 enforcement, toastStore unique IDs,
  shortlistStore dialog state, assistantStore context merge + clearConversation
- Services (37 tests): needService CRUD, propertyService dashboard summary
  active-status filter, matchService computeMatchesForNeed + getStrongMatches,
  futureSignalService summary math (distribution totals, highConfidence count)
- MockAIService (18 tests): follow-up question priority ordering, area ambiguity
  detection (ratio >8 and zero values), max-3 cap, trade-off risk logic
  (LOW/MEDIUM/HIGH thresholds), match explanation headline tiers, provenance shape
- Hooks (20 tests): useNeeds/useProperties/useMatches envelope unwrap, disabled-
  when-empty guards, useCreateNeed/useCreateProperty mutations, useNeed/useMatchDetail

All 257 tests pass.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-24 16:55:02 +02:00

58 lines
2.0 KiB
TypeScript

import { describe, it, expect, beforeEach } from 'vitest'
import { useToastStore } from '../toastStore'
describe('toastStore', () => {
beforeEach(() => {
useToastStore.setState({ toasts: [] })
})
describe('showToast', () => {
it('adds a toast with message and default severity success', () => {
useToastStore.getState().showToast('Gespeichert')
const { toasts } = useToastStore.getState()
expect(toasts).toHaveLength(1)
expect(toasts[0].message).toBe('Gespeichert')
expect(toasts[0].severity).toBe('success')
expect(toasts[0].duration).toBe(4000)
})
it('accepts custom severity and duration', () => {
useToastStore.getState().showToast('Fehler', 'error', 8000)
const { toasts } = useToastStore.getState()
expect(toasts[0].severity).toBe('error')
expect(toasts[0].duration).toBe(8000)
})
it('assigns unique ids across multiple toasts', () => {
useToastStore.getState().showToast('A')
useToastStore.getState().showToast('B')
const ids = useToastStore.getState().toasts.map(t => t.id)
expect(new Set(ids).size).toBe(2)
})
it('stacks multiple toasts', () => {
useToastStore.getState().showToast('First')
useToastStore.getState().showToast('Second')
expect(useToastStore.getState().toasts).toHaveLength(2)
})
})
describe('dismissToast', () => {
it('removes the toast with the given id', () => {
useToastStore.getState().showToast('Keep')
useToastStore.getState().showToast('Remove')
const { toasts } = useToastStore.getState()
const idToRemove = toasts[1].id
useToastStore.getState().dismissToast(idToRemove)
expect(useToastStore.getState().toasts).toHaveLength(1)
expect(useToastStore.getState().toasts[0].message).toBe('Keep')
})
it('is a no-op for unknown id', () => {
useToastStore.getState().showToast('Keep')
useToastStore.getState().dismissToast('nonexistent-id')
expect(useToastStore.getState().toasts).toHaveLength(1)
})
})
})