Yicong-Huang commented on code in PR #5071:
URL: https://github.com/apache/texera/pull/5071#discussion_r3251558671


##########
frontend/src/app/workspace/service/joint-ui/joint-ui.service.spec.ts:
##########
@@ -327,9 +327,188 @@
 //   });
 // });
 
+import { of } from "rxjs";
+import * as joint from "jointjs";
+import { JointUIService, operatorNameClass } from "./joint-ui.service";
+import { OperatorPredicate } from "../../types/workflow-common.interface";
+
 describe("JointUIService", () => {
   // Pre-existing spec body is commented out. Placeholder keeps Vitest's
   // discovery happy; rewriting the real tests against the new test
   // runner is tracked in #4861.
   it.todo("add unit tests for JointUIService");
+
+  describe("truncateOperatorDisplayName", () => {
+    // Deterministic measurer: 10px per character. With the 200-px budget,
+    // 20 chars fit exactly; longer strings get truncated to a prefix plus "…".
+    const measure = (text: string) => text.length * 10;
+    const budget = JointUIService.MAX_OPERATOR_NAME_PIXELS;
+    const charsThatFit = budget / 10;
+
+    it("returns the name unchanged when it fits within the pixel budget", () 
=> {
+      const name = "a".repeat(charsThatFit);
+      expect(JointUIService.truncateOperatorDisplayName(name, 
measure)).toBe(name);
+    });
+
+    it("truncates and appends an ellipsis when the name exceeds the budget", 
() => {
+      const name = "a".repeat(charsThatFit + 10);
+      const result = JointUIService.truncateOperatorDisplayName(name, measure);
+      expect(result.endsWith("…")).toBe(true);
+      expect(measure(result)).toBeLessThanOrEqual(budget);
+      // Ellipsis takes 10px, leaving 190px for the prefix → 19 chars.
+      expect(result).toBe("a".repeat(charsThatFit - 1) + "…");
+    });
+
+    it("returns an empty string unchanged", () => {
+      expect(JointUIService.truncateOperatorDisplayName("", measure)).toBe("");
+    });
+
+    it("truncates CJK characters at code-point boundaries", () => {
+      // CJK characters are each a single code point (UTF-16 length 1) — the
+      // 10-px measurer treats them like any other char. 19 chars fit in the
+      // 190-px prefix budget once the ellipsis is reserved.
+      const name = "你".repeat(charsThatFit + 5);

Review Comment:
   I think it is best effort for measuring char pixels. It may not be accurate 
compare to rendered version, but I think we are fine for now. 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to