mirror of
https://github.com/snapotter-hq/SnapOtter.git
synced 2026-08-03 07:46:42 +02:00
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:
@@ -563,3 +563,106 @@ describe("SVG input", () => {
|
||||
expect(result.downloadUrl).toBeDefined();
|
||||
});
|
||||
});
|
||||
|
||||
// ── makeTransparent explicitly false ──────────────────────────
|
||||
describe("Explicit makeTransparent false", () => {
|
||||
it("replaces color normally when makeTransparent is false", async () => {
|
||||
const res = await postTool(
|
||||
{ sourceColor: "#FF0000", targetColor: "#00FF00", makeTransparent: false, tolerance: 30 },
|
||||
solidRedBuffer,
|
||||
);
|
||||
expect(res.statusCode).toBe(200);
|
||||
const result = JSON.parse(res.body);
|
||||
expect(result.downloadUrl).toBeDefined();
|
||||
|
||||
// Download and verify color changed (not transparent)
|
||||
const dlRes = await app.inject({
|
||||
method: "GET",
|
||||
url: result.downloadUrl,
|
||||
headers: { authorization: `Bearer ${adminToken}` },
|
||||
});
|
||||
const { data } = await sharp(dlRes.rawPayload)
|
||||
.removeAlpha()
|
||||
.raw()
|
||||
.toBuffer({ resolveWithObject: true });
|
||||
// First pixel should be green-ish
|
||||
expect(data[1]).toBeGreaterThan(data[0]); // green > red
|
||||
});
|
||||
});
|
||||
|
||||
// ── makeTransparent on HEIC input ─────────────────────────────
|
||||
describe("makeTransparent on HEIC", () => {
|
||||
it("makes pixels transparent in a HEIC image", { timeout: 120_000 }, async () => {
|
||||
const HEIC = readFileSync(join(FIXTURES, "test-200x150.heic"));
|
||||
const res = await postTool(
|
||||
{ sourceColor: "#808080", makeTransparent: true, tolerance: 100 },
|
||||
HEIC,
|
||||
"photo.heic",
|
||||
"image/heic",
|
||||
);
|
||||
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.channels).toBe(4);
|
||||
});
|
||||
});
|
||||
|
||||
// ── Invalid settings JSON ─────────────────────────────────────
|
||||
describe("Invalid settings JSON", () => {
|
||||
it("rejects malformed settings JSON", async () => {
|
||||
const { body: payload, contentType } = createMultipartPayload([
|
||||
{ name: "file", filename: "test.png", contentType: "image/png", content: PNG },
|
||||
{ name: "settings", content: "not-valid-json" },
|
||||
]);
|
||||
const res = await app.inject({
|
||||
method: "POST",
|
||||
url: "/api/v1/tools/replace-color",
|
||||
payload,
|
||||
headers: {
|
||||
"content-type": contentType,
|
||||
authorization: `Bearer ${adminToken}`,
|
||||
},
|
||||
});
|
||||
expect(res.statusCode).toBe(400);
|
||||
});
|
||||
});
|
||||
|
||||
// ── Verify pixel accuracy with exact tolerance ────────────────
|
||||
describe("Pixel accuracy verification", () => {
|
||||
it("replaces all pixels in solid image at tolerance=0", async () => {
|
||||
const res = await postTool(
|
||||
{ sourceColor: "#FF0000", targetColor: "#FFFFFF", tolerance: 0 },
|
||||
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}` },
|
||||
});
|
||||
|
||||
// All pixels should be white now
|
||||
const { data, info } = await sharp(dlRes.rawPayload)
|
||||
.removeAlpha()
|
||||
.raw()
|
||||
.toBuffer({ resolveWithObject: true });
|
||||
|
||||
// Check a sample of pixels are white (R=255, G=255, B=255)
|
||||
let whiteCount = 0;
|
||||
const totalPixels = info.width * info.height;
|
||||
for (let i = 0; i < data.length; i += 3) {
|
||||
if (data[i] > 250 && data[i + 1] > 250 && data[i + 2] > 250) {
|
||||
whiteCount++;
|
||||
}
|
||||
}
|
||||
// Nearly all pixels should be white
|
||||
expect(whiteCount / totalPixels).toBeGreaterThan(0.9);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user