File tree Expand file tree Collapse file tree 3 files changed +32
-0
lines changed Expand file tree Collapse file tree 3 files changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -59,3 +59,9 @@ typings/
59
59
60
60
# compiled
61
61
dist
62
+
63
+ # I don't see this committed, so putting in ignore
64
+ package-lock.json
65
+
66
+ # vim swap files
67
+ ** /* .swp
Original file line number Diff line number Diff line change @@ -35,6 +35,11 @@ class EllipisWithTooltip extends React.Component {
35
35
}
36
36
}
37
37
38
+ componentWillReceiveProps ( nextProps ) {
39
+ if ( nextProps . children === this . props . children ) return ;
40
+ this . setState ( { hasOverflowingChildren : false } ) ;
41
+ }
42
+
38
43
render ( ) {
39
44
const { hasOverflowingChildren, text } = this . state ;
40
45
const {
Original file line number Diff line number Diff line change @@ -109,4 +109,25 @@ describe('Ellipsis', () => {
109
109
110
110
expect ( toJson ( wrapper ) ) . toMatchSnapshot ( ) ;
111
111
} ) ;
112
+
113
+ it ( 'should update text when props change' , ( ) => {
114
+ const wrapper = setup ( 'this is some long text' ) ;
115
+ let domElement = wrapper . find ( '#a div' ) . getDOMNode ( ) ;
116
+
117
+ expect ( wrapper . state ( ) . hasOverflowingChildren ) . toEqual ( false ) ;
118
+ Object . defineProperty ( domElement , 'clientWidth' , { get ( ) { return 300 ; } } ) ;
119
+ Object . defineProperty ( domElement , 'scrollWidth' , { get ( ) { return 400 ; } } ) ;
120
+ wrapper . find ( '#a div' ) . simulate ( 'mouseEnter' ) ;
121
+ expect ( wrapper . state ( ) . hasOverflowingChildren ) . toEqual ( true ) ;
122
+
123
+ expect ( wrapper . state ( ) . text ) . toEqual ( 'this is some long text' ) ;
124
+ wrapper . setProps ( { children : 'this changed' } ) ;
125
+ expect ( wrapper . state ( ) . hasOverflowingChildren ) . toEqual ( false ) ;
126
+ domElement = wrapper . find ( '#a div' ) . getDOMNode ( ) ;
127
+ Object . defineProperty ( domElement , 'clientWidth' , { get ( ) { return 300 ; } } ) ;
128
+ Object . defineProperty ( domElement , 'scrollWidth' , { get ( ) { return 400 ; } } ) ;
129
+ wrapper . find ( '#a div' ) . simulate ( 'mouseEnter' ) ;
130
+ expect ( wrapper . state ( ) . hasOverflowingChildren ) . toEqual ( true ) ;
131
+ expect ( wrapper . state ( ) . text ) . toEqual ( 'this changed' ) ;
132
+ } ) ;
112
133
} ) ;
You can’t perform that action at this time.
0 commit comments