diff --git a/lib/components/normal-components/PushButton.ts b/lib/components/normal-components/PushButton.ts index d930b5de9..fde2aa234 100644 --- a/lib/components/normal-components/PushButton.ts +++ b/lib/components/normal-components/PushButton.ts @@ -7,6 +7,7 @@ import { } from "lib/utils/constants" import { NormalComponent } from "../base-components/NormalComponent/NormalComponent" import { Port } from "../primitive-components/Port" +import { Trace } from "../primitive-components/Trace/Trace" import { symbols } from "schematic-symbols" export class PushButton extends NormalComponent< @@ -27,6 +28,23 @@ export class PushButton extends NormalComponent< return [] } + doInitialCreateTracesFromProps() { + const { _parsedProps: props } = this + + if (props.externallyConnectedPins) { + for (const [pin1, pin2] of props.externallyConnectedPins) { + this.add( + new Trace({ + from: `${this.getSubcircuitSelector()} > port.${pin1}`, + to: `${this.getSubcircuitSelector()} > port.${pin2}`, + }), + ) + } + } + + this._createTracesFromConnectionsProp() + } + override initPorts() { super.initPorts({ pinCount: 2, diff --git a/tests/components/normal-components/__snapshots__/pushbutton-externally-connected-pins-pcb.snap.svg b/tests/components/normal-components/__snapshots__/pushbutton-externally-connected-pins-pcb.snap.svg new file mode 100644 index 000000000..ec14c056a --- /dev/null +++ b/tests/components/normal-components/__snapshots__/pushbutton-externally-connected-pins-pcb.snap.svg @@ -0,0 +1 @@ +SW1 \ No newline at end of file diff --git a/tests/components/normal-components/pushbutton-externally-connected-pins.test.tsx b/tests/components/normal-components/pushbutton-externally-connected-pins.test.tsx new file mode 100644 index 000000000..261de9088 --- /dev/null +++ b/tests/components/normal-components/pushbutton-externally-connected-pins.test.tsx @@ -0,0 +1,35 @@ +import { test, expect } from "bun:test" +import { getTestFixture } from "tests/fixtures/get-test-fixture" + +test(" creates traces for externally connected pins", () => { + const { circuit } = getTestFixture() + + circuit.add( + + + , + ) + + circuit.render() + + const sourceTraces = circuit + .getCircuitJson() + .filter((elm) => elm.type === "source_trace") + + expect(sourceTraces).toHaveLength(1) + const sourcePortsById = new Map( + circuit.db.source_port + .list() + .map((sourcePort) => [sourcePort.source_port_id, sourcePort]), + ) + expect( + sourceTraces[0].connected_source_port_ids.map( + (sourcePortId) => sourcePortsById.get(sourcePortId)?.name, + ), + ).toEqual(["pin1", "pin2"]) + expect(circuit).toMatchPcbSnapshot(import.meta.path) +})