From cbe372cba04e5858527e4c00e16a4795b2614f3a Mon Sep 17 00:00:00 2001 From: Reinier Balt Date: Thu, 1 Mar 2012 20:31:16 +0100 Subject: [PATCH] migrate preferences, project_* and recurring todo features --- features/context_list.feature | 2 +- features/edit_a_todo.feature | 34 +-- features/preferences.feature | 1 - features/project_edit.feature | 27 +- features/project_list.feature | 38 +-- features/recurring_todos.feature | 18 +- .../step_definitions/context_list_steps.rb | 5 +- features/step_definitions/context_steps.rb | 8 +- features/step_definitions/generic_steps.rb | 19 +- .../step_definitions/preferences_steps.rb | 2 +- .../step_definitions/project_list_steps.rb | 235 +++++++++--------- features/step_definitions/project_steps.rb | 198 +++++---------- .../step_definitions/recurring_todo_steps.rb | 44 ++-- features/step_definitions/todo_edit_steps.rb | 2 +- features/step_definitions/todo_steps.rb | 30 +-- features/step_definitions/todo_tag_steps.rb | 12 +- features/support/world.rb | 43 +++- 17 files changed, 334 insertions(+), 384 deletions(-) diff --git a/features/context_list.feature b/features/context_list.feature index 999e790f..14cd97ae 100644 --- a/features/context_list.feature +++ b/features/context_list.feature @@ -44,7 +44,7 @@ Feature: Manage the list of contexts Then the badge should show 2 And the context list badge for active contexts should show 2 When I delete the context "@computer" - Then he should see that a context named "@computer" is not present + Then I should see that a context named "@computer" is not present And the badge should show 1 And the context list badge for active contexts should show 1 diff --git a/features/edit_a_todo.feature b/features/edit_a_todo.feature index 6cd59880..f203dbb4 100644 --- a/features/edit_a_todo.feature +++ b/features/edit_a_todo.feature @@ -58,12 +58,12 @@ Feature: Edit a next action from every page | @home | first action | test, bla | | @home | second action | bla | When I go to the - Then I should not see empty message for todos + Then I should not see empty message for todos of And I should see "first action" When I delete the todo "first action" - Then I should not see empty message for todos + Then I should not see empty message for todos of When I delete the todo "second action" - Then I should see empty message for todos + Then I should see empty message for todos of Scenarios: | page | page type | @@ -76,12 +76,12 @@ Feature: Edit a next action from every page Given I have a context called "visible context" And I have a project called "visible project" When I go to the - Then I should see empty message for todos + Then I should see empty message for todos of When I submit a new action with description "visible todo" to project "visible project" with tags "starred" in the context "visible context" Then I should see "visible todo" - And I should not see empty message for todos + And I should not see empty message for todos of When I mark "visible todo" as complete - And I should see empty message for todos + And I should see empty message for todos of And I should see "visible todo" in the completed container Scenarios: @@ -96,12 +96,12 @@ Feature: Edit a next action from every page Given I have a context called "visible context" And I have a project called "visible project" When I go to the - Then I should see empty message for deferred todos + Then I should see empty message for deferred todos of When I submit a new deferred action with description "visible todo" to project "visible project" with tags "starred" in the context "visible context" Then I should see "visible todo" - And I should not see empty message for deferred todos + And I should not see empty message for deferred todos of When I mark "visible todo" as complete - And I should see empty message for deferred todos + And I should see empty message for deferred todos of And I should see "visible todo" in the completed container Scenarios: @@ -113,14 +113,14 @@ Feature: Edit a next action from every page Scenario Outline: I can mark a completed todo active and it will update empty messages and context containers Given I have a completed todo with description "visible todo" in project "visible project" with tags "starred" in the context "visible context" When I go to the - Then I should see empty message for todos + Then I should see empty message for todos of And I should not see the container for context "visible context" - And I should not see empty message for completed todos + And I should not see empty message for completed todos of When I mark the complete todo "visible todo" active Then I should see the container for context "visible context" - And I should see empty message for completed todos + And I should see empty message for completed todos of And I should see "visible todo" in the context container for "visible context" - And I should not see empty message for todos + And I should not see empty message for todos of Scenarios: | page | page type | @@ -131,11 +131,11 @@ Feature: Edit a next action from every page Scenario Outline: I can mark a completed todo active and it will update empty messages for pages without context containers Given I have a completed todo with description "visible todo" in project "visible project" with tags "starred" in the context "visible context" When I go to the - Then I should see empty message for todos - And I should not see empty message for completed todos + Then I should see empty message for todos of + And I should not see empty message for completed todos of When I mark the complete todo "visible todo" active - And I should see empty message for completed todos - And I should not see empty message for todos + And I should see empty message for completed todos of + And I should not see empty message for todos of Scenarios: | page | page type | diff --git a/features/preferences.feature b/features/preferences.feature index c2f9d389..3a39927f 100644 --- a/features/preferences.feature +++ b/features/preferences.feature @@ -34,7 +34,6 @@ Feature: Manage preferences And I set the password to "secret" and confirmation to "wrong" Then I should see "Password doesn't match confirmation" - Scenario: I can edit preferences When I go to the preferences page Then I should see "Logout (testuser)" diff --git a/features/project_edit.feature b/features/project_edit.feature index 986eb8aa..bdba3c95 100644 --- a/features/project_edit.feature +++ b/features/project_edit.feature @@ -113,49 +113,50 @@ Feature: Edit a project Scenario: Cancelling editing a project will restore project settings Given I have a project called "test" When I go to the "test" project - Then I should see "This project is active with no default context and with no default tags" + Then I should see the default project settings When I open the project edit form - Then I should not see "This project is active with no default context and with no default tags" + Then I should not see the default project settings When I cancel the project edit form - Then I should see "This project is active with no default context and with no default tags" + Then I should see the default project settings @selenium Scenario: Moving the todo to the tickler will move todo to tickler container and update empty messages Given I have a project "test" with 1 todos When I go to the "test" project Then I should see "todo 1" in the action container - And I should see "Currently there are no deferred or pending actions" - And I should not see "Currently there are no incomplete actions in this project" + And I should see empty message for deferred todos of project + And I should see empty message for completed todos of project When I defer "todo 1" for 1 day Then I should see "todo 1" in the deferred container - And I should not see "Currently there are no deferred or pending actions" - And I should see "Currently there are no incomplete actions in this project" + And I should not see empty message for deferred todos of project + And I should see empty message for completed todos of project + And I should see empty message for todos of project @selenium Scenario: Moving the todo out of the tickler will move todo to active container and update empty messages Given I have a project "test" with 1 deferred todos When I go to the "test" project Then I should see "todo 1" in the deferred container - And I should see "Currently there are no incomplete actions in this project" - And I should not see "Currently there are no deferred or pending actions" + And I should see empty message for todos of project + And I should not see empty message for deferred todos of project When I clear the show from date of "todo 1" Then I should see "todo 1" in the action container - And I should see "Currently there are no deferred or pending actions" - And I should not see "Currently there are no incomplete actions in this project" + And I should see empty message for deferred todos of project + And I should not see empty message for todos of project @selenium Scenario: Making all todos inactive will show empty message Given I have a project "test" with 1 todos When I go to the "test" project And I mark "todo 1" as complete - Then I should see "Currently there are no incomplete actions in this project" + Then I should see empty message for todos of project @selenium Scenario: Making all deferred todos inactive will show empty message Given I have a project "test" with 1 deferred todos When I go to the "test" project And I mark "todo 1" as complete - Then I should see "Currently there are no incomplete actions in this project" + Then I should see empty message for todos of project # Ticket #1043 @selenium diff --git a/features/project_list.feature b/features/project_list.feature index a57ba857..572bec84 100644 --- a/features/project_list.feature +++ b/features/project_list.feature @@ -24,34 +24,34 @@ Feature: Manage the list of projects And I follow "manage me" Then I should be on the "manage me" project page - @selenium + @javascript Scenario: Editing a project name will update the list When I go to the projects page And I edit the project name of "manage me" to "manage him" Then I should see "manage him" - @selenium + @javascript Scenario: Deleting a project will remove it from the list When I go to the projects page And I delete project "manage me" - Then I should not see "manage me" + Then I should see that a project named "manage me" is not present And the badge should show 2 And the project list badge for "active" projects should show 2 - @selenium + @javascript Scenario: Deleting a project after a edit will remove it from the list # make sure the js is enabled after an edit and another edit When I go to the projects page And I edit the project name of "manage me" to "manage him" - Then I should see "manage him" + Then I should see a project named "manage him" When I edit the project name of "manage him" to "manage her" - Then I should see "manage her" + Then I should see a project named "manage her" When I delete project "manage her" - Then I should not see "manage her" + Then I should not see a project named "manage her" And the badge should show 2 And the project list badge for "active" projects should show 2 - @selenium + @javascript Scenario: Changing project state will move project to other state list When I go to the projects page Then the project "manage me" should be in state list "active" @@ -62,14 +62,14 @@ Feature: Manage the list of projects And the project list badge for "active" projects should show 2 And the project list badge for "hidden" projects should show 1 - @selenium + @javascript Scenario: Dragging a project to change list order of projects When I go to the projects page Then the project "manage me" should be above the project "upgrade jquery" When I drag the project "manage me" below "upgrade jquery" Then the project "upgrade jquery" should be above the project "manage me" - @selenium + @javascript Scenario: Hiding and unhiding the new project form When I go to the projects page Then the new project form should be visible @@ -78,7 +78,7 @@ Feature: Manage the list of projects When I follow "Create a new project" Then the new project form should be visible - @selenium + @javascript Scenario: Adding a new project When I go to the projects page And I submit a new project with name "finish cucumber tests" @@ -86,20 +86,20 @@ Feature: Manage the list of projects And the badge should show 4 And the project list badge for "active" projects should show 4 - @selenium + @javascript Scenario: Adding a new project and take me to the project page When I go to the projects page And I submit a new project with name "finish cucumber tests" and select take me to the project Then I should be on the "finish cucumber tests" project page - @selenium + @javascript Scenario: Sorting the project alphabetically When I go to the projects page Then the project "manage me" should be above the project "a project name starting with a" When I sort the active list alphabetically Then the project "a project name starting with a" should be above the project "manage me" - @selenium + @javascript Scenario: Sorting the project by number of task Given I have a project "test" with 2 todos And I have a project "very busy" with 10 todos @@ -108,7 +108,7 @@ Feature: Manage the list of projects When I sort the list by number of tasks Then the project "very busy" should be above the project "test" - @selenium + @javascript Scenario: Can add a project with comma in the name When I go to the projects page And I submit a new project with name "foo,bar" @@ -116,25 +116,25 @@ Feature: Manage the list of projects And the badge should show 4 And the project list badge for "active" projects should show 4 - @selenium + @javascript Scenario: Listing projects with only active actions Given I have a project "do it now" with 2 active todos When I go to the projects page Then the project "do it now" should have 2 actions listed - @selenium + @javascript Scenario: Listing projects with both active and deferred actions Given I have a project "now and later" with 2 active actions and 2 deferred actions When I go to the projects page Then the project "now and later" should have 2 actions listed - @selenium + @javascript Scenario: Listing projects with only deferred actions Given I have a project "only later" with 3 deferred actions When I go to the projects page Then the project "only later" should have 3 deferred actions listed - @selenium + @javascript Scenario: Listing projects with no actions Given I have a project "all done" with 0 active actions and 0 deferred actions When I go to the projects page diff --git a/features/recurring_todos.feature b/features/recurring_todos.feature index e541cb7f..1d725410 100644 --- a/features/recurring_todos.feature +++ b/features/recurring_todos.feature @@ -11,7 +11,7 @@ Feature: Manage recurring todos And I have a context called "test context" And I have a repeat pattern called "run tests" - @selenium + @javascript Scenario: Being able to select daily, weekly, monthly and yearly pattern When I go to the repeating todos page And I follow "Add a new recurring action" @@ -25,26 +25,26 @@ Feature: Manage recurring todos When I select "Daily" recurrence pattern Then I should see the form for "Daily" recurrence pattern - @selenium + @javascript Scenario: I can mark a repeat pattern as starred When I go to the repeating todos page And I star the pattern "run tests" Then the pattern "run tests" should be starred - @selenium + @javascript Scenario: I can edit a repeat pattern When I go to the repeating todos page And I edit the name of the pattern "run tests" to "report test results" Then the pattern "report test results" should be in the state list "active" And I should not see "run tests" - @selenium + @javascript Scenario: I can delete a repeat pattern When I go to the repeating todos page And I delete the pattern "run tests" And I should not see "run tests" - @selenium + @javascript Scenario: I can mark a repeat pattern as done When I go to the repeating todos page Then the pattern "run tests" should be in the state list "active" @@ -53,7 +53,7 @@ Feature: Manage recurring todos Then the pattern "run tests" should be in the state list "completed" And the state list "active" should be empty - @selenium + @javascript Scenario: I can reactivate a repeat pattern Given I have a completed repeat pattern "I'm done" When I go to the repeating todos page @@ -62,14 +62,14 @@ Feature: Manage recurring todos Then the pattern "I'm done" should be in the state list "active" And the state list "completed" should be empty - @selenium + @javascript Scenario: Following the recurring todo link of a todo takes me to the recurring todos page When I go to the home page Then I should see the todo "run tests" When I follow the recurring todo link of "run tests" Then I should be on the repeating todos page - @selenium + @javascript Scenario: Deleting a recurring todo with ending pattern will show message When I go to the repeating todos page And I mark the pattern "run tests" as complete @@ -78,7 +78,7 @@ Feature: Manage recurring todos When I delete the action "run tests" Then I should see "There is no next action after the recurring action you just deleted. The recurrence is completed" - @selenium + @javascript Scenario: Deleting a recurring todo with active pattern will show new todo When I go to the home page Then I should see "run tests" diff --git a/features/step_definitions/context_list_steps.rb b/features/step_definitions/context_list_steps.rb index c360c8d6..e10037e6 100644 --- a/features/step_definitions/context_list_steps.rb +++ b/features/step_definitions/context_list_steps.rb @@ -6,7 +6,10 @@ When /^I delete the context "([^\"]*)"$/ do |context_name| click_link "delete_context_#{context.id}" end get_confirm_text.should == "Are you sure that you want to delete the context '#{context_name}'? Be aware that this will also delete all (repeating) actions in this context!" - wait_for_animations_to_end + + wait_until do + !page.has_css?("a#delete_context_#{context.id}") + end end When /^I edit the context to rename it to "([^\"]*)"$/ do |new_name| diff --git a/features/step_definitions/context_steps.rb b/features/step_definitions/context_steps.rb index 6bc85ee9..36df09ad 100644 --- a/features/step_definitions/context_steps.rb +++ b/features/step_definitions/context_steps.rb @@ -71,18 +71,18 @@ Then /^he should see that a context named "([^\"]*)" is not present$/ do |contex step "I should not see \"#{context_name} (\"" end -Then /^I should not see empty message for context todos/ do +Then /^I should not see empty message for todos of context/ do find("div#c#{@context.id}empty-nd").should_not be_visible end -Then /^I should see empty message for context todos/ do +Then /^I should see empty message for todos of context/ do find("div#c#{@context.id}empty-nd").should be_visible end -Then /^I should not see empty message for context completed todos$/ do +Then /^I should not see empty message for completed todos of context$/ do find("div#empty-d").should_not be_visible end -When /^I should see empty message for context completed todos$/ do +When /^I should see empty message for completed todos of context$/ do find("div#empty-d").should be_visible end diff --git a/features/step_definitions/generic_steps.rb b/features/step_definitions/generic_steps.rb index f9af1e7c..06d8d7ae 100644 --- a/features/step_definitions/generic_steps.rb +++ b/features/step_definitions/generic_steps.rb @@ -15,22 +15,6 @@ Then /the badge should show (.*)/ do |number| badge.should == number.to_i end -Then /^I should see the empty message in the deferred container$/ do - page.should have_xpath("//div[@id='tickler']//div[@id='tickler-empty-nd']") -end - -Then /^I should see the empty tickler message$/ do - wait_for :timeout => 5 do - selenium.is_visible("xpath=//div[@id='tickler-empty-nd']") - end -end - -Then /^I should not see the empty tickler message$/ do - wait_for :timeout => 5 do - !selenium.is_visible("xpath=//div[@id='tickler-empty-nd']") - end -end - Then /^I should see an error flash message saying "([^"]*)"$/ do |message| xpath = "//div[@id='message_holder']/h4[@id='flash']" text = page.find(:xpath, xpath).text @@ -41,3 +25,6 @@ Then /^I should see "([^"]*)" $/ do |text| Then "I should see \"#{text}\"" end +Then /^I should save and open the page$/ do + save_and_open_page +end diff --git a/features/step_definitions/preferences_steps.rb b/features/step_definitions/preferences_steps.rb index bd14c8fc..feb4b180 100644 --- a/features/step_definitions/preferences_steps.rb +++ b/features/step_definitions/preferences_steps.rb @@ -4,7 +4,7 @@ When /^I edit my last name to "([^"]*)"$/ do |last_name| end When /^I set the password and confirmation to "([^"]*)"$/ do |new_password| - When "I set the password to \"#{new_password}\" and confirmation to \"#{new_password}\"" + step "I set the password to \"#{new_password}\" and confirmation to \"#{new_password}\"" end When /^I set the password to "([^"]*)" and confirmation to "([^"]*)"$/ do |new_password, new_password_confirmation| diff --git a/features/step_definitions/project_list_steps.rb b/features/step_definitions/project_list_steps.rb index 270a5f78..341f18bc 100644 --- a/features/step_definitions/project_list_steps.rb +++ b/features/step_definitions/project_list_steps.rb @@ -1,97 +1,3 @@ -When /^I delete project "([^"]*)"$/ do |project_name| - project = @current_user.projects.find_by_name(project_name) - project.should_not be_nil - click_link "delete_project_#{project.id}" - selenium.get_confirmation.should == "Are you sure that you want to delete the project '#{project_name}'?" - wait_for do - !selenium.is_element_present("delete_project_#{project.id}") - end -end - -When /^I drag the project "([^"]*)" below "([^"]*)"$/ do |project_drag, project_drop| - drag_id = @current_user.projects.find_by_name(project_drag).id - drop_id = @current_user.projects.find_by_name(project_drop).id - - container_height = selenium.get_element_height("//div[@id='container_project_#{drag_id}']").to_i - vertical_offset = container_height*2 - coord_string = "10,#{vertical_offset}" - - drag_project_handle_xpath = "//div[@id='project_#{drag_id}']//span[@class='handle']" - drop_project_container_xpath = "//div[@id='container_project_#{drop_id}']" - - selenium.mouse_down_at(drag_project_handle_xpath,"2,2") - selenium.mouse_move_at(drop_project_container_xpath,coord_string) - # no need to simulate mouse_over for this test - selenium.mouse_up_at(drop_project_container_xpath,coord_string) -end - -When /^I submit a new project with name "([^"]*)"$/ do |project_name| - fill_in "project[name]", :with => project_name - submit_new_project_form -end - -When /^I submit a new project with name "([^"]*)" and select take me to the project$/ do |project_name| - fill_in "project[name]", :with => project_name - check "go_to_project" - submit_new_project_form - selenium.wait_for_page_to_load(5000) # follow the redirect -end - -When /^I sort the active list alphabetically$/ do - click_link "Alphabetically" - wait_for_ajax - selenium.get_confirmation.should == "Are you sure that you want to sort these projects alphabetically? This will replace the existing sort order." -end - -When /^I sort the list by number of tasks$/ do - click_link "By number of tasks" - wait_for_ajax - selenium.get_confirmation.should == "Are you sure that you want to sort these projects by the number of tasks? This will replace the existing sort order." -end - -Then /^I should see that a project named "([^"]*)" is not present$/ do |project_name| - Then "I should not see \"#{project_name}\"" -end - -Then /^I should see that a project named "([^"]*)" is present$/ do |project_name| - Then "I should see \"#{project_name}\"" -end - -Then /^the project "([^"]*)" should be above the project "([^"]*)"$/ do |project_high, project_low| - high_id = @current_user.projects.find_by_name(project_high).id - low_id = @current_user.projects.find_by_name(project_low).id - high_pos = selenium.get_element_position_top("//div[@id='project_#{high_id}']").to_i - low_pos = selenium.get_element_position_top("//div[@id='project_#{low_id}']").to_i - (high_pos < low_pos).should be_true -end - -Then /^the project "([^"]*)" should not be in state list "([^"]*)"$/ do |project_name, state_name| - project = @current_user.projects.find_by_name(project_name) - project.should_not be_nil - xpath = "//div[@id='list-#{state_name}-projects-container']//div[@id='project_#{project.id}']" - response.should_not have_xpath(xpath) -end - -Then /^the project "([^"]*)" should be in state list "([^"]*)"$/ do |project_name, state_name| - project = @current_user.projects.find_by_name(project_name) - project.should_not be_nil - xpath = "//div[@id='list-#{state_name}-projects-container']//div[@id='project_#{project.id}']" - response.should have_xpath(xpath) -end - -Then /^the project list badge for "([^"]*)" projects should show (\d+)$/ do |state_name, count| - selenium.get_text("xpath=//span[@id='#{state_name}-projects-count']").should == count -end - -Then /^the new project form should be visible$/ do - selenium.is_visible("project_new").should == true -end - -Then /^the new project form should not be visible$/ do - selenium.is_visible("project_new").should == false -end - - Given /^I have a project "([^"]*)" with (\d+) active todos$/ do |name, count| @context = @current_user.contexts.find_or_create_by_name("Context A") @project = @current_user.projects.find_or_create_by_name(name) @@ -106,36 +12,131 @@ Given /^I have a project "([^"]*)" with (\d+) active todos$/ do |name, count| end end +Given /^I have a project "([^"]*)" with (\d+) deferred actions$/ do |name, deferred| + step "I have a project \"#{name}\" with #{deferred} active todos" + @todos.each do |t| + t.show_from = Time.zone.now + 1.week + t.description = "deferred " + t.description + t.save! + end +end + +Given /^I have a project "([^"]*)" with (\d+) active actions and (\d+) deferred actions$/ do |name, active_count, deferred_count| + step "I have a project \"#{name}\" with #{active_count} active todos" + step "I have a project \"#{name}\" with #{deferred_count} deferred actions" +end + +When /^I delete project "([^"]*)"$/ do |project_name| + project = @current_user.projects.find_by_name(project_name) + project.should_not be_nil + + handle_js_confirm do + click_link "delete_project_#{project.id}" + end + get_confirm_text.should == "Are you sure that you want to delete the project '#{project_name}'?" + + wait_until do + !page.has_css?("a#delete_project_#{project.id}") + end +end + +When /^I drag the project "([^"]*)" below "([^"]*)"$/ do |project_drag, project_drop| + drag_id = @current_user.projects.find_by_name(project_drag).id + sortable_css = "div.ui-sortable div#container_project_#{drag_id}" + + drag_index = project_list_find_index(project_drag) + drop_index = project_list_find_index(project_drop) + + page.execute_script "$('#{sortable_css}').simulateDragSortable({move: #{drop_index-drag_index}, handle: '.grip'});" +end + +When /^I submit a new project with name "([^"]*)"$/ do |project_name| + fill_in "project[name]", :with => project_name + submit_new_project_form +end + +When /^I submit a new project with name "([^"]*)" and select take me to the project$/ do |project_name| + fill_in "project[name]", :with => project_name + check "go_to_project" + submit_new_project_form +end + +When /^I sort the active list alphabetically$/ do + handle_js_confirm do + click_link "Alphabetically" + wait_for_ajax + end + get_confirm_text.should == "Are you sure that you want to sort these projects alphabetically? This will replace the existing sort order." +end + +When /^I sort the list by number of tasks$/ do + handle_js_confirm do + click_link "By number of tasks" + wait_for_ajax + end + get_confirm_text.should == "Are you sure that you want to sort these projects by the number of tasks? This will replace the existing sort order." +end + +Then /^I should see that a project named "([^"]*)" is not present$/ do |project_name| + within "div#display_box" do + step "I should not see \"#{project_name}\"" + end +end + +Then /^I should see that a project named "([^"]*)" is present$/ do |project_name| + within "div#display_box" do + step "I should see \"#{project_name}\"" + end +end + +Then /^I should see a project named "([^"]*)"$/ do |project_name| + step "I should see that a project named \"#{project_name}\" is present" +end + +Then /^I should not see a project named "([^"]*)"$/ do |project_name| + step "I should see that a project named \"#{project_name}\" is not present" +end + +Then /^the project "([^"]*)" should be above the project "([^"]*)"$/ do |project_high, project_low| + project_list_find_index(project_high).should < project_list_find_index(project_low) +end + +Then /^the project "([^"]*)" should not be in state list "([^"]*)"$/ do |project_name, state_name| + project = @current_user.projects.find_by_name(project_name) + project.should_not be_nil + xpath = "//div[@id='list-#{state_name}-projects-container']//div[@id='project_#{project.id}']" + page.has_xpath?(xpath).should_not be_true +end + +Then /^the project "([^"]*)" should be in state list "([^"]*)"$/ do |project_name, state_name| + project = @current_user.projects.find_by_name(project_name) + project.should_not be_nil + xpath = "//div[@id='list-#{state_name}-projects-container']//div[@id='project_#{project.id}']" + page.has_xpath?(xpath).should be_true +end + +Then /^the project list badge for "([^"]*)" projects should show (\d+)$/ do |state_name, count| + page.find(:xpath, "//span[@id='#{state_name}-projects-count']").text.should == count +end + +Then /^the new project form should be visible$/ do + page.has_css?("div#project_new", :visible => true).should be_true +end + +Then /^the new project form should not be visible$/ do + page.has_css?("div#project_new", :visible => true).should be_false +end + Then /^the project "([^"]*)" should have (\d+) actions listed$/ do |name, count| project = @current_user.projects.find_by_name(name) project.should_not be_nil xpath = "//div[@id='list-active-projects-container']//div[@id='project_#{project.id}']//span[@class='needsreview']" - selenium.get_text("xpath=#{xpath}").should == "#{project.name} (#{count} actions)" -end - -Given /^I have a project "([^"]*)" with (\d+) active actions and (\d+) deferred actions$/ do |name, active_count, deferred_count| - Given "I have a project \"#{name}\" with #{active_count} active todos" - Given "I have a project \"#{name}\" with #{deferred_count} deferred actions" -end - -Given /^I have a project "([^"]*)" with (\d+) deferred actions$/ do |name, deferred| - @context = @current_user.contexts.find_or_create_by_name("Context A") - @project = @current_user.projects.find_or_create_by_name(name) - - 1.upto deferred.to_i do |i| - todo = @current_user.todos.create!( - :project_id => @project.id, - :context_id => @context.id, - :description => "deferred todo #{i}") - todo.show_from = Time.zone.now + 1.week - todo.save! - end + page.find(:xpath, xpath).text.should == "#{project.name} (#{count} actions)" end Then /^the project "([^"]*)" should have (\d+) deferred actions listed$/ do |name, deferred| project = @current_user.projects.find_by_name(name) project.should_not be_nil xpath = "//div[@id='list-active-projects-container']//div[@id='project_#{project.id}']//span[@class='needsreview']" - selenium.get_text("xpath=#{xpath}").should == "#{project.name} (#{deferred} deferred actions)" -end - + page.find(:xpath, xpath).text.should == "#{project.name} (#{deferred} deferred actions)" +end \ No newline at end of file diff --git a/features/step_definitions/project_steps.rb b/features/step_definitions/project_steps.rb index d890f523..3068dca4 100644 --- a/features/step_definitions/project_steps.rb +++ b/features/step_definitions/project_steps.rb @@ -1,5 +1,5 @@ Given /^I have an outdated project "([^"]*)" with (\d+) todos$/ do |project_name, num_todos| - Given "I have a project \"#{project_name}\" with #{num_todos} todos" + step "I have a project \"#{project_name}\" with #{num_todos} todos" @project = @current_user.projects.find_by_name(project_name) @project.last_reviewed = @current_user.time - @current_user.prefs.review_period.days-1 @project.save @@ -87,125 +87,61 @@ end When /^I open the project edit form$/ do click_link "link_edit_project_#{@project.id}" - - wait_for do - selenium.is_element_present("submit_project_#{@project.id}") - end + page.should have_css("button#submit_project_#{@project.id}", :visible => true) end When /^I cancel the project edit form$/ do click_link "cancel_project_#{@project.id}" - if selenium.is_visible("submit_project_#{@project.id}") - wait_for do - !selenium.is_visible("submit_project_#{@project.id}") - end + wait_until do + !page.has_css?("submit_project_#{@project.id}") end end When /^I edit the project description to "([^\"]*)"$/ do |new_description| - click_link "link_edit_project_#{@project.id}" - fill_in "project[description]", :with => new_description - click_button "submit_project_#{@project.id}" - - wait_for do - !selenium.is_element_present("submit_project_#{@project.id}") + edit_project(@project) do + fill_in "project[description]", :with => new_description end end When /^I edit the project name to "([^\"]*)"$/ do |new_title| - click_link "link_edit_project_#{@project.id}" - - wait_for do - selenium.is_element_present("submit_project_#{@project.id}") - end - - fill_in "project[name]", :with => new_title - - selenium.click "submit_project_#{@project.id}", - :wait_for => :text, - :text => "Project saved", - :timeout => 5 - - wait_for do - !selenium.is_element_present("submit_project_#{@project.id}") + edit_project(@project) do + fill_in "project[name]", :with => new_title end end When /^I try to edit the project name to "([^\"]*)"$/ do |new_title| - click_link "link_edit_project_#{@project.id}" - - wait_for do - selenium.is_element_present("submit_project_#{@project.id}") + edit_project_no_wait(@project) do + fill_in "project[name]", :with => new_title end - - fill_in "project[name]", :with => new_title - - selenium.click "submit_project_#{@project.id}", - :wait_for => :text, - :text => "There were problems with the following fields:", - :timeout => 5 end When /^I edit the default context to "([^"]*)"$/ do |default_context| - click_link "link_edit_project_#{@project.id}" - - wait_for do - selenium.is_element_present("submit_project_#{@project.id}") - end - - fill_in "project[default_context_name]", :with => default_context - - selenium.click "submit_project_#{@project.id}", - :wait_for => :text, - :text => "Project saved", - :timeout => 5 - - wait_for :timeout => 5 do - !selenium.is_element_present("submit_project_#{@project.id}") + edit_project(@project) do + fill_in "project[default_context_name]", :with => default_context end end -Then /^I should not see empty message for project todos/ do - find("div#p#{@project.id}empty-nd").should_not be_visible -end - -Then /^I should see empty message for project todos/ do - find("div#p#{@project.id}empty-nd").should be_visible -end - -Then /^I should not see empty message for project deferred todos/ do - find("div#tickler-empty-nd").should_not be_visible -end - -Then /^I should see empty message for project deferred todos/ do - find("div#tickler-empty-nd").should be_visible -end - -Then /^I should not see empty message for project completed todos$/ do - find("div#empty-d").should_not be_visible -end - -When /^I should see empty message for project completed todos$/ do - find("div#empty-d").should be_visible +Then /^I should (see|not see) empty message for (todos|deferred todos|completed todos) of project/ do |visible, state| + case state + when "todos" + css = "div#p#{@project.id}empty-nd" + when "deferred todos" + css = "div#tickler-empty-nd" + when "completed todos" + css = "div#empty-d" + else + css = "wrong state" + end + + elem = find(css) + elem.nil?.should be_false + elem.visible?.should(visible=="see" ? be_true : be_false) end Then /^I edit the default tags to "([^"]*)"$/ do |default_tags| - click_link "link_edit_project_#{@project.id}" - - wait_for do - selenium.is_element_present("submit_project_#{@project.id}") - end - - fill_in "project[default_tags]", :with => default_tags - - selenium.click "submit_project_#{@project.id}", - :wait_for => :text, - :text => "Project saved", - :timeout => 5 - - wait_for :timeout => 5 do - !selenium.is_element_present("submit_project_#{@project.id}") + edit_project(@project) do + fill_in "project[default_tags]", :with => default_tags end end @@ -222,41 +158,40 @@ When /^I try to edit the project name of "([^"]*)" to "([^"]*)"$/ do |project_cu end When /^I edit the project name in place to be "([^"]*)"$/ do |new_project_name| - selenium.click "project_name" + page.find("div#project_name").click fill_in "value", :with => new_project_name click_button "Ok" end When /^I click to edit the project name in place$/ do - selenium.click "css=div#project_name" + page.find("div#project_name").click end Then /^I should be able to change the project name in place$/ do #Note that this is not changing the project name - selenium.wait_for_element "css=div#project_name>form>input" - selenium.click "css=div#project_name > form > button[type=cancel]" + wait_until do + page.has_css? "div#project_name>form>input" + end + page.find("div#project_name > form > button[type=cancel]").click end When /^I edit the project settings$/ do @project.should_not be_nil click_link "link_edit_project_#{@project.id}" - selenium.wait_for_element("xpath=//div[@id='edit_project_#{@project.id}']/form//button[@id='submit_project_#{@project.id}']") - + page.has_xpath?("//div[@id='edit_project_#{@project.id}']/form//button[@id='submit_project_#{@project.id}']").should be_true end Then /^I should not be able to change the project name in place$/ do step "I click to edit the project name in place" - found = selenium.element? "xpath=//div[@id='project_name']/form/input" - !found + page.has_xpath?("//div[@id='project_name']/form/input").should be_false end When /^I close the project settings$/ do @project.should_not be_nil click_link "Cancel" - wait_for :wait_for => :effects , :javascript_framework => 'jquery' do - true - end + wait_for_ajax + wait_for_animations_to_end end @@ -264,21 +199,8 @@ When /^I edit the project state of "([^"]*)" to "([^"]*)"$/ do |project_name, st project = @current_user.projects.find_by_name(project_name) project.should_not be_nil - click_link "link_edit_project_#{project.id}" - selenium.wait_for_element("xpath=//div[@id='edit_project_#{project.id}']/form//button[@id='submit_project_#{project.id}']") - - choose "project_state_#{state_name}" - - # changed to make sure selenium waits until the saving has a result either - # positive or negative. Was: :element=>"flash", :text=>"Project saved" - # we may need to change it back if you really need a positive outcome, i.e. - # this step needs to fail if the project was not saved successfully - selenium.click "submit_project_#{project.id}", - :wait_for => :text, - :text => /(Project saved|1 error prohibited this project from being saved)/ - - wait_for do # wait for the form to go away - !selenium.is_element_present("submit_project_#{project.id}") + edit_project_settings(project) do + choose "project_state_#{state_name}" end end @@ -303,9 +225,7 @@ When /^I cancel adding a note to the project$/ do end Then /^the form for adding a note should not be visible$/ do - wait_for do # wait for the form to go away - !selenium.is_visible("edit_form_note") - end + page.should_not have_css("edit_form_note") end Then /^I should go to that note page$/ do @@ -315,33 +235,45 @@ Then /^I should go to that note page$/ do end Then /^I should see one note in the project$/ do - selenium.wait_for_element("xpath=//div[@class='note_wrapper']") + page.should have_xpath("//div[@class='note_wrapper']") end -Then /^I should see the bold text "([^\"]*)" in the project description$/ do |bold| +Then /^I should see the bold text "([^\"]*)" in the project description$/ do |text_in_bold| xpath="//div[@class='project_description']/p/strong" - response.should have_xpath(xpath) - bold_text = response.selenium.get_text("xpath=#{xpath}") + page.should have_xpath(xpath) + bold_text = page.find(:xpath, xpath).text - bold_text.should =~ /#{bold}/ + bold_text.should =~ /#{text_in_bold}/ end -Then /^I should see the italic text "([^\"]*)" in the project description$/ do |italic| +Then /^I should see the italic text "([^\"]*)" in the project description$/ do |text_in_italic| xpath="//div[@class='project_description']/p/em" - response.should have_xpath(xpath) - italic_text = response.selenium.get_text("xpath=#{xpath}") + page.should have_xpath(xpath) + italic_text = page.find(:xpath, xpath).text - italic_text.should =~ /#{italic}/ + italic_text.should =~ /#{text_in_italic}/ end Then /^the project title should be "(.*)"$/ do |title| - wait_for :timeout => 2 do - selenium.get_text("css=h2#project_name_container div#project_name") == title + wait_until do + page.find("h2#project_name_container div#project_name").text == title end end Then /^I should see the project name is "([^"]*)"$/ do |project_name| step "the project title should be \"#{project_name}\"" end + +Then /^I should (see|not see) the default project settings$/ do |visible| + default_settings = "This project is active with no default context and with no default tags" + if visible == "see" + elem = page.find("div.project_settings") + elem.visible?.should be_true + elem.text.should =~ /#{default_settings}/ + else + elem = page.find("div.project_settings") + elem.visible?.should be_false + end +end \ No newline at end of file diff --git a/features/step_definitions/recurring_todo_steps.rb b/features/step_definitions/recurring_todo_steps.rb index a300434e..837c6034 100644 --- a/features/step_definitions/recurring_todo_steps.rb +++ b/features/step_definitions/recurring_todo_steps.rb @@ -22,19 +22,19 @@ Given /^I have a repeat pattern called "([^"]*)"$/ do |pattern_name| end Given /^I have a completed repeat pattern "([^"]*)"$/ do |pattern_name| - Given "I have a repeat pattern called \"#{pattern_name}\"" + step "I have a repeat pattern called \"#{pattern_name}\"" @recurring_todo.toggle_completion! @recurring_todo.completed?.should be_true end Given /^I have (\d+) completed repeat patterns$/ do |number_of_patterns| 1.upto number_of_patterns.to_i do |i| - Given "I have a completed repeat pattern \"Repeating Todo #{i}\"" + step "I have a completed repeat pattern \"Repeating Todo #{i}\"" end end When /^I select "([^\"]*)" recurrence pattern$/ do |recurrence_period| - selenium.click("recurring_todo_recurring_period_#{recurrence_period.downcase}") + page.find("#recurring_todo_recurring_period_#{recurrence_period.downcase}").click end When /^I edit the name of the pattern "([^\"]*)" to "([^\"]*)"$/ do |pattern_name, new_name| @@ -45,75 +45,69 @@ When /^I edit the name of the pattern "([^\"]*)" to "([^\"]*)"$/ do |pattern_nam wait_for_ajax fill_in "edit_recurring_todo_description", :with => new_name - selenium.click "recurring_todo_edit_update_button" + page.find("button#recurring_todo_edit_update_button").click - wait_for do - !selenium.is_visible("edit-recurring-todo") - end + page.should_not have_css("div#edit-recurring-todo", :visible => true) end When /^I star the pattern "([^\"]*)"$/ do |pattern_name| pattern = @current_user.recurring_todos.find_by_description(pattern_name) pattern.should_not be_nil click_link "star_icon_#{pattern.id}" - wait_for_ajax end When /^I delete the pattern "([^"]*)"$/ do |pattern_name| pattern = @current_user.recurring_todos.find_by_description(pattern_name) pattern.should_not be_nil - click_link "delete_icon_#{pattern.id}" - selenium.get_confirmation.should == "Are you sure that you want to delete the recurring action '#{pattern_name}'?" - wait_for do - !selenium.is_element_present("delete_icon_#{pattern.id}") + + handle_js_confirm do + click_link "delete_icon_#{pattern.id}" end + get_confirm_text.should == "Are you sure that you want to delete the recurring action '#{pattern_name}'?" + + page.should_not have_css("#delete_icon_#{pattern.id}") end When /^I mark the pattern "([^"]*)" as complete$/ do |pattern_name| pattern = @current_user.recurring_todos.find_by_description(pattern_name) pattern.should_not be_nil pattern.completed?.should be_false - selenium.click "check_#{pattern.id}" - wait_for_ajax + page.find("#check_#{pattern.id}").click end When /^I mark the pattern "([^"]*)" as active$/ do |pattern_name| pattern = @current_user.recurring_todos.find_by_description(pattern_name) pattern.should_not be_nil pattern.completed?.should be_true - selenium.click "check_#{pattern.id}" - wait_for_ajax + page.find("#check_#{pattern.id}").click end When /^I follow the recurring todo link of "([^"]*)"$/ do |action_description| todo = @current_user.todos.find_by_description(action_description) todo.should_not be_nil - recurring_todo_link = "xpath=//div[@id='todo_#{todo.id}']//a[@class='recurring_icon']/img" - selenium.click( recurring_todo_link ) - selenium.wait_for_page_to_load(5000) + page.find(:xpath, "//div[@id='todo_#{todo.id}']//a[@class='recurring_icon']/img").click end Then /^the state list "([^"]*)" should be empty$/ do |state| empty_id = "recurring-todos-empty-nd" if state.downcase == "active" empty_id = "completed-empty-nd" if state.downcase == "completed" - selenium.is_visible( empty_id ) + empty_msg = page.find("div##{empty_id}") + empty_msg.visible?.should be_true end Then /^the pattern "([^\"]*)" should be starred$/ do |pattern_name| pattern = @current_user.recurring_todos.find_by_description(pattern_name) pattern.should_not be_nil - xpath = "//div[@id='recurring_todo_#{pattern.id}']//img[@class='todo_star starred']" - response.should have_xpath(xpath) + page.should have_xpath("//div[@id='recurring_todo_#{pattern.id}']//img[@class='todo_star starred']") end Then /^I should see the form for "([^\"]*)" recurrence pattern$/ do |recurrence_period| - selenium.is_visible("recurring_#{recurrence_period.downcase}") + page.should have_css("#recurring_#{recurrence_period.downcase}", :visible => true) end Then /^the pattern "([^"]*)" should be in the state list "([^"]*)"$/ do |pattern_name, state_name| pattern = @current_user.recurring_todos.find_by_description(pattern_name) pattern.should_not be_nil - xpath = "//div[@id='#{state_name}_recurring_todos_container']//div[@id='recurring_todo_#{pattern.id}']" - response.should have_xpath(xpath) + page.should have_xpath("//div[@id='#{state_name}_recurring_todos_container']//div[@id='recurring_todo_#{pattern.id}']") end diff --git a/features/step_definitions/todo_edit_steps.rb b/features/step_definitions/todo_edit_steps.rb index 880a5cda..78216f86 100644 --- a/features/step_definitions/todo_edit_steps.rb +++ b/features/step_definitions/todo_edit_steps.rb @@ -144,7 +144,7 @@ When /^I remove the show from date from "([^"]*)"$/ do |action_description| todo.should_not be_nil open_edit_form_for(todo) - page.find("//div[@id='edit_todo_#{todo.id}']//a[@id='show_from_x_todo_#{todo.id}']/img").click + page.find(:xpath, "//div[@id='edit_todo_#{todo.id}']//a[@id='show_from_x_todo_#{todo.id}']/img").click submit_edit_todo_form(todo) end diff --git a/features/step_definitions/todo_steps.rb b/features/step_definitions/todo_steps.rb index c53aa979..2ec6aa41 100644 --- a/features/step_definitions/todo_steps.rb +++ b/features/step_definitions/todo_steps.rb @@ -67,16 +67,11 @@ Then /^there should not be an error$/ do end Then /^I should see the todo "([^\"]*)"$/ do |todo_description| - selenium.is_element_present("//span[.=\"#{todo_description}\"]").should be_true + page.should have_xpath("//span[.=\"#{todo_description}\"]", :visible => true) end Then /^I should not see the todo "([^\"]*)"$/ do |todo_description| - xpath = "//span[.=\"#{todo_description}\"]" - if selenium.is_element_present(xpath) - wait_for :timeout => 5 do - !selenium.is_element_present(xpath) - end - end + page.should_not have_xpath("//span[.=\"#{todo_description}\"]", :visible => true) end Then /^I should see a completed todo "([^"]*)"$/ do |todo_description| @@ -160,22 +155,22 @@ end Then /^the project field of the new todo form should contain "([^"]*)"$/ do |project_name| xpath= "//form[@id='todo-form-new-action']/input[@id='todo_project_name']" - project_name.should == response.selenium.get_value("xpath=#{xpath}") + project_name.should == page.find(:xpath, xpath).value end Then /^the default context of the new todo form should be "([^"]*)"$/ do |context_name| xpath= "//form[@id='todo-form-new-action']/input[@id='todo_context_name']" - context_name.should == response.selenium.get_value("xpath=#{xpath}") + context_name.should == page.find(:xpath, xpath).value end Then /^the tag field in the new todo form should be empty$/ do xpath= "//form[@id='todo-form-new-action']/input[@id='todo_tag_list']" - assert response.selenium.get_value("xpath=#{xpath}").blank? + page.find(:xpath, xpath).value.blank?.should be_true end Then /^the tag field in the new todo form should be "([^"]*)"$/ do |tag_list| xpath= "//form[@id='todo-form-new-action']/input[@id='todo_tag_list']" - tag_list.should == response.selenium.get_value("xpath=#{xpath}") + tag_list.should == page.find(:xpath, xpath).value end Then /^the tags of "([^"]*)" should be "([^"]*)"$/ do |todo_description, tag_list| @@ -193,19 +188,19 @@ Then /^I should see "([^"]*)" in the completed section of the mobile site$/ do | page.should have_xpath(xpath) end -Then /^I should not see empty message for home todos/ do +Then /^I should not see empty message for todos of home/ do find("div#no_todos_in_view").should_not be_visible end -Then /^I should see empty message for home todos/ do +Then /^I should see empty message for todos of home/ do find("div#no_todos_in_view").should be_visible end -Then /^I should not see empty message for home completed todos$/ do +Then /^I should not see empty message for completed todos of home$/ do find("div#empty-d").should_not be_visible end -Then /^I should see empty message for home completed todos$/ do +Then /^I should see empty message for completed todos of home$/ do find("div#empty-d").should be_visible end @@ -221,7 +216,4 @@ Then /^I should see the notes of "([^"]*)"$/ do |todo_description| todo.should_not be_nil page.find("div#notes_todo_#{todo.id}").should be_visible -end - - - +end \ No newline at end of file diff --git a/features/step_definitions/todo_tag_steps.rb b/features/step_definitions/todo_tag_steps.rb index 3909668d..3fce3d8f 100644 --- a/features/step_definitions/todo_tag_steps.rb +++ b/features/step_definitions/todo_tag_steps.rb @@ -1,23 +1,23 @@ -Then /^I should not see empty message for tag todos/ do +Then /^I should not see empty message for todos of tag$/ do find("div#no_todos_in_view").should_not be_visible end -Then /^I should see empty message for tag todos/ do +Then /^I should see empty message for todos of tag$/ do find("div#no_todos_in_view").should be_visible end -Then /^I should not see empty message for tag completed todos$/ do +Then /^I should not see empty message for completed todos of tag$/ do find("div#empty-d").should_not be_visible end -Then /^I should see empty message for tag completed todos$/ do +Then /^I should see empty message for completed todos of tag$/ do find("div#empty-d").should be_visible end -Then /^I should not see empty message for tag deferred todos$/ do +Then /^I should not see empty message for deferred todos of tag$/ do find("div#tickler-empty-nd").should_not be_visible end -Then /^I should see empty message for tag deferred todos$/ do +Then /^I should see empty message for deferred todos of tag$/ do find("div#tickler-empty-nd").should be_visible end diff --git a/features/support/world.rb b/features/support/world.rb index 59d0c0fd..d9aacf3d 100644 --- a/features/support/world.rb +++ b/features/support/world.rb @@ -15,11 +15,16 @@ module TracksStepHelper within "form#context-form" do find("button#context_new_submit").click end + wait_for_ajax wait_for_animations_to_end end def submit_new_project_form - selenium.click("xpath=//form[@id='project_form']//button[@id='project_new_project_submit']", :wait_for => :ajax, :javascript_framework => :jquery) + within "form#project_form" do + click_button "project_new_project_submit" + end + wait_for_ajax + wait_for_animations_to_end end def wait_for_form_to_go_away(todo) @@ -103,6 +108,42 @@ module TracksStepHelper contexts = page.all("div.context").map { |x| x[:id] } return contexts.find_index(div_id) end + + def project_list_find_index(project_name) + # TODO: refactor with context_list_find_index + div_id = "project_#{@current_user.projects.find_by_name(project_name).id}" + project = page.all("div.project").map { |x| x[:id] } + return project.find_index(div_id) + end + + def open_project_edit_form(project) + click_link "link_edit_project_#{project.id}" + page.should have_css("button#submit_project_#{project.id}") + end + + def submit_project_edit_form(project) + page.find("button#submit_project_#{project.id}").click + end + + def edit_project_no_wait(project) + open_project_edit_form(project) + yield + submit_project_edit_form(project) + end + + def edit_project(project) + open_project_edit_form(project) + yield + submit_project_edit_form(project) + page.should_not have_css("button#submit_project_#{project.id}", :visible => true) + end + + def edit_project_settings(project) + open_project_edit_form(project) + yield + submit_project_edit_form(project) + page.should_not have_css("button#submit_project_#{project.id}", :visible => true) + end end