|
| 1 | +import { test, expect } from "bun:test" |
| 2 | +import { runTscircuitCode } from "tscircuit" |
| 3 | +import { getGraphicsForBpcGraph } from "bpc-graph" |
| 4 | +import { convertCircuitJsonToBpc } from "../lib" |
| 5 | +import { getSvgFromGraphicsObject } from "graphics-debug" |
| 6 | + |
| 7 | +test("example04", async () => { |
| 8 | + const circuitJson = await runTscircuitCode(` |
| 9 | + export default () => ( |
| 10 | + <board width="10mm" height="10mm"> |
| 11 | + <resistor |
| 12 | + resistance="1k" |
| 13 | + footprint="0402" |
| 14 | + name="R1" |
| 15 | + schX={3} |
| 16 | + pcbX={3} |
| 17 | + /> |
| 18 | + <capacitor |
| 19 | + capacitance="1000pF" |
| 20 | + footprint="0402" |
| 21 | + name="C1" |
| 22 | + schX={-3} |
| 23 | + pcbX={-3} |
| 24 | + /> |
| 25 | + <trace from=".R1 > .pin1" to=".C1 > .pin2" /> |
| 26 | + </board> |
| 27 | + ) |
| 28 | + `) |
| 29 | + |
| 30 | + const bpc = convertCircuitJsonToBpc(circuitJson) |
| 31 | + |
| 32 | + const graphics = getGraphicsForBpcGraph(bpc) |
| 33 | + |
| 34 | + expect(bpc).toMatchInlineSnapshot(` |
| 35 | + { |
| 36 | + "boxes": [ |
| 37 | + { |
| 38 | + "boxId": "schematic_component_0", |
| 39 | + "center": { |
| 40 | + "x": 3, |
| 41 | + "y": 0, |
| 42 | + }, |
| 43 | + "kind": "floating", |
| 44 | + }, |
| 45 | + { |
| 46 | + "boxId": "schematic_component_1", |
| 47 | + "center": { |
| 48 | + "x": -3, |
| 49 | + "y": 0, |
| 50 | + }, |
| 51 | + "kind": "floating", |
| 52 | + }, |
| 53 | + ], |
| 54 | + "pins": [ |
| 55 | + { |
| 56 | + "boxId": "schematic_component_0", |
| 57 | + "color": "component_center", |
| 58 | + "networkId": "center_schematic_component_0", |
| 59 | + "offset": { |
| 60 | + "x": 0, |
| 61 | + "y": 0, |
| 62 | + }, |
| 63 | + "pinId": "schematic_component_0_center", |
| 64 | + }, |
| 65 | + { |
| 66 | + "boxId": "schematic_component_0", |
| 67 | + "color": "normal", |
| 68 | + "networkId": "unnamedsubcircuit31_connectivity_net0", |
| 69 | + "offset": { |
| 70 | + "x": -0.5512907, |
| 71 | + "y": 0.0002732499999993365, |
| 72 | + }, |
| 73 | + "pinId": "schematic_port_0", |
| 74 | + }, |
| 75 | + { |
| 76 | + "boxId": "schematic_component_0", |
| 77 | + "color": "not_connected", |
| 78 | + "networkId": "disconnected-0", |
| 79 | + "offset": { |
| 80 | + "x": 0.5512907000000005, |
| 81 | + "y": -0.0002732499999993365, |
| 82 | + }, |
| 83 | + "pinId": "schematic_port_1", |
| 84 | + }, |
| 85 | + { |
| 86 | + "boxId": "schematic_component_1", |
| 87 | + "color": "component_center", |
| 88 | + "networkId": "center_schematic_component_1", |
| 89 | + "offset": { |
| 90 | + "x": 0, |
| 91 | + "y": 0, |
| 92 | + }, |
| 93 | + "pinId": "schematic_component_1_center", |
| 94 | + }, |
| 95 | + { |
| 96 | + "boxId": "schematic_component_1", |
| 97 | + "color": "not_connected", |
| 98 | + "networkId": "disconnected-1", |
| 99 | + "offset": { |
| 100 | + "x": -0.5512093000000005, |
| 101 | + "y": -0.00027334999999961695, |
| 102 | + }, |
| 103 | + "pinId": "schematic_port_2", |
| 104 | + }, |
| 105 | + { |
| 106 | + "boxId": "schematic_component_1", |
| 107 | + "color": "normal", |
| 108 | + "networkId": "unnamedsubcircuit31_connectivity_net0", |
| 109 | + "offset": { |
| 110 | + "x": 0.5512093, |
| 111 | + "y": 0.00027334999999961695, |
| 112 | + }, |
| 113 | + "pinId": "schematic_port_3", |
| 114 | + }, |
| 115 | + ], |
| 116 | + } |
| 117 | + `) |
| 118 | + |
| 119 | + expect( |
| 120 | + getSvgFromGraphicsObject(graphics, { |
| 121 | + backgroundColor: "white", |
| 122 | + }), |
| 123 | + ).toMatchSvgSnapshot(import.meta.path) |
| 124 | +}) |
0 commit comments