@@ -4,72 +4,101 @@ import ModalTrigger from '../src/ModalTrigger';
44
55describe ( 'ModalTrigger' , function ( ) {
66 it ( 'Should create ModalTrigger element' , function ( ) {
7- let instance = ReactTestUtils . renderIntoDocument (
7+ const instance = ReactTestUtils . renderIntoDocument (
88 < ModalTrigger modal = { < div > test</ div > } >
99 < button > button</ button >
1010 </ ModalTrigger >
1111 ) ;
12- let modalTrigger = instance . getDOMNode ( ) ;
12+ const modalTrigger = React . findDOMNode ( instance ) ;
1313 assert . equal ( modalTrigger . nodeName , 'BUTTON' ) ;
1414 } ) ;
1515
1616 it ( 'Should pass ModalTrigger onMouseOver prop to child' , function ( ) {
17- let called = false ;
18- let callback = function ( ) {
19- called = true ;
20- } ;
21- let instance = ReactTestUtils . renderIntoDocument (
17+ const callback = sinon . spy ( ) ;
18+ const instance = ReactTestUtils . renderIntoDocument (
2219 < ModalTrigger modal = { < div > test</ div > } onMouseOver = { callback } >
2320 < button > button</ button >
2421 </ ModalTrigger >
2522 ) ;
26- let modalTrigger = instance . getDOMNode ( ) ;
23+ const modalTrigger = React . findDOMNode ( instance ) ;
2724 ReactTestUtils . Simulate . mouseOver ( modalTrigger ) ;
28- assert . equal ( called , true ) ;
25+ callback . called . should . be . true ;
2926 } ) ;
3027
3128 it ( 'Should pass ModalTrigger onMouseOut prop to child' , function ( ) {
32- let called = false ;
33- let callback = function ( ) {
34- called = true ;
35- } ;
36- let instance = ReactTestUtils . renderIntoDocument (
29+ const callback = sinon . spy ( ) ;
30+ const instance = ReactTestUtils . renderIntoDocument (
3731 < ModalTrigger modal = { < div > test</ div > } onMouseOut = { callback } >
3832 < button > button</ button >
3933 </ ModalTrigger >
4034 ) ;
41- let modalTrigger = instance . getDOMNode ( ) ;
35+ const modalTrigger = React . findDOMNode ( instance ) ;
4236 ReactTestUtils . Simulate . mouseOut ( modalTrigger ) ;
43- assert . equal ( called , true ) ;
37+ callback . called . should . be . true ;
4438 } ) ;
4539
4640 it ( 'Should pass ModalTrigger onFocus prop to child' , function ( ) {
47- let called = false ;
48- let callback = function ( ) {
49- called = true ;
50- } ;
51- let instance = ReactTestUtils . renderIntoDocument (
41+ const callback = sinon . spy ( ) ;
42+ const instance = ReactTestUtils . renderIntoDocument (
5243 < ModalTrigger modal = { < div > test</ div > } onFocus = { callback } >
5344 < button > button</ button >
5445 </ ModalTrigger >
5546 ) ;
56- let modalTrigger = instance . getDOMNode ( ) ;
47+ const modalTrigger = React . findDOMNode ( instance ) ;
5748 ReactTestUtils . Simulate . focus ( modalTrigger ) ;
58- assert . equal ( called , true ) ;
49+ callback . called . should . be . true ;
5950 } ) ;
6051
6152 it ( 'Should pass ModalTrigger onBlur prop to child' , function ( ) {
62- let called = false ;
63- let callback = function ( ) {
64- called = true ;
65- } ;
66- let instance = ReactTestUtils . renderIntoDocument (
53+ const callback = sinon . spy ( ) ;
54+ const instance = ReactTestUtils . renderIntoDocument (
6755 < ModalTrigger modal = { < div > test</ div > } onBlur = { callback } >
6856 < button > button</ button >
6957 </ ModalTrigger >
7058 ) ;
71- let modalTrigger = instance . getDOMNode ( ) ;
59+ const modalTrigger = React . findDOMNode ( instance ) ;
7260 ReactTestUtils . Simulate . blur ( modalTrigger ) ;
73- assert . equal ( called , true ) ;
61+ callback . called . should . be . true ;
62+ } ) ;
63+
64+ // This is just a copy of the test case for OverlayTrigger.
65+ it ( 'Should forward requested context' , function ( ) {
66+ const contextTypes = {
67+ key : React . PropTypes . string
68+ } ;
69+
70+ const contextSpy = sinon . spy ( ) ;
71+ class ContextReader extends React . Component {
72+ render ( ) {
73+ contextSpy ( this . context . key ) ;
74+ return < div /> ;
75+ }
76+ }
77+ ContextReader . contextTypes = contextTypes ;
78+
79+ const TriggerWithContext = ModalTrigger . withContext ( contextTypes ) ;
80+ class ContextHolder extends React . Component {
81+ getChildContext ( ) {
82+ return { key : 'value' } ;
83+ }
84+
85+ render ( ) {
86+ return (
87+ < TriggerWithContext
88+ trigger = "click"
89+ modal = { < ContextReader /> }
90+ >
91+ < button > button</ button >
92+ </ TriggerWithContext >
93+ ) ;
94+ }
95+ }
96+ ContextHolder . childContextTypes = contextTypes ;
97+
98+ const instance = ReactTestUtils . renderIntoDocument ( < ContextHolder /> ) ;
99+ const modalTrigger = React . findDOMNode ( instance ) ;
100+ ReactTestUtils . Simulate . click ( modalTrigger ) ;
101+
102+ contextSpy . calledWith ( 'value' ) . should . be . true ;
74103 } ) ;
75104} ) ;
0 commit comments