@@ -36,7 +36,7 @@ import { IRoomState } from "../../../../src/components/structures/RoomView";
3636import { canEditContent } from "../../../../src/utils/EventUtils" ;
3737import { copyPlaintext , getSelectedText } from "../../../../src/utils/strings" ;
3838import MessageContextMenu from "../../../../src/components/views/context_menus/MessageContextMenu" ;
39- import { makeBeaconEvent , makeBeaconInfoEvent , stubClient } from '../../../test-utils' ;
39+ import { makeBeaconEvent , makeBeaconInfoEvent , makeLocationEvent , stubClient } from '../../../test-utils' ;
4040import dispatcher from '../../../../src/dispatcher/dispatcher' ;
4141import SettingsStore from '../../../../src/settings/SettingsStore' ;
4242import { ReadPinsEventId } from '../../../../src/components/views/right_panel/types' ;
@@ -308,6 +308,49 @@ describe('MessageContextMenu', () => {
308308 } ) ;
309309 } ) ;
310310
311+ describe ( 'open as map link' , ( ) => {
312+ it ( 'does not allow opening a plain message in open street maps' , ( ) => {
313+ const eventContent = MessageEvent . from ( "hello" ) ;
314+ const menu = createMenuWithContent ( eventContent ) ;
315+ expect ( menu . find ( 'a[aria-label="Open in OpenStreetMap"]' ) ) . toHaveLength ( 0 ) ;
316+ } ) ;
317+
318+ it ( 'does not allow opening a beacon that does not have a shareable location event' , ( ) => {
319+ const deadBeaconEvent = makeBeaconInfoEvent ( '@alice' , roomId , { isLive : false } ) ;
320+ const beacon = new Beacon ( deadBeaconEvent ) ;
321+ const beacons = new Map < BeaconIdentifier , Beacon > ( ) ;
322+ beacons . set ( getBeaconInfoIdentifier ( deadBeaconEvent ) , beacon ) ;
323+ const menu = createMenu ( deadBeaconEvent , { } , { } , beacons ) ;
324+ expect ( menu . find ( 'a[aria-label="Open in OpenStreetMap"]' ) ) . toHaveLength ( 0 ) ;
325+ } ) ;
326+
327+ it ( 'allows opening a location event in open street map' , ( ) => {
328+ const locationEvent = makeLocationEvent ( 'geo:50,50' ) ;
329+ const menu = createMenu ( locationEvent ) ;
330+ // exists with a href with the lat/lon from the location event
331+ expect (
332+ menu . find ( 'a[aria-label="Open in OpenStreetMap"]' ) . at ( 0 ) . props ( ) . href ,
333+ ) . toEqual ( 'https://www.openstreetmap.org/?mlat=50&mlon=50#map=16/50/50' ) ;
334+ } ) ;
335+
336+ it ( 'allows opening a beacon that has a shareable location event' , ( ) => {
337+ const liveBeaconEvent = makeBeaconInfoEvent ( '@alice' , roomId , { isLive : true } ) ;
338+ const beaconLocation = makeBeaconEvent (
339+ '@alice' , { beaconInfoId : liveBeaconEvent . getId ( ) , geoUri : 'geo:51,41' } ,
340+ ) ;
341+ const beacon = new Beacon ( liveBeaconEvent ) ;
342+ // @ts -ignore illegally set private prop
343+ beacon . _latestLocationEvent = beaconLocation ;
344+ const beacons = new Map < BeaconIdentifier , Beacon > ( ) ;
345+ beacons . set ( getBeaconInfoIdentifier ( liveBeaconEvent ) , beacon ) ;
346+ const menu = createMenu ( liveBeaconEvent , { } , { } , beacons ) ;
347+ // exists with a href with the lat/lon from the location event
348+ expect (
349+ menu . find ( 'a[aria-label="Open in OpenStreetMap"]' ) . at ( 0 ) . props ( ) . href ,
350+ ) . toEqual ( 'https://www.openstreetmap.org/?mlat=51&mlon=41#map=16/51/41' ) ;
351+ } ) ;
352+ } ) ;
353+
311354 describe ( "right click" , ( ) => {
312355 it ( 'copy button does work as expected' , ( ) => {
313356 const text = "hello" ;
0 commit comments