From a9ae0300d17ba8d3933e59a98ceaa236ad9d3553 Mon Sep 17 00:00:00 2001 From: Ion Biziiac Date: Fri, 30 May 2014 11:33:39 +0300 Subject: [PATCH] Add cukes for warning message when closing work package modal with changes --- features/step_definitions/custom_web_steps.rb | 4 ++++ .../step_definitions/timelines_then_steps.rb | 4 ++++ features/step_definitions/web_steps.rb | 14 ++++++++++++++ features/support/env.rb | 5 +++++ features/timelines/timeline_modal_views.feature | 17 +++++++++++++++++ 5 files changed, 44 insertions(+) diff --git a/features/step_definitions/custom_web_steps.rb b/features/step_definitions/custom_web_steps.rb index e77848c56a..8bf84811d7 100644 --- a/features/step_definitions/custom_web_steps.rb +++ b/features/step_definitions/custom_web_steps.rb @@ -37,6 +37,10 @@ When /^I click(?:| on) "([^"]*)"$/ do |name| click_link_or_button(name) end +When /^I click(?:| on) the div "([^"]*)"$/ do |name| + find("##{name}").click +end + When /^(?:|I )jump to [Pp]roject "([^\"]*)"$/ do |project| click_link('Projects') # supports both variants of finding: by class and by id diff --git a/features/step_definitions/timelines_then_steps.rb b/features/step_definitions/timelines_then_steps.rb index 9a2097f754..59c015fa46 100644 --- a/features/step_definitions/timelines_then_steps.rb +++ b/features/step_definitions/timelines_then_steps.rb @@ -74,6 +74,10 @@ Then(/^I should see a modal window$/) do steps 'Then I should see a modal window with selector "#modalDiv"' end +Then(/^I should not see a modal window$/) do + page.should_not have_selector("#modalDiv") +end + Then(/^(.*) in the modal$/) do |step| step(step + ' in the iframe "modalIframe"') end diff --git a/features/step_definitions/web_steps.rb b/features/step_definitions/web_steps.rb index 58d5b2d27a..ce2960e033 100644 --- a/features/step_definitions/web_steps.rb +++ b/features/step_definitions/web_steps.rb @@ -435,6 +435,11 @@ When /^(?:|I )click on the first button matching "([^"]*)"$/ do |button| first(:button, button).click end + +When /^(?:|I )click on the first anchor matching "([^"]*)"$/ do |anchor| + find(:xpath, "(//a[text()='#{anchor}'])[1]").click +end + def find_lowest_containing_element text, selector elements = [] @@ -473,3 +478,12 @@ end Then(/^I should see a confirm dialog$/) do page.should have_selector("#confirm_dialog") end + +Then /^I confirm the JS confirm dialog$/ do + page.driver.browser.switch_to.alert.accept rescue Selenium::WebDriver::Error::NoAlertOpenError +end + +Then /^I should see a JS confirm dialog$/ do + page.driver.browser.switch_to.alert.text.should_not be_nil + page.driver.browser.switch_to.alert.accept +end diff --git a/features/support/env.rb b/features/support/env.rb index cf9a2885ee..d70035a181 100644 --- a/features/support/env.rb +++ b/features/support/env.rb @@ -105,6 +105,11 @@ end # See https://github.com/cucumber/cucumber-rails/blob/master/features/choose_javascript_database_strategy.feature Cucumber::Rails::Database.javascript_strategy = :truncation +# Remove any modal dialog remaining from the scenarios which finish in an unclean state +Before do |scenario| + page.driver.browser.switch_to.alert.accept rescue Selenium::WebDriver::Error::NoAlertOpenError +end + # Capybara.register_driver :selenium do |app| # Capybara::Selenium::Driver.new(app, :browser => :chrome) # end diff --git a/features/timelines/timeline_modal_views.feature b/features/timelines/timeline_modal_views.feature index 883780f6cd..c57035a9ab 100644 --- a/features/timelines/timeline_modal_views.feature +++ b/features/timelines/timeline_modal_views.feature @@ -88,3 +88,20 @@ Feature: Timeline View Tests When I ctrl-click on "#2" in the modal Then I should see "February" in the new window Then I should see "Avocado Rincon" in the new window + + @javascript + Scenario: closing the modal window with changes should display a warning message + When the role "manager" may have the following rights: + | view_timelines | + | edit_timelines | + | view_work_packages | + | edit_work_packages | + And there is a timeline "Testline" for project "ecookbook" + And I go to the page of the timeline "Testline" of the project called "ecookbook" + And I wait for timeline to load table + And I click on the Planning Element with name "January" + And I click on the first anchor matching "Update" in the modal + And I fill in "work_package_notes" with "A new comment" in the modal + And I click on the div "ui-dialog-closer" + Then I confirm the JS confirm dialog + And I should not see a modal window