Skip to content

Commit

Permalink
Update test and add new view with_jquery_animation
Browse files Browse the repository at this point in the history
  • Loading branch information
kuei0221 committed Jan 23, 2021
1 parent 6b5476c commit f95e581
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
24 changes: 24 additions & 0 deletions lib/capybara/spec/views/with_jquery_animation.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@

<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8"/>
<title>with_jquery_animation</title>
<style>
body {
height: 2000px;
}
</style>
</head>

<body id="with_animation">
<a href="#" id='scroll'>scroll top 500</a>

<script src="/jquery.js" type="text/javascript" charset="utf-8"></script>
<script type='text/javascript'>
$('#scroll').click(function(e){
e.preventDefault();
$('html, body').animate({ scrollTop: 500 }, 'slow');
});
</script>
</body>
</html>
14 changes: 14 additions & 0 deletions spec/shared_selenium_session.rb
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,13 @@
JS
expect(scroll_y).to eq 500
end

it 'should scroll the page instantly without jquery animation', requires: [:js] do
@animation_session.visit('with_jquery_animation')
@animation_session.click_link('scroll top 500')
scroll_y = @animation_session.evaluate_script('window.scrollY')
expect(scroll_y).to eq 500
end
end

context 'when set to `false`' do
Expand All @@ -433,6 +440,13 @@
# measured over 0.5 seconds: 0, 75, 282, 478, 500
expect(scroll_y).to be < 500
end

it 'should scroll the page with jquery animation', requires: [:js] do
@animation_session.visit('with_jquery_animation')
@animation_session.click_link('scroll top 500')
scroll_y = @animation_session.evaluate_script('window.scrollY')
expect(scroll_y).to be < 500
end
end

context 'if we pass in css that matches elements' do
Expand Down

0 comments on commit f95e581

Please sign in to comment.