2019-01-15 22:58:23 +03:00
import React from 'react' ;
import { mount } from 'enzyme' ;
import { I18nProvider } from '@lingui/react' ;
2019-01-24 21:05:36 +03:00
import Lookup from '../../src/components/Lookup' ;
2019-01-15 22:58:23 +03:00
2019-01-24 21:05:36 +03:00
let mockData = [ { name : 'foo' , id : 0 , isChecked : false } ] ;
2019-01-15 22:58:23 +03:00
describe ( '<Lookup />' , ( ) => {
test ( 'initially renders succesfully' , ( ) => {
mount (
< Lookup
lookup _header = "Foo Bar"
lookupChange = { ( ) => { } }
data = { mockData }
/ >
) ;
} ) ;
test ( 'calls "onLookup" when search icon is clicked' , ( ) => {
const spy = jest . spyOn ( Lookup . prototype , 'onLookup' ) ;
const wrapper = mount (
< I18nProvider >
2019-01-16 21:15:51 +03:00
< Lookup
lookup _header = "Foo Bar"
lookupChange = { ( ) => { } }
data = { mockData }
/ >
2019-01-15 22:58:23 +03:00
< / I18nProvider >
) ;
expect ( spy ) . not . toHaveBeenCalled ( ) ;
2019-01-25 23:22:32 +03:00
const searchItem = wrapper . find ( '.pf-c-input-group__text#search' ) ;
searchItem . first ( ) . simulate ( 'click' ) ;
2019-01-15 22:58:23 +03:00
expect ( spy ) . toHaveBeenCalled ( ) ;
} ) ;
2019-01-16 21:15:51 +03:00
test ( 'calls "onChecked" when a user changes a checkbox' , ( ) => {
const spy = jest . spyOn ( Lookup . prototype , 'onChecked' ) ;
const wrapper = mount (
< I18nProvider >
< Lookup
lookup _header = "Foo Bar"
lookupChange = { ( ) => { } }
data = { mockData }
/ >
< / I18nProvider >
2019-01-26 00:49:46 +03:00
) ;
2019-01-25 23:22:32 +03:00
const searchItem = wrapper . find ( '.pf-c-input-group__text#search' ) ;
searchItem . first ( ) . simulate ( 'click' ) ;
2019-01-16 21:15:51 +03:00
wrapper . find ( 'input[type="checkbox"]' ) . simulate ( 'change' ) ;
expect ( spy ) . toHaveBeenCalled ( ) ;
} ) ;
test ( 'calls "onRemove" when remove icon is clicked' , ( ) => {
const spy = jest . spyOn ( Lookup . prototype , 'onRemove' ) ;
2019-01-24 21:05:36 +03:00
mockData = [ { name : 'foo' , id : 0 , isChecked : false } , { name : 'bar' , id : 1 , isChecked : true } ] ;
2019-01-16 21:15:51 +03:00
const wrapper = mount (
< I18nProvider >
< Lookup
lookup _header = "Foo Bar"
lookupChange = { ( ) => { } }
data = { mockData }
/ >
< / I18nProvider >
) ;
2019-01-25 23:22:32 +03:00
const removeIcon = wrapper . find ( '.awx-c-icon--remove' ) . first ( ) ;
removeIcon . simulate ( 'click' ) ;
2019-01-16 21:15:51 +03:00
expect ( spy ) . toHaveBeenCalled ( ) ;
} ) ;
test ( '"wrapTags" method properly handles data' , ( ) => {
const spy = jest . spyOn ( Lookup . prototype , 'wrapTags' ) ;
2019-01-24 21:05:36 +03:00
mockData = [ { name : 'foo' , id : 0 , isChecked : false } , { name : 'bar' , id : 1 , isChecked : false } ] ;
2019-01-16 21:15:51 +03:00
const wrapper = mount (
< I18nProvider >
< Lookup
lookup _header = "Foo Bar"
lookupChange = { ( ) => { } }
data = { mockData }
/ >
< / I18nProvider >
) ;
expect ( spy ) . toHaveBeenCalled ( ) ;
const pill = wrapper . find ( 'span.awx-c-tag--pill' ) ;
expect ( pill ) . toHaveLength ( 0 ) ;
} ) ;
2019-01-15 22:58:23 +03:00
} ) ;