88import React from "react" ;
99import { render , screen } from "jest-matrix-react" ;
1010import { mocked } from "jest-mock" ;
11+ import userEvent from "@testing-library/user-event" ;
1112
1213import { RoomListPanel } from "../../../../../../src/components/views/rooms/RoomListPanel" ;
1314import { shouldShowComponent } from "../../../../../../src/customisations/helpers/UIComponents" ;
1415import { MetaSpace } from "../../../../../../src/stores/spaces" ;
16+ import { LandmarkNavigation } from "../../../../../../src/accessibility/LandmarkNavigation" ;
17+ import { ReleaseAnnouncementStore } from "../../../../../../src/stores/ReleaseAnnouncementStore" ;
1518
1619jest . mock ( "../../../../../../src/customisations/helpers/UIComponents" , ( ) => ( {
1720 shouldShowComponent : jest . fn ( ) ,
1821} ) ) ;
1922
23+ jest . mock ( "../../../../../../src/accessibility/LandmarkNavigation" , ( ) => ( {
24+ LandmarkNavigation : {
25+ findAndFocusNextLandmark : jest . fn ( ) ,
26+ } ,
27+ Landmark : {
28+ ROOM_SEARCH : "something" ,
29+ } ,
30+ } ) ) ;
31+
32+ // mock out release announcements as they interfere with what's focused
33+ // (this can be removed once the new room list announcement is gone)
34+ jest . spyOn ( ReleaseAnnouncementStore . instance , "getReleaseAnnouncement" ) . mockReturnValue ( null ) ;
35+
2036describe ( "<RoomListPanel />" , ( ) => {
2137 function renderComponent ( ) {
2238 return render ( < RoomListPanel activeSpace = { MetaSpace . Home } /> ) ;
2339 }
2440
2541 beforeEach ( ( ) => {
42+ jest . clearAllMocks ( ) ;
43+
2644 // By default, we consider shouldShowComponent(UIComponent.FilterContainer) should return true
2745 mocked ( shouldShowComponent ) . mockReturnValue ( true ) ;
2846 } ) ;
@@ -37,4 +55,38 @@ describe("<RoomListPanel />", () => {
3755 renderComponent ( ) ;
3856 expect ( screen . queryByRole ( "button" , { name : "Search Ctrl K" } ) ) . toBeNull ( ) ;
3957 } ) ;
58+
59+ it ( "should move to the next landmark when the shortcut key is pressed" , async ( ) => {
60+ renderComponent ( ) ;
61+
62+ const userEv = userEvent . setup ( ) ;
63+
64+ // Pick something arbitrary and focusable in the room list component and focus it
65+ const exploreRooms = screen . getByRole ( "button" , { name : "Explore rooms" } ) ;
66+ exploreRooms . focus ( ) ;
67+ expect ( exploreRooms ) . toHaveFocus ( ) ;
68+
69+ screen . getByRole ( "navigation" , { name : "Room list" } ) . focus ( ) ;
70+ await userEv . keyboard ( "{Control>}{F6}{/Control}" ) ;
71+
72+ expect ( LandmarkNavigation . findAndFocusNextLandmark ) . toHaveBeenCalled ( ) ;
73+ } ) ;
74+
75+ it ( "should not move to the next landmark if room list loses focus" , async ( ) => {
76+ renderComponent ( ) ;
77+
78+ const userEv = userEvent . setup ( ) ;
79+
80+ // Pick something arbitrary and focusable in the room list component and focus it
81+ const exploreRooms = screen . getByRole ( "button" , { name : "Explore rooms" } ) ;
82+ exploreRooms . focus ( ) ;
83+ expect ( exploreRooms ) . toHaveFocus ( ) ;
84+
85+ exploreRooms . blur ( ) ;
86+ expect ( exploreRooms ) . not . toHaveFocus ( ) ;
87+
88+ await userEv . keyboard ( "{Control>}{F6}{/Control}" ) ;
89+
90+ expect ( LandmarkNavigation . findAndFocusNextLandmark ) . not . toHaveBeenCalled ( ) ;
91+ } ) ;
4092} ) ;
0 commit comments