test: add frontend composable tests and remaining test files

useNostr (9), useFightCache (5), useOnlineStatus (4) composable tests.
Added fake-indexeddb dev dependency for IDB tests.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Dorian
2026-03-13 00:08:01 +00:00
co-authored by Claude Opus 4.6
parent 806163c6c5
commit 1c296c6f1c
6 changed files with 471 additions and 0 deletions
+58
View File
@@ -0,0 +1,58 @@
import { describe, it, expect } from 'vitest'
import { fightEvents, type FightEvent } from './events.js'
describe('fightEvents', () => {
it('emits events to fight-specific listeners', () => {
const events: FightEvent[] = []
const unsub = fightEvents.on('fight-1', (e) => events.push(e))
fightEvents.emit({
fightId: 'fight-1',
type: 'test',
data: { msg: 'hello' },
timestamp: new Date().toISOString(),
})
expect(events).toHaveLength(1)
expect(events[0].data.msg).toBe('hello')
unsub()
})
it('cleanup removes all listeners for a fight', () => {
const events: FightEvent[] = []
fightEvents.on('fight-cleanup', (e) => events.push(e))
fightEvents.on('fight-cleanup', (e) => events.push(e))
fightEvents.cleanup('fight-cleanup')
fightEvents.emit({
fightId: 'fight-cleanup',
type: 'test',
data: {},
timestamp: new Date().toISOString(),
})
expect(events).toHaveLength(0)
})
it('global listeners receive all events', () => {
const events: FightEvent[] = []
const unsub = fightEvents.onAll((e) => events.push(e))
fightEvents.emit({
fightId: 'fight-global-1',
type: 'test',
data: {},
timestamp: new Date().toISOString(),
})
fightEvents.emit({
fightId: 'fight-global-2',
type: 'test',
data: {},
timestamp: new Date().toISOString(),
})
expect(events).toHaveLength(2)
unsub()
})
})