-
-
Notifications
You must be signed in to change notification settings - Fork 1
fix: Enable nested group display in command tree view #32
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 all commits
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 |
|---|---|---|
|
|
@@ -19,15 +19,15 @@ describe("command-tree-provider", () => { | |
| expect(result).toHaveLength(2); | ||
| expect(result[0]).toBeInstanceOf(CommandTreeItem); | ||
| expect(result[0].label).toBe("Test Command 1"); | ||
| expect(result[0].commandString).toBe("echo hello"); | ||
| expect(result[0].useVsCodeApi).toBe(false); | ||
| expect(result[0].terminalName).toBeUndefined(); | ||
| expect((result[0] as CommandTreeItem).commandString).toBe("echo hello"); | ||
| expect((result[0] as CommandTreeItem).useVsCodeApi).toBe(false); | ||
| expect((result[0] as CommandTreeItem).terminalName).toBeUndefined(); | ||
|
Comment on lines
+22
to
+24
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. These repetitive type casts make the code harder to read. Since you've already asserted the type with For example: const commandItem = result[0] as CommandTreeItem;
expect(commandItem.commandString).toBe("echo hello");
expect(commandItem.useVsCodeApi).toBe(false);
expect(commandItem.terminalName).toBeUndefined(); |
||
|
|
||
| expect(result[1]).toBeInstanceOf(CommandTreeItem); | ||
| expect(result[1].label).toBe("Test Command 2"); | ||
| expect(result[1].commandString).toBe("ls -la"); | ||
| expect(result[1].useVsCodeApi).toBe(false); | ||
| expect(result[1].terminalName).toBeUndefined(); | ||
| expect((result[1] as CommandTreeItem).commandString).toBe("ls -la"); | ||
| expect((result[1] as CommandTreeItem).useVsCodeApi).toBe(false); | ||
| expect((result[1] as CommandTreeItem).terminalName).toBeUndefined(); | ||
kubrickcode marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }); | ||
|
|
||
| it("should create command tree items with VS Code API and terminal name", () => { | ||
|
|
@@ -44,9 +44,9 @@ describe("command-tree-provider", () => { | |
|
|
||
| expect(result).toHaveLength(1); | ||
| expect(result[0].label).toBe("VS Code Command"); | ||
| expect(result[0].commandString).toBe("workbench.action.openSettings"); | ||
| expect(result[0].useVsCodeApi).toBe(true); | ||
| expect(result[0].terminalName).toBe("settings-terminal"); | ||
| expect((result[0] as CommandTreeItem).commandString).toBe("workbench.action.openSettings"); | ||
| expect((result[0] as CommandTreeItem).useVsCodeApi).toBe(true); | ||
| expect((result[0] as CommandTreeItem).terminalName).toBe("settings-terminal"); | ||
kubrickcode marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }); | ||
|
|
||
| it("should handle commands with empty command string", () => { | ||
|
|
@@ -58,8 +58,8 @@ describe("command-tree-provider", () => { | |
| const result = createTreeItemsFromGroup(commands); | ||
|
|
||
| expect(result).toHaveLength(2); | ||
| expect(result[0].commandString).toBe(""); | ||
| expect(result[1].commandString).toBe(""); | ||
| expect((result[0] as CommandTreeItem).commandString).toBe(""); | ||
| expect((result[1] as CommandTreeItem).commandString).toBe(""); | ||
kubrickcode marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }); | ||
|
|
||
| it("should handle empty commands array", () => { | ||
|
|
@@ -107,12 +107,35 @@ describe("command-tree-provider", () => { | |
| const result = createTreeItemsFromGroup(commands); | ||
|
|
||
| expect(result).toHaveLength(3); | ||
| expect(result[0].useVsCodeApi).toBe(false); | ||
| expect(result[0].terminalName).toBeUndefined(); | ||
| expect(result[1].useVsCodeApi).toBe(false); | ||
| expect(result[1].terminalName).toBe("test-terminal"); | ||
| expect(result[2].useVsCodeApi).toBe(true); | ||
| expect(result[2].terminalName).toBeUndefined(); | ||
| expect((result[0] as CommandTreeItem).useVsCodeApi).toBe(false); | ||
| expect((result[0] as CommandTreeItem).terminalName).toBeUndefined(); | ||
| expect((result[1] as CommandTreeItem).useVsCodeApi).toBe(false); | ||
| expect((result[1] as CommandTreeItem).terminalName).toBe("test-terminal"); | ||
| expect((result[2] as CommandTreeItem).useVsCodeApi).toBe(true); | ||
| expect((result[2] as CommandTreeItem).terminalName).toBeUndefined(); | ||
kubrickcode marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }); | ||
|
|
||
| it("should handle nested groups", () => { | ||
| const commands: ButtonConfig[] = [ | ||
| { name: "Simple Command", command: "echo simple" }, | ||
| { | ||
| name: "Nested Group", | ||
| group: [ | ||
| { name: "Sub Command 1", command: "echo sub1" }, | ||
| { name: "Sub Command 2", command: "echo sub2" }, | ||
| ], | ||
| }, | ||
| ]; | ||
|
|
||
| const result = createTreeItemsFromGroup(commands); | ||
|
|
||
| expect(result).toHaveLength(2); | ||
| expect(result[0]).toBeInstanceOf(CommandTreeItem); | ||
| expect((result[0] as CommandTreeItem).commandString).toBe("echo simple"); | ||
|
|
||
| expect(result[1]).toBeInstanceOf(GroupTreeItem); | ||
| expect(result[1].label).toBe("Nested Group"); | ||
| expect((result[1] as GroupTreeItem).commands).toHaveLength(2); | ||
kubrickcode marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }); | ||
|
Comment on lines
+118
to
139
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. This test case is a great addition for verifying group handling. However, it only tests a single level of grouping. Given the PR's goal is to fix nested group display, it would be more robust to test at least two levels of nesting to ensure the recursive nature of group display works as expected. This would involve checking the children of the created it("should handle deeply nested groups", () => {
const commands: ButtonConfig[] = [
{
name: "L1 Group",
group: [
{ name: "L1 Cmd", command: "echo 1" },
{ name: "L2 Group", group: [{ name: "L2 Cmd", command: "echo 2" }] },
],
},
];
const l1Items = createTreeItemsFromGroup(commands);
expect(l1Items).toHaveLength(1);
const l1Group = l1Items[0] as GroupTreeItem;
expect(l1Group).toBeInstanceOf(GroupTreeItem);
expect(l1Group.label).toBe("L1 Group");
const l2Items = createTreeItemsFromGroup(l1Group.commands);
expect(l2Items).toHaveLength(2);
const l2Group = l2Items[1] as GroupTreeItem;
expect(l2Group).toBeInstanceOf(GroupTreeItem);
expect(l2Group.label).toBe("L2 Group");
expect(l2Group.commands[0].name).toBe("L2 Cmd");
}); |
||
| }); | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.