@@ -510,6 +510,43 @@ public void CanNavigateProgrammaticallyWithStateReplaceHistoryEntry()
510510 Assert . Equal ( typeof ( TestRouter ) . FullName , testSelector . SelectedOption . GetDomProperty ( "value" ) ) ;
511511 }
512512
513+ [ Fact ]
514+ public void NavigationToSamePathDoesNotScrollToTheTop ( )
515+ {
516+ // This test checks if the navigation to same path or path with query appeneded,
517+ // keeps the scroll in the position from before navigation
518+ // but moves it when we navigate to a fragment
519+ SetUrlViaPushState ( "/" ) ;
520+
521+ var app = Browser . MountTestComponent < TestRouter > ( ) ;
522+ var testSelector = Browser . WaitUntilTestSelectorReady ( ) ;
523+
524+ app . FindElement ( By . LinkText ( "Programmatic navigation cases" ) ) . Click ( ) ;
525+ Browser . True ( ( ) => Browser . Url . EndsWith ( "/ProgrammaticNavigationCases" , StringComparison . Ordinal ) ) ;
526+ Browser . Contains ( "programmatic navigation" , ( ) => app . FindElement ( By . Id ( "test-info" ) ) . Text ) ;
527+
528+ var jsExecutor = ( IJavaScriptExecutor ) Browser ;
529+ var maxScrollPosition = ( long ) jsExecutor . ExecuteScript ( "return document.documentElement.scrollHeight - window.innerHeight;" ) ;
530+ // scroll max up to find the position of fragment
531+ BrowserScrollY = 0 ;
532+ var fragmentScrollPosition = ( long ) jsExecutor . ExecuteScript ( "return document.getElementById('fragment').getBoundingClientRect().top + window.scrollY;" ) ;
533+
534+ // scroll maximally down
535+ BrowserScrollY = maxScrollPosition ;
536+
537+ app . FindElement ( By . Id ( "do-self-navigate" ) ) . Click ( ) ;
538+ var scrollPosition = BrowserScrollY ;
539+ Assert . True ( scrollPosition == maxScrollPosition , "Expected to stay scrolled down." ) ;
540+
541+ app . FindElement ( By . Id ( "do-self-navigate-with-query" ) ) . Click ( ) ;
542+ scrollPosition = BrowserScrollY ;
543+ Assert . True ( scrollPosition == maxScrollPosition , "Expected to stay scrolled down." ) ;
544+
545+ app . FindElement ( By . Id ( "do-self-navigate-to-fragment" ) ) . Click ( ) ;
546+ scrollPosition = BrowserScrollY ;
547+ Assert . True ( scrollPosition == fragmentScrollPosition , "Expected to scroll to the fragment." ) ;
548+ }
549+
513550 [ Fact ]
514551 public void CanNavigateProgrammaticallyValidateNoReplaceHistoryEntry ( )
515552 {
0 commit comments