@@ -23,22 +23,28 @@ import { mocked } from "jest-mock";
23
23
import { SlidingSync } from "matrix-js-sdk/src/sliding-sync" ;
24
24
import { Room } from "matrix-js-sdk/src/matrix" ;
25
25
26
- import { useSlidingSyncRoomSearch } from "../../src/hooks/useSlidingSyncRoomSearch" ;
26
+ import { SlidingSyncRoomSearchOpts , useSlidingSyncRoomSearch } from "../../src/hooks/useSlidingSyncRoomSearch" ;
27
27
import { MockEventEmitter , stubClient } from "../test-utils" ;
28
28
import { SlidingSyncManager } from "../../src/SlidingSyncManager" ;
29
29
30
+ type RoomSearchHook = {
31
+ loading : boolean ;
32
+ rooms : Room [ ] ;
33
+ search ( opts : SlidingSyncRoomSearchOpts ) : Promise < boolean > ;
34
+ } ;
35
+
30
36
// hooks must be inside a React component else you get:
31
37
// "Invalid hook call. Hooks can only be called inside of the body of a function component."
32
- function RoomSearchComponent ( { onClick } ) {
38
+ function RoomSearchComponent ( props : { onClick : ( h : RoomSearchHook ) => void } ) {
33
39
const roomSearch = useSlidingSyncRoomSearch ( ) ;
34
- return < div onClick = { ( ) => onClick ( roomSearch ) } /> ;
40
+ return < div onClick = { ( ) => props . onClick ( roomSearch ) } /> ;
35
41
}
36
42
37
43
describe ( "useSlidingSyncRoomSearch" , ( ) => {
38
44
it ( "should display rooms when searching" , async ( ) => {
39
45
const client = stubClient ( ) ;
40
- const roomA = new Room ( "!a:localhost" , client , client . getUserId ( ) ) ;
41
- const roomB = new Room ( "!b:localhost" , client , client . getUserId ( ) ) ;
46
+ const roomA = new Room ( "!a:localhost" , client , client . getUserId ( ) ! ) ;
47
+ const roomB = new Room ( "!b:localhost" , client , client . getUserId ( ) ! ) ;
42
48
const slidingSync = mocked (
43
49
new MockEventEmitter ( {
44
50
getListData : jest . fn ( ) ,
@@ -67,7 +73,7 @@ describe("useSlidingSyncRoomSearch", () => {
67
73
} ) ;
68
74
69
75
// first check that everything is empty and then do the search
70
- let executeHook = ( roomSearch ) => {
76
+ let executeHook = ( roomSearch : RoomSearchHook ) => {
71
77
expect ( roomSearch . loading ) . toBe ( false ) ;
72
78
expect ( roomSearch . rooms ) . toEqual ( [ ] ) ;
73
79
roomSearch . search ( {
@@ -77,7 +83,7 @@ describe("useSlidingSyncRoomSearch", () => {
77
83
} ;
78
84
const wrapper = mount (
79
85
< RoomSearchComponent
80
- onClick = { ( roomSearch ) => {
86
+ onClick = { ( roomSearch : RoomSearchHook ) => {
81
87
executeHook ( roomSearch ) ;
82
88
} }
83
89
/> ,
0 commit comments