@@ -285,3 +285,89 @@ describe('DirectionsControl', () => {
285285 expect ( result . wps ) . toBe ( '13.4,52.5,10,48' ) ;
286286 } ) ;
287287} ) ;
288+
289+ describe ( 'DirectionsControl URL parsing' , ( ) => {
290+ beforeEach ( ( ) => {
291+ vi . clearAllMocks ( ) ;
292+ mockResults . data = null ;
293+ mockWaypoints . length = 0 ;
294+ mockWaypoints . push (
295+ { id : '0' , geocodeResults : [ ] , userInput : '' } ,
296+ { id : '1' , geocodeResults : [ ] , userInput : '' }
297+ ) ;
298+ } ) ;
299+
300+ it ( 'should process URL params with valid coordinates (Berlin)' , async ( ) => {
301+ const parseUrlParams = await import ( '@/utils/parse-url-params' ) ;
302+ vi . mocked ( parseUrlParams . parseUrlParams ) . mockReturnValue ( {
303+ wps : '13.365016850476763,52.483706198952575,13.422421655040836,52.49336042169804' ,
304+ } ) ;
305+
306+ render ( < DirectionsControl /> ) ;
307+
308+ expect ( mockReverseGeocode ) . toHaveBeenCalledTimes ( 2 ) ;
309+ expect ( mockReverseGeocode ) . toHaveBeenCalledWith (
310+ 13.365016850476763 ,
311+ 52.483706198952575 ,
312+ 0 ,
313+ { isPermalink : true }
314+ ) ;
315+ expect ( mockReverseGeocode ) . toHaveBeenCalledWith (
316+ 13.422421655040836 ,
317+ 52.49336042169804 ,
318+ 1 ,
319+ { isPermalink : true }
320+ ) ;
321+ } ) ;
322+
323+ it ( 'should process URL params with valid coordinates where lng > 90 (Singapore)' , async ( ) => {
324+ const parseUrlParams = await import ( '@/utils/parse-url-params' ) ;
325+ vi . mocked ( parseUrlParams . parseUrlParams ) . mockReturnValue ( {
326+ wps : '103.66492937866911,1.4827280571964963,103.66421854954496,1.4840285187178779' ,
327+ } ) ;
328+
329+ render ( < DirectionsControl /> ) ;
330+
331+ expect ( mockReverseGeocode ) . toHaveBeenCalledTimes ( 2 ) ;
332+ expect ( mockReverseGeocode ) . toHaveBeenCalledWith (
333+ 103.66492937866911 ,
334+ 1.4827280571964963 ,
335+ 0 ,
336+ { isPermalink : true }
337+ ) ;
338+ expect ( mockReverseGeocode ) . toHaveBeenCalledWith (
339+ 103.66421854954496 ,
340+ 1.4840285187178779 ,
341+ 1 ,
342+ { isPermalink : true }
343+ ) ;
344+ } ) ;
345+
346+ it ( 'should skip truly invalid coordinates from URL' , async ( ) => {
347+ const parseUrlParams = await import ( '@/utils/parse-url-params' ) ;
348+ vi . mocked ( parseUrlParams . parseUrlParams ) . mockReturnValue ( {
349+ wps : '999,999' ,
350+ } ) ;
351+
352+ render ( < DirectionsControl /> ) ;
353+
354+ expect ( mockReverseGeocode ) . not . toHaveBeenCalled ( ) ;
355+ } ) ;
356+
357+ it ( 'should handle coordinates near edge of valid range' , async ( ) => {
358+ const parseUrlParams = await import ( '@/utils/parse-url-params' ) ;
359+ vi . mocked ( parseUrlParams . parseUrlParams ) . mockReturnValue ( {
360+ wps : '179.9,89,-179.9,-89' ,
361+ } ) ;
362+
363+ render ( < DirectionsControl /> ) ;
364+
365+ expect ( mockReverseGeocode ) . toHaveBeenCalledTimes ( 2 ) ;
366+ expect ( mockReverseGeocode ) . toHaveBeenCalledWith ( 179.9 , 89 , 0 , {
367+ isPermalink : true ,
368+ } ) ;
369+ expect ( mockReverseGeocode ) . toHaveBeenCalledWith ( - 179.9 , - 89 , 1 , {
370+ isPermalink : true ,
371+ } ) ;
372+ } ) ;
373+ } ) ;
0 commit comments