Skip to content

Commit

Permalink
Format
Browse files Browse the repository at this point in the history
  • Loading branch information
andrii-balitskyi committed Nov 6, 2024
1 parent 63b06f8 commit cd5ea7a
Show file tree
Hide file tree
Showing 17 changed files with 119 additions and 76 deletions.
16 changes: 14 additions & 2 deletions lib/components/normal-components/Capacitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,20 @@ export class Capacitor extends NormalComponent<
}

initPorts() {
this.add(new Port({ name: "pin1", pinNumber: 1, aliases: ["anode", "pos", "left"] }))
this.add(new Port({ name: "pin2", pinNumber: 2, aliases: ["cathode", "neg", "right"] }))
this.add(
new Port({
name: "pin1",
pinNumber: 1,
aliases: ["anode", "pos", "left"],
}),
)
this.add(
new Port({
name: "pin2",
pinNumber: 2,
aliases: ["cathode", "neg", "right"],
}),
)
}

doInitialCreateNetsFromProps() {
Expand Down
12 changes: 10 additions & 2 deletions lib/components/normal-components/Diode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,18 @@ export class Diode extends NormalComponent<

initPorts() {
this.add(
new Port({ name: "pin1", pinNumber: 1, aliases: ["anode", "pos", "left"] }),
new Port({
name: "pin1",
pinNumber: 1,
aliases: ["anode", "pos", "left"],
}),
)
this.add(
new Port({ name: "pin2", pinNumber: 2, aliases: ["cathode", "neg", "right"] }),
new Port({
name: "pin2",
pinNumber: 2,
aliases: ["cathode", "neg", "right"],
}),
)
}

Expand Down
6 changes: 5 additions & 1 deletion lib/components/normal-components/Inductor.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { inductorProps } from "@tscircuit/props"
import type { SourceSimpleInductor } from "circuit-json"
import { FTYPE, type BaseSymbolName,type PassivePorts } from "lib/utils/constants"
import {
FTYPE,
type BaseSymbolName,
type PassivePorts,
} from "lib/utils/constants"
import { NormalComponent } from "../base-components/NormalComponent"
import { Port } from "../primitive-components/Port"

Expand Down
19 changes: 16 additions & 3 deletions lib/components/normal-components/Led.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,28 @@ export class Led extends NormalComponent<
get config() {
return {
componentName: "Led",
schematicSymbolName: this.props.symbolName ?? "led_horz" as BaseSymbolName,
schematicSymbolName:
this.props.symbolName ?? ("led_horz" as BaseSymbolName),
zodProps: ledProps,
sourceFtype: "simple_diode" as Ftype,
}
}

initPorts() {
this.add(new Port({ name: "pin1", pinNumber: 1, aliases: ["anode", "pos", "left"] }))
this.add(new Port({ name: "pin2", pinNumber: 2, aliases: ["cathode", "neg", "right"] }))
this.add(
new Port({
name: "pin1",
pinNumber: 1,
aliases: ["anode", "pos", "left"],
}),
)
this.add(
new Port({
name: "pin2",
pinNumber: 2,
aliases: ["cathode", "neg", "right"],
}),
)
}

pos = this.portMap.pin1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ test("chip with cadModel positionOffset", () => {
positionOffset: { x: 1, y: 2, z: 3 },
}}
/>
</board>
</board>,
)

