@@ -29,6 +29,8 @@ import { flushPromisesWithFakeTimers, mkRoom, stubClient } from "../../../test-u
2929import { shouldShowFeedback } from "../../../../src/utils/Feedback" ;
3030import SettingsStore from "../../../../src/settings/SettingsStore" ;
3131import { SettingLevel } from "../../../../src/settings/SettingLevel" ;
32+ import defaultDispatcher from "../../../../src/dispatcher/dispatcher" ;
33+ import SdkConfig from "../../../../src/SdkConfig" ;
3234
3335jest . useFakeTimers ( ) ;
3436
@@ -40,6 +42,11 @@ jest.mock("../../../../src/utils/direct-messages", () => ({
4042 startDmOnFirstMessage : jest . fn ( ) ,
4143} ) ) ;
4244
45+ jest . mock ( "../../../../src/dispatcher/dispatcher" , ( ) => ( {
46+ register : jest . fn ( ) ,
47+ dispatch : jest . fn ( ) ,
48+ } ) ) ;
49+
4350interface IUserChunkMember {
4451 user_id : string ;
4552 display_name ?: string ;
@@ -122,7 +129,7 @@ describe("Spotlight Dialog", () => {
122129 } ;
123130
124131 const testPublicRoom : IPublicRoomsChunkRoom = {
125- room_id : "@ room247:matrix.org" ,
132+ room_id : "! room247:matrix.org" ,
126133 name : "Room #247" ,
127134 topic : "We hope you'll have a <b>shining</b> experience!" ,
128135 world_readable : false ,
@@ -352,6 +359,34 @@ describe("Spotlight Dialog", () => {
352359 expect ( startDmOnFirstMessage ) . toHaveBeenCalledWith ( mockedClient , [ new DirectoryMember ( testPerson ) ] ) ;
353360 } ) ;
354361
362+ it ( "should pass via of the server being explored when joining room from directory" , async ( ) => {
363+ SdkConfig . put ( {
364+ room_directory : {
365+ servers : [ "example.tld" ] ,
366+ } ,
367+ } ) ;
368+ localStorage . setItem ( "mx_last_room_directory_server" , "example.tld" ) ;
369+
370+ render ( < SpotlightDialog initialFilter = { Filter . PublicRooms } onFinished = { ( ) => null } /> ) ;
371+
372+ jest . advanceTimersByTime ( 200 ) ;
373+ await flushPromisesWithFakeTimers ( ) ;
374+
375+ const content = document . querySelector ( "#mx_SpotlightDialog_content" ) ! ;
376+ const options = content . querySelectorAll ( "div.mx_SpotlightDialog_option" ) ;
377+ expect ( options . length ) . toBe ( 1 ) ;
378+ expect ( options [ 0 ] . innerHTML ) . toContain ( testPublicRoom . name ) ;
379+
380+ fireEvent . click ( options [ 0 ] ! ) ;
381+ expect ( defaultDispatcher . dispatch ) . toHaveBeenCalledWith (
382+ expect . objectContaining ( {
383+ action : "view_room" ,
384+ room_id : testPublicRoom . room_id ,
385+ via_servers : [ "example.tld" ] ,
386+ } ) ,
387+ ) ;
388+ } ) ;
389+
355390 describe ( "Feedback prompt" , ( ) => {
356391 it ( "should show feedback prompt if feedback is enabled" , async ( ) => {
357392 mocked ( shouldShowFeedback ) . mockReturnValue ( true ) ;
0 commit comments