6
6
*/
7
7
8
8
import { renderHook } from "jest-matrix-react" ;
9
- import { type MatrixClient , RoomType } from "matrix-js-sdk/src/matrix" ;
9
+ import { type MatrixClient , type Room , RoomType } from "matrix-js-sdk/src/matrix" ;
10
10
import { mocked } from "jest-mock" ;
11
11
12
12
import { useRoomListHeaderViewModel } from "../../../../../src/components/viewmodels/roomlist/RoomListHeaderViewModel" ;
@@ -16,16 +16,23 @@ import { shouldShowComponent } from "../../../../../src/customisations/helpers/U
16
16
import SettingsStore from "../../../../../src/settings/SettingsStore" ;
17
17
import defaultDispatcher from "../../../../../src/dispatcher/dispatcher" ;
18
18
import { Action } from "../../../../../src/dispatcher/actions" ;
19
+ import { showCreateNewRoom } from "../../../../../src/utils/space" ;
19
20
20
21
jest . mock ( "../../../../../src/customisations/helpers/UIComponents" , ( ) => ( {
21
22
shouldShowComponent : jest . fn ( ) ,
22
23
} ) ) ;
23
24
25
+ jest . mock ( "../../../../../src/utils/space" , ( ) => ( {
26
+ showCreateNewRoom : jest . fn ( ) ,
27
+ } ) ) ;
28
+
24
29
describe ( "useRoomListHeaderViewModel" , ( ) => {
25
30
let matrixClient : MatrixClient ;
31
+ let space : Room ;
26
32
27
33
beforeEach ( ( ) => {
28
34
matrixClient = stubClient ( ) ;
35
+ space = mkStubRoom ( "spaceId" , "spaceName" , matrixClient ) ;
29
36
} ) ;
30
37
31
38
afterEach ( ( ) => {
@@ -39,8 +46,7 @@ describe("useRoomListHeaderViewModel", () => {
39
46
} ) ;
40
47
41
48
it ( "should return the current space name as title" , ( ) => {
42
- const room = mkStubRoom ( "spaceId" , "spaceName" , matrixClient ) ;
43
- jest . spyOn ( SpaceStore . instance , "activeSpaceRoom" , "get" ) . mockReturnValue ( room ) ;
49
+ jest . spyOn ( SpaceStore . instance , "activeSpaceRoom" , "get" ) . mockReturnValue ( space ) ;
44
50
const { result } = renderHook ( ( ) => useRoomListHeaderViewModel ( ) ) ;
45
51
46
52
expect ( result . current . title ) . toStrictEqual ( "spaceName" ) ;
@@ -81,6 +87,14 @@ describe("useRoomListHeaderViewModel", () => {
81
87
expect ( spy ) . toHaveBeenCalledWith ( Action . CreateRoom ) ;
82
88
} ) ;
83
89
90
+ it ( "should call showCreateNewRoom when createRoom is called in a space" , ( ) => {
91
+ jest . spyOn ( SpaceStore . instance , "activeSpaceRoom" , "get" ) . mockReturnValue ( space ) ;
92
+ const { result } = renderHook ( ( ) => useRoomListHeaderViewModel ( ) ) ;
93
+ result . current . createRoom ( new Event ( "click" ) ) ;
94
+
95
+ expect ( showCreateNewRoom ) . toHaveBeenCalledWith ( space ) ;
96
+ } ) ;
97
+
84
98
it ( "should fire Action.CreateRoom with RoomType.UnstableCall when createVideoRoom is called and feature_element_call_video_rooms is enabled" , ( ) => {
85
99
jest . spyOn ( SettingsStore , "getValue" ) . mockReturnValue ( true ) ;
86
100
const spy = jest . spyOn ( defaultDispatcher , "dispatch" ) ;
@@ -98,4 +112,12 @@ describe("useRoomListHeaderViewModel", () => {
98
112
99
113
expect ( spy ) . toHaveBeenCalledWith ( { action : Action . CreateRoom , type : RoomType . ElementVideo } ) ;
100
114
} ) ;
115
+
116
+ it ( "should call showCreateNewRoom when createVideoRoom is called in a space" , ( ) => {
117
+ jest . spyOn ( SpaceStore . instance , "activeSpaceRoom" , "get" ) . mockReturnValue ( space ) ;
118
+ const { result } = renderHook ( ( ) => useRoomListHeaderViewModel ( ) ) ;
119
+ result . current . createVideoRoom ( ) ;
120
+
121
+ expect ( showCreateNewRoom ) . toHaveBeenCalledWith ( space , RoomType . ElementVideo ) ;
122
+ } ) ;
101
123
} ) ;
0 commit comments