@@ -662,6 +662,91 @@ public void CanUpdateHrefOnLinkTagWithIntegrity()
662662 Browser . Equal ( "rgba(0, 0, 255, 1)" , ( ) => originalH1Elem . GetCssValue ( "color" ) ) ;
663663 }
664664
665+ [ Theory ]
666+ //[InlineData(false, false)] // FAILS, do-navigation scroll is not at thr top
667+ [ InlineData ( false , true ) ] // PASSES
668+ //[InlineData(true, true)] // FAILS: go back: Y=0, not 3211, streaming mode is lost on going back and many more
669+ //[InlineData(true, false)] // FAILS, do-navigation scroll is not at the top
670+ public void EnhancedNavigationScrollBehavesSameAsFullNavigation ( bool enableStreaming , bool suppressEnhancedNavigation )
671+ {
672+ // This test checks if the navigation to other path moves the scroll to the top of the page,
673+ // or to the beginning of a fragment, regardless of the previous scroll position,
674+ // checks if going backwards and forwards preserves the scroll position
675+ Navigate ( $ "{ ServerPathBase } /nav/testing-scroll/{ enableStreaming } ") ;
676+ EnhancedNavigationTestUtil . SuppressEnhancedNavigation ( this , suppressEnhancedNavigation , skipNavigation : true ) ;
677+ AssertWeAreOnScrollTestPage ( ) ;
678+ AssertStreamingMode ( ) ;
679+
680+ // assert enhanced navigation is enabled/disabled, as requested
681+ var elementForStalenessCheck = Browser . Exists ( By . TagName ( "html" ) ) ;
682+
683+ var jsExecutor = ( IJavaScriptExecutor ) Browser ;
684+ var maxScrollPosition = ( long ) jsExecutor . ExecuteScript ( "return document.documentElement.scrollHeight - window.innerHeight;" ) ;
685+
686+ // scroll maximally down and go to another page - we should land at the top of that page
687+ Browser . SetScrollY ( maxScrollPosition ) ;
688+ Browser . Exists ( By . Id ( "do-navigation" ) ) . Click ( ) ;
689+ AssertEnhancedNavigation ( ) ;
690+ AssertWeAreOnHashPage ( ) ;
691+ AssertStreamingMode ( ) ;
692+ Assert . Equal ( 0 , Browser . GetScrollY ( ) ) ;
693+ var fragmentScrollPosition = ( long ) jsExecutor . ExecuteScript ( "return Math.round(document.getElementById('some-content').getBoundingClientRect().top + window.scrollY);" ) ;
694+ fragmentScrollPosition = 357 ; // why 357, can we have non-static value?
695+
696+ // go back and check if the scroll position is preserved
697+ Browser . Navigate ( ) . Back ( ) ;
698+ AssertEnhancedNavigation ( ) ;
699+ AssertWeAreOnScrollTestPage ( ) ;
700+ AssertStreamingMode ( ) ;
701+ Assert . Equal ( maxScrollPosition - 1 , Browser . GetScrollY ( ) ) ;
702+
703+ // navigate to a fragment on another page - we should land at the beginning of the fragment
704+ Browser . Exists ( By . Id ( "do-navigation-with-fragment" ) ) . Click ( ) ;
705+ AssertEnhancedNavigation ( ) ;
706+ AssertWeAreOnHashPage ( ) ;
707+ //AssertStreamingMode();
708+ Assert . Equal ( fragmentScrollPosition , Browser . GetScrollY ( ) ) ;
709+
710+ // go back to be able to go forward and check if the scroll position is preserved
711+ Browser . Navigate ( ) . Back ( ) ;
712+ AssertEnhancedNavigation ( ) ;
713+ AssertWeAreOnScrollTestPage ( ) ;
714+ AssertStreamingMode ( ) ;
715+
716+ Browser . Navigate ( ) . Forward ( ) ;
717+ AssertEnhancedNavigation ( ) ;
718+ AssertWeAreOnHashPage ( ) ;
719+ AssertStreamingMode ( ) ;
720+ Assert . Equal ( fragmentScrollPosition , Browser . GetScrollY ( ) ) ;
721+
722+ void AssertStreamingMode ( )
723+ {
724+ if ( enableStreaming )
725+ {
726+ Browser . Contains ( "We add it asynchronously via streaming rendering." , ( ) => Browser . Exists ( By . Id ( "streaming-info" ) ) . Text ) ;
727+ }
728+ else
729+ {
730+ Browser . DoesNotExist ( By . Id ( "streaming-info" ) ) ;
731+ }
732+ }
733+
734+ void AssertEnhancedNavigation ( )
735+ {
736+ Assert . Equal ( suppressEnhancedNavigation , IsElementStale ( elementForStalenessCheck ) ) ;
737+ }
738+
739+ void AssertWeAreOnScrollTestPage ( )
740+ {
741+ Browser . Equal ( "Go back to me" , ( ) => Browser . Exists ( By . Id ( "test-info" ) ) . Text ) ;
742+ }
743+
744+ void AssertWeAreOnHashPage ( )
745+ {
746+ Browser . Equal ( "Scroll to hash" , ( ) => Browser . Exists ( By . Id ( "test-info" ) ) . Text ) ;
747+ }
748+ }
749+
665750 private void AssertEnhancedUpdateCountEquals ( long count )
666751 => Browser . Equal ( count , ( ) => ( ( IJavaScriptExecutor ) Browser ) . ExecuteScript ( "return window.enhancedPageUpdateCount;" ) ) ;
667752
0 commit comments