Introduce adapter injection and migrate test suite
All checks were successful
CI / check (push) Successful in 2m13s
CI / build-image (push) Has been skipped

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>
This commit is contained in:
Lukas
2026-04-01 23:55:45 +02:00
parent 228c1c667f
commit 2c643cc98b
42 changed files with 1879 additions and 1190 deletions

View File

@@ -1,8 +1,5 @@
import { useCallback, useRef, useState } from "react";
import {
getAllSourceCodes,
getDefaultFetchUrl,
} from "../adapters/bestiary-index-adapter.js";
import { useAdapters } from "../contexts/adapter-context.js";
const BATCH_SIZE = 6;
@@ -32,6 +29,7 @@ interface BulkImportHook {
}
export function useBulkImport(): BulkImportHook {
const { bestiaryIndex } = useAdapters();
const [state, setState] = useState<BulkImportState>(IDLE_STATE);
const countersRef = useRef({ completed: 0, failed: 0 });
@@ -42,7 +40,7 @@ export function useBulkImport(): BulkImportHook {
isSourceCached: (sourceCode: string) => Promise<boolean>,
refreshCache: () => Promise<void>,
) => {
const allCodes = getAllSourceCodes();
const allCodes = bestiaryIndex.getAllSourceCodes();
const total = allCodes.length;
countersRef.current = { completed: 0, failed: 0 };
@@ -83,7 +81,7 @@ export function useBulkImport(): BulkImportHook {
chain.then(() =>
Promise.allSettled(
batch.map(async ({ code }) => {
const url = getDefaultFetchUrl(code, baseUrl);
const url = bestiaryIndex.getDefaultFetchUrl(code, baseUrl);
try {
await fetchAndCacheSource(code, url);
countersRef.current.completed++;
@@ -117,7 +115,7 @@ export function useBulkImport(): BulkImportHook {
});
})();
},
[],
[bestiaryIndex],
);
const reset = useCallback(() => {