-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathcheck-connector-accessible-orientation.test.tsx
More file actions
144 lines (136 loc) · 3.89 KB
/
Copy pathcheck-connector-accessible-orientation.test.tsx
File metadata and controls
144 lines (136 loc) · 3.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
import { expect, test } from "bun:test"
import { convertCircuitJsonToPcbSvg } from "circuit-to-svg"
import { Circuit } from "tscircuit"
import { checkConnectorAccessibleOrientation } from "lib/check-connector-accessible-orientation"
const TYPE_C_6P_FOOTPRINT = (
<footprint>
<platedhole
portHints={["pin7"]}
pcbX="4.319904999999949mm"
pcbY="-2.300014400000009mm"
holeWidth="0.5999987999999999mm"
holeHeight="1.3999972mm"
outerWidth="1.0999978mm"
outerHeight="1.8999962mm"
shape="pill"
/>
<platedhole
portHints={["pin8"]}
pcbX="-4.3199050000000625mm"
pcbY="-2.300014400000009mm"
holeWidth="0.5999987999999999mm"
holeHeight="1.3999972mm"
outerWidth="1.0999978mm"
outerHeight="1.8999962mm"
shape="pill"
/>
<platedhole
portHints={["pin9"]}
pcbX="4.319904999999949mm"
pcbY="1.5000795999999355mm"
holeWidth="0.5999987999999999mm"
holeHeight="1.3999972mm"
outerWidth="1.0999978mm"
outerHeight="1.8999962mm"
shape="pill"
/>
<platedhole
portHints={["pin10"]}
pcbX="-4.3199050000000625mm"
pcbY="1.5000795999999355mm"
holeWidth="0.5999987999999999mm"
holeHeight="1.3999972mm"
outerWidth="1.0999978mm"
outerHeight="1.8999962mm"
shape="pill"
/>
<smtpad
portHints={["pin11"]}
pcbX="-2.6998930000000883mm"
pcbY="1.7500155999998697mm"
width="0.7999983999999999mm"
height="1.1999975999999999mm"
shape="rect"
/>
<smtpad
portHints={["pin12"]}
pcbX="-1.4999970000001213mm"
pcbY="1.7500155999998697mm"
width="0.6999986mm"
height="1.1999975999999999mm"
shape="rect"
/>
<smtpad
portHints={["pin13"]}
pcbX="-0.4999990000001162mm"
pcbY="1.7500155999998697mm"
width="0.6999986mm"
height="1.1999975999999999mm"
shape="rect"
/>
<smtpad
portHints={["pin14"]}
pcbX="0.4999990000000025mm"
pcbY="1.7500155999998697mm"
width="0.6999986mm"
height="1.1999975999999999mm"
shape="rect"
/>
<smtpad
portHints={["pin15"]}
pcbX="1.4999970000000076mm"
pcbY="1.7500155999998697mm"
width="0.6999986mm"
height="1.1999975999999999mm"
shape="rect"
/>
<smtpad
portHints={["pin16"]}
pcbX="2.6998929999999746mm"
pcbY="1.7500155999998697mm"
width="0.7999983999999999mm"
height="1.1999975999999999mm"
shape="rect"
/>
</footprint>
)
test("connector orientation warning is emitted when cable insertion points inward", async () => {
const circuit = new Circuit()
circuit.add(
<board width="30mm" height="20mm" routingDisabled>
<connector
name="J1"
pcbX="-13mm"
pcbY="0mm"
footprint={TYPE_C_6P_FOOTPRINT}
pinLabels={{ 1: ["A"], 2: ["B"] }}
/>
</board>,
)
await circuit.renderUntilSettled()
const circuitJson = circuit.getCircuitJson()
const warnings = checkConnectorAccessibleOrientation(circuitJson as any)
expect(warnings).toHaveLength(1)
expect(warnings[0]).toMatchObject({
type: "pcb_connector_not_in_accessible_orientation_warning",
facing_direction: "y-",
recommended_facing_direction: "x-",
})
expect(
convertCircuitJsonToPcbSvg([...circuitJson, ...warnings] as any, {
shouldDrawErrors: true,
}),
).toMatchSvgSnapshot(import.meta.path)
})
test("connector orientation check skips components without cable_insertion_center", async () => {
const circuit = new Circuit()
circuit.add(
<board width="30mm" height="20mm" routingDisabled>
<chip name="U1" pcbX="10mm" pcbY="0mm" pinLabels={{ 1: ["P1"] }} />
</board>,
)
await circuit.renderUntilSettled()
const circuitJson = circuit.getCircuitJson()
const warnings = checkConnectorAccessibleOrientation(circuitJson as any)
expect(warnings).toHaveLength(0)
})