-
Notifications
You must be signed in to change notification settings - Fork 0
feat: emit textAutoResize and text truncation in design tree #217
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
Merged
+200
−0
Merged
Changes from all commits
Commits
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1089,4 +1089,168 @@ describe("generateDesignTree", () => { | |
| expect(output).not.toContain("url(images/"); | ||
| }); | ||
| }); | ||
|
|
||
| describe("text auto-resize and truncation", () => { | ||
| it("emits text-resize: auto for WIDTH_AND_HEIGHT", () => { | ||
| const file = makeFile( | ||
| makeNode({ | ||
| id: "1:1", | ||
| name: "Title", | ||
| type: "TEXT", | ||
| characters: "Hello", | ||
| style: { fontFamily: "Inter", textAutoResize: "WIDTH_AND_HEIGHT" }, | ||
| absoluteBoundingBox: { x: 0, y: 0, width: 100, height: 20 }, | ||
| }) | ||
| ); | ||
|
|
||
| const output = generateDesignTree(file); | ||
|
|
||
| expect(output).toContain("text-resize: auto"); | ||
| }); | ||
|
|
||
| it("emits text-resize: fixed-height for HEIGHT", () => { | ||
| const file = makeFile( | ||
| makeNode({ | ||
| id: "1:1", | ||
| name: "Body", | ||
| type: "TEXT", | ||
| characters: "Wrapped text", | ||
| style: { fontFamily: "Inter", textAutoResize: "HEIGHT" }, | ||
| absoluteBoundingBox: { x: 0, y: 0, width: 300, height: 48 }, | ||
| }) | ||
| ); | ||
|
|
||
| const output = generateDesignTree(file); | ||
|
|
||
| expect(output).toContain("text-resize: fixed-height"); | ||
| }); | ||
|
|
||
| it("emits text-resize: truncate with max-lines for TRUNCATE", () => { | ||
| const file = makeFile( | ||
| makeNode({ | ||
| id: "1:1", | ||
| name: "Truncated", | ||
| type: "TEXT", | ||
| characters: "Long text that gets cut off", | ||
| style: { fontFamily: "Inter", textAutoResize: "TRUNCATE" }, | ||
| maxLines: 2, | ||
| absoluteBoundingBox: { x: 0, y: 0, width: 200, height: 40 }, | ||
| }) | ||
| ); | ||
|
|
||
| const output = generateDesignTree(file); | ||
|
|
||
| expect(output).toContain("text-resize: truncate"); | ||
| expect(output).toContain("text-overflow: ellipsis"); | ||
| expect(output).toContain("max-lines: 2"); | ||
| }); | ||
|
|
||
| it("emits text-overflow: ellipsis when textTruncation is ENDING", () => { | ||
| const file = makeFile( | ||
| makeNode({ | ||
| id: "1:1", | ||
| name: "Ellipsis", | ||
| type: "TEXT", | ||
| characters: "Truncated text", | ||
| style: { fontFamily: "Inter", textAutoResize: "HEIGHT" }, | ||
| textTruncation: "ENDING", | ||
| maxLines: 3, | ||
| absoluteBoundingBox: { x: 0, y: 0, width: 200, height: 60 }, | ||
| }) | ||
| ); | ||
|
|
||
| const output = generateDesignTree(file); | ||
|
|
||
| expect(output).toContain("text-overflow: ellipsis"); | ||
| expect(output).toContain("max-lines: 3"); | ||
| }); | ||
|
|
||
| it("emits paragraph-spacing when set", () => { | ||
| const file = makeFile( | ||
| makeNode({ | ||
| id: "1:1", | ||
| name: "Paragraphs", | ||
| type: "TEXT", | ||
| characters: "First paragraph\n\nSecond paragraph", | ||
| style: { fontFamily: "Inter", paragraphSpacing: 16 }, | ||
| absoluteBoundingBox: { x: 0, y: 0, width: 300, height: 100 }, | ||
| }) | ||
| ); | ||
|
|
||
| const output = generateDesignTree(file); | ||
|
|
||
| expect(output).toContain("paragraph-spacing: 16px"); | ||
| }); | ||
|
|
||
| it("emits text-resize: truncate without max-lines when maxLines is not set", () => { | ||
| const file = makeFile( | ||
| makeNode({ | ||
| id: "1:1", | ||
| name: "TruncateNoMax", | ||
| type: "TEXT", | ||
| characters: "Truncated", | ||
| style: { fontFamily: "Inter", textAutoResize: "TRUNCATE" }, | ||
| absoluteBoundingBox: { x: 0, y: 0, width: 200, height: 40 }, | ||
| }) | ||
| ); | ||
|
|
||
| const output = generateDesignTree(file); | ||
|
|
||
| expect(output).toContain("text-resize: truncate"); | ||
| expect(output).toContain("text-overflow: ellipsis"); | ||
| expect(output).not.toContain("max-lines:"); | ||
| }); | ||
|
|
||
| it("does not emit text-overflow for textTruncation: DISABLED", () => { | ||
| const file = makeFile( | ||
| makeNode({ | ||
| id: "1:1", | ||
| name: "NoTruncation", | ||
| type: "TEXT", | ||
| characters: "Normal text", | ||
| style: { fontFamily: "Inter", textAutoResize: "HEIGHT" }, | ||
| textTruncation: "DISABLED", | ||
| absoluteBoundingBox: { x: 0, y: 0, width: 200, height: 40 }, | ||
| }) | ||
| ); | ||
|
|
||
| const output = generateDesignTree(file); | ||
|
|
||
| expect(output).not.toContain("text-overflow:"); | ||
| }); | ||
|
|
||
| it("does not emit paragraph-spacing for 0", () => { | ||
| const file = makeFile( | ||
| makeNode({ | ||
| id: "1:1", | ||
| name: "ZeroSpacing", | ||
| type: "TEXT", | ||
| characters: "Text", | ||
| style: { fontFamily: "Inter", paragraphSpacing: 0 }, | ||
| absoluteBoundingBox: { x: 0, y: 0, width: 200, height: 40 }, | ||
| }) | ||
| ); | ||
|
|
||
| const output = generateDesignTree(file); | ||
|
|
||
| expect(output).not.toContain("paragraph-spacing:"); | ||
| }); | ||
|
|
||
| it("does not emit text-resize for NONE or missing textAutoResize", () => { | ||
| const file = makeFile( | ||
| makeNode({ | ||
| id: "1:1", | ||
| name: "Plain", | ||
| type: "TEXT", | ||
| characters: "No resize", | ||
| style: { fontFamily: "Inter" }, | ||
| absoluteBoundingBox: { x: 0, y: 0, width: 100, height: 20 }, | ||
| }) | ||
| ); | ||
|
|
||
| const output = generateDesignTree(file); | ||
|
|
||
| expect(output).not.toContain("text-resize:"); | ||
| }); | ||
| }); | ||
|
Comment on lines
+1093
to
+1255
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. 🧹 Nitpick | 🔵 Trivial Good test coverage with a few edge cases to consider. The test suite covers the main scenarios well. Consider adding these edge cases for completeness:
💡 Optional: Additional edge case testsit("emits text-resize: truncate without max-lines when maxLines is not set", () => {
const file = makeFile(
makeNode({
id: "1:1",
name: "TruncateNoMax",
type: "TEXT",
characters: "Truncated",
style: { fontFamily: "Inter", textAutoResize: "TRUNCATE" },
absoluteBoundingBox: { x: 0, y: 0, width: 200, height: 40 },
})
);
const output = generateDesignTree(file);
expect(output).toContain("text-resize: truncate");
expect(output).not.toContain("max-lines:");
});
it("does not emit text-overflow for textTruncation: DISABLED", () => {
const file = makeFile(
makeNode({
id: "1:1",
name: "NoTruncation",
type: "TEXT",
characters: "Normal text",
style: { fontFamily: "Inter", textAutoResize: "HEIGHT" },
textTruncation: "DISABLED",
absoluteBoundingBox: { x: 0, y: 0, width: 200, height: 40 },
})
);
const output = generateDesignTree(file);
expect(output).not.toContain("text-overflow:");
});🤖 Prompt for AI Agents |
||
| }); | ||
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
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.
Uh oh!
There was an error while loading. Please reload this page.