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:
@@ -319,3 +319,104 @@ describe("Edge size inputs", () => {
|
||||
expect(result.processedSize).toBeGreaterThan(0);
|
||||
});
|
||||
});
|
||||
|
||||
// ── Unauthenticated request ────────────────────────────────────
|
||||
describe("Authentication", () => {
|
||||
it("rejects unauthenticated request", async () => {
|
||||
const { body: payload, contentType } = makePayload({
|
||||
sourceColor: "#FF0000",
|
||||
targetColor: "#00FF00",
|
||||
});
|
||||
const res = await app.inject({
|
||||
method: "POST",
|
||||
url: "/api/v1/tools/replace-color",
|
||||
payload,
|
||||
headers: { "content-type": contentType },
|
||||
});
|
||||
expect(res.statusCode).toBe(401);
|
||||
});
|
||||
});
|
||||
|
||||
// ── Preserves dimensions ────────────────────────────────────────
|
||||
describe("Dimension preservation", () => {
|
||||
it("output preserves original dimensions", async () => {
|
||||
const res = await postTool(
|
||||
{ sourceColor: "#FF0000", targetColor: "#0000FF", tolerance: 30 },
|
||||
solidRedBuffer,
|
||||
);
|
||||
expect(res.statusCode).toBe(200);
|
||||
const result = JSON.parse(res.body);
|
||||
|
||||
const dlRes = await app.inject({
|
||||
method: "GET",
|
||||
url: result.downloadUrl,
|
||||
headers: { authorization: `Bearer ${adminToken}` },
|
||||
});
|
||||
const meta = await sharp(dlRes.rawPayload).metadata();
|
||||
expect(meta.width).toBe(50);
|
||||
expect(meta.height).toBe(50);
|
||||
});
|
||||
});
|
||||
|
||||
// ── makeTransparent on WebP (alpha-capable, no forced PNG) ──────
|
||||
describe("WebP with makeTransparent", () => {
|
||||
it("keeps WebP when makeTransparent is used on WebP input", async () => {
|
||||
const WEBP = readFileSync(join(FIXTURES, "test-50x50.webp"));
|
||||
const res = await postTool(
|
||||
{ sourceColor: "#808080", makeTransparent: true, tolerance: 100 },
|
||||
WEBP,
|
||||
"test.webp",
|
||||
"image/webp",
|
||||
);
|
||||
expect(res.statusCode).toBe(200);
|
||||
const result = JSON.parse(res.body);
|
||||
|
||||
const dlRes = await app.inject({
|
||||
method: "GET",
|
||||
url: result.downloadUrl,
|
||||
headers: { authorization: `Bearer ${adminToken}` },
|
||||
});
|
||||
const meta = await sharp(dlRes.rawPayload).metadata();
|
||||
// WebP supports alpha, so no format conversion needed
|
||||
expect(meta.channels).toBe(4);
|
||||
});
|
||||
});
|
||||
|
||||
// ── Blend behavior with medium tolerance ────────────────────────
|
||||
describe("Blend behavior", () => {
|
||||
it("partially blends colors within tolerance range", async () => {
|
||||
// Create a gradient: pure red on left, slightly off-red on right
|
||||
const w = 100;
|
||||
const h = 50;
|
||||
const raw = Buffer.alloc(w * h * 3);
|
||||
for (let y = 0; y < h; y++) {
|
||||
for (let x = 0; x < w; x++) {
|
||||
const idx = (y * w + x) * 3;
|
||||
raw[idx] = 255;
|
||||
raw[idx + 1] = Math.round((x / w) * 100);
|
||||
raw[idx + 2] = 0;
|
||||
}
|
||||
}
|
||||
const gradientBuf = await sharp(raw, { raw: { width: w, height: h, channels: 3 } })
|
||||
.png()
|
||||
.toBuffer();
|
||||
|
||||
const res = await postTool(
|
||||
{ sourceColor: "#FF0000", targetColor: "#0000FF", tolerance: 50 },
|
||||
gradientBuf,
|
||||
"gradient.png",
|
||||
"image/png",
|
||||
);
|
||||
expect(res.statusCode).toBe(200);
|
||||
const result = JSON.parse(res.body);
|
||||
expect(result.processedSize).toBeGreaterThan(0);
|
||||
});
|
||||
});
|
||||
|
||||
// ── Invalid target color format ─────────────────────────────────
|
||||
describe("Target color validation", () => {
|
||||
it("rejects invalid target color format", async () => {
|
||||
const res = await postTool({ sourceColor: "#FF0000", targetColor: "blue" });
|
||||
expect(res.statusCode).toBe(400);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user