@@ -15,16 +15,13 @@ limitations under the License.
15
15
*/
16
16
17
17
import React from 'react' ;
18
- // eslint-disable-next-line deprecate/import
19
- import { mount } from 'enzyme' ;
18
+ import { render , screen , fireEvent } from "@testing-library/react" ;
20
19
import { mocked } from 'jest-mock' ;
21
20
import { MatrixClient } from 'matrix-js-sdk/src/matrix' ;
22
- import { act } from "react-dom/test-utils" ;
23
21
24
22
import SpacePanel from '../../../../src/components/views/spaces/SpacePanel' ;
25
23
import { MatrixClientPeg } from '../../../../src/MatrixClientPeg' ;
26
24
import { SpaceKey } from '../../../../src/stores/spaces' ;
27
- import { findByTestId } from '../../../test-utils' ;
28
25
import { shouldShowComponent } from '../../../../src/customisations/helpers/UIComponents' ;
29
26
import { UIComponent } from '../../../../src/settings/UIFeature' ;
30
27
@@ -47,10 +44,6 @@ jest.mock('../../../../src/customisations/helpers/UIComponents', () => ({
47
44
} ) ) ;
48
45
49
46
describe ( '<SpacePanel />' , ( ) => {
50
- const defaultProps = { } ;
51
- const getComponent = ( props = { } ) =>
52
- mount ( < SpacePanel { ...defaultProps } { ...props } /> ) ;
53
-
54
47
const mockClient = {
55
48
getUserId : jest . fn ( ) . mockReturnValue ( '@test:test' ) ,
56
49
isGuest : jest . fn ( ) ,
@@ -67,26 +60,21 @@ describe('<SpacePanel />', () => {
67
60
68
61
describe ( 'create new space button' , ( ) => {
69
62
it ( 'renders create space button when UIComponent.CreateSpaces component should be shown' , ( ) => {
70
- const component = getComponent ( ) ;
71
- expect ( findByTestId ( component , ' create-space-button' ) . length ) . toBeTruthy ( ) ;
63
+ render ( < SpacePanel /> ) ;
64
+ screen . getByTestId ( " create-space-button" ) ;
72
65
} ) ;
73
66
74
67
it ( 'does not render create space button when UIComponent.CreateSpaces component should not be shown' , ( ) => {
75
68
mocked ( shouldShowComponent ) . mockReturnValue ( false ) ;
76
- const component = getComponent ( ) ;
69
+ render ( < SpacePanel /> ) ;
77
70
expect ( shouldShowComponent ) . toHaveBeenCalledWith ( UIComponent . CreateSpaces ) ;
78
- expect ( findByTestId ( component , ' create-space-button' ) . length ) . toBeFalsy ( ) ;
71
+ expect ( screen . queryByTestId ( " create-space-button" ) ) . toBeFalsy ( ) ;
79
72
} ) ;
80
73
81
- it ( 'opens context menu on create space button click' , async ( ) => {
82
- const component = getComponent ( ) ;
83
-
84
- await act ( async ( ) => {
85
- findByTestId ( component , 'create-space-button' ) . at ( 0 ) . simulate ( 'click' ) ;
86
- component . setProps ( { } ) ;
87
- } ) ;
88
-
89
- expect ( component . find ( 'SpaceCreateMenu' ) . length ) . toBeTruthy ( ) ;
74
+ it ( 'opens context menu on create space button click' , ( ) => {
75
+ render ( < SpacePanel /> ) ;
76
+ fireEvent . click ( screen . getByTestId ( "create-space-button" ) ) ;
77
+ screen . getByTestId ( "create-space-button" ) ;
90
78
} ) ;
91
79
} ) ;
92
80
} ) ;
0 commit comments