-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0ff80bc
commit 7dc292f
Showing
4 changed files
with
146 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
tests/components/normal-components/board-auto-size.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import { test, expect } from "bun:test" | ||
import { getTestFixture } from "tests/fixtures/get-test-fixture" | ||
|
||
test("board auto-sizes when no dimensions provided", () => { | ||
const { circuit } = getTestFixture() | ||
|
||
circuit.add( | ||
<board> | ||
<resistor name="R1" resistance="10k" footprint="0402" pcbX={5} pcbY={5} /> | ||
<capacitor | ||
name="C1" | ||
capacitance="10uF" | ||
footprint="0603" | ||
pcbX={-5} | ||
pcbY={-5} | ||
/> | ||
</board>, | ||
) | ||
|
||
circuit.render() | ||
|
||
const pcb_board = circuit.db.pcb_board.list()[0] | ||
|
||
// Board should be larger than component bounds | ||
expect(pcb_board.width).toBeGreaterThan(10) | ||
expect(pcb_board.height).toBeGreaterThan(10) | ||
}) | ||
|
||
test("board respects explicit dimensions", () => { | ||
const { circuit } = getTestFixture() | ||
circuit.add( | ||
<board width="50mm" height="50mm"> | ||
<resistor name="R1" resistance="10k" footprint="0402" pcbX={5} pcbY={5} /> | ||
</board>, | ||
) | ||
circuit.render() | ||
const pcb_board = circuit.db.pcb_board.list()[0] | ||
expect(pcb_board.width).toBe(50) | ||
expect(pcb_board.height).toBe(50) | ||
}) | ||
|
||
test("board auto-sizes with nested components", () => { | ||
const { circuit } = getTestFixture() | ||
circuit.add( | ||
<board> | ||
<resistor | ||
name="R1" | ||
resistance="10k" | ||
footprint="0402" | ||
pcbX={10} | ||
pcbY={10} | ||
/> | ||
<resistor | ||
name="R2" | ||
resistance="10k" | ||
footprint="0402" | ||
pcbX={-10} | ||
pcbY={-10} | ||
/> | ||
</board>, | ||
) | ||
circuit.render() | ||
const pcb_board = circuit.db.pcb_board.list()[0] | ||
|
||
// Should be at least 20mm (component spread) + padding | ||
expect(pcb_board.width).toBeGreaterThan(22) | ||
expect(pcb_board.height).toBeGreaterThan(22) | ||
}) | ||
|
||
test("board centers around components", () => { | ||
const { circuit } = getTestFixture() | ||
circuit.add( | ||
<board> | ||
<resistor name="R1" resistance="10k" footprint="0402" pcbX={5} pcbY={0} /> | ||
</board>, | ||
) | ||
circuit.render() | ||
const pcb_board = circuit.db.pcb_board.list()[0] | ||
expect(pcb_board.center.x).toBe(5) | ||
expect(pcb_board.center.y).toBe(0) | ||
}) |