Elffuss BraidHub

kikocis/continue public

main · 3.0 KiBRawPermalink
1// Note: This test file tests the formatArgs function that was used in the old ToolPermissionRequest component
2// The function has been moved to ToolPermissionSelector but these tests are still valid for testing the pure function logic
3
4// Extract the formatArgs function for testing
5// This mirrors the implementation in both ToolPermissionRequest.tsx and ToolPermissionSelector.tsx
6function formatArgs(args: any): string {
7 if (!args || Object.keys(args).length === 0) return "";
8
9 const firstKey = Object.keys(args)[0];
10 const firstValue = args[firstKey];
11
12 if (typeof firstValue === "string" && firstValue.length > 60) {
13 return `${firstValue.substring(0, 60)}...`;
14 }
15
16 return String(firstValue);
17}
18
19describe("formatArgs function", () => {
20 describe("formatArgs", () => {
21 it("should return empty string for no arguments", () => {
22 expect(formatArgs({})).toBe("");
23 expect(formatArgs(null)).toBe("");
24 expect(formatArgs(undefined)).toBe("");
25 });
26
27 it("should return first argument value as string", () => {
28 expect(formatArgs({ path: "/test.txt" })).toBe("/test.txt");
29 expect(formatArgs({ count: 42 })).toBe("42");
30 expect(formatArgs({ enabled: true })).toBe("true");
31 expect(formatArgs({ data: null })).toBe("null");
32 });
33
34 it("should truncate long strings", () => {
35 const longString = "a".repeat(100);
36 const result = formatArgs({ content: longString });
37 expect(result).toBe("a".repeat(60) + "...");
38 expect(result.length).toBe(63); // 60 chars + "..."
39 });
40
41 it("should not truncate short strings", () => {
42 const shortString = "a".repeat(30);
43 const result = formatArgs({ content: shortString });
44 expect(result).toBe(shortString);
45 expect(result).not.toContain("...");
46 });
47
48 it("should handle exactly 60 character strings", () => {
49 const exactString = "a".repeat(60);
50 const result = formatArgs({ content: exactString });
51 expect(result).toBe(exactString);
52 expect(result).not.toContain("...");
53 });
54
55 it("should handle 61 character strings", () => {
56 const slightlyLongString = "a".repeat(61);
57 const result = formatArgs({ content: slightlyLongString });
58 expect(result).toBe("a".repeat(60) + "...");
59 });
60
61 it("should use first key when multiple arguments", () => {
62 const args = { path: "/test.txt", mode: "read", format: "json" };
63 const result = formatArgs(args);
64 expect(result).toBe("/test.txt"); // Should use first key in insertion order
65 });
66
67 it("should handle non-string types", () => {
68 expect(formatArgs({ arr: [1, 2, 3] })).toBe("1,2,3");
69 expect(formatArgs({ obj: { a: 1, b: 2 } })).toBe("[object Object]");
70 expect(formatArgs({ num: 123.456 })).toBe("123.456");
71 });
72
73 it("should handle special characters", () => {
74 expect(formatArgs({ path: "/special/chars!@#$%^&*()_+" })).toBe(
75 "/special/chars!@#$%^&*()_+",
76 );
77 expect(formatArgs({ emoji: "🎉🎊✨" })).toBe("🎉🎊✨");
78 });
79 });
80});