2018-12-04 22:46:18 +03:00
import React from 'react' ;
import { mount } from 'enzyme' ;
import Tooltip from '../../src/components/Tooltip' ;
describe ( '<Tooltip />' , ( ) => {
2018-12-04 23:27:43 +03:00
let elem ;
let content ;
let mouseOverHandler ;
let mouseOutHandler ;
2018-12-04 22:46:18 +03:00
test ( 'initially renders without crashing' , ( ) => {
2018-12-04 23:27:43 +03:00
elem = mount ( < Tooltip / > ) ;
expect ( elem . length ) . toBe ( 1 ) ;
} ) ;
test ( 'shows/hides with mouse over and leave' , ( ) => {
elem = mount ( < Tooltip / > ) ;
mouseOverHandler = elem . find ( '.mouseOverHandler' ) ;
mouseOutHandler = elem . find ( '.mouseOutHandler' ) ;
expect ( elem . state ( ) . isDisplayed ) . toBe ( false ) ;
elem . update ( ) ;
content = elem . find ( '.pf-c-tooltip__content' ) ;
expect ( content . length ) . toBe ( 0 ) ;
mouseOverHandler . props ( ) . onMouseOver ( ) ;
expect ( elem . state ( ) . isDisplayed ) . toBe ( true ) ;
elem . update ( ) ;
content = elem . find ( '.pf-c-tooltip__content' ) ;
expect ( content . length ) . toBe ( 1 ) ;
mouseOutHandler . props ( ) . onMouseLeave ( ) ;
expect ( elem . state ( ) . isDisplayed ) . toBe ( false ) ;
elem . update ( ) ;
content = elem . find ( '.pf-c-tooltip__content' ) ;
expect ( content . length ) . toBe ( 0 ) ;
} ) ;
test ( 'shows/hides with focus and blur' , ( ) => {
elem = mount ( < Tooltip / > ) ;
mouseOverHandler = elem . find ( '.mouseOverHandler' ) ;
mouseOutHandler = elem . find ( '.mouseOutHandler' ) ;
expect ( elem . state ( ) . isDisplayed ) . toBe ( false ) ;
elem . update ( ) ;
content = elem . find ( '.pf-c-tooltip__content' ) ;
expect ( content . length ) . toBe ( 0 ) ;
mouseOverHandler . props ( ) . onFocus ( ) ;
expect ( elem . state ( ) . isDisplayed ) . toBe ( true ) ;
elem . update ( ) ;
content = elem . find ( '.pf-c-tooltip__content' ) ;
expect ( content . length ) . toBe ( 1 ) ;
mouseOutHandler . props ( ) . onBlur ( ) ;
expect ( elem . state ( ) . isDisplayed ) . toBe ( false ) ;
elem . update ( ) ;
content = elem . find ( '.pf-c-tooltip__content' ) ;
expect ( content . length ) . toBe ( 0 ) ;
2018-12-04 22:46:18 +03:00
} ) ;
} ) ;