diff --git a/devtools/client/debugger/new/src/components/PrimaryPanes/SourcesTree.js b/devtools/client/debugger/new/src/components/PrimaryPanes/SourcesTree.js index bce42227fe48..afa8e861d21b 100644 --- a/devtools/client/debugger/new/src/components/PrimaryPanes/SourcesTree.js +++ b/devtools/client/debugger/new/src/components/PrimaryPanes/SourcesTree.js @@ -164,6 +164,10 @@ class SourcesTree extends Component { this.props.focusItem({ thread: this.props.thread, item }); }; + onActivate = (item: TreeNode) => { + this.selectItem(item); + }; + // NOTE: we get the source from sources because item.contents is cached getSource(item: TreeNode): ?Source { const source = getSourceFromNode(item); @@ -194,13 +198,6 @@ class SourcesTree extends Component { this.props.setExpandedState(this.props.thread, expandedState); }; - onKeyDown = (e: KeyboardEvent) => { - const { focused } = this.props; - if (e.keyCode === 13 && focused) { - this.selectItem(focused); - } - }; - isEmpty() { const { sourceTree } = this.state; return sourceTree.contents.length === 0; @@ -280,6 +277,7 @@ class SourcesTree extends Component { onCollapse: this.onCollapse, onExpand: this.onExpand, onFocus: this.onFocus, + onActivate: this.onActivate, renderItem: this.renderItem, preventBlur: true }; @@ -336,7 +334,7 @@ class SourcesTree extends Component { return this.renderPane( this.renderThreadHeader(), -
+
{this.renderTree()}
); diff --git a/devtools/client/debugger/new/src/components/PrimaryPanes/tests/SourcesTree.spec.js b/devtools/client/debugger/new/src/components/PrimaryPanes/tests/SourcesTree.spec.js index 833254616dd4..9fa1480358d6 100644 --- a/devtools/client/debugger/new/src/components/PrimaryPanes/tests/SourcesTree.spec.js +++ b/devtools/client/debugger/new/src/components/PrimaryPanes/tests/SourcesTree.spec.js @@ -177,26 +177,17 @@ describe("SourcesTree", () => { }); }); - describe("focusItem", () => { - it("update the focused item", async () => { + describe("activateItem", () => { + it("select activated item", async () => { + const { instance, props } = render(); const item = createMockItem(); - const { component, props } = render({ focused: item }); + const spy = jest.spyOn(instance, "selectItem"); - await component - .find(".sources-list") - .simulate("keydown", { keyCode: 13 }); - - expect(props.selectSource).toHaveBeenCalledWith(item.contents.id); - }); - - it("allows focus on the (index)", async () => { - const item = createMockItem("https://davidwalsh.name/", "(index)"); - - const { component, props } = render({ focused: item }); - await component - .find(".sources-list") - .simulate("keydown", { keyCode: 13 }); - expect(props.selectSource).toHaveBeenCalledWith(item.contents.id); + instance.onActivate(item); + expect(spy).toHaveBeenCalledWith(item); + expect(props.selectSource).toHaveBeenCalledWith( + "server1.conn13.child1/39" + ); }); }); @@ -214,14 +205,6 @@ describe("SourcesTree", () => { instance.selectItem(createMockDirectory()); expect(props.selectSource).not.toHaveBeenCalled(); }); - - it("does not select if no item is focused on", async () => { - const { component, props } = render(); - await component - .find(".sources-list") - .simulate("keydown", { keyCode: 13 }); - expect(props.selectSource).not.toHaveBeenCalled(); - }); }); describe("handles items", () => { diff --git a/devtools/client/debugger/new/src/components/PrimaryPanes/tests/__snapshots__/SourcesTree.spec.js.snap b/devtools/client/debugger/new/src/components/PrimaryPanes/tests/__snapshots__/SourcesTree.spec.js.snap index 8d6ac0f50a20..9b153a6660d4 100644 --- a/devtools/client/debugger/new/src/components/PrimaryPanes/tests/__snapshots__/SourcesTree.spec.js.snap +++ b/devtools/client/debugger/new/src/components/PrimaryPanes/tests/__snapshots__/SourcesTree.spec.js.snap @@ -8,7 +8,6 @@ exports[`SourcesTree After changing expanded nodes Shows the tree with four.js,