1
1
import React from 'react' ;
2
- import { mount } from 'enzyme' ;
2
+ import { render , screen } from '@testing-library/react' ;
3
+ import userEvent from '@testing-library/user-event' ;
3
4
4
5
import FormTabs from '../tabs' ;
5
6
import RenderWithProvider from '../../../../__mocks__/with-provider' ;
6
7
import { FormRenderer , validatorTypes } from '@data-driven-forms/react-form-renderer' ;
7
8
import { componentMapper , FormTemplate } from '../index' ;
8
- import { Tab } from 'semantic-ui-react' ;
9
9
10
10
describe ( 'tabs' , ( ) => {
11
11
const props = {
@@ -28,37 +28,34 @@ describe('tabs', () => {
28
28
} ;
29
29
30
30
it ( 'should render tabs correctly' , ( ) => {
31
- const wrapper = mount (
31
+ render (
32
32
< RenderWithProvider value = { { formOptions } } >
33
33
< FormTabs { ...props } />
34
34
</ RenderWithProvider >
35
35
) ;
36
36
37
- expect ( wrapper . find ( Tab ) ) . toHaveLength ( 1 ) ;
38
- expect ( wrapper . find ( Tab . Pane ) ) . toHaveLength ( 2 ) ;
37
+ expect ( screen . getAllByText ( 'Content' ) ) . toHaveLength ( 2 ) ;
38
+ expect ( screen . getByText ( 'cosiTitle' ) ) . toBeInTheDocument ( ) ;
39
+ expect ( screen . getByText ( 'cosiTitle2' ) ) . toBeInTheDocument ( ) ;
39
40
} ) ;
40
41
41
42
it ( 'should switch tabs correctly' , ( ) => {
42
- const wrapper = mount (
43
+ render (
43
44
< RenderWithProvider value = { { formOptions } } >
44
45
< FormTabs { ...props } />
45
46
</ RenderWithProvider >
46
47
) ;
47
48
48
- expect ( wrapper . find ( Tab . Pane ) . first ( ) . prop ( 'active' ) ) . toEqual ( true ) ;
49
- expect ( wrapper . find ( Tab . Pane ) . last ( ) . prop ( 'active' ) ) . toEqual ( false ) ;
49
+ expect ( screen . getByText ( 'cosiTitle' ) ) . toHaveClass ( 'active item' ) ;
50
50
51
- const secondTabButton = wrapper . find ( 'a.item' ) . last ( ) ;
52
- secondTabButton . simulate ( 'click' ) ;
53
- wrapper . update ( ) ;
51
+ userEvent . click ( screen . getByText ( 'cosiTitle2' ) ) ;
54
52
55
- expect ( wrapper . find ( Tab . Pane ) . first ( ) . prop ( 'active' ) ) . toEqual ( false ) ;
56
- expect ( wrapper . find ( Tab . Pane ) . last ( ) . prop ( 'active' ) ) . toEqual ( true ) ;
53
+ expect ( screen . getByText ( 'cosiTitle2' ) ) . toHaveClass ( 'active item' ) ;
57
54
} ) ;
58
55
59
56
it ( 'validate all tabs' , ( ) => {
60
57
const onSubmit = jest . fn ( ) ;
61
- const wrapper = mount (
58
+ render (
62
59
< FormRenderer
63
60
componentMapper = { componentMapper }
64
61
FormTemplate = { ( props ) => < FormTemplate { ...props } /> }
@@ -78,6 +75,7 @@ describe('tabs', () => {
78
75
component : 'text-field' ,
79
76
name : 'name' ,
80
77
validate : [ { type : validatorTypes . REQUIRED } ] ,
78
+ 'aria-label' : 'name' ,
81
79
} ,
82
80
] ,
83
81
} ,
@@ -89,6 +87,7 @@ describe('tabs', () => {
89
87
component : 'text-field' ,
90
88
name : 'password' ,
91
89
validate : [ { type : validatorTypes . REQUIRED } ] ,
90
+ 'aria-label' : 'password' ,
92
91
} ,
93
92
] ,
94
93
} ,
@@ -99,24 +98,13 @@ describe('tabs', () => {
99
98
/>
100
99
) ;
101
100
102
- wrapper
103
- . find ( 'input' )
104
- . first ( )
105
- . simulate ( 'change' , { target : { value : 'NAME' } } ) ;
106
- wrapper . update ( ) ;
107
-
108
- wrapper . find ( 'form' ) . simulate ( 'submit' ) ;
109
- wrapper . update ( ) ;
101
+ userEvent . type ( screen . getByLabelText ( 'name' ) , 'NAME' ) ;
102
+ userEvent . click ( screen . getByText ( 'Submit' ) ) ;
110
103
111
104
expect ( onSubmit ) . not . toHaveBeenCalled ( ) ;
112
105
113
- wrapper
114
- . find ( 'input' )
115
- . last ( )
116
- . simulate ( 'change' , { target : { value : 'PASSWORD' } } ) ;
117
- wrapper . update ( ) ;
118
-
119
- wrapper . find ( 'form' ) . simulate ( 'submit' ) ;
106
+ userEvent . type ( screen . getByLabelText ( 'password' ) , 'PASSWORD' ) ;
107
+ userEvent . click ( screen . getByText ( 'Submit' ) ) ;
120
108
121
109
expect ( onSubmit ) . toHaveBeenCalledWith ( { name : 'NAME' , password : 'PASSWORD' } ) ;
122
110
} ) ;
0 commit comments