From 3c0b27efa0a5bfb3419ca491b9cc2f62ae487708 Mon Sep 17 00:00:00 2001 From: seveibar Date: Thu, 5 Sep 2024 19:33:55 -0700 Subject: [PATCH] add keyswitch implementation --- .../base-components/PrimitiveComponent.ts | 2 +- .../primitive-components/Constraint.ts | 2 + .../example2-switchshaft-pcb.snap.svg | 11 ++++ tests/examples/example2-switchshaft.test.tsx | 63 +++++++++++++++++++ 4 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 tests/examples/__snapshots__/example2-switchshaft-pcb.snap.svg create mode 100644 tests/examples/example2-switchshaft.test.tsx diff --git a/lib/components/base-components/PrimitiveComponent.ts b/lib/components/base-components/PrimitiveComponent.ts index 4867e59..9cdc316 100644 --- a/lib/components/base-components/PrimitiveComponent.ts +++ b/lib/components/base-components/PrimitiveComponent.ts @@ -92,8 +92,8 @@ export abstract class PrimitiveComponent< ) as z.infer if (!this.componentName) { this.componentName = this.constructor.name - this.lowercaseComponentName = this.componentName.toLowerCase() } + this.lowercaseComponentName = this.componentName.toLowerCase() } setProps(props: Partial>) { diff --git a/lib/components/primitive-components/Constraint.ts b/lib/components/primitive-components/Constraint.ts index 814f1c5..ce51615 100644 --- a/lib/components/primitive-components/Constraint.ts +++ b/lib/components/primitive-components/Constraint.ts @@ -13,6 +13,8 @@ const edgeSpecifiers = [ export type EdgeSpecifier = (typeof edgeSpecifiers)[number] export class Constraint extends PrimitiveComponent { + componentName = "Constraint" + get config() { return { zodProps: constraintProps, diff --git a/tests/examples/__snapshots__/example2-switchshaft-pcb.snap.svg b/tests/examples/__snapshots__/example2-switchshaft-pcb.snap.svg new file mode 100644 index 0000000..73b01e3 --- /dev/null +++ b/tests/examples/__snapshots__/example2-switchshaft-pcb.snap.svg @@ -0,0 +1,11 @@ + \ No newline at end of file diff --git a/tests/examples/example2-switchshaft.test.tsx b/tests/examples/example2-switchshaft.test.tsx new file mode 100644 index 0000000..d9d5d72 --- /dev/null +++ b/tests/examples/example2-switchshaft.test.tsx @@ -0,0 +1,63 @@ +import { test, expect } from "bun:test" +import { getTestFixture } from "tests/fixtures/get-test-fixture" + +const SwitchShaft = (props: { + name: string + pcbX?: number + pcbY?: number +}) => ( + + + + + + + + + + + + + } + /> +) + +test("example2-switchshaft", async () => { + const { circuit } = getTestFixture() + + circuit.add( + + + , + ) + + expect(circuit.getCircuitJson()).toMatchPcbSnapshot(import.meta.path) +})