-
Notifications
You must be signed in to change notification settings - Fork 51k
Expand file tree
/
Copy pathSelectEventPlugin-test.internal.js
More file actions
91 lines (75 loc) · 2.5 KB
/
SelectEventPlugin-test.internal.js
File metadata and controls
91 lines (75 loc) · 2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/**
* Copyright (c) 2013-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @emails react-core
*/
'use strict';
var React;
var ReactDOM;
var ReactDOMComponentTree;
var ReactTestUtils;
var SelectEventPlugin;
describe('SelectEventPlugin', () => {
function extract(node, topLevelEvent) {
return SelectEventPlugin.extractEvents(
topLevelEvent,
ReactDOMComponentTree.getInstanceFromNode(node),
{target: node},
node,
);
}
beforeEach(() => {
React = require('react');
ReactDOM = require('react-dom');
ReactTestUtils = require('react-dom/test-utils');
// TODO: can we express this test with only public API?
ReactDOMComponentTree = require('../../client/ReactDOMComponentTree');
SelectEventPlugin = require('../SelectEventPlugin').default;
});
it('should skip extraction if no listeners are present', () => {
class WithoutSelect extends React.Component {
render() {
return <input type="text" />;
}
}
var rendered = ReactTestUtils.renderIntoDocument(<WithoutSelect />);
var node = ReactDOM.findDOMNode(rendered);
node.focus();
// It seems that .focus() isn't triggering this event in our test
// environment so we need to ensure it gets set for this test to be valid.
var fakeNativeEvent = function() {};
fakeNativeEvent.target = node;
ReactTestUtils.simulateNativeEventOnNode('topFocus', node, fakeNativeEvent);
var mousedown = extract(node, 'topMouseDown');
expect(mousedown).toBe(null);
var mouseup = extract(node, 'topMouseUp');
expect(mouseup).toBe(null);
});
it('should extract if an `onSelect` listener is present', () => {
class WithSelect extends React.Component {
render() {
return <input type="text" onSelect={this.props.onSelect} />;
}
}
var cb = jest.fn();
var rendered = ReactTestUtils.renderIntoDocument(
<WithSelect onSelect={cb} />,
);
var node = ReactDOM.findDOMNode(rendered);
node.selectionStart = 0;
node.selectionEnd = 0;
node.focus();
var focus = extract(node, 'topFocus');
expect(focus).toBe(null);
var mousedown = extract(node, 'topMouseDown');
expect(mousedown).toBe(null);
var mouseup = extract(node, 'topMouseUp');
expect(mouseup).not.toBe(null);
expect(typeof mouseup).toBe('object');
expect(mouseup.type).toBe('select');
expect(mouseup.target).toBe(node);
});
});