Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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');
});
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
});
}
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']);
});
});
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();
});
setTimeout(() => {
Simulate.keyDown(node, {
keyCode: KeyCode.ENTER,
});
setTimeout(() => {
expect(instance.state.value.map(v => v.key)).toContain('A');
done();
}, 100);
}, 100);
});
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');
});
);
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);
});
});
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();
});
});
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();
});
});
keys.forEach((key) => {
Simulate.keyDown(inputNode, {key, stopPropagation})
expect(stopPropagation).toHaveBeenCalled()
expect(onDateSubmitted).toHaveBeenCalledWith('someday', 'tomorrow')
stopPropagation.reset()
onDateSubmitted.reset()
})
});