refactor(characters): drive shared UI from active character

This commit is contained in:
2026-07-17 19:33:59 +08:00
parent 8bb1e21886
commit 7bd5defa5e
42 changed files with 335 additions and 118 deletions
@@ -2,7 +2,9 @@ import { act, type Dispatch } from "react";
import { createRoot, type Root } from "react-dom/client";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import { getCharacterBySlug } from "@/data/constants/character";
import type { LoginStatus } from "@/data/schemas/auth";
import { CharacterProvider } from "@/providers/character-provider";
import { getCharacterRoutes } from "@/router/routes";
import type { PrivateRoomEvent } from "@/stores/private-room";
import type { PrivateRoomUnlockPaywallRequest } from "@/stores/private-room/private-room-state";
@@ -80,7 +82,7 @@ describe("Private Room paywall navigation", () => {
renderHarness(root, "guest", roomDispatch);
expect(mocks.openAuth).toHaveBeenCalledWith(
getCharacterRoutes("elio").privateRoom,
getCharacterRoutes("maya").privateRoom,
);
expect(mocks.openSubscription).not.toHaveBeenCalled();
});
@@ -91,9 +93,13 @@ function renderHarness(
loginStatus: LoginStatus,
roomDispatch: Dispatch<PrivateRoomEvent>,
): void {
const character = getCharacterBySlug("maya");
if (!character) throw new Error("Missing Maya character fixture");
act(() => {
root.render(
<Harness loginStatus={loginStatus} roomDispatch={roomDispatch} />,
<CharacterProvider character={character}>
<Harness loginStatus={loginStatus} roomDispatch={roomDispatch} />
</CharacterProvider>,
);
});
}