-
Notifications
You must be signed in to change notification settings - Fork 78
Bug: fix for Undefined behaviour for unnamed chips (pun intended) #1470
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
Open
codecraft26
wants to merge
3
commits into
tscircuit:main
Choose a base branch
from
codecraft26:issue-#1467
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+301
−18
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
133 changes: 133 additions & 0 deletions
133
tests/components/normal-components/unnamed-component-naming.test.tsx
This file contains hidden or 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,133 @@ | ||
import { it, expect } from "bun:test" | ||
import { RootCircuit } from "lib/RootCircuit" | ||
import { Chip } from "lib/components/normal-components/Chip" | ||
import "lib/register-catalogue" | ||
import { getTestFixture } from "tests/fixtures/get-test-fixture" | ||
|
||
it("should not return undefined for component names", async () => { | ||
const { circuit } = getTestFixture() | ||
|
||
circuit.add( | ||
<board width="10mm" height="10mm"> | ||
<chip | ||
name="U1" | ||
footprint="soic8" | ||
pinLabels={{ | ||
"1": "VCC", | ||
"8": "GND", | ||
}} | ||
schPinArrangement={{ | ||
leftSize: 4, | ||
rightSize: 4, | ||
}} | ||
/> | ||
</board>, | ||
) | ||
|
||
circuit.render() | ||
|
||
const chip = circuit.selectOne("chip") as Chip | ||
|
||
expect(chip).not.toBeNull() | ||
expect(chip.name).toBeDefined() | ||
expect(typeof chip.name).toBe("string") | ||
expect(chip.name).not.toBe("undefined") | ||
expect(chip.name).toBe("U1") | ||
}) | ||
|
||
it("should handle components with undefined names gracefully", async () => { | ||
const { circuit } = getTestFixture() | ||
|
||
circuit.add( | ||
<board width="10mm" height="10mm"> | ||
<chip | ||
name={undefined as any} | ||
footprint="soic8" | ||
pinLabels={{ | ||
"1": "VCC", | ||
"8": "GND", | ||
}} | ||
schPinArrangement={{ | ||
leftSize: 4, | ||
rightSize: 4, | ||
}} | ||
/> | ||
</board>, | ||
) | ||
|
||
circuit.render() | ||
|
||
const chip = circuit.selectOne("chip") as Chip | ||
|
||
expect(chip).not.toBeNull() | ||
expect(chip.name).toBeDefined() | ||
expect(typeof chip.name).toBe("string") | ||
expect(chip.name).not.toBe("undefined") | ||
expect(chip.name).toMatch(/^unnamed_chip\d+$/) | ||
}) | ||
|
||
it("should handle components with empty string names", async () => { | ||
const { circuit } = getTestFixture() | ||
|
||
circuit.add( | ||
<board width="10mm" height="10mm"> | ||
<chip | ||
name="" | ||
footprint="soic8" | ||
pinLabels={{ | ||
"1": "VCC", | ||
"8": "GND", | ||
}} | ||
schPinArrangement={{ | ||
leftSize: 4, | ||
rightSize: 4, | ||
}} | ||
/> | ||
</board>, | ||
) | ||
|
||
circuit.render() | ||
|
||
const chip = circuit.selectOne("chip") as Chip | ||
|
||
expect(chip).not.toBeNull() | ||
expect(chip.name).toBeDefined() | ||
expect(typeof chip.name).toBe("string") | ||
expect(chip.name).not.toBe("undefined") | ||
expect(chip.name).not.toBe("") | ||
expect(chip.name).toMatch(/^unnamed_chip\d+$/) | ||
}) | ||
|
||
it("should handle components with whitespace-only names", async () => { | ||
const { circuit } = getTestFixture() | ||
|
||
circuit.add( | ||
<board width="10mm" height="10mm"> | ||
<chip | ||
name=" " | ||
footprint="soic8" | ||
pinLabels={{ | ||
"1": "VCC", | ||
"8": "GND", | ||
}} | ||
schPinArrangement={{ | ||
leftSize: 4, | ||
rightSize: 4, | ||
}} | ||
/> | ||
</board>, | ||
) | ||
|
||
circuit.render() | ||
|
||
const chip = circuit.selectOne("chip") as Chip | ||
|
||
expect(chip).not.toBeNull() | ||
expect(chip.name).toBeDefined() | ||
expect(typeof chip.name).toBe("string") | ||
expect(chip.name).not.toBe("undefined") | ||
expect(chip.name).not.toBe(" ") | ||
// The component should have a valid name (not undefined) | ||
// Note: The exact format may vary depending on render phase timing | ||
expect(chip.name).toMatch(/^unnamed_chip/) | ||
}) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test file violates the established rule that a
*.test.ts
file may contain at most onetest(...)
function. When additional tests are needed, they must be split into separate numbered files (e.g.,add1.test.ts
,add2.test.ts
). The current file already contains one test before line 91, and this modification adds two additional test functions:should assign consistent names to unnamed chips
(lines 91-153) andshould handle chips with empty string names
(lines 155-203). These additional tests must be moved to separate numbered files such aschip2.test.tsx
andchip3.test.tsx
.Spotted by Graphite Agent (based on custom rule: Custom rule)

Is this helpful? React 👍 or 👎 to let us know.