@@ -15,13 +15,14 @@ limitations under the License.
15
15
*/
16
16
17
17
import React from "react" ;
18
- import { fireEvent , render , screen , waitFor , cleanup } from "@testing-library/react" ;
18
+ import { fireEvent , render , screen , waitFor , cleanup , act } from "@testing-library/react" ;
19
19
import userEvent from "@testing-library/user-event" ;
20
20
import { mocked } from "jest-mock" ;
21
21
import { Room , User , MatrixClient , RoomMember , MatrixEvent , EventType } from "matrix-js-sdk/src/matrix" ;
22
22
import { Phase , VerificationRequest } from "matrix-js-sdk/src/crypto/verification/request/VerificationRequest" ;
23
23
import { DeviceTrustLevel , UserTrustLevel } from "matrix-js-sdk/src/crypto/CrossSigning" ;
24
24
import { DeviceInfo } from "matrix-js-sdk/src/crypto/deviceinfo" ;
25
+ import { defer } from "matrix-js-sdk/src/utils" ;
25
26
26
27
import UserInfo , {
27
28
BanToggleButton ,
@@ -44,6 +45,7 @@ import * as mockVerification from "../../../../src/verification";
44
45
import Modal from "../../../../src/Modal" ;
45
46
import { E2EStatus } from "../../../../src/utils/ShieldUtils" ;
46
47
import { DirectoryMember , startDmOnFirstMessage } from "../../../../src/utils/direct-messages" ;
48
+ import { flushPromises } from "../../../test-utils" ;
47
49
48
50
jest . mock ( "../../../../src/utils/direct-messages" , ( ) => ( {
49
51
...jest . requireActual ( "../../../../src/utils/direct-messages" ) ,
@@ -608,15 +610,30 @@ describe("<UserOptionsSection />", () => {
608
610
] ) (
609
611
"clicking »message« %s should start a DM" ,
610
612
async ( test : string , member : RoomMember | User , expectedAvatarUrl : string | undefined ) => {
613
+ const deferred = defer < string > ( ) ;
614
+ mocked ( startDmOnFirstMessage ) . mockReturnValue ( deferred . promise ) ;
615
+
611
616
renderComponent ( { member } ) ;
612
617
await userEvent . click ( screen . getByText ( "Message" ) ) ;
618
+
619
+ // Checking the attribute, because the button is a DIV and toBeDisabled() does not work.
620
+ expect ( screen . getByText ( "Message" ) ) . toHaveAttribute ( "disabled" ) ;
621
+
613
622
expect ( startDmOnFirstMessage ) . toHaveBeenCalledWith ( mockClient , [
614
623
new DirectoryMember ( {
615
624
user_id : member . userId ,
616
625
display_name : member . rawDisplayName ,
617
626
avatar_url : expectedAvatarUrl ,
618
627
} ) ,
619
628
] ) ;
629
+
630
+ await act ( async ( ) => {
631
+ deferred . resolve ( "!dm:example.com" ) ;
632
+ await flushPromises ( ) ;
633
+ } ) ;
634
+
635
+ // Checking the attribute, because the button is a DIV and toBeDisabled() does not work.
636
+ expect ( screen . getByText ( "Message" ) ) . not . toHaveAttribute ( "disabled" ) ;
620
637
} ,
621
638
) ;
622
639
} ) ;
0 commit comments