mirror of
https://github.com/snapotter-hq/SnapOtter.git
synced 2026-08-03 07:46:42 +02:00
test: reorganize flat test files into purpose-based subdirectories (phase 6)
Group 245 flat integration tests and 25 loose unit tests into
discoverable subdirectories per spec section 6:
integration/tools/{image,video,audio,document,data}/ (156 files)
integration/platform/ (64 files)
integration/generated/ (14 files)
integration/security/ (10 files)
unit/security/ (8 files, new subdir)
unit/api/ (7 files moved in)
unit/web/ (3 files moved in)
unit/shared/ (6 files moved in)
unit/image-engine/ (1 file moved in)
All moves via git mv (history preserved). Relative imports repaired
for both depth levels (platform/generated/security = +1, tools/ = +2):
static from-imports, dynamic import() calls, vi.mock() paths,
import.meta.dirname joins, and __dirname joins.
Vitest discovery unchanged (no test.include in config, recursive glob
matches subdirs, shard-by-hash unaffected). test-server.ts and
tool-route-drift.test.ts stay at integration root. fixtures/ untouched.
Parity gate: 13189 passing test names before = 13189 after (0 dropped).
This commit is contained in:
@@ -0,0 +1,129 @@
|
||||
import sharp from "sharp";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import {
|
||||
generateBackground,
|
||||
getDominantBackground,
|
||||
} from "../../../apps/api/src/lib/beautify/backgrounds.js";
|
||||
|
||||
describe("generateBackground", () => {
|
||||
it("generates a solid color background", async () => {
|
||||
const buf = await generateBackground({
|
||||
type: "solid",
|
||||
color: "#ff0000",
|
||||
width: 200,
|
||||
height: 100,
|
||||
});
|
||||
const meta = await sharp(buf).metadata();
|
||||
expect(meta.width).toBe(200);
|
||||
expect(meta.height).toBe(100);
|
||||
expect(meta.channels).toBe(4);
|
||||
});
|
||||
|
||||
it("generates a linear gradient background", async () => {
|
||||
const buf = await generateBackground({
|
||||
type: "linear-gradient",
|
||||
stops: [
|
||||
{ color: "#667eea", position: 0 },
|
||||
{ color: "#764ba2", position: 100 },
|
||||
],
|
||||
angle: 135,
|
||||
width: 400,
|
||||
height: 300,
|
||||
});
|
||||
const meta = await sharp(buf).metadata();
|
||||
expect(meta.width).toBe(400);
|
||||
expect(meta.height).toBe(300);
|
||||
});
|
||||
|
||||
it("generates a radial gradient background", async () => {
|
||||
const buf = await generateBackground({
|
||||
type: "radial-gradient",
|
||||
stops: [
|
||||
{ color: "#667eea", position: 0 },
|
||||
{ color: "#764ba2", position: 100 },
|
||||
],
|
||||
width: 400,
|
||||
height: 300,
|
||||
});
|
||||
const meta = await sharp(buf).metadata();
|
||||
expect(meta.width).toBe(400);
|
||||
expect(meta.height).toBe(300);
|
||||
});
|
||||
|
||||
it("generates a transparent background", async () => {
|
||||
const buf = await generateBackground({
|
||||
type: "transparent",
|
||||
width: 200,
|
||||
height: 100,
|
||||
});
|
||||
const meta = await sharp(buf).metadata();
|
||||
expect(meta.width).toBe(200);
|
||||
expect(meta.height).toBe(100);
|
||||
expect(meta.hasAlpha).toBe(true);
|
||||
});
|
||||
|
||||
it("generates an image background", async () => {
|
||||
const red = await sharp({
|
||||
create: {
|
||||
width: 800,
|
||||
height: 600,
|
||||
channels: 4,
|
||||
background: { r: 255, g: 0, b: 0, alpha: 1 },
|
||||
},
|
||||
})
|
||||
.png()
|
||||
.toBuffer();
|
||||
|
||||
const buf = await generateBackground({
|
||||
type: "image",
|
||||
imageBuffer: red,
|
||||
width: 400,
|
||||
height: 300,
|
||||
});
|
||||
const meta = await sharp(buf).metadata();
|
||||
expect(meta.width).toBe(400);
|
||||
expect(meta.height).toBe(300);
|
||||
});
|
||||
|
||||
it("generates multi-stop linear gradient", async () => {
|
||||
const buf = await generateBackground({
|
||||
type: "linear-gradient",
|
||||
stops: [
|
||||
{ color: "#0f0c29", position: 0 },
|
||||
{ color: "#302b63", position: 50 },
|
||||
{ color: "#24243e", position: 100 },
|
||||
],
|
||||
angle: 135,
|
||||
width: 400,
|
||||
height: 300,
|
||||
});
|
||||
const meta = await sharp(buf).metadata();
|
||||
expect(meta.width).toBe(400);
|
||||
expect(meta.height).toBe(300);
|
||||
});
|
||||
});
|
||||
|
||||
describe("getDominantBackground", () => {
|
||||
it("returns solid color for solid type", () => {
|
||||
const result = getDominantBackground({ type: "solid", color: "#ff0000" });
|
||||
expect(result).toEqual({ r: 255, g: 0, b: 0, alpha: 1 });
|
||||
});
|
||||
|
||||
it("returns last gradient stop for gradient type", () => {
|
||||
const result = getDominantBackground({
|
||||
type: "linear-gradient",
|
||||
stops: [
|
||||
{ color: "#667eea", position: 0 },
|
||||
{ color: "#764ba2", position: 100 },
|
||||
],
|
||||
});
|
||||
expect(result.r).toBe(118);
|
||||
expect(result.g).toBe(75);
|
||||
expect(result.b).toBe(162);
|
||||
});
|
||||
|
||||
it("returns transparent for transparent type", () => {
|
||||
const result = getDominantBackground({ type: "transparent" });
|
||||
expect(result.alpha).toBe(0);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user