How to use the react-addons-test-utils.Simulate.keyDown function in react-addons-test-utils

To help you get started, we’ve selected a few react-addons-test-utils examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github NiGhTTraX / react-test-buffet / tests / acceptance / adding-todos.spec.js View on Github external
it('should add a new todo when pressing enter', function() {
      const node = $component.find('.new-todo')[0];

      // TODO: this exposes too much of the internals; figure out a way to write
      // tests without knowing all of this
      Simulate.change(node, { target: { value: 'buy milk' } });
      Simulate.keyDown(node, { keyCode: ENTER });

      expect($component.find('.todo')).to.have.length(1);
      expect($component.find('.todo').text()).to.equal('buy milk');
    });
github NiGhTTraX / react-test-buffet / tests / acceptance / adding-todos.spec.js View on Github external
function addTodo($component, todo) {
  const node = $component.find('.new-todo')[0];

  // TODO: this exposes too much of the internals; figure out a way to write
  // tests without knowing all of this
  Simulate.change(node, { target: { value: todo } });
  Simulate.keyDown(node, {
    keyCode: ENTER
  });
}
github enigma-io / boundless / UIList / __tests__ / unit.js View on Github external
it('should move focus to the beginning if on the last child (loop)', () => {
            Simulate.focus(element.refs['item_1']);
            Simulate.keyDown(ReactDOM.findDOMNode(element.refs.list), {...eventBase, key: 'ArrowRight'});

            expect(document.activeElement).toBe(element.refs['item_0']);
        });
    });
github mozilla / addons-frontend / tests / client / admin / components / TestSearchForm.js View on Github external
it('looks up the add-on to see if you are lucky on Shift+Enter', () => {
    loadAddon.returns(Promise.resolve('adblock'));
    input.value = 'adblock@adblock.com';
    Simulate.keyDown(input, { key: 'Enter', shiftKey: true });
    expect(loadAddon.calledWith({ api, query: 'adblock@adblock.com' })).toBeTruthy();
  });
github react-component / select / tests / tags.spec.js View on Github external
setTimeout(() => {
      Simulate.keyDown(node, {
        keyCode: KeyCode.ENTER,
      });
      setTimeout(() => {
        expect(instance.state.value.map(v => v.key)).toContain('A');
        done();
      }, 100);
    }, 100);
  });
github react-component / menu / tests / MenuItemGroup.spec.js View on Github external
expectActive('none');

    const menuNode = ReactDOM.findDOMNode(menu);

    Simulate.keyDown(menuNode, {
      keyCode: KeyCode.DOWN,
    });

    expectActive('1');
    Simulate.keyDown(menuNode, {
      keyCode: KeyCode.DOWN,
    });
    expectActive('2');
    Simulate.keyDown(menuNode, {
      keyCode: KeyCode.DOWN,
    });
    expectActive('3');
    Simulate.keyDown(menuNode, {
      keyCode: KeyCode.DOWN,
    });
    expectActive('4');
    Simulate.keyDown(menuNode, {
      keyCode: KeyCode.DOWN,
    });
    expectActive('5');
    Simulate.keyDown(menuNode, {
      keyCode: KeyCode.DOWN,
    });
    expectActive('none');
  });
github mlaursen / react-md / src / js / Tooltips / __tests__ / Tooltips.js View on Github external
);

    const testNode = findRenderedDOMComponentWithTag(tooltipTest, 'a');
    const event = { pageX: 0, pageY: 0 };
    const touchEvent = { changedTouches: [event] };
    Simulate.mouseDown(testNode, event);
    Simulate.mouseUp(testNode, event);
    Simulate.mouseLeave(testNode, event);
    Simulate.focus(testNode);
    Simulate.blur(testNode);
    Simulate.touchStart(testNode, touchEvent);
    Simulate.touchMove(testNode, touchEvent);
    Simulate.touchCancel(testNode, touchEvent);
    Simulate.touchEnd(testNode, touchEvent);
    Simulate.keyUp(testNode);
    Simulate.keyDown(testNode);

    expect(onMouseDown.mock.calls.length).toBe(1);
    expect(onMouseUp.mock.calls.length).toBe(1);
    expect(onMouseLeave.mock.calls.length).toBe(1);
    expect(onFocus.mock.calls.length).toBe(1);
    expect(onBlur.mock.calls.length).toBe(1);
    expect(onTouchStart.mock.calls.length).toBe(1);
    expect(onTouchMove.mock.calls.length).toBe(1);
    expect(onTouchCancel.mock.calls.length).toBe(1);
    expect(onTouchEnd.mock.calls.length).toBe(1);
    expect(onKeyUp.mock.calls.length).toBe(1);
    expect(onKeyDown.mock.calls.length).toBe(1);
  });
});
github nylas-mail-lives / nylas-mail / spec / components / editable-list-spec.jsx View on Github external
it('does not clear the selection when esc pressed but prop does not allow it', () => {
      const onSelectItem = jasmine.createSpy('onSelectItem');
      const list = makeList(['1', '2'], {selected: '1', allowEmptySelection: false, onSelectItem});
      const innerList = findRenderedDOMComponentWithClass(list, 'items-wrapper');

      Simulate.keyDown(innerList, {key: 'Escape'});

      expect(onSelectItem).not.toHaveBeenCalled();
    });
  });
github nylas-mail-lives / nylas-mail / spec / components / editable-list-spec.jsx View on Github external
it('does not call onItemCreated when no value entered', () => {
      const onItemCreated = jasmine.createSpy('onItemCreated');
      const list = makeList(['1', '2'], {initialState: {creatingItem: true}, onItemCreated});
      const createItem = findRenderedDOMComponentWithClass(list, 'create-item-input');
      const input = createItem.querySelector('input');
      findDOMNode(input).value = '';

      Simulate.keyDown(input, {key: 'Enter'});

      expect(onItemCreated).not.toHaveBeenCalled();
    });
  });
github nylas-mail-lives / nylas-mail / spec / components / date-input-spec.jsx View on Github external
keys.forEach((key) => {
        Simulate.keyDown(inputNode, {key, stopPropagation})
        expect(stopPropagation).toHaveBeenCalled()
        expect(onDateSubmitted).toHaveBeenCalledWith('someday', 'tomorrow')
        stopPropagation.reset()
        onDateSubmitted.reset()
      })
    });