Replace direct adapter/persistence imports with context-based injection (AdapterContext + useAdapters) so tests use in-memory implementations instead of vi.mock. Migrate component tests from context mocking to AllProviders with real hooks. Extract export/import logic from ActionBar into useEncounterExportImport hook. Add bestiary-cache and bestiary-index-adapter test suites. Raise adapter coverage thresholds (68→80 lines, 56→62 branches). 77 test files, 891 tests, all passing. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
39 lines
915 B
TypeScript
39 lines
915 B
TypeScript
import { createContext, type ReactNode, useContext } from "react";
|
|
import type {
|
|
BestiaryCachePort,
|
|
BestiaryIndexPort,
|
|
EncounterPersistence,
|
|
PlayerCharacterPersistence,
|
|
UndoRedoPersistence,
|
|
} from "../adapters/ports.js";
|
|
|
|
export interface Adapters {
|
|
encounterPersistence: EncounterPersistence;
|
|
undoRedoPersistence: UndoRedoPersistence;
|
|
playerCharacterPersistence: PlayerCharacterPersistence;
|
|
bestiaryCache: BestiaryCachePort;
|
|
bestiaryIndex: BestiaryIndexPort;
|
|
}
|
|
|
|
const AdapterContext = createContext<Adapters | null>(null);
|
|
|
|
export function AdapterProvider({
|
|
adapters,
|
|
children,
|
|
}: {
|
|
adapters: Adapters;
|
|
children: ReactNode;
|
|
}) {
|
|
return (
|
|
<AdapterContext.Provider value={adapters}>
|
|
{children}
|
|
</AdapterContext.Provider>
|
|
);
|
|
}
|
|
|
|
export function useAdapters(): Adapters {
|
|
const ctx = useContext(AdapterContext);
|
|
if (!ctx) throw new Error("useAdapters requires AdapterProvider");
|
|
return ctx;
|
|
}
|