2008-04-23 14:54:07 +00:00
|
|
|
require File.expand_path(File.dirname(__FILE__) + "/spec_helper")
|
2008-03-02 20:14:52 +00:00
|
|
|
|
2008-04-23 14:54:07 +00:00
|
|
|
describe "clicks_link" do
|
|
|
|
before do
|
2008-03-02 20:14:52 +00:00
|
|
|
@session = ActionController::Integration::Session.new
|
|
|
|
@session.stubs(:assert_response)
|
|
|
|
@session.stubs(:get_via_redirect)
|
|
|
|
@session.stubs(:response).returns(@response=mock)
|
|
|
|
end
|
|
|
|
|
2008-04-23 14:54:07 +00:00
|
|
|
it "should_use_get_by_default" do
|
2008-03-02 20:14:52 +00:00
|
|
|
@response.stubs(:body).returns(<<-EOS)
|
|
|
|
<a href="/page">Link text</a>
|
|
|
|
EOS
|
|
|
|
@session.expects(:get_via_redirect).with("/page", {})
|
|
|
|
@session.clicks_link "Link text"
|
|
|
|
end
|
|
|
|
|
2008-04-23 14:54:07 +00:00
|
|
|
it "should_click_get_links" do
|
2008-03-02 20:14:52 +00:00
|
|
|
@response.stubs(:body).returns(<<-EOS)
|
|
|
|
<a href="/page">Link text</a>
|
|
|
|
EOS
|
|
|
|
@session.expects(:get_via_redirect).with("/page", {})
|
|
|
|
@session.clicks_get_link "Link text"
|
|
|
|
end
|
|
|
|
|
2008-04-23 14:54:07 +00:00
|
|
|
it "should_click_delete_links" do
|
2008-03-02 20:14:52 +00:00
|
|
|
@response.stubs(:body).returns(<<-EOS)
|
|
|
|
<a href="/page">Link text</a>
|
|
|
|
EOS
|
|
|
|
@session.expects(:delete_via_redirect).with("/page", {})
|
|
|
|
@session.clicks_delete_link "Link text"
|
|
|
|
end
|
|
|
|
|
2008-04-23 14:54:07 +00:00
|
|
|
it "should_click_post_links" do
|
2008-03-02 20:14:52 +00:00
|
|
|
@response.stubs(:body).returns(<<-EOS)
|
|
|
|
<a href="/page">Link text</a>
|
|
|
|
EOS
|
|
|
|
@session.expects(:post_via_redirect).with("/page", {})
|
|
|
|
@session.clicks_post_link "Link text"
|
|
|
|
end
|
|
|
|
|
2008-04-23 14:54:07 +00:00
|
|
|
it "should_click_put_links" do
|
2008-03-02 20:14:52 +00:00
|
|
|
@response.stubs(:body).returns(<<-EOS)
|
|
|
|
<a href="/page">Link text</a>
|
|
|
|
EOS
|
|
|
|
@session.expects(:put_via_redirect).with("/page", {})
|
|
|
|
@session.clicks_put_link "Link text"
|
|
|
|
end
|
|
|
|
|
2008-04-23 14:54:07 +00:00
|
|
|
it "should_click_rails_javascript_links_with_authenticity_tokens" do
|
2008-03-02 20:14:52 +00:00
|
|
|
@response.stubs(:body).returns(<<-EOS)
|
|
|
|
<a href="/posts" onclick="var f = document.createElement('form');
|
|
|
|
f.style.display = 'none';
|
|
|
|
this.parentNode.appendChild(f);
|
|
|
|
f.method = 'POST';
|
|
|
|
f.action = this.href;
|
|
|
|
var s = document.createElement('input');
|
|
|
|
s.setAttribute('type', 'hidden');
|
|
|
|
s.setAttribute('name', 'authenticity_token');
|
|
|
|
s.setAttribute('value', 'aa79cb354597a60a3786e7e291ed4f74d77d3a62');
|
|
|
|
f.appendChild(s);
|
|
|
|
f.submit();
|
|
|
|
return false;">Posts</a>
|
|
|
|
EOS
|
|
|
|
@session.expects(:post_via_redirect).with("/posts", "authenticity_token" => "aa79cb354597a60a3786e7e291ed4f74d77d3a62")
|
|
|
|
@session.clicks_link "Posts"
|
|
|
|
end
|
|
|
|
|
2008-04-23 14:54:07 +00:00
|
|
|
it "should_click_rails_javascript_delete_links" do
|
2008-03-02 20:14:52 +00:00
|
|
|
@response.stubs(:body).returns(<<-EOS)
|
|
|
|
<a href="/posts/1" onclick="var f = document.createElement('form');
|
|
|
|
f.style.display = 'none';
|
|
|
|
this.parentNode.appendChild(f);
|
|
|
|
f.method = 'POST';
|
|
|
|
f.action = this.href;
|
|
|
|
var m = document.createElement('input');
|
|
|
|
m.setAttribute('type', 'hidden');
|
|
|
|
m.setAttribute('name', '_method');
|
|
|
|
m.setAttribute('value', 'delete');
|
|
|
|
f.appendChild(m);
|
|
|
|
f.submit();
|
|
|
|
return false;">Delete</a>
|
|
|
|
EOS
|
|
|
|
@session.expects(:delete_via_redirect).with("/posts/1", {})
|
|
|
|
@session.clicks_link "Delete"
|
|
|
|
end
|
|
|
|
|
2008-04-23 14:54:07 +00:00
|
|
|
it "should_click_rails_javascript_post_links" do
|
2008-03-02 20:14:52 +00:00
|
|
|
@response.stubs(:body).returns(<<-EOS)
|
|
|
|
<a href="/posts" onclick="var f = document.createElement('form');
|
|
|
|
f.style.display = 'none';
|
|
|
|
this.parentNode.appendChild(f);
|
|
|
|
f.method = 'POST';
|
|
|
|
f.action = this.href;
|
|
|
|
f.submit();
|
|
|
|
return false;">Posts</a>
|
|
|
|
EOS
|
|
|
|
@session.expects(:post_via_redirect).with("/posts", {})
|
|
|
|
@session.clicks_link "Posts"
|
|
|
|
end
|
|
|
|
|
2008-04-23 14:54:07 +00:00
|
|
|
it "should_click_rails_javascript_put_links" do
|
2008-03-02 20:14:52 +00:00
|
|
|
@response.stubs(:body).returns(<<-EOS)
|
|
|
|
<a href="/posts" onclick="var f = document.createElement('form');
|
|
|
|
f.style.display = 'none';
|
|
|
|
this.parentNode.appendChild(f);
|
|
|
|
f.method = 'POST';
|
|
|
|
f.action = this.href;
|
|
|
|
var m = document.createElement('input');
|
|
|
|
m.setAttribute('type', 'hidden');
|
|
|
|
m.setAttribute('name', '_method');
|
|
|
|
m.setAttribute('value', 'put');
|
|
|
|
f.appendChild(m);
|
|
|
|
f.submit();
|
|
|
|
return false;">Put</a></h2>
|
|
|
|
EOS
|
|
|
|
@session.expects(:put_via_redirect).with("/posts", {})
|
|
|
|
@session.clicks_link "Put"
|
|
|
|
end
|
|
|
|
|
2008-04-23 14:54:07 +00:00
|
|
|
it "should_assert_valid_response" do
|
2008-03-02 20:14:52 +00:00
|
|
|
@response.stubs(:body).returns(<<-EOS)
|
|
|
|
<a href="/page">Link text</a>
|
|
|
|
EOS
|
|
|
|
@session.expects(:assert_response).with(:success)
|
|
|
|
@session.clicks_link "Link text"
|
|
|
|
end
|
|
|
|
|
2008-04-23 14:54:07 +00:00
|
|
|
it "should_not_be_case_sensitive" do
|
2008-03-02 20:14:52 +00:00
|
|
|
@response.stubs(:body).returns(<<-EOS)
|
|
|
|
<a href="/page">Link text</a>
|
|
|
|
EOS
|
|
|
|
@session.expects(:get_via_redirect).with("/page", {})
|
|
|
|
@session.clicks_link "LINK TEXT"
|
|
|
|
end
|
|
|
|
|
2008-04-23 14:54:07 +00:00
|
|
|
it "should_match_link_substrings" do
|
2008-03-02 20:14:52 +00:00
|
|
|
@response.stubs(:body).returns(<<-EOS)
|
|
|
|
<a href="/page">This is some cool link text, isn't it?</a>
|
|
|
|
EOS
|
|
|
|
@session.expects(:get_via_redirect).with("/page", {})
|
|
|
|
@session.clicks_link "Link text"
|
|
|
|
end
|
|
|
|
|
2008-04-23 14:54:07 +00:00
|
|
|
it "should_work_with_elements_in_the_link" do
|
2008-03-02 20:14:52 +00:00
|
|
|
@response.stubs(:body).returns(<<-EOS)
|
|
|
|
<a href="/page"><span>Link text</span></a>
|
|
|
|
EOS
|
|
|
|
@session.expects(:get_via_redirect).with("/page", {})
|
|
|
|
@session.clicks_link "Link text"
|
|
|
|
end
|
|
|
|
|
2008-04-23 14:54:07 +00:00
|
|
|
it "should_match_the_first_matching_link" do
|
2008-03-02 20:14:52 +00:00
|
|
|
@response.stubs(:body).returns(<<-EOS)
|
|
|
|
<a href="/page1">Link text</a>
|
|
|
|
<a href="/page2">Link text</a>
|
|
|
|
EOS
|
|
|
|
@session.expects(:get_via_redirect).with("/page1", {})
|
|
|
|
@session.clicks_link "Link text"
|
|
|
|
end
|
2008-03-13 22:01:00 +00:00
|
|
|
|
2008-04-23 14:54:07 +00:00
|
|
|
it "should_choose_the_shortest_link_text_match" do
|
2008-03-13 22:01:00 +00:00
|
|
|
@response.stubs(:body).returns(<<-EOS)
|
|
|
|
<a href="/page1">Linkerama</a>
|
|
|
|
<a href="/page2">Link</a>
|
|
|
|
EOS
|
|
|
|
|
|
|
|
@session.expects(:get_via_redirect).with("/page2", {})
|
|
|
|
@session.clicks_link "Link"
|
|
|
|
end
|
|
|
|
|
2008-04-23 14:54:07 +00:00
|
|
|
it "should_click_link_within_a_selector" do
|
2008-04-12 21:07:33 +00:00
|
|
|
@response.stubs(:body).returns(<<-EOS)
|
|
|
|
<a href="/page1">Link</a>
|
|
|
|
<div id="container">
|
|
|
|
<a href="/page2">Link</a>
|
|
|
|
</div>
|
|
|
|
EOS
|
|
|
|
|
|
|
|
@session.expects(:get_via_redirect).with("/page2", {})
|
|
|
|
@session.clicks_link_within "#container", "Link"
|
|
|
|
end
|
2008-03-06 15:04:01 +00:00
|
|
|
|
2008-04-23 14:54:07 +00:00
|
|
|
it "should_not_make_request_when_link_is_local_anchor" do
|
2008-03-06 15:04:01 +00:00
|
|
|
@response.stubs(:body).returns(<<-EOS)
|
|
|
|
<a href="#section-1">Jump to Section 1</a>
|
|
|
|
EOS
|
|
|
|
# Don't know why @session.expects(:get_via_redirect).never doesn't work here
|
|
|
|
@session.expects(:send).with('get_via_redirect', '#section-1', {}).never
|
|
|
|
@session.clicks_link "Jump to Section 1"
|
|
|
|
end
|
2008-04-12 23:20:43 +00:00
|
|
|
|
2008-04-23 14:54:07 +00:00
|
|
|
it "should_follow_relative_links" do
|
2008-04-12 23:20:43 +00:00
|
|
|
@session.current_page.stubs(:url).returns("/page")
|
|
|
|
@response.stubs(:body).returns(<<-EOS)
|
|
|
|
<a href="sub">Jump to sub page</a>
|
|
|
|
EOS
|
|
|
|
@session.expects(:get_via_redirect).with("/page/sub", {})
|
|
|
|
@session.clicks_link "Jump to sub page"
|
|
|
|
end
|
|
|
|
|
2008-04-23 14:54:07 +00:00
|
|
|
it "should_follow_query_parameters" do
|
2008-04-12 23:20:43 +00:00
|
|
|
@session.current_page.stubs(:url).returns("/page")
|
|
|
|
@response.stubs(:body).returns(<<-EOS)
|
|
|
|
<a href="?foo=bar">Jump to foo bar</a>
|
|
|
|
EOS
|
|
|
|
@session.expects(:get_via_redirect).with("/page?foo=bar", {})
|
|
|
|
@session.clicks_link "Jump to foo bar"
|
|
|
|
end
|
2008-03-02 20:14:52 +00:00
|
|
|
end
|