@@ -2,77 +2,87 @@ import '../assets/bootstrap.less';
2
2
import expect from 'expect.js' ;
3
3
import React from 'react' ;
4
4
import ReactDOM from 'react-dom' ;
5
- import TestUtils from 'react-addons-test-utils' ;
5
+ import { Simulate } from 'react-addons-test-utils' ;
6
6
import $ from 'jquery' ;
7
7
import Tooltip from '../index' ;
8
8
import async from 'async' ;
9
9
window . $ = $ ;
10
- const Simulate = TestUtils . Simulate ;
11
10
12
- function timeout ( ms ) {
11
+ const timeout = ( ms ) => {
13
12
return ( done ) => {
14
13
setTimeout ( done , ms ) ;
15
14
} ;
16
- }
15
+ } ;
17
16
18
- describe ( 'rc-tooltip' , function run ( ) {
19
- this . timeout ( 40000 ) ;
20
- const div = document . createElement ( 'div' ) ;
21
- div . style . margin = '100px' ;
22
- document . body . insertBefore ( div , document . body . firstChild ) ;
17
+ const expectComponentPopupToBeOk = ( component ) => {
18
+ const popupDomNode = component . getPopupDomNode ( ) ;
19
+ expect ( popupDomNode ) . to . be . ok ( ) ;
20
+ } ;
21
+
22
+ const expectPopupToHaveContent = ( component , content ) => {
23
+ const popupDomNode = component . getPopupDomNode ( ) ;
24
+ expect ( $ ( popupDomNode ) . find ( '.x-content' ) . html ( ) ) . to . be ( content ) ;
25
+ expect ( popupDomNode ) . to . be . ok ( ) ;
26
+ } ;
27
+
28
+ const expectPopupToBeHidden = ( component ) => {
29
+ const popupDomNode = component . getPopupDomNode ( ) ;
30
+ expect ( $ ( popupDomNode ) . css ( 'display' ) ) . to . be ( 'none' ) ;
31
+ } ;
32
+
33
+ const verifyContent = ( component , content , done ) => {
34
+ const componentDomNode = ReactDOM . findDOMNode ( component ) ;
35
+ async . series ( [ timeout ( 20 ) , ( next ) => {
36
+ expectPopupToHaveContent ( component , content ) ;
37
+ expectComponentPopupToBeOk ( component ) ;
38
+ Simulate . click ( componentDomNode ) ;
39
+ next ( ) ;
40
+ } , timeout ( 20 ) , ( next ) => {
41
+ expectPopupToBeHidden ( component ) ;
42
+ next ( ) ;
43
+ } ] , done ) ;
44
+ } ;
45
+
46
+ describe ( 'rc-tooltip' , ( ) => {
47
+ let div ;
48
+ before ( ( ) => {
49
+ timeout ( 40000 ) ;
50
+ div = document . createElement ( 'div' ) ;
51
+ div . style . margin = '100px' ;
52
+ document . body . insertBefore ( div , document . body . firstChild ) ;
53
+ } ) ;
23
54
24
55
afterEach ( ( ) => {
25
56
ReactDOM . unmountComponentAtNode ( div ) ;
26
57
} ) ;
27
58
28
- describe ( 'trigger ' , ( ) => {
29
- it ( 'works ' , ( done ) => {
59
+ describe ( 'shows and hides itself on click ' , ( ) => {
60
+ it ( 'using an element overlay ' , ( done ) => {
30
61
const tooltip = ReactDOM . render (
31
62
< Tooltip
32
63
trigger = { [ 'click' ] }
33
64
placement = "left"
34
- overlay = { < strong className = "x-content" > tooltip2 </ strong > }
65
+ overlay = { < strong className = "x-content" > Tooltip content </ strong > }
35
66
>
36
- < div className = "target" > click </ div >
67
+ < div className = "target" > Click this </ div >
37
68
</ Tooltip > , div ) ;
38
- const domNode = ReactDOM . findDOMNode ( tooltip ) ;
39
- Simulate . click ( domNode ) ;
40
- async . series ( [ timeout ( 20 ) , ( next ) => {
41
- const popupDomNode = tooltip . getPopupDomNode ( ) ;
42
- expect ( $ ( popupDomNode ) . find ( '.x-content' ) . html ( ) ) . to . be ( 'tooltip2' ) ;
43
- expect ( popupDomNode ) . to . be . ok ( ) ;
44
- Simulate . click ( domNode ) ;
45
- next ( ) ;
46
- } , timeout ( 20 ) , ( next ) => {
47
- const popupDomNode = tooltip . getPopupDomNode ( ) ;
48
- expect ( $ ( popupDomNode ) . css ( 'display' ) ) . to . be ( 'none' ) ;
49
- next ( ) ;
50
- } ] , done ) ;
69
+ const componentDomNode = ReactDOM . findDOMNode ( tooltip ) ;
70
+ Simulate . click ( componentDomNode ) ;
71
+ verifyContent ( tooltip , 'Tooltip content' , done ) ;
51
72
} ) ;
52
- } ) ;
53
- describe ( 'trigger-functon' , ( ) => {
54
- it ( 'works with a function overlay' , ( done ) => {
73
+
74
+ it ( 'using a function overlay' , ( done ) => {
55
75
const tooltip = ReactDOM . render (
56
76
< Tooltip
57
77
trigger = { [ 'click' ] }
58
78
placement = "left"
59
- overlay = { ( ) => ( < strong className = "x-content" > tooltip </ strong > ) }
79
+ overlay = { ( ) => ( < strong className = "x-content" > Tooltip content </ strong > ) }
60
80
>
61
- < div className = "target" > click </ div >
81
+ < div className = "target" > Click this </ div >
62
82
</ Tooltip > , div ) ;
63
- const domNode = ReactDOM . findDOMNode ( tooltip ) ;
64
- Simulate . click ( domNode ) ;
65
- async . series ( [ timeout ( 20 ) , ( next ) => {
66
- const popupDomNode = tooltip . getPopupDomNode ( ) ;
67
- expect ( $ ( popupDomNode ) . find ( '.x-content' ) . html ( ) ) . to . be ( 'tooltip' ) ;
68
- expect ( popupDomNode ) . to . be . ok ( ) ;
69
- Simulate . click ( domNode ) ;
70
- next ( ) ;
71
- } , timeout ( 20 ) , ( next ) => {
72
- const popupDomNode = tooltip . getPopupDomNode ( ) ;
73
- expect ( $ ( popupDomNode ) . css ( 'display' ) ) . to . be ( 'none' ) ;
74
- next ( ) ;
75
- } ] , done ) ;
83
+ const componentDomNode = ReactDOM . findDOMNode ( tooltip ) ;
84
+ Simulate . click ( componentDomNode ) ;
85
+ verifyContent ( tooltip , 'Tooltip content' , done ) ;
76
86
} ) ;
77
87
} ) ;
78
88
} ) ;
0 commit comments