feat: add courtyardrect element generation#17
Conversation
| test("test pcb_courtyard_rect conversion - basic courtyard", async () => { | ||
| const circuitJson: AnyCircuitElement[] = [ | ||
| { | ||
| type: "pcb_smtpad", | ||
| pcb_smtpad_id: "pad1", | ||
| shape: "rect", | ||
| x: -1, | ||
| y: 0, | ||
| width: 0.6, | ||
| height: 0.8, | ||
| layer: "top", | ||
| pcb_component_id: "comp1", | ||
| pcb_port_id: "port1", | ||
| port_hints: ["1", "left"], | ||
| }, | ||
| { | ||
| type: "pcb_smtpad", | ||
| pcb_smtpad_id: "pad2", | ||
| shape: "rect", | ||
| x: 1, | ||
| y: 0, | ||
| width: 0.6, | ||
| height: 0.8, | ||
| layer: "top", | ||
| pcb_component_id: "comp1", | ||
| pcb_port_id: "port2", | ||
| port_hints: ["2", "right"], | ||
| }, | ||
| { | ||
| type: "pcb_courtyard_rect", | ||
| pcb_courtyard_rect_id: "courtyard1", | ||
| center: { x: 0, y: 0 }, | ||
| width: 3, | ||
| height: 2, | ||
| layer: "top", | ||
| stroke_width: 0.1, | ||
| pcb_component_id: "comp1", | ||
| }, | ||
| ] | ||
|
|
||
| const tscircuit = convertCircuitJsonToTscircuit(circuitJson, { | ||
| componentName: "ComponentWithCourtyard", | ||
| }) | ||
|
|
||
| expect(tscircuit).toMatchInlineSnapshot(` | ||
| "import { type ChipProps } from "tscircuit" | ||
| export const ComponentWithCourtyard = (props: ChipProps) => ( | ||
| <chip | ||
| footprint={<footprint> | ||
| <smtpad portHints={["1","left"]} pcbX="-1mm" pcbY="0mm" width="0.6mm" height="0.8mm" shape="rect" /> | ||
| <smtpad portHints={["2","right"]} pcbX="1mm" pcbY="0mm" width="0.6mm" height="0.8mm" shape="rect" /> | ||
| <courtyardrect pcbX="0mm" pcbY="0mm" width="3mm" height="2mm" layer="top" /> | ||
| </footprint>} | ||
| {...props} | ||
| /> | ||
| )" | ||
| `) | ||
| }) | ||
|
|
||
| test("test pcb_courtyard_rect conversion - multiple courtyards different layers", async () => { | ||
| const circuitJson: AnyCircuitElement[] = [ | ||
| { | ||
| type: "pcb_smtpad", | ||
| pcb_smtpad_id: "pad1", | ||
| shape: "rect", | ||
| x: 0, | ||
| y: 0, | ||
| width: 1, | ||
| height: 1, | ||
| layer: "top", | ||
| pcb_component_id: "comp1", | ||
| pcb_port_id: "port1", | ||
| port_hints: ["1"], | ||
| }, | ||
| { | ||
| type: "pcb_courtyard_rect", | ||
| pcb_courtyard_rect_id: "courtyard1", | ||
| center: { x: 0, y: 0 }, | ||
| width: 2.5, | ||
| height: 2.5, | ||
| layer: "top", | ||
| stroke_width: 0.1, | ||
| pcb_component_id: "comp1", | ||
| }, | ||
| { | ||
| type: "pcb_courtyard_rect", | ||
| pcb_courtyard_rect_id: "courtyard2", | ||
| center: { x: 0, y: 0 }, | ||
| width: 3, | ||
| height: 3, | ||
| layer: "bottom", | ||
| stroke_width: 0.1, | ||
| pcb_component_id: "comp1", | ||
| }, | ||
| ] | ||
|
|
||
| const tscircuit = convertCircuitJsonToTscircuit(circuitJson, { | ||
| componentName: "ComponentWithMultipleCourtyards", | ||
| }) | ||
|
|
||
| expect(tscircuit).toMatchInlineSnapshot(` | ||
| "import { type ChipProps } from "tscircuit" | ||
| export const ComponentWithMultipleCourtyards = (props: ChipProps) => ( | ||
| <chip | ||
| footprint={<footprint> | ||
| <smtpad portHints={["1"]} pcbX="0mm" pcbY="0mm" width="1mm" height="1mm" shape="rect" /> | ||
| <courtyardrect pcbX="0mm" pcbY="0mm" width="2.5mm" height="2.5mm" layer="top" /> | ||
| <courtyardrect pcbX="0mm" pcbY="0mm" width="3mm" height="3mm" layer="bottom" /> | ||
| </footprint>} | ||
| {...props} | ||
| /> | ||
| )" | ||
| `) | ||
| }) | ||
|
|
||
| test("test pcb_courtyard_rect conversion - offset courtyard", async () => { | ||
| const circuitJson: AnyCircuitElement[] = [ | ||
| { | ||
| type: "pcb_plated_hole", | ||
| pcb_plated_hole_id: "hole1", | ||
| shape: "circle", | ||
| outer_diameter: 1.5, | ||
| hole_diameter: 0.8, | ||
| x: -2.54, | ||
| y: 0, | ||
| layers: ["top", "bottom"], | ||
| pcb_component_id: "comp1", | ||
| pcb_port_id: "port1", | ||
| port_hints: ["1"], | ||
| }, | ||
| { | ||
| type: "pcb_plated_hole", | ||
| pcb_plated_hole_id: "hole2", | ||
| shape: "circle", | ||
| outer_diameter: 1.5, | ||
| hole_diameter: 0.8, | ||
| x: 2.54, | ||
| y: 0, | ||
| layers: ["top", "bottom"], | ||
| pcb_component_id: "comp1", | ||
| pcb_port_id: "port2", | ||
| port_hints: ["2"], | ||
| }, | ||
| { | ||
| type: "pcb_courtyard_rect", | ||
| pcb_courtyard_rect_id: "courtyard1", | ||
| center: { x: 0, y: 0 }, | ||
| width: 6.5, | ||
| height: 3.5, | ||
| layer: "top", | ||
| stroke_width: 0.1, | ||
| pcb_component_id: "comp1", | ||
| }, | ||
| ] | ||
|
|
||
| const tscircuit = convertCircuitJsonToTscircuit(circuitJson, { | ||
| componentName: "ComponentWithOffsetCourtyard", | ||
| }) | ||
|
|
||
| expect(tscircuit).toMatchInlineSnapshot(` | ||
| "import { type ChipProps } from "tscircuit" | ||
| export const ComponentWithOffsetCourtyard = (props: ChipProps) => ( | ||
| <chip | ||
| footprint={<footprint> | ||
| <platedhole portHints={["1"]} pcbX="-2.54mm" pcbY="0mm" outerDiameter="1.5mm" holeDiameter="0.8mm" shape="circle" /> | ||
| <platedhole portHints={["2"]} pcbX="2.54mm" pcbY="0mm" outerDiameter="1.5mm" holeDiameter="0.8mm" shape="circle" /> | ||
| <courtyardrect pcbX="0mm" pcbY="0mm" width="6.5mm" height="3.5mm" layer="top" /> | ||
| </footprint>} | ||
| {...props} | ||
| /> | ||
| )" | ||
| `) | ||
| }) | ||
|
|
||
| test("test pcb_courtyard_rect conversion - courtyard without layer defaults to top", async () => { | ||
| const circuitJson: AnyCircuitElement[] = [ | ||
| { | ||
| type: "pcb_smtpad", | ||
| pcb_smtpad_id: "pad1", | ||
| shape: "rect", | ||
| x: 0, | ||
| y: 0, | ||
| width: 1, | ||
| height: 1, | ||
| layer: "top", | ||
| pcb_component_id: "comp1", | ||
| pcb_port_id: "port1", | ||
| port_hints: ["1"], | ||
| }, | ||
| { | ||
| type: "pcb_courtyard_rect", | ||
| pcb_courtyard_rect_id: "courtyard1", | ||
| center: { x: 0, y: 0 }, | ||
| width: 2, | ||
| height: 2, | ||
| layer: "top", | ||
| stroke_width: 0.1, | ||
| pcb_component_id: "comp1", | ||
| }, | ||
| ] | ||
|
|
||
| const tscircuit = convertCircuitJsonToTscircuit(circuitJson, { | ||
| componentName: "ComponentWithDefaultLayerCourtyard", | ||
| }) | ||
|
|
||
| expect(tscircuit).toMatchInlineSnapshot(` | ||
| "import { type ChipProps } from "tscircuit" | ||
| export const ComponentWithDefaultLayerCourtyard = (props: ChipProps) => ( | ||
| <chip | ||
| footprint={<footprint> | ||
| <smtpad portHints={["1"]} pcbX="0mm" pcbY="0mm" width="1mm" height="1mm" shape="rect" /> | ||
| <courtyardrect pcbX="0mm" pcbY="0mm" width="2mm" height="2mm" layer="top" /> | ||
| </footprint>} | ||
| {...props} | ||
| /> | ||
| )" | ||
| `) | ||
| }) |
There was a problem hiding this comment.
This test file violates the constraint that each *.test.ts file may contain at most one test(...) function. The file currently contains 4 test functions on lines 11, 70, 126, and 185. Split this file into separate numbered files: test7-support-courtyards1.test.tsx, test7-support-courtyards2.test.tsx, test7-support-courtyards3.test.tsx, and test7-support-courtyards4.test.tsx, with each file containing exactly one test function.
Spotted by Graphite Agent (based on custom rule: Custom rule)
Is this helpful? React 👍 or 👎 to let us know.
66f6b12 to
f473a15
Compare
| componentName: "Test7Component", | ||
| }) | ||
|
|
||
| expect(tscircuit).toMatchInlineSnapshot(` |
There was a problem hiding this comment.
please run the code in the test using runTscircuitCode or whatever to verify it is correct
There was a problem hiding this comment.
correct meaning runnable etc.
Summary
Testing