1
1
import { mount , shallow } from 'enzyme' ;
2
2
import Downshift from 'downshift' ;
3
3
import Modal from 'views/components/Modal' ;
4
+ import { waitForComponentToPaint } from 'test-utils/wait' ;
4
5
import { ModulesSelectComponent } from './ModulesSelect' ;
5
6
6
7
const modules = [
@@ -32,9 +33,10 @@ const commonProps = {
32
33
} ;
33
34
34
35
describe ( ModulesSelectComponent , ( ) => {
35
- it ( 'should show results on input value change' , ( ) => {
36
+ it ( 'should show results on input value change' , async ( ) => {
36
37
const wrapper = mount ( < ModulesSelectComponent { ...commonProps } matchBreakpoint /> ) ;
37
38
wrapper . setState ( { isOpen : true } ) ;
39
+ await waitForComponentToPaint ( wrapper ) ;
38
40
const input = wrapper . find ( 'input' ) ;
39
41
expect ( wrapper . find ( 'li' ) ) . toHaveLength ( 0 ) ;
40
42
input . simulate ( 'change' , { target : { value : 'T' } } ) ;
@@ -43,17 +45,19 @@ describe(ModulesSelectComponent, () => {
43
45
expect ( wrapper . find ( 'li' ) ) . toHaveLength ( 0 ) ;
44
46
} ) ;
45
47
46
- it ( 'should indicate module is added' , ( ) => {
48
+ it ( 'should indicate module is added' , async ( ) => {
47
49
const wrapper = mount ( < ModulesSelectComponent { ...commonProps } matchBreakpoint /> ) ;
48
50
wrapper . setState ( { isOpen : true , inputValue : 'T' } ) ;
51
+ await waitForComponentToPaint ( wrapper ) ;
49
52
const result = wrapper . find ( 'li' ) . at ( 1 ) ;
50
53
expect ( result . prop ( 'disabled' ) ) . toBe ( true ) ;
51
54
expect ( result . find ( '.badge' ) . exists ( ) ) . toBe ( true ) ;
52
55
} ) ;
53
56
54
- it ( 'should call onChange when module is selected' , ( ) => {
57
+ it ( 'should call onChange when module is selected' , async ( ) => {
55
58
const wrapper = mount ( < ModulesSelectComponent { ...commonProps } matchBreakpoint /> ) ;
56
59
wrapper . setState ( { isOpen : true , inputValue : 'T' } ) ;
60
+ await waitForComponentToPaint ( wrapper ) ;
57
61
wrapper . find ( 'li' ) . first ( ) . simulate ( 'click' ) ;
58
62
expect ( commonProps . onChange ) . toHaveBeenCalledWith ( modules [ 0 ] . moduleCode ) ;
59
63
// remain open
0 commit comments