mirror of
				https://github.com/teamcapybara/capybara.git
				synced 2022-11-09 12:08:07 -05:00 
			
		
		
		
	Add "scroll-behavior: auto;" CSS to Capybara::Server::AnimationDisabler to disable scroll animation
This commit is contained in:
		
							parent
							
								
									d68ea2ae4c
								
							
						
					
					
						commit
						7be5795001
					
				
					 3 changed files with 43 additions and 1 deletions
				
			
		| 
						 | 
				
			
			@ -46,10 +46,11 @@ module Capybara
 | 
			
		|||
      DISABLE_MARKUP_TEMPLATE = <<~HTML
 | 
			
		||||
        <script defer>(typeof jQuery !== 'undefined') && (jQuery.fx.off = true);</script>
 | 
			
		||||
        <style>
 | 
			
		||||
           %<selector>s, %<selector>s::before, %<selector>s::after {
 | 
			
		||||
          %<selector>s, %<selector>s::before, %<selector>s::after {
 | 
			
		||||
             transition: none !important;
 | 
			
		||||
             animation-duration: 0s !important;
 | 
			
		||||
             animation-delay: 0s !important;
 | 
			
		||||
             scroll-behavior: auto !important;
 | 
			
		||||
          }
 | 
			
		||||
        </style>
 | 
			
		||||
      HTML
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -18,6 +18,14 @@
 | 
			
		|||
      });
 | 
			
		||||
    </script>
 | 
			
		||||
    <style>
 | 
			
		||||
      html {
 | 
			
		||||
        scroll-behavior: smooth;
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      body {
 | 
			
		||||
        min-height: 2000px;
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      .transition.away {
 | 
			
		||||
          width: 0%;
 | 
			
		||||
      }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -388,6 +388,39 @@ RSpec.shared_examples 'Capybara::Session' do |session, mode|
 | 
			
		|||
          @animation_session.find_link('animate me away').right_click
 | 
			
		||||
          expect(@animation_session).to have_content('Animation Ended', wait: 0.1)
 | 
			
		||||
        end
 | 
			
		||||
 | 
			
		||||
        it 'should scroll the page instantly', requires: [:js] do
 | 
			
		||||
          @animation_session.visit('with_animation')
 | 
			
		||||
          scroll_y = @animation_session.evaluate_script(<<~JS)
 | 
			
		||||
            (function(){
 | 
			
		||||
              window.scrollTo(0,500);
 | 
			
		||||
              return window.scrollY;
 | 
			
		||||
            })()
 | 
			
		||||
          JS
 | 
			
		||||
          expect(scroll_y).to eq 500
 | 
			
		||||
        end
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
      context 'when set to `false`' do
 | 
			
		||||
        before(:context) do # rubocop:disable RSpec/BeforeAfterAll
 | 
			
		||||
          skip "Safari doesn't support multiple sessions" if safari?(session)
 | 
			
		||||
          # NOTE: Although Capybara.SpecHelper.reset! sets Capybara.disable_animation to false,
 | 
			
		||||
          # it doesn't affect any of these tests because the settings are applied per-session
 | 
			
		||||
          Capybara.disable_animation = false
 | 
			
		||||
          @animation_session = Capybara::Session.new(session.mode, TestApp.new)
 | 
			
		||||
        end
 | 
			
		||||
 | 
			
		||||
        it 'should scroll the page with a smooth animation', requires: [:js] do
 | 
			
		||||
          @animation_session.visit('with_animation')
 | 
			
		||||
          scroll_y = @animation_session.evaluate_script(<<~JS)
 | 
			
		||||
            (function(){
 | 
			
		||||
              window.scrollTo(0,500);
 | 
			
		||||
              return window.scrollY;
 | 
			
		||||
            })()
 | 
			
		||||
          JS
 | 
			
		||||
          # measured over 0.5 seconds: 0, 75, 282, 478, 500
 | 
			
		||||
          expect(scroll_y).to be < 500
 | 
			
		||||
        end
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
      context 'if we pass in css that matches elements' do
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue