test: expand coverage across all layers -- 1,268 new tests, fix replace-color div-by-zero

14-agent parallel test expansion covering integration, unit, E2E, E2E-Docker,
cross-format matrix, adversarial, GUI navigation/tools/settings/visual/a11y/perf.

- Integration: expand 23 tool test files with HEIC, stress, batch, edge cases
- Unit: close coverage gaps in image-engine, stores, lib (metadata, auto-enhance,
  connection-store, lazy-with-retry, collage/file-store HEIC preview)
- AI bridge: 141 new tests for dispatcher buffering, crash recovery, OOM/segfault
- Cross-format: 794 parameterized tests (16 formats x 12 tools + no-crash matrix)
- Adversarial: memory stress (50x large file), zero-byte, corrupted headers, unicode
- E2E-Docker: expand 8 spec files with dimension verification, pipeline chains
- GUI E2E: tool UI settings/interactions for all 47 tools, remove all test.skip,
  RBAC per-role verification, visual screenshot naming, cross-browser smoke tests,
  a11y ARIA/focus/contrast, performance budgets, 15-tool stability test
- Fix: replace-color.ts tolerance=0 caused division-by-zero producing NaN pixels

Total: 8,958 tests passing across 202 files. Zero failures, zero skips.
This commit is contained in:
SnapOtter
2026-05-09 18:02:58 +08:00
parent 7b1f09f5d0
commit a0556772e8
76 changed files with 13112 additions and 117 deletions
+90
View File
@@ -937,6 +937,23 @@ describe("useThemeStore", () => {
useThemeStore.getState().applyServerDefault("dark");
expect(localStorage.getItem("snapotter-theme-user-set")).toBeNull();
});
it("system theme resolves to dark when matchMedia prefers dark", () => {
const originalMatchMedia = globalThis.matchMedia;
vi.stubGlobal(
"matchMedia",
vi.fn().mockReturnValue({
matches: true,
addEventListener: vi.fn(),
removeEventListener: vi.fn(),
}),
);
useThemeStore.getState().setTheme("system");
const s = useThemeStore.getState();
expect(s.theme).toBe("system");
expect(s.resolvedTheme).toBe("dark");
vi.stubGlobal("matchMedia", originalMatchMedia);
});
});
// ==========================================================================
@@ -1512,6 +1529,79 @@ describe("useCollageStore", () => {
expect(s.phase).toBe("upload");
});
it("addImages triggers async preview loading for HEIC files", async () => {
// Override the mocked needsServerPreview to return true for this test
const imagePreview = await import("@/lib/image-preview");
const needsMock = vi.mocked(imagePreview.needsServerPreview);
const fetchPreviewMock = vi.mocked(imagePreview.fetchDecodedPreview);
needsMock.mockReturnValueOnce(true);
fetchPreviewMock.mockResolvedValueOnce("blob:preview-decoded");
const heicFile = new File(["heic-data"], "photo.heic", { type: "image/heic" });
useCollageStore.getState().addImages([heicFile]);
// The image should initially have previewLoading = true
expect(useCollageStore.getState().images[0].previewLoading).toBe(true);
// Wait for the async fetchDecodedPreview to complete
await vi.waitFor(() => {
const img = useCollageStore.getState().images[0];
expect(img.previewLoading).toBe(false);
});
// The preview blob URL should be set
expect(useCollageStore.getState().images[0].previewBlobUrl).toBe("blob:preview-decoded");
});
it("addImages preview callback handles image removed before resolve", async () => {
const imagePreview = await import("@/lib/image-preview");
const needsMock = vi.mocked(imagePreview.needsServerPreview);
const fetchPreviewMock = vi.mocked(imagePreview.fetchDecodedPreview);
needsMock.mockReturnValueOnce(true);
let resolvePreview!: (v: string | null) => void;
fetchPreviewMock.mockReturnValueOnce(
new Promise((resolve) => {
resolvePreview = resolve;
}),
);
const heicFile = new File(["data"], "gone.heic", { type: "image/heic" });
useCollageStore.getState().addImages([heicFile]);
// Remove the image before the preview resolves
useCollageStore.getState().removeImage(0);
// Now resolve the preview -- should not crash (idx === -1 path)
resolvePreview("blob:late-preview");
// Give the promise chain time to settle
await new Promise((r) => setTimeout(r, 10));
// Store should still be in reset state
expect(useCollageStore.getState().images).toEqual([]);
});
it("addImages preview callback handles null URL from fetchDecodedPreview", async () => {
const imagePreview = await import("@/lib/image-preview");
const needsMock = vi.mocked(imagePreview.needsServerPreview);
const fetchPreviewMock = vi.mocked(imagePreview.fetchDecodedPreview);
needsMock.mockReturnValueOnce(true);
fetchPreviewMock.mockResolvedValueOnce(null);
const heicFile = new File(["data"], "fail.heic", { type: "image/heic" });
useCollageStore.getState().addImages([heicFile]);
// Wait for the async preview to resolve with null
await vi.waitFor(() => {
const img = useCollageStore.getState().images[0];
expect(img.previewLoading).toBe(false);
});
// previewBlobUrl should NOT be set when URL is null
expect(useCollageStore.getState().images[0].previewBlobUrl).toBeUndefined();
});
it("clearImages revokes all blob URLs and resets to upload phase", () => {
const file1 = new File(["a"], "a.png", { type: "image/png" });
const file2 = new File(["b"], "b.png", { type: "image/png" });