@@ -22,6 +22,8 @@ import { hasCreateRoomRights, createRoom } from "../../../../../src/components/v
22
22
import dispatcher from "../../../../../src/dispatcher/dispatcher" ;
23
23
import { Action } from "../../../../../src/dispatcher/actions" ;
24
24
import { SdkContextClass } from "../../../../../src/contexts/SDKContext" ;
25
+ import SpaceStore from "../../../../../src/stores/spaces/SpaceStore" ;
26
+ import { UPDATE_SELECTED_SPACE } from "../../../../../src/stores/spaces" ;
25
27
26
28
jest . mock ( "../../../../../src/components/viewmodels/roomlist/utils" , ( ) => ( {
27
29
hasCreateRoomRights : jest . fn ( ) . mockReturnValue ( false ) ,
@@ -185,6 +187,33 @@ describe("RoomListViewModel", () => {
185
187
expect ( fn ) . toHaveBeenLastCalledWith ( expect . arrayContaining ( [ FilterKey . MentionsFilter ] ) ) ;
186
188
} ) ;
187
189
190
+ it ( "should remove all filters when active space is changed" , async ( ) => {
191
+ mockAndCreateRooms ( ) ;
192
+ const { result : vm } = renderHook ( ( ) => useRoomListViewModel ( ) ) ;
193
+
194
+ // Let's first toggle the People filter
195
+ const i = vm . current . primaryFilters . findIndex ( ( f ) => f . name === "People" ) ;
196
+ act ( ( ) => {
197
+ vm . current . primaryFilters [ i ] . toggle ( ) ;
198
+ } ) ;
199
+ expect ( vm . current . primaryFilters [ i ] . active ) . toEqual ( true ) ;
200
+
201
+ // Let's say we toggle the mentions secondary filter
202
+ act ( ( ) => {
203
+ vm . current . activateSecondaryFilter ( SecondaryFilters . MentionsOnly ) ;
204
+ } ) ;
205
+ expect ( vm . current . activeSecondaryFilter ) . toEqual ( SecondaryFilters . MentionsOnly ) ;
206
+
207
+ // Simulate a space change
208
+ await act ( ( ) => SpaceStore . instance . emit ( UPDATE_SELECTED_SPACE ) ) ;
209
+
210
+ // Primary filer should have been unapplied
211
+ expect ( vm . current . activePrimaryFilter ) . toEqual ( undefined ) ;
212
+
213
+ // Secondary filter should be reset to "All Activity"
214
+ expect ( vm . current . activeSecondaryFilter ) . toEqual ( SecondaryFilters . AllActivity ) ;
215
+ } ) ;
216
+
188
217
const testcases : Array < [ string , { secondary : SecondaryFilters ; filterKey : FilterKey } , string ] > = [
189
218
[
190
219
"Mentions only" ,
0 commit comments