Vitest +14 cases on avatarInfo reducers

The three reducers that drive the InfoStand pilot
(applyUserBadgesUpdate / applyUserFigureUpdate /
applyFavouriteGroupUpdate, in src/hooks/rooms/widgets/avatarInfo.reducers.ts)
have been live for ~10 commits without coverage. They encode
non-trivial branches: 'state not AvatarInfoUser' bail-out,
'event for different user / roomIndex' bail-out, dedup-equality
bail-out, and the clearGroup logic (status === -1 || habboGroupId <= 0).
Add tests pinning every branch.

Two import-tightening tweaks made the reducer module itself
testable in jsdom without dragging the renderer SDK in:

- Renderer event types are now type-only imports — they're erased
  at compile time, so the runtime module load of @nitrots/nitro-renderer
  is skipped. The reducer body only reads plain event fields (no
  ) so this is safe.
- AvatarInfoUser / dedupeBadges / IAvatarInfo come from concrete file
  paths instead of '../../../api' (the barrel pulls in Pixi-bound
  modules via the renderer side-imports).

Tests cover each branch by constructing AvatarInfoUser via the
actual class (so the instanceof guard hits) and casting plain event
objects through  for the typed parameter.

Net Vitest count: 99 -> 113 (8 test files).
This commit is contained in:
simoleo89
2026-05-11 23:04:52 +02:00
parent 9f3cd9bd46
commit 3c732f1c1a
2 changed files with 215 additions and 2 deletions
@@ -1,5 +1,7 @@
import { RoomSessionFavoriteGroupUpdateEvent, RoomSessionUserBadgesEvent, RoomSessionUserFigureUpdateEvent } from '@nitrots/nitro-renderer';
import { AvatarInfoUser, dedupeBadges, IAvatarInfo } from '../../../api';
import type { RoomSessionFavoriteGroupUpdateEvent, RoomSessionUserBadgesEvent, RoomSessionUserFigureUpdateEvent } from '@nitrots/nitro-renderer';
import { dedupeBadges } from '../../../api/avatar/dedupeBadges';
import type { IAvatarInfo } from '../../../api/room/widgets/IAvatarInfo';
import { AvatarInfoUser } from '../../../api/room/widgets/AvatarInfoUser';
/**
* Pure reducers consumed by useAvatarInfoWidget to update the inspected