|
| 1 | +import { describe, it, expect } from "vitest"; |
| 2 | + |
| 3 | +import { RegistryImpl } from "@/lib/component/Registry"; |
| 4 | + |
| 5 | +describe("Test that RegistryImpl", () => { |
| 6 | + it("works", () => { |
| 7 | + const registry = new RegistryImpl(); |
| 8 | + expect(registry.types).toEqual([]); |
| 9 | + |
| 10 | + const A = () => void 0; |
| 11 | + const B = () => void 0; |
| 12 | + const C = () => void 0; |
| 13 | + const unregisterA = registry.register(A); |
| 14 | + const unregisterB = registry.register(B); |
| 15 | + const unregisterC = registry.register(C); |
| 16 | + |
| 17 | + expect(registry.lookup("A")).toBe(A); |
| 18 | + expect(registry.lookup("B")).toBe(B); |
| 19 | + expect(registry.lookup("C")).toBe(C); |
| 20 | + expect(new Set(registry.types)).toEqual(new Set(["A", "B", "C"])); |
| 21 | + |
| 22 | + unregisterA(); |
| 23 | + expect(registry.lookup("A")).toBeUndefined(); |
| 24 | + expect(registry.lookup("B")).toBe(B); |
| 25 | + expect(registry.lookup("C")).toBe(C); |
| 26 | + expect(new Set(registry.types)).toEqual(new Set(["B", "C"])); |
| 27 | + |
| 28 | + unregisterB(); |
| 29 | + expect(registry.lookup("A")).toBeUndefined(); |
| 30 | + expect(registry.lookup("B")).toBeUndefined(); |
| 31 | + expect(registry.lookup("C")).toBe(C); |
| 32 | + expect(new Set(registry.types)).toEqual(new Set(["C"])); |
| 33 | + |
| 34 | + const C2 = () => void 0; |
| 35 | + const unregisterC2 = registry.register(C2, "C"); |
| 36 | + expect(registry.lookup("A")).toBeUndefined(); |
| 37 | + expect(registry.lookup("B")).toBeUndefined(); |
| 38 | + expect(registry.lookup("C")).toBe(C2); |
| 39 | + expect(new Set(registry.types)).toEqual(new Set(["C"])); |
| 40 | + |
| 41 | + unregisterC2(); |
| 42 | + expect(registry.lookup("A")).toBeUndefined(); |
| 43 | + expect(registry.lookup("B")).toBeUndefined(); |
| 44 | + expect(registry.lookup("C")).toBe(C); |
| 45 | + expect(new Set(registry.types)).toEqual(new Set(["C"])); |
| 46 | + |
| 47 | + unregisterC(); |
| 48 | + expect(registry.lookup("A")).toBeUndefined(); |
| 49 | + expect(registry.lookup("B")).toBeUndefined(); |
| 50 | + expect(registry.lookup("C")).toBeUndefined(); |
| 51 | + expect(registry.types).toEqual([]); |
| 52 | + }); |
| 53 | +}); |
0 commit comments