100 lines
2.6 KiB
TypeScript
100 lines
2.6 KiB
TypeScript
import { describe, test, expect, beforeEach } from "bun:test";
|
|
import {
|
|
registerEffect,
|
|
getEffect,
|
|
hasEffect,
|
|
getAllEffects,
|
|
clearEffects,
|
|
} from "../src/registry";
|
|
import type { EffectDefinition } from "../src/types";
|
|
|
|
/** Minimal stub definition for testing registry logic */
|
|
function createStubDefinition(type: string): EffectDefinition {
|
|
return {
|
|
type,
|
|
name: type.charAt(0).toUpperCase() + type.slice(1),
|
|
keywords: [type],
|
|
params: [
|
|
{
|
|
key: "intensity",
|
|
label: "Intensity",
|
|
type: "number",
|
|
default: 50,
|
|
min: 0,
|
|
max: 100,
|
|
step: 1,
|
|
},
|
|
],
|
|
renderer: {
|
|
type: "webgl",
|
|
passes: [
|
|
{
|
|
fragmentShader: "void main() { gl_FragColor = vec4(1.0); }",
|
|
uniforms: () => ({ u_intensity: 0.5 }),
|
|
},
|
|
],
|
|
},
|
|
};
|
|
}
|
|
|
|
describe("Effect Registry", () => {
|
|
beforeEach(() => {
|
|
clearEffects();
|
|
});
|
|
|
|
test("registerEffect adds effect to registry", () => {
|
|
const def = createStubDefinition("blur");
|
|
registerEffect({ definition: def });
|
|
expect(hasEffect({ effectType: "blur" })).toBe(true);
|
|
});
|
|
|
|
test("hasEffect returns false for unregistered type", () => {
|
|
expect(hasEffect({ effectType: "nonexistent" })).toBe(false);
|
|
});
|
|
|
|
test("getEffect returns registered definition", () => {
|
|
const def = createStubDefinition("blur");
|
|
registerEffect({ definition: def });
|
|
const result = getEffect({ effectType: "blur" });
|
|
expect(result.type).toBe("blur");
|
|
expect(result.name).toBe("Blur");
|
|
});
|
|
|
|
test("getEffect throws for unknown type", () => {
|
|
expect(() => getEffect({ effectType: "unknown" })).toThrow(
|
|
"Unknown effect type: unknown",
|
|
);
|
|
});
|
|
|
|
test("getAllEffects returns all registered definitions", () => {
|
|
registerEffect({ definition: createStubDefinition("blur") });
|
|
registerEffect({ definition: createStubDefinition("brightness") });
|
|
const all = getAllEffects();
|
|
expect(all).toHaveLength(2);
|
|
expect(all.map((e) => e.type)).toContain("blur");
|
|
expect(all.map((e) => e.type)).toContain("brightness");
|
|
});
|
|
|
|
test("registerEffect overwrites duplicate type", () => {
|
|
const def1 = createStubDefinition("blur");
|
|
def1.name = "Blur V1";
|
|
registerEffect({ definition: def1 });
|
|
|
|
const def2 = createStubDefinition("blur");
|
|
def2.name = "Blur V2";
|
|
registerEffect({ definition: def2 });
|
|
|
|
expect(getAllEffects()).toHaveLength(1);
|
|
expect(getEffect({ effectType: "blur" }).name).toBe("Blur V2");
|
|
});
|
|
|
|
test("clearEffects removes all entries", () => {
|
|
registerEffect({ definition: createStubDefinition("blur") });
|
|
registerEffect({ definition: createStubDefinition("contrast") });
|
|
expect(getAllEffects()).toHaveLength(2);
|
|
|
|
clearEffects();
|
|
expect(getAllEffects()).toHaveLength(0);
|
|
});
|
|
});
|