1
0
Fork 0
mirror of https://github.com/teamcapybara/capybara.git synced 2022-11-09 12:08:07 -05:00

Merge pull request #2399 from DocSpring/scroll_behavior_auto

Add "scroll-behavior: auto" CSS to Capybara::Server::AnimationDisabler
This commit is contained in:
Thomas Walpole 2020-10-04 15:49:43 -07:00 committed by GitHub
commit f43b6499ec
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 43 additions and 1 deletions

View file

@ -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

View file

@ -18,6 +18,14 @@
});
</script>
<style>
html {
scroll-behavior: smooth;
}
body {
min-height: 2000px;
}
.transition.away {
width: 0%;
}

View file

@ -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