Files
Epicnabbo-Catalogus-Updated…/src/lib/services/effectmap.test.ts
T
openhands 4993b75608 perf: self-host fonts, drop unused generated code and add swf tests
- Self-host Nunito and Pixelify Sans via next/font instead of Google Fonts CDN
  (removes render-blocking external stylesheets and preconnects)
- Remove stale mariadb entry from serverExternalPackages (app uses mysql2)
- Exclude unused src/generated Prisma client from typecheck and remove it
- Add unit tests for swf-parser, effectmap and figuremap (0% coverage -> 90%+)
2026-08-09 12:12:02 +02:00

86 lines
2.3 KiB
TypeScript

import { promises as fs } from "node:fs";
import os from "node:os";
import path from "node:path";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import type { EffectMapEntry } from "@/types/effects";
import {
__setEffectMapPathForTests,
listLocalEffects,
mergeEffect,
readEffectMap,
removeEffect,
} from "./effectmap";
vi.mock("@/lib/services/site-settings", () => ({
siteSettings: { get: vi.fn(async () => "") },
}));
let dir: string;
let file: string;
const ENTRY: EffectMapEntry = {
id: "fx_1",
lib: "fx_1",
type: "fx",
revision: 1,
};
beforeEach(async () => {
dir = await fs.mkdtemp(path.join(os.tmpdir(), "effectmap-"));
file = path.join(dir, "EffectMap.json");
await fs.writeFile(file, JSON.stringify({ effects: [ENTRY] }));
__setEffectMapPathForTests(file);
});
afterEach(async () => {
__setEffectMapPathForTests(null);
await fs.rm(dir, { recursive: true, force: true });
});
describe("lib/services/effectmap", () => {
it("lists local effects from the map", async () => {
const effects = await listLocalEffects();
expect(effects).toEqual([ENTRY]);
});
it("returns an empty list when the file has no effects array", async () => {
await fs.writeFile(file, JSON.stringify({}));
expect(await readEffectMap()).toEqual({ effects: [] });
});
it("adds a new effect via mergeEffect", async () => {
const added: EffectMapEntry = {
id: "fx_2",
lib: "fx_2",
type: "fx",
revision: 2,
};
await mergeEffect(added);
const effects = await listLocalEffects();
expect(effects).toHaveLength(2);
expect(effects).toContainEqual(added);
});
it("updates an existing effect in place via mergeEffect", async () => {
await mergeEffect({ ...ENTRY, revision: 5 });
const effects = await listLocalEffects();
expect(effects).toHaveLength(1);
expect(effects[0].revision).toBe(5);
});
it("removes an effect by id", async () => {
expect(await removeEffect("fx_1")).toBe(true);
expect(await listLocalEffects()).toEqual([]);
});
it("removes an effect by lib name", async () => {
expect(await removeEffect("fx_1")).toBe(true);
expect(await listLocalEffects()).toEqual([]);
});
it("reports false when nothing was removed", async () => {
expect(await removeEffect("missing")).toBe(false);
expect(await listLocalEffects()).toHaveLength(1);
});
});