project.render()
Expand Down
8 changes: 7 additions & 1 deletion tests/components/normal-components/inductor.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@ test("<inductor /> component", async () => {

circuit.add(
<board width="12mm" height="10mm">
<inductor name="U1" inductance="10" footprint="axial_p0.3in" pcbX={0} pcbY={0} />
<inductor
name="U1"
inductance="10"
footprint="axial_p0.3in"
pcbX={0}
pcbY={0}
/>
</board>,
)

Expand Down
18 changes: 9 additions & 9 deletions tests/components/normal-components/power-source.test.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { expect, it } from "bun:test";
import { getTestFixture } from "tests/fixtures/get-test-fixture";
import { expect, it } from "bun:test"
import { getTestFixture } from "tests/fixtures/get-test-fixture"

it("should render a power source", async () => {
const { project } = getTestFixture();
const { project } = getTestFixture()

project.add(
<board width="10mm" height="10mm">
<powersource name="pwr" voltage={5} schX={2} schY={3} pcbX={0} pcbY={0} />
</board>
);
</board>,
)

project.render();
expect(project.db.schematic_component.list()).toHaveLength(1);
expect(project.db.schematic_port.list()).toHaveLength(2);
});
project.render()
expect(project.db.schematic_component.list()).toHaveLength(1)
expect(project.db.schematic_port.list()).toHaveLength(2)
})
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
],
"edit_events": [],
"manual_trace_hints": []
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ test("Manual edits prop usage", () => {

project.add(
<board width="10mm" height="10mm" manualEdits={manualEdits}>
<resistor name="R1" resistance="100" footprint="0402"/>
<resistor name="R1" resistance="100" footprint="0402" />
</board>,
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ test("manual trace hints correctly change trace routes", async () => {
expect(traceRoute.map((p) => ("layer" in p ? p.layer : ""))).toContain(
"bottom",
)

expect(circuit.selectAll("tracehint").length).toBe(1)

expect(circuit.db.pcb_trace_hint.list().length).toBe(1)

expect(circuit.db.pcb_trace_hint.list()[0].pcb_port_id).toBeTruthy()

expect(circuit).toMatchPcbSnapshot(import.meta.path)
})
16 changes: 8 additions & 8 deletions tests/components/primitive-components/net-alias.test.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { expect, it } from "bun:test";
import { getTestFixture } from "tests/fixtures/get-test-fixture";
import { expect, it } from "bun:test"
import { getTestFixture } from "tests/fixtures/get-test-fixture"

it("should render a net alias", async () => {
const { project } = getTestFixture();
const { project } = getTestFixture()

project.add(
<board width="10mm" height="10mm">
<netalias net="net1" schX="1mm" schY="1mm" />
</board>
);
</board>,
)

project.render();
project.render()

expect(project.db.schematic_net_label.list()).toHaveLength(1);
});
expect(project.db.schematic_net_label.list()).toHaveLength(1)
})
30 changes: 15 additions & 15 deletions tests/components/primitive-components/silkscreen-rect.test.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { expect, test } from "bun:test";
import { getTestFixture } from "tests/fixtures/get-test-fixture";
import { expect, test } from "bun:test"
import { getTestFixture } from "tests/fixtures/get-test-fixture"

