mirror of
https://github.com/snapotter-hq/SnapOtter.git
synced 2026-08-03 07:46:42 +02:00
test: expand API and GUI test coverage across all tools
Add ~500 new E2E tests and ~300 new integration tests covering: - 24 new GUI E2E specs: navigation, responsive layout, keyboard shortcuts, tool UI for all 35 non-AI tools, batch/pipeline workflows, settings/RBAC, visual regression, accessibility, and performance budgets - 3 new E2E-Docker specs: batch workflows, advanced pipelines, cross-format - 1 new adversarial integration test: memory pressure, corrupted files, unicode filenames, extreme dimensions, pipeline/batch edge cases - 29 expanded integration test files: HEIC/HEIF input, large files, parameter boundaries, batch processing, format edge cases across all tools - Cross-format matrix expanded: 641 tests covering every tool x 18 formats - AI bridge unit tests expanded: lifecycle, tool modules, error propagation - Unit test gaps filled: analytics, tool-registry, web stores Also fixes: - vitest.config.ts: exclude e2e-docs and e2e-landing from Vitest runner - AI E2E specs: add sidecar health check to skip gracefully when Python AI backend is not running instead of timing out
This commit is contained in:
@@ -35,8 +35,9 @@ vi.mock("posthog-js", () => ({
|
||||
},
|
||||
}));
|
||||
|
||||
const mockSentryInit = vi.fn();
|
||||
vi.mock("@sentry/react", () => ({
|
||||
init: vi.fn(),
|
||||
init: mockSentryInit,
|
||||
}));
|
||||
|
||||
const noop = () => {};
|
||||
@@ -202,4 +203,199 @@ describe("analytics lib", () => {
|
||||
expect(callsWithConsent).toBeGreaterThanOrEqual(callsWithoutConsent);
|
||||
});
|
||||
});
|
||||
|
||||
describe("error resilience", () => {
|
||||
it("track swallows exception from posthog.capture", () => {
|
||||
setAnalyticsConsent(true);
|
||||
mockCapture.mockImplementationOnce(() => {
|
||||
throw new Error("capture boom");
|
||||
});
|
||||
expect(() => track("should_not_throw")).not.toThrow();
|
||||
});
|
||||
|
||||
it("identify swallows exception from posthog.identify", () => {
|
||||
setAnalyticsConsent(true);
|
||||
mockIdentify.mockImplementationOnce(() => {
|
||||
throw new Error("identify boom");
|
||||
});
|
||||
expect(() => identify("inst-x", { foo: "bar" })).not.toThrow();
|
||||
});
|
||||
|
||||
it("startErrorReplay swallows exception from posthog.startSessionRecording", () => {
|
||||
setAnalyticsConsent(true);
|
||||
mockStartSessionRecording.mockImplementationOnce(() => {
|
||||
throw new Error("replay boom");
|
||||
});
|
||||
expect(() => startErrorReplay()).not.toThrow();
|
||||
});
|
||||
});
|
||||
|
||||
describe("consent gating prevents calls", () => {
|
||||
it("track does not call capture when consent is false", () => {
|
||||
mockCapture.mockClear();
|
||||
setAnalyticsConsent(false);
|
||||
track("blocked_event");
|
||||
expect(mockCapture).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("identify does not call identify when consent is false", () => {
|
||||
mockIdentify.mockClear();
|
||||
setAnalyticsConsent(false);
|
||||
identify("blocked-id", {});
|
||||
expect(mockIdentify).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("startErrorReplay does not call startSessionRecording when consent is false", () => {
|
||||
mockStartSessionRecording.mockClear();
|
||||
setAnalyticsConsent(false);
|
||||
startErrorReplay();
|
||||
expect(mockStartSessionRecording).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe("Sentry beforeSend callback", () => {
|
||||
function getBeforeSend() {
|
||||
const sentryCall = mockSentryInit.mock.calls.find((call: unknown[]) => call[0]?.beforeSend);
|
||||
return sentryCall ? sentryCall[0].beforeSend : null;
|
||||
}
|
||||
|
||||
it("scrubs file extensions from exception values", () => {
|
||||
const beforeSend = getBeforeSend();
|
||||
if (!beforeSend) return;
|
||||
|
||||
setAnalyticsConsent(true);
|
||||
const event = {
|
||||
user: { email: "test@example.com", username: "user1" },
|
||||
exception: {
|
||||
values: [
|
||||
{
|
||||
value: "Failed to load /tmp/workspace/image.jpg",
|
||||
stacktrace: {
|
||||
frames: [
|
||||
{
|
||||
filename: "/Users/test/project/file.png",
|
||||
abs_path: "/home/user/data/files/photo.jpeg",
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
|
||||
const result = beforeSend(event);
|
||||
expect(result.user.email).toBeUndefined();
|
||||
expect(result.user.username).toBeUndefined();
|
||||
expect(result.exception.values[0].value).toContain("[REDACTED]");
|
||||
expect(result.exception.values[0].stacktrace.frames[0].filename).toContain("[REDACTED]");
|
||||
expect(result.exception.values[0].stacktrace.frames[0].abs_path).toContain("[REDACTED]");
|
||||
});
|
||||
|
||||
it("returns null when consent is not granted", () => {
|
||||
const beforeSend = getBeforeSend();
|
||||
if (!beforeSend) return;
|
||||
|
||||
setAnalyticsConsent(false);
|
||||
const result = beforeSend({ exception: { values: [] } });
|
||||
expect(result).toBeNull();
|
||||
});
|
||||
|
||||
it("handles event without user or exception fields", () => {
|
||||
const beforeSend = getBeforeSend();
|
||||
if (!beforeSend) return;
|
||||
|
||||
setAnalyticsConsent(true);
|
||||
const result = beforeSend({});
|
||||
expect(result).toBeDefined();
|
||||
});
|
||||
|
||||
it("handles exception values without stacktrace", () => {
|
||||
const beforeSend = getBeforeSend();
|
||||
if (!beforeSend) return;
|
||||
|
||||
setAnalyticsConsent(true);
|
||||
const event = {
|
||||
exception: { values: [{ value: "plain error" }] },
|
||||
};
|
||||
const result = beforeSend(event);
|
||||
expect(result).toBeDefined();
|
||||
expect(result.exception.values[0].value).toBe("plain error");
|
||||
});
|
||||
});
|
||||
|
||||
describe("Sentry beforeBreadcrumb callback", () => {
|
||||
function getBeforeBreadcrumb() {
|
||||
const sentryCall = mockSentryInit.mock.calls.find(
|
||||
(call: unknown[]) => call[0]?.beforeBreadcrumb,
|
||||
);
|
||||
return sentryCall ? sentryCall[0].beforeBreadcrumb : null;
|
||||
}
|
||||
|
||||
it("returns null for ui.click breadcrumbs", () => {
|
||||
const beforeBreadcrumb = getBeforeBreadcrumb();
|
||||
if (!beforeBreadcrumb) return;
|
||||
|
||||
setAnalyticsConsent(true);
|
||||
const result = beforeBreadcrumb({ category: "ui.click" });
|
||||
expect(result).toBeNull();
|
||||
});
|
||||
|
||||
it("returns null for fetch breadcrumbs with file extension URLs", () => {
|
||||
const beforeBreadcrumb = getBeforeBreadcrumb();
|
||||
if (!beforeBreadcrumb) return;
|
||||
|
||||
setAnalyticsConsent(true);
|
||||
const result = beforeBreadcrumb({
|
||||
category: "fetch",
|
||||
data: { url: "https://example.com/uploads/photo.png" },
|
||||
});
|
||||
expect(result).toBeNull();
|
||||
});
|
||||
|
||||
it("scrubs messages containing file paths", () => {
|
||||
const beforeBreadcrumb = getBeforeBreadcrumb();
|
||||
if (!beforeBreadcrumb) return;
|
||||
|
||||
setAnalyticsConsent(true);
|
||||
const breadcrumb = {
|
||||
category: "console",
|
||||
message: "Error loading /tmp/workspace/file.jpg",
|
||||
};
|
||||
const result = beforeBreadcrumb(breadcrumb);
|
||||
expect(result).not.toBeNull();
|
||||
expect(result.message).toContain("[REDACTED]");
|
||||
});
|
||||
|
||||
it("returns null when consent is not granted", () => {
|
||||
const beforeBreadcrumb = getBeforeBreadcrumb();
|
||||
if (!beforeBreadcrumb) return;
|
||||
|
||||
setAnalyticsConsent(false);
|
||||
const result = beforeBreadcrumb({ category: "console", message: "test" });
|
||||
expect(result).toBeNull();
|
||||
});
|
||||
|
||||
it("passes through fetch breadcrumbs without file extension URLs", () => {
|
||||
const beforeBreadcrumb = getBeforeBreadcrumb();
|
||||
if (!beforeBreadcrumb) return;
|
||||
|
||||
setAnalyticsConsent(true);
|
||||
const breadcrumb = {
|
||||
category: "fetch",
|
||||
data: { url: "https://example.com/api/v1/health" },
|
||||
};
|
||||
const result = beforeBreadcrumb(breadcrumb);
|
||||
expect(result).not.toBeNull();
|
||||
});
|
||||
|
||||
it("passes through breadcrumbs without message field", () => {
|
||||
const beforeBreadcrumb = getBeforeBreadcrumb();
|
||||
if (!beforeBreadcrumb) return;
|
||||
|
||||
setAnalyticsConsent(true);
|
||||
const breadcrumb = { category: "navigation" };
|
||||
const result = beforeBreadcrumb(breadcrumb);
|
||||
expect(result).not.toBeNull();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -361,3 +361,76 @@ describe("getToolRegistryEntry", () => {
|
||||
expect(entry?.ResultsPanel).toBeDefined();
|
||||
});
|
||||
});
|
||||
|
||||
// ==========================================================================
|
||||
// Wrapper components (lines 305-324)
|
||||
// ==========================================================================
|
||||
|
||||
import { render } from "@testing-library/react";
|
||||
import React from "react";
|
||||
|
||||
function renderSettings(Settings: React.ComponentType<Record<string, unknown>>, props = {}) {
|
||||
return render(
|
||||
React.createElement(React.Suspense, { fallback: null }, React.createElement(Settings, props)),
|
||||
);
|
||||
}
|
||||
|
||||
describe("CropSettingsWrapper", () => {
|
||||
it("renders null when cropProps is undefined", () => {
|
||||
const entry = getToolRegistryEntry("crop");
|
||||
expect(entry).toBeDefined();
|
||||
const { container } = renderSettings(entry!.Settings as never);
|
||||
expect(container.innerHTML).toBe("");
|
||||
});
|
||||
|
||||
it("renders CropSettings when cropProps is provided", () => {
|
||||
const entry = getToolRegistryEntry("crop");
|
||||
expect(entry).toBeDefined();
|
||||
const cropProps = {
|
||||
cropState: {
|
||||
crop: { x: 0, y: 0, width: 50, height: 50, unit: "%" },
|
||||
aspect: undefined,
|
||||
showGrid: true,
|
||||
imgDimensions: { width: 200, height: 150 },
|
||||
},
|
||||
onCropChange: vi.fn(),
|
||||
onAspectChange: vi.fn(),
|
||||
onGridToggle: vi.fn(),
|
||||
};
|
||||
const { container } = renderSettings(entry!.Settings as never, { cropProps });
|
||||
expect(container).toBeDefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe("EraseObjectSettingsWrapper", () => {
|
||||
it("renders null when eraserProps is undefined", () => {
|
||||
const entry = getToolRegistryEntry("erase-object");
|
||||
expect(entry).toBeDefined();
|
||||
const { container } = renderSettings(entry!.Settings as never);
|
||||
expect(container.innerHTML).toBe("");
|
||||
});
|
||||
|
||||
it("renders EraseObjectSettings when eraserProps is provided", () => {
|
||||
const entry = getToolRegistryEntry("erase-object");
|
||||
expect(entry).toBeDefined();
|
||||
const eraserProps = {
|
||||
eraserRef: React.createRef(),
|
||||
hasStrokes: false,
|
||||
brushSize: 20,
|
||||
onBrushSizeChange: vi.fn(),
|
||||
};
|
||||
const { container } = renderSettings(entry!.Settings as never, { eraserProps });
|
||||
expect(container).toBeDefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe("makeColorSettingsComponent", () => {
|
||||
it("adjust-colors Settings renders without throwing", () => {
|
||||
const entry = getToolRegistryEntry("adjust-colors");
|
||||
expect(entry).toBeDefined();
|
||||
const { container } = renderSettings(entry!.Settings as never, {
|
||||
onPreviewFilter: vi.fn(),
|
||||
});
|
||||
expect(container).toBeDefined();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user