it('calls its `onClick` callback', () => { const domNode = ReactDOM.findDOMNode(treeNodeComponent); TestUtils.Simulate.click(domNode); invariant(props); expect(props.onClick).toHaveBeenCalled(); });
waitsForPromise(async () => { invariant(renderComponent); const component = renderComponent(props); await component.setRoots([nodes['G']]); await component.selectNodeKey(nodes['G'].getKey()); expect(component.getSelectedNodes()).toEqual([nodes['G']]); expect(component.isNodeKeyExpanded(nodes['G'].getKey())).toBe(true); const nodeComponents = getNodeComponents(component); TestUtils.Simulate.click(ReactDOM.findDOMNode(nodeComponents['G'])); expect(component.isNodeKeyExpanded(nodes['G'].getKey())).toBe(false); TestUtils.Simulate.click(ReactDOM.findDOMNode(nodeComponents['G'])); expect(component.isNodeKeyExpanded(nodes['G'].getKey())).toBe(true); invariant(onConfirmSelection); expect(onConfirmSelection.callCount).toBe(0); });
it('calls its `onClickArrow` callback, not its `onClick` callback', () => { const arrow = TestUtils.findRenderedDOMComponentWithClass( treeNodeComponent, 'nuclide-tree-component-item-arrow', ); TestUtils.Simulate.click(arrow); invariant(props); expect(props.onClick).not.toHaveBeenCalled(); expect(props.onClickArrow).toHaveBeenCalled(); });
it('does not expand on click when node is selected', () => { const nodeComponent = renderEntryComponentIntoDocument( FileTreeEntryComponent, { rootUri: '/a/', uri: '/a/b', isSelected: true, isContainer: false, } ); const domNode = ReactDOM.findDOMNode(nodeComponent); TestUtils.Simulate.click(domNode); expect(actions.expandNode).not.toHaveBeenCalled(); });
waitsForPromise(async () => { invariant(renderComponent); const component = renderComponent(props); await component.setRoots([nodes.G]); expect(component.getSelectedNodes()).toEqual([]); const nodeComponents = getNodeComponents(component); TestUtils.Simulate.click(ReactDOM.findDOMNode(nodeComponents.G.refs.arrow)); expect(component.getSelectedNodes()).toEqual([]); invariant(onConfirmSelection); expect(onConfirmSelection.callCount).toBe(0); });
waitsForPromise(async () => { invariant(renderComponent); const component = renderComponent(props); await component.setRoots([nodes['G']]); expect(component.getSelectedNodes()).toEqual([]); const nodeComponents = getNodeComponents(component); TestUtils.Simulate.mouseDown(ReactDOM.findDOMNode(nodeComponents['G']), {button: 2}); expect(component.getSelectedNodes()).toEqual([nodeComponents['G'].props.node]); TestUtils.Simulate.mouseDown( ReactDOM.findDOMNode(nodeComponents['H']), {button: 0, ctrlKey: true} ); expect(component.getSelectedNodes()).toEqual([nodeComponents['H'].props.node]); TestUtils.Simulate.mouseDown(ReactDOM.findDOMNode(nodeComponents['I']), {button: 0}); expect(component.getSelectedNodes()).toEqual([nodeComponents['H'].props.node]); invariant(onConfirmSelection); expect(onConfirmSelection.callCount).toBe(0); });
it('opens a file if a selected node is clicked', () => { const nodeComponent = renderEntryComponentIntoDocument( FileTreeEntryComponent, { rootUri: '/a/', uri: '/a/b', isSelected: true, isContainer: false, usePreviewTabs: true, }, ); const domNode = ReactDOM.findDOMNode(nodeComponent); TestUtils.Simulate.click(domNode); expect(actions.confirmNode).toHaveBeenCalled(); });
it('expands on click when node is selected', () => { const nodeComponent = renderEntryComponentIntoDocument( FileTreeEntryComponent, { rootUri: '/a/', uri: '/a/b/', isSelected: true, isContainer: true, } ); // The onClick is listened not by the <li> element, but by its first child. const domNode = ReactDOM.findDOMNode(nodeComponent).children[0]; TestUtils.Simulate.click(domNode); expect(actions.expandNode).toHaveBeenCalled(); });
waitsForPromise(async () => { invariant(renderComponent); const component = renderComponent(props); await component.setRoots([nodes.G]); await component.expandNodeKey(nodes.H.getKey()); await component.selectNodeKey(nodes.J.getKey()); expect(component.getSelectedNodes()).toEqual([nodes.J]); const nodeComponents = getNodeComponents(component); TestUtils.Simulate.click(ReactDOM.findDOMNode(nodeComponents.J)); invariant(onConfirmSelection); expect(onConfirmSelection).toHaveBeenCalledWith(nodes.J); expect(onConfirmSelection.callCount).toBe(1); });
function clickNodeWithLabel(component: TreeRootComponent, label: string): void { const nodeComponents = getNodeComponents(component); TestUtils.Simulate.click(ReactDOM.findDOMNode(nodeComponents[label])); }