@@ -13,7 +13,12 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313See the License for the specific language governing permissions and
1414limitations under the License.
1515*/
16- import { linkify , Type } from "../src/linkify-matrix" ;
16+
17+ import { EventListeners } from "linkifyjs" ;
18+
19+ import { linkify , Type , options } from "../src/linkify-matrix" ;
20+ import dispatcher from "../src/dispatcher/dispatcher" ;
21+ import { Action } from "../src/dispatcher/actions" ;
1722
1823describe ( "linkify-matrix" , ( ) => {
1924 const linkTypesByInitialCharacter : Record < string , string > = {
@@ -324,6 +329,26 @@ describe("linkify-matrix", () => {
324329
325330 describe ( "roomalias plugin" , ( ) => {
326331 genTests ( "#" ) ;
332+
333+ it ( "should intercept clicks with a ViewRoom dispatch" , ( ) => {
334+ const dispatchSpy = jest . spyOn ( dispatcher , "dispatch" ) ;
335+
336+ const handlers = ( options . events as ( href : string , type : string ) => EventListeners ) (
337+ "#room:server.com" ,
338+ "roomalias" ,
339+ ) ;
340+
341+ const event = new MouseEvent ( "mousedown" ) ;
342+ event . preventDefault = jest . fn ( ) ;
343+ handlers . click ( event ) ;
344+ expect ( event . preventDefault ) . toHaveBeenCalled ( ) ;
345+ expect ( dispatchSpy ) . toHaveBeenCalledWith (
346+ expect . objectContaining ( {
347+ action : Action . ViewRoom ,
348+ room_alias : "#room:server.com" ,
349+ } ) ,
350+ ) ;
351+ } ) ;
327352 } ) ;
328353
329354 describe ( "userid plugin" , ( ) => {
@@ -344,6 +369,28 @@ describe("linkify-matrix", () => {
344369 } ,
345370 ] ) ;
346371 } ) ;
372+
373+ it ( "should intercept clicks with a ViewUser dispatch" , ( ) => {
374+ const dispatchSpy = jest . spyOn ( dispatcher , "dispatch" ) ;
375+
376+ const handlers = ( options . events as ( href : string , type : string ) => EventListeners ) (
377+ "@localpart:server.com" ,
378+ "userid" ,
379+ ) ;
380+
381+ const event = new MouseEvent ( "mousedown" ) ;
382+ event . preventDefault = jest . fn ( ) ;
383+ handlers . click ( event ) ;
384+ expect ( event . preventDefault ) . toHaveBeenCalled ( ) ;
385+ expect ( dispatchSpy ) . toHaveBeenCalledWith (
386+ expect . objectContaining ( {
387+ action : Action . ViewUser ,
388+ member : expect . objectContaining ( {
389+ userId : "@localpart:server.com" ,
390+ } ) ,
391+ } ) ,
392+ ) ;
393+ } ) ;
347394 } ) ;
348395
349396 describe ( "matrix uri" , ( ) => {
0 commit comments