11import React from 'react' ;
2- import { mount } from 'enzyme' ;
2+ import { render , screen } from '@testing-library/react' ;
3+ import userEvent from '@testing-library/user-event' ;
34
45import FormTabs from '../tabs' ;
56import RenderWithProvider from '../../../../__mocks__/with-provider' ;
67import { FormRenderer , validatorTypes } from '@data-driven-forms/react-form-renderer' ;
78import { componentMapper , FormTemplate } from '../index' ;
8- import { Tab } from 'semantic-ui-react' ;
99
1010describe ( 'tabs' , ( ) => {
1111 const props = {
@@ -28,37 +28,34 @@ describe('tabs', () => {
2828 } ;
2929
3030 it ( 'should render tabs correctly' , ( ) => {
31- const wrapper = mount (
31+ render (
3232 < RenderWithProvider value = { { formOptions } } >
3333 < FormTabs { ...props } />
3434 </ RenderWithProvider >
3535 ) ;
3636
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 ( ) ;
3940 } ) ;
4041
4142 it ( 'should switch tabs correctly' , ( ) => {
42- const wrapper = mount (
43+ render (
4344 < RenderWithProvider value = { { formOptions } } >
4445 < FormTabs { ...props } />
4546 </ RenderWithProvider >
4647 ) ;
4748
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' ) ;
5050
51- const secondTabButton = wrapper . find ( 'a.item' ) . last ( ) ;
52- secondTabButton . simulate ( 'click' ) ;
53- wrapper . update ( ) ;
51+ userEvent . click ( screen . getByText ( 'cosiTitle2' ) ) ;
5452
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' ) ;
5754 } ) ;
5855
5956 it ( 'validate all tabs' , ( ) => {
6057 const onSubmit = jest . fn ( ) ;
61- const wrapper = mount (
58+ render (
6259 < FormRenderer
6360 componentMapper = { componentMapper }
6461 FormTemplate = { ( props ) => < FormTemplate { ...props } /> }
@@ -78,6 +75,7 @@ describe('tabs', () => {
7875 component : 'text-field' ,
7976 name : 'name' ,
8077 validate : [ { type : validatorTypes . REQUIRED } ] ,
78+ 'aria-label' : 'name' ,
8179 } ,
8280 ] ,
8381 } ,
@@ -89,6 +87,7 @@ describe('tabs', () => {
8987 component : 'text-field' ,
9088 name : 'password' ,
9189 validate : [ { type : validatorTypes . REQUIRED } ] ,
90+ 'aria-label' : 'password' ,
9291 } ,
9392 ] ,
9493 } ,
@@ -99,24 +98,13 @@ describe('tabs', () => {
9998 />
10099 ) ;
101100
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' ) ) ;
110103
111104 expect ( onSubmit ) . not . toHaveBeenCalled ( ) ;
112105
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' ) ) ;
120108
121109 expect ( onSubmit ) . toHaveBeenCalledWith ( { name : 'NAME' , password : 'PASSWORD' } ) ;
122110 } ) ;
0 commit comments