@@ -28,12 +28,10 @@ import {
28
28
VerificationPhase as Phase ,
29
29
VerificationRequestEvent ,
30
30
type CryptoApi ,
31
- type DeviceVerificationStatus ,
32
31
} from "matrix-js-sdk/src/crypto-api" ;
33
32
34
33
import UserInfo , {
35
34
BanToggleButton ,
36
- DeviceItem ,
37
35
disambiguateDevices ,
38
36
getPowerLevels ,
39
37
isMuted ,
@@ -48,7 +46,6 @@ import { RightPanelPhases } from "../../../../../src/stores/right-panel/RightPan
48
46
import { MatrixClientPeg } from "../../../../../src/MatrixClientPeg" ;
49
47
import MatrixClientContext from "../../../../../src/contexts/MatrixClientContext" ;
50
48
import MultiInviter from "../../../../../src/utils/MultiInviter" ;
51
- import * as mockVerification from "../../../../../src/verification" ;
52
49
import Modal from "../../../../../src/Modal" ;
53
50
import { DirectoryMember , startDmOnFirstMessage } from "../../../../../src/utils/direct-messages" ;
54
51
import { clearAllModals , flushPromises } from "../../../../test-utils" ;
@@ -532,153 +529,6 @@ describe("<UserInfoHeader />", () => {
532
529
} ) ;
533
530
} ) ;
534
531
535
- describe ( "<DeviceItem />" , ( ) => {
536
- const device = { deviceId : "deviceId" , displayName : "deviceName" } as Device ;
537
- const defaultProps = {
538
- userId : defaultUserId ,
539
- device,
540
- isUserVerified : false ,
541
- } ;
542
-
543
- const renderComponent = ( props = { } ) => {
544
- const Wrapper = ( wrapperProps = { } ) => {
545
- return < MatrixClientContext . Provider value = { mockClient } { ...wrapperProps } /> ;
546
- } ;
547
-
548
- return render ( < DeviceItem { ...defaultProps } { ...props } /> , {
549
- wrapper : Wrapper ,
550
- } ) ;
551
- } ;
552
-
553
- const setMockDeviceTrust = ( isVerified = false , isCrossSigningVerified = false ) => {
554
- mockCrypto . getDeviceVerificationStatus . mockResolvedValue ( {
555
- isVerified : ( ) => isVerified ,
556
- crossSigningVerified : isCrossSigningVerified ,
557
- } as DeviceVerificationStatus ) ;
558
- } ;
559
-
560
- const mockVerifyDevice = jest . spyOn ( mockVerification , "verifyDevice" ) ;
561
-
562
- beforeEach ( ( ) => {
563
- setMockDeviceTrust ( ) ;
564
- } ) ;
565
-
566
- afterEach ( ( ) => {
567
- mockCrypto . getDeviceVerificationStatus . mockReset ( ) ;
568
- mockVerifyDevice . mockClear ( ) ;
569
- } ) ;
570
-
571
- afterAll ( ( ) => {
572
- mockVerifyDevice . mockRestore ( ) ;
573
- } ) ;
574
-
575
- it ( "with unverified user and device, displays button without a label" , async ( ) => {
576
- renderComponent ( ) ;
577
- await flushPromises ( ) ;
578
-
579
- expect ( screen . getByRole ( "button" , { name : device . displayName ! } ) ) . toBeInTheDocument ( ) ;
580
- expect ( screen . queryByText ( / t r u s t e d / i) ) . not . toBeInTheDocument ( ) ;
581
- } ) ;
582
-
583
- it ( "with verified user only, displays button with a 'Not trusted' label" , async ( ) => {
584
- renderComponent ( { isUserVerified : true } ) ;
585
- await flushPromises ( ) ;
586
-
587
- const button = screen . getByRole ( "button" , { name : device . displayName } ) ;
588
- expect ( button ) . toHaveTextContent ( `${ device . displayName } Not trusted` ) ;
589
- } ) ;
590
-
591
- it ( "with verified device only, displays no button without a label" , async ( ) => {
592
- setMockDeviceTrust ( true ) ;
593
- renderComponent ( ) ;
594
- await flushPromises ( ) ;
595
-
596
- expect ( screen . getByText ( device . displayName ! ) ) . toBeInTheDocument ( ) ;
597
- expect ( screen . queryByText ( / t r u s t e d / ) ) . not . toBeInTheDocument ( ) ;
598
- } ) ;
599
-
600
- it ( "when userId is the same as userId from client, uses isCrossSigningVerified to determine if button is shown" , async ( ) => {
601
- const deferred = defer < DeviceVerificationStatus > ( ) ;
602
- mockCrypto . getDeviceVerificationStatus . mockReturnValue ( deferred . promise ) ;
603
-
604
- mockClient . getSafeUserId . mockReturnValueOnce ( defaultUserId ) ;
605
- mockClient . getUserId . mockReturnValueOnce ( defaultUserId ) ;
606
- renderComponent ( ) ;
607
- await flushPromises ( ) ;
608
-
609
- // set trust to be false for isVerified, true for isCrossSigningVerified
610
- deferred . resolve ( {
611
- isVerified : ( ) => false ,
612
- crossSigningVerified : true ,
613
- } as DeviceVerificationStatus ) ;
614
-
615
- await expect ( screen . findByText ( device . displayName ! ) ) . resolves . toBeInTheDocument ( ) ;
616
- // expect to see no button in this case
617
- expect ( screen . queryByRole ( "button" ) ) . not . toBeInTheDocument ( ) ;
618
- } ) ;
619
-
620
- it ( "with verified user and device, displays no button and a 'Trusted' label" , async ( ) => {
621
- setMockDeviceTrust ( true ) ;
622
- renderComponent ( { isUserVerified : true } ) ;
623
- await flushPromises ( ) ;
624
-
625
- expect ( screen . queryByRole ( "button" ) ) . not . toBeInTheDocument ( ) ;
626
- expect ( screen . getByText ( device . displayName ! ) ) . toBeInTheDocument ( ) ;
627
- expect ( screen . getByText ( "Trusted" ) ) . toBeInTheDocument ( ) ;
628
- } ) ;
629
-
630
- it ( "does not call verifyDevice if client.getUser returns null" , async ( ) => {
631
- mockClient . getUser . mockReturnValueOnce ( null ) ;
632
- renderComponent ( ) ;
633
- await flushPromises ( ) ;
634
-
635
- const button = screen . getByRole ( "button" , { name : device . displayName ! } ) ;
636
- expect ( button ) . toBeInTheDocument ( ) ;
637
- await userEvent . click ( button ) ;
638
-
639
- expect ( mockVerifyDevice ) . not . toHaveBeenCalled ( ) ;
640
- } ) ;
641
-
642
- it ( "calls verifyDevice if client.getUser returns an object" , async ( ) => {
643
- mockClient . getUser . mockReturnValueOnce ( defaultUser ) ;
644
- // set mock return of isGuest to short circuit verifyDevice call to avoid
645
- // even more mocking
646
- mockClient . isGuest . mockReturnValueOnce ( true ) ;
647
- renderComponent ( ) ;
648
- await flushPromises ( ) ;
649
-
650
- const button = screen . getByRole ( "button" , { name : device . displayName ! } ) ;
651
- expect ( button ) . toBeInTheDocument ( ) ;
652
- await userEvent . click ( button ) ;
653
-
654
- expect ( mockVerifyDevice ) . toHaveBeenCalledTimes ( 1 ) ;
655
- expect ( mockVerifyDevice ) . toHaveBeenCalledWith ( mockClient , defaultUser , device ) ;
656
- } ) ;
657
-
658
- it ( "with display name" , async ( ) => {
659
- const { container } = renderComponent ( ) ;
660
- await flushPromises ( ) ;
661
-
662
- expect ( container ) . toMatchSnapshot ( ) ;
663
- } ) ;
664
-
665
- it ( "without display name" , async ( ) => {
666
- const device = { deviceId : "deviceId" } as Device ;
667
- const { container } = renderComponent ( { device, userId : defaultUserId } ) ;
668
- await flushPromises ( ) ;
669
-
670
- expect ( container ) . toMatchSnapshot ( ) ;
671
- } ) ;
672
-
673
- it ( "ambiguous display name" , async ( ) => {
674
- const device = { deviceId : "deviceId" , ambiguous : true , displayName : "my display name" } ;
675
- const { container } = renderComponent ( { device, userId : defaultUserId } ) ;
676
- await flushPromises ( ) ;
677
-
678
- expect ( container ) . toMatchSnapshot ( ) ;
679
- } ) ;
680
- } ) ;
681
-
682
532
describe ( "<UserOptionsSection />" , ( ) => {
683
533
const member = new RoomMember ( defaultRoomId , defaultUserId ) ;
684
534
const defaultProps = { member, canInvite : false , isSpace : false } ;
0 commit comments