2018-12-11 04:41:47 +03:00
import React from 'react' ;
import { mount } from 'enzyme' ;
2019-02-20 00:14:28 +03:00
import { I18nProvider } from '@lingui/react' ;
2018-12-12 00:42:24 +03:00
import AnsibleSelect from '../../src/components/AnsibleSelect' ;
2018-12-11 04:41:47 +03:00
2019-01-24 21:05:36 +03:00
const label = 'test select' ;
const mockData = [ '/venv/baz/' , '/venv/ansible/' ] ;
2018-12-12 00:20:55 +03:00
describe ( '<AnsibleSelect />' , ( ) => {
2018-12-17 19:44:11 +03:00
test ( 'initially renders succesfully' , async ( ) => {
mount (
2019-02-20 00:14:28 +03:00
< I18nProvider >
< AnsibleSelect
value = "foo"
name = "bar"
onChange = { ( ) => { } }
label = { label }
data = { mockData }
/ >
< / I18nProvider >
2018-12-17 19:44:11 +03:00
) ;
2018-12-11 04:41:47 +03:00
} ) ;
2019-02-13 22:52:11 +03:00
2018-12-11 04:41:47 +03:00
test ( 'calls "onSelectChange" on dropdown select change' , ( ) => {
2018-12-12 00:20:55 +03:00
const spy = jest . spyOn ( AnsibleSelect . prototype , 'onSelectChange' ) ;
2018-12-17 19:44:11 +03:00
const wrapper = mount (
2019-02-20 00:14:28 +03:00
< I18nProvider >
< AnsibleSelect
value = "foo"
name = "bar"
onChange = { ( ) => { } }
label = { label }
data = { mockData }
/ >
< / I18nProvider >
2018-12-17 19:44:11 +03:00
) ;
2018-12-11 04:41:47 +03:00
expect ( spy ) . not . toHaveBeenCalled ( ) ;
wrapper . find ( 'select' ) . simulate ( 'change' ) ;
expect ( spy ) . toHaveBeenCalled ( ) ;
} ) ;
2019-02-13 22:52:11 +03:00
2019-02-12 17:42:41 +03:00
test ( 'Returns correct select options if defaultSelected props is passed' , ( ) => {
const wrapper = mount (
2019-02-20 00:14:28 +03:00
< I18nProvider >
< AnsibleSelect
value = "foo"
name = "bar"
onChange = { ( ) => { } }
label = { label }
data = { mockData }
defaultSelected = { mockData [ 1 ] }
/ >
< / I18nProvider >
2019-02-12 17:42:41 +03:00
) ;
2019-02-18 05:57:00 +03:00
expect ( wrapper . find ( 'FormSelect' ) ) . toHaveLength ( 1 ) ;
2019-02-12 17:42:41 +03:00
} ) ;
2019-01-07 15:21:50 +03:00
} ) ;