@@ -16,9 +16,8 @@ limitations under the License.
1616*/
1717
1818import React from "react" ;
19- import { act } from "react-dom/test-utils" ;
20- // eslint-disable-next-line deprecate/import
21- import { mount , ReactWrapper } from "enzyme" ;
19+ import { render , screen } from "@testing-library/react" ;
20+ import userEvent from "@testing-library/user-event" ;
2221
2322import InteractiveAuthDialog from "../../../../src/components/views/dialogs/InteractiveAuthDialog" ;
2423import { flushPromises , getMockClientWithEventEmitter , unmockClientPeg } from "../../../test-utils" ;
@@ -33,7 +32,10 @@ describe("InteractiveAuthDialog", function () {
3332 makeRequest : jest . fn ( ) . mockResolvedValue ( undefined ) ,
3433 onFinished : jest . fn ( ) ,
3534 } ;
36- const getComponent = ( props = { } ) => mount ( < InteractiveAuthDialog { ...defaultProps } { ...props } /> ) ;
35+
36+ const renderComponent = ( props = { } ) => render ( < InteractiveAuthDialog { ...defaultProps } { ...props } /> ) ;
37+ const getPasswordField = ( ) => screen . getByLabelText ( "Password" ) ;
38+ const getSubmitButton = ( ) => screen . getByRole ( "button" , { name : "Continue" } ) ;
3739
3840 beforeEach ( function ( ) {
3941 jest . clearAllMocks ( ) ;
@@ -44,8 +46,6 @@ describe("InteractiveAuthDialog", function () {
4446 unmockClientPeg ( ) ;
4547 } ) ;
4648
47- const getSubmitButton = ( wrapper : ReactWrapper ) => wrapper . find ( '[type="submit"]' ) . at ( 0 ) ;
48-
4949 it ( "Should successfully complete a password flow" , async ( ) => {
5050 const onFinished = jest . fn ( ) ;
5151 const makeRequest = jest . fn ( ) . mockResolvedValue ( { a : 1 } ) ;
@@ -56,31 +56,24 @@ describe("InteractiveAuthDialog", function () {
5656 flows : [ { stages : [ "m.login.password" ] } ] ,
5757 } ;
5858
59- const wrapper = getComponent ( { makeRequest, onFinished, authData } ) ;
59+ renderComponent ( { makeRequest, onFinished, authData } ) ;
6060
61- const passwordNode = wrapper . find ( 'input[type="password"]' ) . at ( 0 ) ;
62- const submitNode = getSubmitButton ( wrapper ) ;
61+ const passwordField = getPasswordField ( ) ;
62+ const submitButton = getSubmitButton ( ) ;
6363
64- const formNode = wrapper . find ( "form" ) . at ( 0 ) ;
65- expect ( passwordNode ) . toBeTruthy ( ) ;
66- expect ( submitNode ) . toBeTruthy ( ) ;
64+ expect ( passwordField ) . toBeTruthy ( ) ;
65+ expect ( submitButton ) . toBeTruthy ( ) ;
6766
6867 // submit should be disabled
69- expect ( submitNode . props ( ) . disabled ) . toBe ( true ) ;
68+ expect ( submitButton ) . toBeDisabled ( ) ;
7069
7170 // put something in the password box
72- act ( ( ) => {
73- passwordNode . simulate ( "change" , { target : { value : "s3kr3t" } } ) ;
74- wrapper . setProps ( { } ) ;
75- } ) ;
71+ await userEvent . type ( passwordField , "s3kr3t" ) ;
7672
77- expect ( wrapper . find ( 'input[type="password"]' ) . at ( 0 ) . props ( ) . value ) . toEqual ( "s3kr3t" ) ;
78- expect ( getSubmitButton ( wrapper ) . props ( ) . disabled ) . toBe ( false ) ;
73+ expect ( submitButton ) . not . toBeDisabled ( ) ;
7974
8075 // hit enter; that should trigger a request
81- act ( ( ) => {
82- formNode . simulate ( "submit" ) ;
83- } ) ;
76+ await userEvent . click ( submitButton ) ;
8477
8578 // wait for auth request to resolve
8679 await flushPromises ( ) ;
0 commit comments