2016-03-07 19:52:19 -05:00
|
|
|
# frozen_string_literal: true
|
2018-02-28 19:11:41 -05:00
|
|
|
|
2016-10-04 14:10:29 -04:00
|
|
|
Capybara::SpecHelper.spec '#accept_alert', requires: [:modals] do
|
2013-04-01 18:41:55 -04:00
|
|
|
before do
|
|
|
|
@session.visit('/with_js')
|
|
|
|
end
|
|
|
|
|
2018-07-10 17:18:39 -04:00
|
|
|
it 'should accept the alert' do
|
2013-04-01 18:41:55 -04:00
|
|
|
@session.accept_alert do
|
|
|
|
@session.click_link('Open alert')
|
|
|
|
end
|
|
|
|
expect(@session).to have_xpath("//a[@id='open-alert' and @opened='true']")
|
|
|
|
end
|
2016-10-04 14:10:29 -04:00
|
|
|
|
2018-07-10 17:18:39 -04:00
|
|
|
it 'should accept the alert if the text matches' do
|
2014-06-27 15:37:33 -04:00
|
|
|
@session.accept_alert 'Alert opened' do
|
2014-06-03 15:18:14 -04:00
|
|
|
@session.click_link('Open alert')
|
|
|
|
end
|
|
|
|
expect(@session).to have_xpath("//a[@id='open-alert' and @opened='true']")
|
|
|
|
end
|
2016-10-04 14:10:29 -04:00
|
|
|
|
2016-10-06 18:08:42 -04:00
|
|
|
it 'should accept the alert if text contains "special" Regex characters' do
|
|
|
|
@session.accept_alert 'opened [*Yay?*]' do
|
|
|
|
@session.click_link('Open alert')
|
|
|
|
end
|
|
|
|
expect(@session).to have_xpath("//a[@id='open-alert' and @opened='true']")
|
|
|
|
end
|
|
|
|
|
2018-07-10 17:18:39 -04:00
|
|
|
it 'should accept the alert if the text matches a regexp' do
|
2016-11-21 14:53:59 -05:00
|
|
|
@session.accept_alert(/op.{2}ed/) do
|
2016-10-06 18:08:42 -04:00
|
|
|
@session.click_link('Open alert')
|
|
|
|
end
|
|
|
|
expect(@session).to have_xpath("//a[@id='open-alert' and @opened='true']")
|
|
|
|
end
|
|
|
|
|
2018-07-10 17:18:39 -04:00
|
|
|
it 'should not accept the alert if the text doesnt match' do
|
2014-06-03 15:18:14 -04:00
|
|
|
expect do
|
2014-06-27 15:37:33 -04:00
|
|
|
@session.accept_alert 'Incorrect Text' do
|
2014-06-03 15:18:14 -04:00
|
|
|
@session.click_link('Open alert')
|
|
|
|
end
|
|
|
|
end.to raise_error(Capybara::ModalNotFound)
|
|
|
|
end
|
2013-04-01 18:41:55 -04:00
|
|
|
|
2018-07-10 17:18:39 -04:00
|
|
|
it 'should return the message presented' do
|
2013-04-01 18:41:55 -04:00
|
|
|
message = @session.accept_alert do
|
|
|
|
@session.click_link('Open alert')
|
|
|
|
end
|
2016-10-06 18:08:42 -04:00
|
|
|
expect(message).to eq('Alert opened [*Yay?*]')
|
2013-04-01 18:41:55 -04:00
|
|
|
end
|
|
|
|
|
2018-07-10 17:18:39 -04:00
|
|
|
it 'should handle the alert if the page changes' do
|
2017-06-09 14:28:47 -04:00
|
|
|
@session.accept_alert do
|
|
|
|
@session.click_link('Alert page change')
|
|
|
|
sleep 1 # ensure page change occurs before the accept_alert block exits
|
|
|
|
end
|
2020-07-04 17:53:22 -04:00
|
|
|
expect(@session).to have_current_path('/with_html', wait: 5)
|
2017-06-09 14:28:47 -04:00
|
|
|
end
|
|
|
|
|
2018-07-10 17:18:39 -04:00
|
|
|
context 'with an asynchronous alert' do
|
|
|
|
it 'should accept the alert' do
|
2013-04-01 18:41:55 -04:00
|
|
|
@session.accept_alert do
|
|
|
|
@session.click_link('Open delayed alert')
|
|
|
|
end
|
|
|
|
expect(@session).to have_xpath("//a[@id='open-delayed-alert' and @opened='true']")
|
|
|
|
end
|
|
|
|
|
2018-07-10 17:18:39 -04:00
|
|
|
it 'should return the message presented' do
|
2013-04-01 18:41:55 -04:00
|
|
|
message = @session.accept_alert do
|
|
|
|
@session.click_link('Open delayed alert')
|
|
|
|
end
|
|
|
|
expect(message).to eq('Delayed alert opened')
|
|
|
|
end
|
2016-10-04 14:10:29 -04:00
|
|
|
|
2018-07-10 17:18:39 -04:00
|
|
|
it 'should allow to adjust the delay' do
|
2017-05-10 15:27:53 -04:00
|
|
|
@session.accept_alert wait: 10 do
|
2014-06-03 15:18:14 -04:00
|
|
|
@session.click_link('Open slow alert')
|
|
|
|
end
|
|
|
|
expect(@session).to have_xpath("//a[@id='open-slow-alert' and @opened='true']")
|
|
|
|
end
|
2013-04-01 18:41:55 -04:00
|
|
|
end
|
2016-03-07 19:52:19 -05:00
|
|
|
end
|