mirror of
https://github.com/snapotter-hq/SnapOtter.git
synced 2026-08-03 07:46:42 +02:00
Unit tests: 1354 → 1781 (+427) - 11 new AI bridge module tests (packages/ai/ from 2/13 → 13/13 files) - files-page-store (0% → full), pdf-to-image-store, features-store expanded - saturation and edit-metadata image-engine operations - analytics route, features route, web analytics lib, api-extended Integration tests: ~2070 → 2320 (+250) - 31 integration files expanded with branch-coverage-targeted tests - progress.ts SSE endpoints (28% → comprehensive, +18 tests) - gif-tools all modes (+18), pdf-to-image format variants (+13) - Cross-format matrix expanded to 17 tools × 17 formats (467 tests) - Adversarial: concurrent, memory pressure, unicode filenames, pipeline limits E2E-Docker: +1020 lines across 6 spec files - Info, colors, sharpening, base64, QR read, JXL/ICO/SVG formats - Strip-metadata, image-enhancement, content-aware-resize expanded - Batch pipelines, multi-format batches, HEIC input coverage
108 lines
3.4 KiB
TypeScript
108 lines
3.4 KiB
TypeScript
import { readFileSync } from "node:fs";
|
|
import { createRequire } from "node:module";
|
|
import path from "node:path";
|
|
import { beforeAll, describe, expect, it } from "vitest";
|
|
|
|
const require = createRequire(
|
|
path.resolve(__dirname, "../../../packages/image-engine/src/index.ts"),
|
|
);
|
|
const sharp = require("sharp") as typeof import("sharp").default;
|
|
|
|
import { saturation } from "@snapotter/image-engine";
|
|
|
|
const FIXTURES_DIR = path.resolve(__dirname, "../../fixtures");
|
|
|
|
let png200x150: Buffer;
|
|
|
|
beforeAll(() => {
|
|
png200x150 = readFileSync(path.join(FIXTURES_DIR, "test-200x150.png"));
|
|
});
|
|
|
|
async function getMeta(img: sharp.Sharp) {
|
|
const buf = await img.toBuffer();
|
|
return sharp(buf).metadata();
|
|
}
|
|
|
|
describe("saturation", () => {
|
|
it("returns a Sharp instance at value 0 (no change)", async () => {
|
|
const img = sharp(png200x150);
|
|
const result = await saturation(img, { value: 0 });
|
|
const meta = await getMeta(result);
|
|
expect(meta.width).toBe(200);
|
|
expect(meta.height).toBe(150);
|
|
});
|
|
|
|
it("increases saturation at value +50", async () => {
|
|
const img = sharp(png200x150);
|
|
const result = await saturation(img, { value: 50 });
|
|
const buf = await result.toBuffer();
|
|
expect(buf.length).toBeGreaterThan(0);
|
|
});
|
|
|
|
it("decreases saturation at value -50", async () => {
|
|
const img = sharp(png200x150);
|
|
const result = await saturation(img, { value: -50 });
|
|
const buf = await result.toBuffer();
|
|
expect(buf.length).toBeGreaterThan(0);
|
|
});
|
|
|
|
it("fully desaturates at value -100", async () => {
|
|
const img = sharp(png200x150);
|
|
const result = await saturation(img, { value: -100 });
|
|
const buf = await result.toBuffer();
|
|
expect(buf.length).toBeGreaterThan(0);
|
|
});
|
|
|
|
it("doubles saturation at value +100", async () => {
|
|
const img = sharp(png200x150);
|
|
const result = await saturation(img, { value: 100 });
|
|
const buf = await result.toBuffer();
|
|
expect(buf.length).toBeGreaterThan(0);
|
|
});
|
|
|
|
it("throws for value below -100", async () => {
|
|
const img = sharp(png200x150);
|
|
await expect(saturation(img, { value: -101 })).rejects.toThrow(
|
|
"Saturation value must be between -100 and +100",
|
|
);
|
|
});
|
|
|
|
it("throws for value above +100", async () => {
|
|
const img = sharp(png200x150);
|
|
await expect(saturation(img, { value: 101 })).rejects.toThrow(
|
|
"Saturation value must be between -100 and +100",
|
|
);
|
|
});
|
|
|
|
it("accepts boundary value -100", async () => {
|
|
const img = sharp(png200x150);
|
|
const result = await saturation(img, { value: -100 });
|
|
const meta = await getMeta(result);
|
|
expect(meta.width).toBe(200);
|
|
});
|
|
|
|
it("accepts boundary value +100", async () => {
|
|
const img = sharp(png200x150);
|
|
const result = await saturation(img, { value: 100 });
|
|
const meta = await getMeta(result);
|
|
expect(meta.width).toBe(200);
|
|
});
|
|
|
|
it("preserves image dimensions", async () => {
|
|
const img = sharp(png200x150);
|
|
const result = await saturation(img, { value: 30 });
|
|
const meta = await getMeta(result);
|
|
expect(meta.width).toBe(200);
|
|
expect(meta.height).toBe(150);
|
|
});
|
|
|
|
it("works with JPEG input", async () => {
|
|
const jpg = readFileSync(path.join(FIXTURES_DIR, "test-100x100.jpg"));
|
|
const img = sharp(jpg);
|
|
const result = await saturation(img, { value: 25 });
|
|
const meta = await getMeta(result);
|
|
expect(meta.width).toBe(100);
|
|
expect(meta.height).toBe(100);
|
|
});
|
|
});
|