From eb1bd05093bceb6946369283ec23a929cf1218c2 Mon Sep 17 00:00:00 2001 From: PxlPal Date: Fri, 15 Aug 2025 11:17:30 +0200 Subject: [PATCH 1/2] Allow numeric internallyConnectedPins --- .../NormalComponent/NormalComponent.ts | 6 +- package.json | 2 +- ...-connected-pins-numbers-schematic.snap.svg | 20 +++++ ...rs-internally-connected-schematic.snap.svg | 20 +++++ ...internally-connected-pins-numbers.test.tsx | 87 +++++++++++++++++++ ...mper-numbers-internally-connected.test.tsx | 66 ++++++++++++++ 6 files changed, 199 insertions(+), 2 deletions(-) create mode 100644 tests/components/normal-components/__snapshots__/internally-connected-pins-numbers-schematic.snap.svg create mode 100644 tests/components/normal-components/__snapshots__/jumper-numbers-internally-connected-schematic.snap.svg create mode 100644 tests/components/normal-components/internally-connected-pins-numbers.test.tsx create mode 100644 tests/components/normal-components/jumper-numbers-internally-connected.test.tsx diff --git a/lib/components/base-components/NormalComponent/NormalComponent.ts b/lib/components/base-components/NormalComponent/NormalComponent.ts index b8bb3387..7dd53002 100644 --- a/lib/components/base-components/NormalComponent/NormalComponent.ts +++ b/lib/components/base-components/NormalComponent/NormalComponent.ts @@ -101,9 +101,13 @@ export class NormalComponent< } get internallyConnectedPinNames(): string[][] { - return ( + const rawPins = this._parsedProps.internallyConnectedPins ?? this.defaultInternallyConnectedPinNames + return rawPins.map((pinGroup: (string | number)[]) => + pinGroup.map((pin: string | number) => + typeof pin === "number" ? `pin${pin}` : pin, + ), ) } diff --git a/package.json b/package.json index 7ec4eae2..6bc504b4 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,7 @@ "@tscircuit/log-soup": "^1.0.2", "@tscircuit/math-utils": "^0.0.18", "@tscircuit/miniflex": "^0.0.4", - "@tscircuit/props": "^0.0.281", + "@tscircuit/props": "^0.0.285", "@tscircuit/schematic-autolayout": "^0.0.6", "@tscircuit/schematic-corpus": "^0.0.110", "@tscircuit/schematic-match-adapt": "^0.0.16", diff --git a/tests/components/normal-components/__snapshots__/internally-connected-pins-numbers-schematic.snap.svg b/tests/components/normal-components/__snapshots__/internally-connected-pins-numbers-schematic.snap.svg new file mode 100644 index 00000000..0ba96c75 --- /dev/null +++ b/tests/components/normal-components/__snapshots__/internally-connected-pins-numbers-schematic.snap.svg @@ -0,0 +1,20 @@ +-2,-1-2,0-2,1-2,2-2,3-2,4-2,5-1,-1-1,0-1,1-1,2-1,3-1,4-1,50,-10,00,10,20,30,40,51,-11,01,11,21,31,41,52,-12,02,12,22,32,42,5SW1SW2SW3 \ No newline at end of file diff --git a/tests/components/normal-components/__snapshots__/jumper-numbers-internally-connected-schematic.snap.svg b/tests/components/normal-components/__snapshots__/jumper-numbers-internally-connected-schematic.snap.svg new file mode 100644 index 00000000..74dd8cc9 --- /dev/null +++ b/tests/components/normal-components/__snapshots__/jumper-numbers-internally-connected-schematic.snap.svg @@ -0,0 +1,20 @@ +-1,-2-1,-1-1,0-1,1-1,20,-20,-10,00,10,21,-21,-11,01,11,22,-22,-12,02,12,23,-23,-13,03,13,24,-24,-14,04,14,25,-25,-15,05,15,26,-26,-16,06,16,27,-27,-17,07,17,28,-28,-18,08,18,2JP112JP212JP312 \ No newline at end of file diff --git a/tests/components/normal-components/internally-connected-pins-numbers.test.tsx b/tests/components/normal-components/internally-connected-pins-numbers.test.tsx new file mode 100644 index 00000000..8adf7670 --- /dev/null +++ b/tests/components/normal-components/internally-connected-pins-numbers.test.tsx @@ -0,0 +1,87 @@ +import { test, expect } from "bun:test" +import { getTestFixture } from "tests/fixtures/get-test-fixture" + +test("internallyConnectedPins with numbers should convert to pin names", async () => { + const { circuit } = getTestFixture() + + circuit.add( + + {/* Test with pure numbers */} + + + {/* Test with mixed strings and numbers */} + + + {/* Test with pure strings */} + + + ) + + await circuit.renderUntilSettled() + + // Check that all pushbuttons were processed correctly + const sw1 = circuit.selectOne("pushbutton.SW1") as any + const sw2 = circuit.selectOne("pushbutton.SW2") as any + const sw3 = circuit.selectOne("pushbutton.SW3") as any + + // Verify internal connections for SW1 (numbers) + const sw1InternalPins = sw1._getInternallyConnectedPins() + expect(sw1InternalPins).toHaveLength(2) + expect(sw1InternalPins[0].map((p: any) => p.props.name).sort()).toEqual(["pin1", "pin2"]) + expect(sw1InternalPins[1].map((p: any) => p.props.name).sort()).toEqual(["pin3", "pin4"]) + + // Verify internal connections for SW2 (mixed) + const sw2InternalPins = sw2._getInternallyConnectedPins() + expect(sw2InternalPins).toHaveLength(2) + expect(sw2InternalPins[0].map((p: any) => p.props.name).sort()).toEqual(["pin1", "pin2"]) + expect(sw2InternalPins[1].map((p: any) => p.props.name).sort()).toEqual(["pin3", "pin4"]) + + // Verify internal connections for SW3 (strings) + const sw3InternalPins = sw3._getInternallyConnectedPins() + expect(sw3InternalPins).toHaveLength(2) + expect(sw3InternalPins[0].map((p: any) => p.props.name).sort()).toEqual(["pin1", "pin2"]) + expect(sw3InternalPins[1].map((p: any) => p.props.name).sort()).toEqual(["pin3", "pin4"]) + + // Verify the internallyConnectedPinNames getter processes numbers correctly + expect(sw1.internallyConnectedPinNames).toEqual([ + ["pin1", "pin2"], + ["pin3", "pin4"], + ]) + expect(sw2.internallyConnectedPinNames).toEqual([ + ["pin1", "pin2"], + ["pin3", "pin4"], + ]) + expect(sw3.internallyConnectedPinNames).toEqual([ + ["pin1", "pin2"], + ["pin3", "pin4"], + ]) + + expect(circuit).toMatchSchematicSnapshot(import.meta.path) +}) \ No newline at end of file diff --git a/tests/components/normal-components/jumper-numbers-internally-connected.test.tsx b/tests/components/normal-components/jumper-numbers-internally-connected.test.tsx new file mode 100644 index 00000000..8b53257e --- /dev/null +++ b/tests/components/normal-components/jumper-numbers-internally-connected.test.tsx @@ -0,0 +1,66 @@ +import { test, expect } from "bun:test" +import { getTestFixture } from "tests/fixtures/get-test-fixture" + +test("jumper internallyConnectedPins with numbers should work correctly", async () => { + const { circuit } = getTestFixture() + + circuit.add( + + {/* Test jumper with numbers */} + + + {/* Test jumper with mixed strings and numbers */} + + + {/* Test jumper with pure strings (existing behavior) */} + + + ) + + await circuit.renderUntilSettled() + + // Check that all jumpers were processed correctly + const jp1 = circuit.selectOne("jumper.JP1") as any + const jp2 = circuit.selectOne("jumper.JP2") as any + const jp3 = circuit.selectOne("jumper.JP3") as any + + // Verify internal connections for JP1 (numbers) + const jp1InternalPins = jp1._getInternallyConnectedPins() + expect(jp1InternalPins).toHaveLength(1) + expect(jp1InternalPins[0].map((p: any) => p.props.name).sort()).toEqual(["pin1", "pin2"]) + + // Verify internal connections for JP2 (mixed) + const jp2InternalPins = jp2._getInternallyConnectedPins() + expect(jp2InternalPins).toHaveLength(1) + expect(jp2InternalPins[0].map((p: any) => p.props.name).sort()).toEqual(["pin1", "pin2"]) + + // Verify internal connections for JP3 (strings) + const jp3InternalPins = jp3._getInternallyConnectedPins() + expect(jp3InternalPins).toHaveLength(1) + expect(jp3InternalPins[0].map((p: any) => p.props.name).sort()).toEqual(["pin1", "pin2"]) + + // Verify the internallyConnectedPinNames getter processes numbers correctly + expect(jp1.internallyConnectedPinNames).toEqual([["pin1", "pin2"]]) + expect(jp2.internallyConnectedPinNames).toEqual([["pin1", "pin2"]]) + expect(jp3.internallyConnectedPinNames).toEqual([["pin1", "pin2"]]) + + expect(circuit).toMatchSchematicSnapshot(import.meta.path) +}) \ No newline at end of file From 0613b65e20fb005314da3926eaaea426f914e2a3 Mon Sep 17 00:00:00 2001 From: tscircuitbot Date: Fri, 15 Aug 2025 09:18:39 +0000 Subject: [PATCH 2/2] formatbot: Automatically format code --- ...internally-connected-pins-numbers.test.tsx | 36 ++++++++++++++----- ...mper-numbers-internally-connected.test.tsx | 19 +++++++--- 2 files changed, 41 insertions(+), 14 deletions(-) diff --git a/tests/components/normal-components/internally-connected-pins-numbers.test.tsx b/tests/components/normal-components/internally-connected-pins-numbers.test.tsx index 8adf7670..a997a831 100644 --- a/tests/components/normal-components/internally-connected-pins-numbers.test.tsx +++ b/tests/components/normal-components/internally-connected-pins-numbers.test.tsx @@ -17,7 +17,7 @@ test("internallyConnectedPins with numbers should convert to pin names", async ( schY={0} footprint="pushbutton_id1.3mm_od2mm" /> - + {/* Test with mixed strings and numbers */} - + , ) await circuit.renderUntilSettled() @@ -54,20 +54,38 @@ test("internallyConnectedPins with numbers should convert to pin names", async ( // Verify internal connections for SW1 (numbers) const sw1InternalPins = sw1._getInternallyConnectedPins() expect(sw1InternalPins).toHaveLength(2) - expect(sw1InternalPins[0].map((p: any) => p.props.name).sort()).toEqual(["pin1", "pin2"]) - expect(sw1InternalPins[1].map((p: any) => p.props.name).sort()).toEqual(["pin3", "pin4"]) + expect(sw1InternalPins[0].map((p: any) => p.props.name).sort()).toEqual([ + "pin1", + "pin2", + ]) + expect(sw1InternalPins[1].map((p: any) => p.props.name).sort()).toEqual([ + "pin3", + "pin4", + ]) // Verify internal connections for SW2 (mixed) const sw2InternalPins = sw2._getInternallyConnectedPins() expect(sw2InternalPins).toHaveLength(2) - expect(sw2InternalPins[0].map((p: any) => p.props.name).sort()).toEqual(["pin1", "pin2"]) - expect(sw2InternalPins[1].map((p: any) => p.props.name).sort()).toEqual(["pin3", "pin4"]) + expect(sw2InternalPins[0].map((p: any) => p.props.name).sort()).toEqual([ + "pin1", + "pin2", + ]) + expect(sw2InternalPins[1].map((p: any) => p.props.name).sort()).toEqual([ + "pin3", + "pin4", + ]) // Verify internal connections for SW3 (strings) const sw3InternalPins = sw3._getInternallyConnectedPins() expect(sw3InternalPins).toHaveLength(2) - expect(sw3InternalPins[0].map((p: any) => p.props.name).sort()).toEqual(["pin1", "pin2"]) - expect(sw3InternalPins[1].map((p: any) => p.props.name).sort()).toEqual(["pin3", "pin4"]) + expect(sw3InternalPins[0].map((p: any) => p.props.name).sort()).toEqual([ + "pin1", + "pin2", + ]) + expect(sw3InternalPins[1].map((p: any) => p.props.name).sort()).toEqual([ + "pin3", + "pin4", + ]) // Verify the internallyConnectedPinNames getter processes numbers correctly expect(sw1.internallyConnectedPinNames).toEqual([ @@ -84,4 +102,4 @@ test("internallyConnectedPins with numbers should convert to pin names", async ( ]) expect(circuit).toMatchSchematicSnapshot(import.meta.path) -}) \ No newline at end of file +}) diff --git a/tests/components/normal-components/jumper-numbers-internally-connected.test.tsx b/tests/components/normal-components/jumper-numbers-internally-connected.test.tsx index 8b53257e..d0e9b2d3 100644 --- a/tests/components/normal-components/jumper-numbers-internally-connected.test.tsx +++ b/tests/components/normal-components/jumper-numbers-internally-connected.test.tsx @@ -32,7 +32,7 @@ test("jumper internallyConnectedPins with numbers should work correctly", async schX={6} schY={0} /> - + , ) await circuit.renderUntilSettled() @@ -45,17 +45,26 @@ test("jumper internallyConnectedPins with numbers should work correctly", async // Verify internal connections for JP1 (numbers) const jp1InternalPins = jp1._getInternallyConnectedPins() expect(jp1InternalPins).toHaveLength(1) - expect(jp1InternalPins[0].map((p: any) => p.props.name).sort()).toEqual(["pin1", "pin2"]) + expect(jp1InternalPins[0].map((p: any) => p.props.name).sort()).toEqual([ + "pin1", + "pin2", + ]) // Verify internal connections for JP2 (mixed) const jp2InternalPins = jp2._getInternallyConnectedPins() expect(jp2InternalPins).toHaveLength(1) - expect(jp2InternalPins[0].map((p: any) => p.props.name).sort()).toEqual(["pin1", "pin2"]) + expect(jp2InternalPins[0].map((p: any) => p.props.name).sort()).toEqual([ + "pin1", + "pin2", + ]) // Verify internal connections for JP3 (strings) const jp3InternalPins = jp3._getInternallyConnectedPins() expect(jp3InternalPins).toHaveLength(1) - expect(jp3InternalPins[0].map((p: any) => p.props.name).sort()).toEqual(["pin1", "pin2"]) + expect(jp3InternalPins[0].map((p: any) => p.props.name).sort()).toEqual([ + "pin1", + "pin2", + ]) // Verify the internallyConnectedPinNames getter processes numbers correctly expect(jp1.internallyConnectedPinNames).toEqual([["pin1", "pin2"]]) @@ -63,4 +72,4 @@ test("jumper internallyConnectedPins with numbers should work correctly", async expect(jp3.internallyConnectedPinNames).toEqual([["pin1", "pin2"]]) expect(circuit).toMatchSchematicSnapshot(import.meta.path) -}) \ No newline at end of file +})