@@ -14,8 +14,12 @@ See the License for the specific language governing permissions and
14
14
limitations under the License.
15
15
*/
16
16
17
+ import { makeLocationContent } from "matrix-js-sdk/src/content-helpers" ;
18
+ import { LOCATION_EVENT_TYPE } from "matrix-js-sdk/src/@types/location" ;
19
+ import { MatrixEvent } from "matrix-js-sdk/src/models/event" ;
20
+
17
21
import sdk from "../../../skinned-sdk" ;
18
- import { parseGeoUri } from "../../../../src/components/views/messages/MLocationBody" ;
22
+ import { createMapSiteLink , parseGeoUri } from "../../../../src/components/views/messages/MLocationBody" ;
19
23
20
24
sdk . getComponent ( "views.messages.MLocationBody" ) ;
21
25
@@ -159,4 +163,80 @@ describe("MLocationBody", () => {
159
163
) ;
160
164
} ) ;
161
165
} ) ;
166
+
167
+ describe ( "createMapSiteLink" , ( ) => {
168
+ it ( "returns null if event does not contain geouri" , ( ) => {
169
+ expect ( createMapSiteLink ( nonLocationEvent ( ) ) ) . toBeNull ( ) ;
170
+ } ) ;
171
+
172
+ it ( "returns OpenStreetMap link if event contains m.location" , ( ) => {
173
+ expect (
174
+ createMapSiteLink ( modernLocationEvent ( "geo:51.5076,-0.1276" ) ) ,
175
+ ) . toEqual (
176
+ "https://www.openstreetmap.org/" +
177
+ "?mlat=51.5076&mlon=-0.1276" +
178
+ "#map=16/51.5076/-0.1276" ,
179
+ ) ;
180
+ } ) ;
181
+
182
+ it ( "returns OpenStreetMap link if event contains geo_uri" , ( ) => {
183
+ expect (
184
+ createMapSiteLink ( oldLocationEvent ( "geo:51.5076,-0.1276" ) ) ,
185
+ ) . toEqual (
186
+ "https://www.openstreetmap.org/" +
187
+ "?mlat=51.5076&mlon=-0.1276" +
188
+ "#map=16/51.5076/-0.1276" ,
189
+ ) ;
190
+ } ) ;
191
+ } ) ;
162
192
} ) ;
193
+
194
+ function oldLocationEvent ( geoUri : string ) : MatrixEvent {
195
+ return new MatrixEvent (
196
+ {
197
+ "event_id" : nextId ( ) ,
198
+ "type" : LOCATION_EVENT_TYPE . name ,
199
+ "content" : {
200
+ "body" : "Something about where I am" ,
201
+ "msgtype" : "m.location" ,
202
+ "geo_uri" : geoUri ,
203
+ } ,
204
+ } ,
205
+ ) ;
206
+ }
207
+
208
+ function modernLocationEvent ( geoUri : string ) : MatrixEvent {
209
+ return new MatrixEvent (
210
+ {
211
+ "event_id" : nextId ( ) ,
212
+ "type" : LOCATION_EVENT_TYPE . name ,
213
+ "content" : makeLocationContent (
214
+ `Found at ${ geoUri } at 2021-12-21T12:22+0000` ,
215
+ geoUri ,
216
+ 252523 ,
217
+ "Human-readable label" ,
218
+ ) ,
219
+ } ,
220
+ ) ;
221
+ }
222
+
223
+ function nonLocationEvent ( ) : MatrixEvent {
224
+ return new MatrixEvent (
225
+ {
226
+ "event_id" : nextId ( ) ,
227
+ "type" : "some.event.type" ,
228
+ "content" : {
229
+ "m.relates_to" : {
230
+ "rel_type" : "m.reference" ,
231
+ "event_id" : "$mypoll" ,
232
+ } ,
233
+ } ,
234
+ } ,
235
+ ) ;
236
+ }
237
+
238
+ let EVENT_ID = 0 ;
239
+ function nextId ( ) : string {
240
+ EVENT_ID ++ ;
241
+ return EVENT_ID . toString ( ) ;
242
+ }
0 commit comments