11import React from 'react' ;
2- import { create } from 'react-test-renderer' ;
3- import { mount } from 'enzyme' ;
4- import { act } from 'react-dom/test-utils' ;
5- import { containerRendersView , TestRouterWrapper } from 'lib/testHelpers' ;
2+ import { containerRendersView , render } from 'lib/testHelpers' ;
63import {
74 clusterConnectConnectorConfigPath ,
85 clusterConnectConnectorEditPath ,
96} from 'lib/paths' ;
107import EditContainer from 'components/Connect/Edit/EditContainer' ;
118import Edit , { EditProps } from 'components/Connect/Edit/Edit' ;
129import { connector } from 'redux/reducers/connect/__test__/fixtures' ;
13- import { ThemeProvider } from 'styled-components' ;
14- import theme from 'theme/theme' ;
10+ import { Route } from 'react-router' ;
11+ import { waitFor } from '@testing-library/dom' ;
12+ import { fireEvent , screen } from '@testing-library/react' ;
1513
1614jest . mock ( 'components/common/PageLoader/PageLoader' , ( ) => 'mock-PageLoader' ) ;
1715
@@ -38,43 +36,29 @@ describe('Edit', () => {
3836 const connectName = 'my-connect' ;
3937 const connectorName = 'my-connector' ;
4038
41- const setupWrapper = ( props : Partial < EditProps > = { } ) => (
42- < ThemeProvider theme = { theme } >
43- < TestRouterWrapper
44- pathname = { pathname }
45- urlParams = { { clusterName, connectName, connectorName } }
46- >
39+ const renderComponent = ( props : Partial < EditProps > = { } ) =>
40+ render (
41+ < Route path = { pathname } >
4742 < Edit
4843 fetchConfig = { jest . fn ( ) }
4944 isConfigFetching = { false }
5045 config = { connector . config }
5146 updateConfig = { jest . fn ( ) }
5247 { ...props }
5348 />
54- </ TestRouterWrapper >
55- </ ThemeProvider >
56- ) ;
57-
58- it ( 'matches snapshot' , ( ) => {
59- const wrapper = create ( setupWrapper ( ) ) ;
60- expect ( wrapper . toJSON ( ) ) . toMatchSnapshot ( ) ;
61- } ) ;
62-
63- it ( 'matches snapshot when fetching config' , ( ) => {
64- const wrapper = create ( setupWrapper ( { isConfigFetching : true } ) ) ;
65- expect ( wrapper . toJSON ( ) ) . toMatchSnapshot ( ) ;
66- } ) ;
67-
68- it ( 'matches snapshot when config has credentials' , ( ) => {
69- const wrapper = create (
70- setupWrapper ( { config : { ...connector . config , password : '******' } } )
49+ </ Route > ,
50+ {
51+ pathname : clusterConnectConnectorEditPath (
52+ clusterName ,
53+ connectName ,
54+ connectorName
55+ ) ,
56+ }
7157 ) ;
72- expect ( wrapper . toJSON ( ) ) . toMatchSnapshot ( ) ;
73- } ) ;
7458
7559 it ( 'fetches config on mount' , ( ) => {
7660 const fetchConfig = jest . fn ( ) ;
77- mount ( setupWrapper ( { fetchConfig } ) ) ;
61+ renderComponent ( { fetchConfig } ) ;
7862 expect ( fetchConfig ) . toHaveBeenCalledTimes ( 1 ) ;
7963 expect ( fetchConfig ) . toHaveBeenCalledWith (
8064 clusterName ,
@@ -85,10 +69,8 @@ describe('Edit', () => {
8569
8670 it ( 'calls updateConfig on form submit' , async ( ) => {
8771 const updateConfig = jest . fn ( ) ;
88- const wrapper = mount ( setupWrapper ( { updateConfig } ) ) ;
89- await act ( async ( ) => {
90- wrapper . find ( 'form' ) . simulate ( 'submit' ) ;
91- } ) ;
72+ renderComponent ( { updateConfig } ) ;
73+ await waitFor ( ( ) => fireEvent . submit ( screen . getByRole ( 'form' ) ) ) ;
9274 expect ( updateConfig ) . toHaveBeenCalledTimes ( 1 ) ;
9375 expect ( updateConfig ) . toHaveBeenCalledWith (
9476 clusterName ,
@@ -100,10 +82,8 @@ describe('Edit', () => {
10082
10183 it ( 'redirects to connector config view on successful submit' , async ( ) => {
10284 const updateConfig = jest . fn ( ) . mockResolvedValueOnce ( connector ) ;
103- const wrapper = mount ( setupWrapper ( { updateConfig } ) ) ;
104- await act ( async ( ) => {
105- wrapper . find ( 'form' ) . simulate ( 'submit' ) ;
106- } ) ;
85+ renderComponent ( { updateConfig } ) ;
86+ await waitFor ( ( ) => fireEvent . submit ( screen . getByRole ( 'form' ) ) ) ;
10787 expect ( mockHistoryPush ) . toHaveBeenCalledTimes ( 1 ) ;
10888 expect ( mockHistoryPush ) . toHaveBeenCalledWith (
10989 clusterConnectConnectorConfigPath (
@@ -116,10 +96,8 @@ describe('Edit', () => {
11696
11797 it ( 'does not redirect to connector config view on unsuccessful submit' , async ( ) => {
11898 const updateConfig = jest . fn ( ) . mockResolvedValueOnce ( undefined ) ;
119- const wrapper = mount ( setupWrapper ( { updateConfig } ) ) ;
120- await act ( async ( ) => {
121- wrapper . find ( 'form' ) . simulate ( 'submit' ) ;
122- } ) ;
99+ renderComponent ( { updateConfig } ) ;
100+ await waitFor ( ( ) => fireEvent . submit ( screen . getByRole ( 'form' ) ) ) ;
123101 expect ( mockHistoryPush ) . not . toHaveBeenCalled ( ) ;
124102 } ) ;
125103 } ) ;
0 commit comments