2012-07-21 16:44:10 -04:00
|
|
|
Capybara::SpecHelper.spec '#click_link' do
|
|
|
|
before do
|
|
|
|
@session.visit('/with_html')
|
|
|
|
end
|
2009-12-15 14:58:51 -05:00
|
|
|
|
2012-07-21 16:44:10 -04:00
|
|
|
it "should wait for asynchronous load", :requires => [:js] do
|
|
|
|
@session.visit('/with_js')
|
|
|
|
@session.click_link('Click me')
|
|
|
|
@session.click_link('Has been clicked')
|
|
|
|
end
|
2010-10-22 10:45:33 -04:00
|
|
|
|
2012-07-21 16:44:10 -04:00
|
|
|
context "with id given" do
|
|
|
|
it "should take user to the linked page" do
|
|
|
|
@session.click_link('foo')
|
|
|
|
@session.body.should include('Another World')
|
2010-01-18 14:33:22 -05:00
|
|
|
end
|
2012-07-21 16:44:10 -04:00
|
|
|
end
|
2010-01-15 10:13:48 -05:00
|
|
|
|
2012-07-21 16:44:10 -04:00
|
|
|
context "with text given" do
|
|
|
|
it "should take user to the linked page" do
|
|
|
|
@session.click_link('labore')
|
|
|
|
@session.body.should include('Bar')
|
2010-01-18 14:33:22 -05:00
|
|
|
end
|
|
|
|
|
2012-07-21 16:44:10 -04:00
|
|
|
it "should accept partial matches" do
|
|
|
|
@session.click_link('abo')
|
|
|
|
@session.body.should include('Bar')
|
2010-01-18 14:33:22 -05:00
|
|
|
end
|
2012-07-21 16:44:10 -04:00
|
|
|
end
|
2010-01-18 14:33:22 -05:00
|
|
|
|
2012-07-21 16:44:10 -04:00
|
|
|
context "with title given" do
|
|
|
|
it "should take user to the linked page" do
|
|
|
|
@session.click_link('awesome title')
|
|
|
|
@session.body.should include('Bar')
|
2009-12-15 14:58:51 -05:00
|
|
|
end
|
2010-01-18 14:33:22 -05:00
|
|
|
|
2012-07-21 16:44:10 -04:00
|
|
|
it "should accept partial matches" do
|
|
|
|
@session.click_link('some tit')
|
|
|
|
@session.body.should include('Bar')
|
2011-08-30 04:54:20 -04:00
|
|
|
end
|
2012-07-21 16:44:10 -04:00
|
|
|
end
|
2011-08-30 04:54:20 -04:00
|
|
|
|
2012-07-21 16:44:10 -04:00
|
|
|
context "with alternative text given to a contained image" do
|
|
|
|
it "should take user to the linked page" do
|
|
|
|
@session.click_link('awesome image')
|
|
|
|
@session.body.should include('Bar')
|
2010-01-18 14:33:22 -05:00
|
|
|
end
|
2010-10-22 10:45:33 -04:00
|
|
|
|
2012-07-21 16:44:10 -04:00
|
|
|
it "should take user to the linked page" do
|
|
|
|
@session.click_link('some imag')
|
|
|
|
@session.body.should include('Bar')
|
2010-02-12 08:41:41 -05:00
|
|
|
end
|
2012-07-21 16:44:10 -04:00
|
|
|
end
|
2010-10-22 10:45:33 -04:00
|
|
|
|
2012-07-21 16:44:10 -04:00
|
|
|
context "with a locator that doesn't exist" do
|
|
|
|
it "should raise an error" do
|
|
|
|
msg = "Unable to find link \"does not exist\""
|
|
|
|
running do
|
|
|
|
@session.click_link('does not exist')
|
|
|
|
end.should raise_error(Capybara::ElementNotFound, msg)
|
2010-10-22 10:45:33 -04:00
|
|
|
end
|
2012-07-21 16:44:10 -04:00
|
|
|
end
|
2010-10-22 10:45:33 -04:00
|
|
|
|
2012-07-21 16:44:10 -04:00
|
|
|
it "should follow relative links" do
|
|
|
|
@session.visit('/')
|
|
|
|
@session.click_link('Relative')
|
|
|
|
@session.body.should include('This is a test')
|
|
|
|
end
|
2010-10-22 10:45:33 -04:00
|
|
|
|
2012-07-21 16:44:10 -04:00
|
|
|
it "should follow redirects" do
|
|
|
|
@session.click_link('Redirect')
|
|
|
|
@session.body.should include('You landed')
|
|
|
|
end
|
2010-10-22 10:45:33 -04:00
|
|
|
|
2012-07-21 16:44:10 -04:00
|
|
|
it "should follow redirects" do
|
|
|
|
@session.click_link('BackToMyself')
|
|
|
|
@session.body.should include('This is a test')
|
|
|
|
end
|
2010-10-22 10:45:33 -04:00
|
|
|
|
2012-07-21 16:44:10 -04:00
|
|
|
it "should add query string to current URL with naked query string" do
|
|
|
|
@session.click_link('Naked Query String')
|
|
|
|
@session.body.should include('Query String sent')
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should do nothing on anchor links" do
|
|
|
|
@session.fill_in("test_field", :with => 'blah')
|
|
|
|
@session.click_link('Normal Anchor')
|
|
|
|
@session.find_field("test_field").value.should == 'blah'
|
|
|
|
@session.click_link('Blank Anchor')
|
|
|
|
@session.find_field("test_field").value.should == 'blah'
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should do nothing on URL+anchor links for the same page" do
|
|
|
|
@session.fill_in("test_field", :with => 'blah')
|
|
|
|
@session.click_link('Anchor on same page')
|
|
|
|
@session.find_field("test_field").value.should == 'blah'
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should follow link on URL+anchor links for a different page" do
|
|
|
|
@session.click_link('Anchor on different page')
|
|
|
|
@session.body.should include('Bar')
|
|
|
|
end
|
|
|
|
|
|
|
|
it "raise an error with links with no href" do
|
|
|
|
running do
|
|
|
|
@session.click_link('No Href')
|
|
|
|
end.should raise_error(Capybara::ElementNotFound)
|
2009-12-15 14:58:51 -05:00
|
|
|
end
|
2010-01-18 14:33:22 -05:00
|
|
|
end
|