@@ -8,6 +8,7 @@ import { render } from './helpers';
88
99describe ( '<Affix>' , ( ) => {
1010 let mountPoint ;
11+ let handlers ;
1112
1213 // This makes the window very tall; hopefully enough to exhibit the affix
1314 // behavior. If this is insufficient, we should modify the Karma config to
@@ -41,9 +42,18 @@ describe('<Affix>', () => {
4142 Content . renderCount = 0 ;
4243 mountPoint = document . createElement ( 'div' ) ;
4344 document . body . appendChild ( mountPoint ) ;
45+ handlers = {
46+ onAffix : sinon . spy ( ) ,
47+ onAffixed : sinon . spy ( ) ,
48+ onAffixTop : sinon . spy ( ) ,
49+ onAffixedTop : sinon . spy ( ) ,
50+ onAffixBottom : sinon . spy ( ) ,
51+ onAffixedBottom : sinon . spy ( )
52+ } ;
4453 } ) ;
4554
4655 afterEach ( ( ) => {
56+ Object . keys ( handlers ) . forEach ( key => handlers [ key ] . reset ( ) ) ;
4757 ReactDOM . unmountComponentAtNode ( mountPoint ) ;
4858 document . body . removeChild ( mountPoint ) ;
4959 window . scrollTo ( 0 , 0 ) ;
@@ -58,6 +68,7 @@ describe('<Affix>', () => {
5868
5969 const content =
6070 ReactTestUtils . findRenderedComponentWithType ( instance , Content ) ;
71+
6172 expect ( content ) . to . exist ;
6273 } ) ;
6374
@@ -76,6 +87,7 @@ describe('<Affix>', () => {
7687 affixStyle = { { color : 'white' } }
7788 bottomClassName = "affix-bottom"
7889 bottomStyle = { { color : 'blue' } }
90+ { ...handlers }
7991 >
8092 < Content style = { { height : 100 } } />
8193 </ Affix >
@@ -88,14 +100,19 @@ describe('<Affix>', () => {
88100 } ) ;
89101
90102 it ( 'should render correctly at top' , ( done ) => {
91- window . scrollTo ( 0 , 99 ) ;
103+ window . scrollTo ( 0 , 101 ) ;
92104
93105 requestAnimationFrame ( ( ) => {
94- expect ( node . className ) . to . equal ( 'affix-top' ) ;
95- expect ( node . style . position ) . to . not . be . ok ;
96- expect ( node . style . top ) . to . not . be . ok ;
97- expect ( node . style . color ) . to . equal ( 'red' ) ;
98- done ( ) ;
106+ window . scrollTo ( 0 , 99 ) ;
107+ requestAnimationFrame ( ( ) => {
108+ expect ( node . className ) . to . equal ( 'affix-top' ) ;
109+ expect ( node . style . position ) . to . not . be . ok ;
110+ expect ( node . style . top ) . to . not . be . ok ;
111+ expect ( node . style . color ) . to . equal ( 'red' ) ;
112+ expect ( handlers . onAffixTop ) . to . been . calledOnce ;
113+ expect ( handlers . onAffixedTop ) . to . been . calledOnce ;
114+ done ( ) ;
115+ } ) ;
99116 } ) ;
100117 } ) ;
101118
@@ -106,6 +123,9 @@ describe('<Affix>', () => {
106123 expect ( node . style . position ) . to . equal ( 'fixed' ) ;
107124 expect ( node . style . top ) . to . not . be . ok ;
108125 expect ( node . style . color ) . to . equal ( 'white' ) ;
126+
127+ expect ( handlers . onAffix ) . to . been . calledOnce ;
128+ expect ( handlers . onAffixed ) . to . been . calledOnce ;
109129 done ( ) ;
110130 } ) ;
111131 } ) ;
@@ -117,6 +137,9 @@ describe('<Affix>', () => {
117137 expect ( node . style . position ) . to . equal ( 'absolute' ) ;
118138 expect ( node . style . top ) . to . equal ( '9900px' ) ;
119139 expect ( node . style . color ) . to . equal ( 'blue' ) ;
140+
141+ expect ( handlers . onAffixBottom ) . to . been . calledOnce ;
142+ expect ( handlers . onAffixedBottom ) . to . been . calledOnce ;
120143 done ( ) ;
121144 } ) ;
122145 } ) ;
@@ -131,6 +154,7 @@ describe('<Affix>', () => {
131154 < Affix
132155 offsetTop = { 100 }
133156 viewportOffsetTop = { 50 }
157+ { ...handlers }
134158 >
135159 < Content />
136160 </ Affix >
0 commit comments