-
Notifications
You must be signed in to change notification settings - Fork 118
Support standard=usb_c for connector using parts-engine #2090
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 7 commits
239db37
3f9ef44
7d9b937
514d1de
9042b56
356f67d
a085bdf
281d9f0
80b8d23
7c79789
df72a64
a2aa513
c4dd580
e5775a1
20324be
52e8732
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -992,6 +992,10 @@ export class NormalComponent< | |
| this.initPorts() | ||
| } | ||
|
|
||
| updateInitializePortsFromChildren(): void { | ||
| this.initPorts() | ||
MustafaMulla29 marked this conversation as resolved.
Show resolved
Hide resolved
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i suspect you don't need this because there's no need to mark this phase dirty because of the render order
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tests are failing if I remove this, I think if we remove this, then it requires a broader changes in other files |
||
| } | ||
|
|
||
| doInitialReactSubtreesRender(): void { | ||
| // Add React-based footprint subtree if provided | ||
| const fpElm = this.props.footprint | ||
|
|
@@ -1551,7 +1555,7 @@ export class NormalComponent< | |
| }) | ||
| } | ||
|
|
||
| private async _getSupplierPartNumbers( | ||
| protected async _getSupplierPartNumbers( | ||
| partsEngine: any, | ||
| source_component: any, | ||
| footprinterString: string | undefined, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| import { test, expect } from "bun:test" | ||
| import type { PartsEngine } from "@tscircuit/props" | ||
| import { getTestFixture } from "tests/fixtures/get-test-fixture" | ||
|
|
||
| test("connector usb_c leaves footprint empty when supplier and manufacturer circuit json are not found", async () => { | ||
| const { circuit } = getTestFixture() | ||
| const calls: Array<{ | ||
| supplierPartNumber?: string | ||
| manufacturerPartNumber?: string | ||
| }> = [] | ||
|
|
||
| const mockPartsEngine: PartsEngine = { | ||
| findPart: async () => ({ jlcpcb: ["C165948"] }), | ||
| fetchPartCircuitJson: async ({ | ||
| supplierPartNumber, | ||
| manufacturerPartNumber, | ||
| }: { | ||
| supplierPartNumber?: string | ||
| manufacturerPartNumber?: string | ||
| }) => { | ||
| calls.push({ supplierPartNumber, manufacturerPartNumber }) | ||
| return undefined | ||
| }, | ||
| } | ||
|
|
||
| circuit.add( | ||
| <board partsEngine={mockPartsEngine} width="20mm" height="20mm"> | ||
| <connector | ||
| name="USB1" | ||
| standard="usb_c" | ||
| manufacturerPartNumber="USB4135-GF-A" | ||
| /> | ||
| </board>, | ||
| ) | ||
|
|
||
| await circuit.renderUntilSettled() | ||
|
|
||
| expect(calls).toEqual([ | ||
| { supplierPartNumber: "C165948", manufacturerPartNumber: undefined }, | ||
| { supplierPartNumber: undefined, manufacturerPartNumber: "USB4135-GF-A" }, | ||
| ]) | ||
|
|
||
| const sourceComponent = circuit.db.source_component | ||
| .list() | ||
| .find((c: any) => c.name === "USB1") | ||
| expect(sourceComponent).toBeTruthy() | ||
| expect(sourceComponent!.supplier_part_numbers).toEqual({ | ||
| jlcpcb: ["C165948"], | ||
| }) | ||
|
|
||
| expect(circuit.db.pcb_smtpad.list().length).toBe(0) | ||
| expect(circuit.db.unknown_error_finding_part.list().length).toBe(0) | ||
| }) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| import { test, expect } from "bun:test" | ||
| import type { PartsEngine } from "@tscircuit/props" | ||
| import { getTestFixture } from "tests/fixtures/get-test-fixture" | ||
|
|
||
| test("connector with standard='usb_c' handles findPart returning 'Not found' without creating footprint", async () => { | ||
| const { circuit } = getTestFixture() | ||
| let fetchCalls = 0 | ||
|
|
||
| const mockPartsEngine: PartsEngine = { | ||
| findPart: async () => "Not found", | ||
| fetchPartCircuitJson: async () => { | ||
| fetchCalls++ | ||
| return undefined | ||
| }, | ||
| } as any | ||
|
|
||
| circuit.add( | ||
| <board partsEngine={mockPartsEngine} width="20mm" height="20mm"> | ||
| <connector name="USB1" standard="usb_c" /> | ||
| </board>, | ||
| ) | ||
|
|
||
| await circuit.renderUntilSettled() | ||
|
|
||
| const sourceComponent = circuit.db.source_component | ||
| .list() | ||
| .find((c: any) => c.name === "USB1") | ||
| expect(sourceComponent).toBeTruthy() | ||
| expect(sourceComponent!.supplier_part_numbers).toEqual({}) | ||
|
|
||
| expect(fetchCalls).toBe(0) | ||
| expect(circuit.db.pcb_smtpad.list().length).toBe(0) | ||
| expect(circuit.db.unknown_error_finding_part.list().length).toBe(0) | ||
| }) |
Uh oh!
There was an error while loading. Please reload this page.