@@ -15,8 +15,9 @@ limitations under the License.
1515*/
1616
1717import React from 'react' ;
18- import { mount } from 'enzyme' ;
18+ import { mount , ReactWrapper , HTMLAttributes } from 'enzyme' ;
1919import { MatrixClient } from 'matrix-js-sdk/src/client' ;
20+ import { Room } from 'matrix-js-sdk/src/matrix' ;
2021import { EventType } from "matrix-js-sdk/src/@types/event" ;
2122import { act } from "react-dom/test-utils" ;
2223import { mocked } from 'jest-mock' ;
@@ -37,23 +38,18 @@ jest.mock('../../../../src/customisations/helpers/UIComponents', () => ({
3738 shouldShowComponent : jest . fn ( ) ,
3839} ) ) ;
3940
40- const blockUIComponent = component => {
41+ const blockUIComponent = ( component : UIComponent ) : void => {
4142 mocked ( shouldShowComponent ) . mockImplementation ( feature => feature !== component ) ;
4243} ;
4344
44- const setupSpace = ( client ) => {
45- const testSpace = mkSpace ( client , "!space:server" ) ;
45+ const setupSpace = ( client : MatrixClient ) : Room => {
46+ const testSpace : Room = mkSpace ( client , "!space:server" ) ;
4647 testSpace . name = "Test Space" ;
4748 client . getRoom = ( ) => testSpace ;
4849 return testSpace ;
4950} ;
5051
51- const setupMainMenu = async ( client , testSpace ) => {
52- const getUserIdForRoomId = jest . fn ( ) ;
53- const getDMRoomsForUserId = jest . fn ( ) ;
54- // @ts -ignore
55- DMRoomMap . sharedInstance = { getUserIdForRoomId, getDMRoomsForUserId } ;
56-
52+ const setupMainMenu = async ( client : MatrixClient , testSpace : Room ) : Promise < ReactWrapper > => {
5753 await testUtils . setupAsyncStoreWithClient ( SpaceStore . instance , client ) ;
5854 act ( ( ) => {
5955 SpaceStore . instance . setActiveSpace ( testSpace . roomId ) ;
@@ -72,12 +68,7 @@ const setupMainMenu = async (client, testSpace) => {
7268 return wrapper ;
7369} ;
7470
75- const setupPlusMenu = async ( client , testSpace ) => {
76- const getUserIdForRoomId = jest . fn ( ) ;
77- const getDMRoomsForUserId = jest . fn ( ) ;
78- // @ts -ignore
79- DMRoomMap . sharedInstance = { getUserIdForRoomId, getDMRoomsForUserId } ;
80-
71+ const setupPlusMenu = async ( client : MatrixClient , testSpace : Room ) : Promise < ReactWrapper > => {
8172 await testUtils . setupAsyncStoreWithClient ( SpaceStore . instance , client ) ;
8273 act ( ( ) => {
8374 SpaceStore . instance . setActiveSpace ( testSpace . roomId ) ;
@@ -96,15 +87,15 @@ const setupPlusMenu = async (client, testSpace) => {
9687 return wrapper ;
9788} ;
9889
99- const checkIsDisabled = menuItem => {
90+ const checkIsDisabled = ( menuItem : ReactWrapper < HTMLAttributes > ) : void => {
10091 expect ( menuItem . props ( ) . disabled ) . toBeTruthy ( ) ;
10192 expect ( menuItem . props ( ) [ 'aria-disabled' ] ) . toBeTruthy ( ) ;
10293} ;
10394
104- const checkMenuLabels = ( items , labelArray ) => {
95+ const checkMenuLabels = ( items : ReactWrapper < HTMLAttributes > , labelArray : Array < string > ) => {
10596 expect ( items ) . toHaveLength ( labelArray . length ) ;
10697
107- const checkLabel = ( item , label ) => {
98+ const checkLabel = ( item : ReactWrapper < HTMLAttributes > , label : string ) => {
10899 expect ( item . find ( ".mx_IconizedContextMenu_label" ) . text ( ) ) . toBe ( label ) ;
109100 } ;
110101
@@ -119,6 +110,12 @@ describe("RoomListHeader", () => {
119110
120111 beforeEach ( ( ) => {
121112 jest . resetAllMocks ( ) ;
113+
114+ const dmRoomMap = {
115+ getUserIdForRoomId : jest . fn ( ) ,
116+ getDMRoomsForUserId : jest . fn ( ) ,
117+ } as unknown as DMRoomMap ;
118+ DMRoomMap . setShared ( dmRoomMap ) ;
122119 client = createTestClient ( ) ;
123120 mocked ( shouldShowComponent ) . mockReturnValue ( true ) ; // show all UIComponents
124121 } ) ;
0 commit comments