test("SilkscreenRect rendering", () => {
const { project } = getTestFixture();
const { project } = getTestFixture()
project.add(
<board width="10mm" height="10mm">
<silkscreenrect
Expand All @@ -12,18 +12,18 @@ test("SilkscreenRect rendering", () => {
height={"1.5mm"}
layer="bottom"
/>
</board>
);
project.render();
</board>,
)
project.render()

const silkscreenRects = project.db.pcb_silkscreen_rect.list();
const silkscreenRects = project.db.pcb_silkscreen_rect.list()

expect(silkscreenRects.length).toBe(1);
expect(silkscreenRects[0].center.x).toBe(2);
expect(silkscreenRects[0].center.y).toBe(3);
expect(silkscreenRects[0].width).toBe(2);
expect(silkscreenRects[0].height).toBe(1.5);
expect(silkscreenRects[0].layer).toBe("bottom");
expect(silkscreenRects.length).toBe(1)
expect(silkscreenRects[0].center.x).toBe(2)
expect(silkscreenRects[0].center.y).toBe(3)
expect(silkscreenRects[0].width).toBe(2)
expect(silkscreenRects[0].height).toBe(1.5)
expect(silkscreenRects[0].layer).toBe("bottom")

expect(project).toMatchPcbSnapshot(import.meta.path);
});
expect(project).toMatchPcbSnapshot(import.meta.path)
})
8 changes: 4 additions & 4 deletions tests/components/primitive-components/silkscreenpath.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ test("SilkscreenPath rendering", () => {
route={[
{ x: "0mm", y: "0mm" },
{ x: "5mm", y: "5mm" },
{ x: "10mm", y: "0mm" }
{ x: "10mm", y: "0mm" },
]}
strokeWidth="0.2mm"
layer="top"
/>
</board>
</board>,
)

project.render()
Expand All @@ -25,11 +25,11 @@ test("SilkscreenPath rendering", () => {
expect(silkscreenPaths.length).toBe(1)
expect(silkscreenPaths[0].layer).toBe("top")
expect(silkscreenPaths[0].stroke_width).toBe(0.2)

expect(silkscreenPaths[0].route).toEqual([
{ x: 0, y: 0 },
{ x: 5, y: 5 },
{ x: 10, y: 0 }
{ x: 10, y: 0 },
])

expect(silkscreenPaths[0].pcb_silkscreen_path_id).toBeTruthy()
Expand Down
22 changes: 11 additions & 11 deletions tests/components/primitive-components/via.test.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { expect, it } from "bun:test";
import type { Via } from "lib/components";
import { getTestFixture } from "tests/fixtures/get-test-fixture";
import { expect, it } from "bun:test"
import type { Via } from "lib/components"
import { getTestFixture } from "tests/fixtures/get-test-fixture"

it("should create a Via component with correct properties", () => {
const { project } = getTestFixture();
const { project } = getTestFixture()

project.add(
<board width="10mm" height="10mm">
Expand All @@ -15,15 +15,15 @@ it("should create a Via component with correct properties", () => {
fromLayer="top"
toLayer="bottom"
/>
</board>
);
</board>,
)

project.render();
project.render()

expect(project).toMatchPcbSnapshot(import.meta.path)

const via = project.selectOne("via") as Via;
const via = project.selectOne("via") as Via

expect(via).not.toBeNull();
expect(via.props.pcbX).toBe("0mm");
});
expect(via).not.toBeNull()
expect(via.props.pcbX).toBe("0mm")
})
2 changes: 1 addition & 1 deletion tests/examples/bug-high-port-number.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ test("bug high port number", async () => {
width={10}
height={10}
// @ts-ignore
// _schDebugObjectsEnabled
// _schDebugObjectsEnabled
>
<chip
name="U1"
Expand Down
26 changes: 13 additions & 13 deletions tests/readme.test.tsx
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
import { expect, it } from "bun:test";
import "lib/register-catalogue";
import { Board, Circuit } from "../index";
import { expect, it } from "bun:test"
import "lib/register-catalogue"
import { Board, Circuit } from "../index"

it("should create soup with various elements", () => {
const project = new Circuit();
const project = new Circuit()

const board = new Board({
width: "10mm",
height: "10mm",
});
project.add(board);
})
project.add(board)

const R1 = <resistor name="R1" resistance="10k" footprint="0402" />;
board.add(R1);
const R1 = <resistor name="R1" resistance="10k" footprint="0402" />
board.add(R1)

board.add(<led name="LED1" footprint="0402" />);
board.add(<led name="LED1" footprint="0402" />)

project.render();
project.render()

// Let's check the db to make sure everything we expect is there

expect(project.db.source_component.select(".R1")?.name).toBe("R1");
expect(project.db.source_component.select(".R1")?.name).toBe("R1")
// expect(project.db.source_component.select(".LED1")?.name).toBe("LED1")

expect(project.db.pcb_smtpad.list()).toHaveLength(4);
expect(project.db.pcb_smtpad.list()).toHaveLength(4)

// console.log("pcb_trace", project.db.pcb_trace.list())

// console.log(project.getSoup())
});
})
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"baseUrl": ".",

"paths": {
"lib/*": ["lib/*"],
"lib/*": ["lib/*"]
},

// Bundler mode
Expand Down

0 comments on commit cd5ea7a

Please sign in to comment.