From 796685072dfbde51ddd147da9399db82a1b4cdda Mon Sep 17 00:00:00 2001 From: Reinier Balt Date: Tue, 1 Jan 2013 17:38:59 +0100 Subject: [PATCH] finish updating cucumber scenario's to the stricter capybara --- features/context_list.feature | 6 ++--- features/mobile_tagging_todos.feature | 6 ++--- features/notes_manage.feature | 4 ++-- features/project_list.feature | 2 +- .../step_definitions/context_list_steps.rb | 8 ++++--- .../mobile_tagging_todos_steps.rb | 4 ++++ features/step_definitions/note_steps.rb | 12 ++++++---- .../step_definitions/project_list_steps.rb | 10 +++++--- features/step_definitions/todo_edit_steps.rb | 4 +++- features/support/world.rb | 23 ++++++++++--------- lib/tracks/done_todos.rb | 10 ++++++-- 11 files changed, 55 insertions(+), 34 deletions(-) create mode 100644 features/step_definitions/mobile_tagging_todos_steps.rb diff --git a/features/context_list.feature b/features/context_list.feature index 81d5ae96..32a92a85 100644 --- a/features/context_list.feature +++ b/features/context_list.feature @@ -62,7 +62,7 @@ Feature: Manage the list of contexts Then I should see that a context named "@ipad" is not present And I should see that the context container for hidden contexts is not present - @javascript + @javascript Scenario: Delete context from context page right after an edit Given I have a context called "@computer" When I go to the contexts page @@ -71,7 +71,7 @@ Feature: Manage the list of contexts Then he should see that a context named "@laptop" is not present And the badge should show 0 - @javascript + @javascript Scenario: Edit context from context twice Given I have a context called "@computer" When I go to the contexts page @@ -82,7 +82,7 @@ Feature: Manage the list of contexts And he should see that a context named "@ipad" is present And the badge should show 1 - @javascript + @javascript Scenario Outline: Add a new context with state Given I have the following contexts | context | hide | diff --git a/features/mobile_tagging_todos.feature b/features/mobile_tagging_todos.feature index c12ffbb8..1d874366 100644 --- a/features/mobile_tagging_todos.feature +++ b/features/mobile_tagging_todos.feature @@ -11,14 +11,14 @@ Feature: Show the actions that are tagged on the mobile page And I have logged in as "testuser" with password "secret" And I have a context called "@mobile" And I have a project "my project" that has the following todos - | context | description | tags | + | context | description | tags | | @mobile | first action | test, bla | | @mobile | second action | bla | Scenario: I can follow the tag of a action to see all actions belonging to that todo When I go to the home page - And I follow "test" + And I follow the tag "test" Then the badge should show 1 When I go to the home page - And I follow "bla" + And I follow the tag "bla" Then the badge should show 2 diff --git a/features/notes_manage.feature b/features/notes_manage.feature index f3a25c4b..6c16826e 100644 --- a/features/notes_manage.feature +++ b/features/notes_manage.feature @@ -35,14 +35,14 @@ Feature: View, add, remove notes And I delete the first note Then the badge should show 1 - @javascript + @javascript Scenario: Edit a note Given I have a project "Pass Final Exam" with 2 notes When I go to the notes page And I edit the first note to "edited note" Then I should see "edited note" - @javascript + @javascript Scenario: Toggle all notes Given I have a context called "@pc" And I have a project "take notes" that has the following todos diff --git a/features/project_list.feature b/features/project_list.feature index 572bec84..0a47468b 100644 --- a/features/project_list.feature +++ b/features/project_list.feature @@ -105,7 +105,7 @@ Feature: Manage the list of projects And I have a project "very busy" with 10 todos When I go to the projects page Then the project "test" should be above the project "very busy" - When I sort the list by number of tasks + When I sort the active list by number of tasks Then the project "very busy" should be above the project "test" @javascript diff --git a/features/step_definitions/context_list_steps.rb b/features/step_definitions/context_list_steps.rb index 71ea6cb8..bec6d301 100644 --- a/features/step_definitions/context_list_steps.rb +++ b/features/step_definitions/context_list_steps.rb @@ -14,9 +14,11 @@ end When /^I edit the context to rename it to "([^\"]*)"$/ do |new_name| find("a#link_edit_context_#{@context.id}").click page.should have_css("button#submit_context_#{@context.id}", :visible=>true) - - fill_in "context_name", :with => new_name - click_button "submit_context_#{@context.id}" + + within "div.edit-form" do + fill_in "context_name", :with => new_name + click_button "submit_context_#{@context.id}" + end # wait for the form to go away page.should have_css("a#link_edit_context_#{@context.id}", :visible=> true) diff --git a/features/step_definitions/mobile_tagging_todos_steps.rb b/features/step_definitions/mobile_tagging_todos_steps.rb new file mode 100644 index 00000000..4c8557af --- /dev/null +++ b/features/step_definitions/mobile_tagging_todos_steps.rb @@ -0,0 +1,4 @@ +When /^I follow the tag "(.*?)"$/ do |tag_name| + # there could be more than one tag on the page, so use the first + all(:xpath, "//span[@class='tag #{tag_name}']/a")[0].click +end \ No newline at end of file diff --git a/features/step_definitions/note_steps.rb b/features/step_definitions/note_steps.rb index e1dd1211..3b4f72ad 100644 --- a/features/step_definitions/note_steps.rb +++ b/features/step_definitions/note_steps.rb @@ -4,7 +4,7 @@ When /^I add note "([^\"]*)" from the "([^\"]*)" project page$/ do |note, projec end When /^I delete the first note$/ do - title = page.find("div.container h2").text + title = page.all("div.container h2").first.text id = title.split(' ').last handle_js_confirm do @@ -20,12 +20,14 @@ When /^I click the icon next to the note$/ do end When /^I edit the first note to "([^"]*)"$/ do |note_body| - title = page.find("div.container h2").text + title = page.all("div.container h2").first.text id = title.split(' ').last click_link "link_edit_note_#{id}" - fill_in "note[body]", :with => note_body - click_button "submit_note_#{id}" + within "form#edit_form_note_#{id}" do + fill_in "note[body]", :with => note_body + click_button "submit_note_#{id}" + end end When /^I toggle the note of "([^"]*)"$/ do |todo_description| @@ -79,5 +81,5 @@ Then /^I should not see the note "([^"]*)"$/ do |note_content| end Then /^I should see the note "([^"]*)"$/ do |note_content| - page.find("div", :text => note_content).should be_visible + page.all("div", :text => note_content).first.should be_visible end \ No newline at end of file diff --git a/features/step_definitions/project_list_steps.rb b/features/step_definitions/project_list_steps.rb index be724953..27391ad0 100644 --- a/features/step_definitions/project_list_steps.rb +++ b/features/step_definitions/project_list_steps.rb @@ -35,15 +35,19 @@ end When /^I sort the active list alphabetically$/ do handle_js_confirm do - click_link "Alphabetically" + within "div#list-active-projects-container" do + click_link "Alphabetically" + end 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 +When /^I sort the active list by number of tasks$/ do handle_js_confirm do - click_link "By number of tasks" + within "div#list-active-projects-container" do + click_link "By number of tasks" + end 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." diff --git a/features/step_definitions/todo_edit_steps.rb b/features/step_definitions/todo_edit_steps.rb index 089b5ea3..04116b94 100644 --- a/features/step_definitions/todo_edit_steps.rb +++ b/features/step_definitions/todo_edit_steps.rb @@ -97,7 +97,9 @@ When /^I try to edit the description of "([^"]*)" to "([^"]*)"$/ do |action_desc todo.should_not be_nil open_edit_form_for(todo) - fill_in "todo_description", :with => new_description + within "form.edit_todo_form" do + fill_in "todo_description", :with => new_description + end submit_button_xpath = "//div[@id='edit_todo_#{todo.id}']//button[@id='submit_todo_#{todo.id}']" page.find(:xpath, submit_button_xpath).click wait_for_ajax diff --git a/features/support/world.rb b/features/support/world.rb index 60955bc0..cfb129b8 100644 --- a/features/support/world.rb +++ b/features/support/world.rb @@ -22,16 +22,15 @@ module TracksStepHelper end def open_edit_form_for(todo) - within "div#line_todo_#{todo.id}" do - find("a#icon_edit_todo_#{todo.id}").click - end + # on calendar page there can be more than 1 occurance of a todo, so we select the first here + all(:css, "div#line_todo_#{todo.id} a#icon_edit_todo_#{todo.id}")[0].click wait_for_ajax wait_for_animations_to_end end - def submit_form(form_css, button_name) + def submit_form(form_xpath, button_name) handle_js_confirm do - within(form_css) do + within(:xpath, form_xpath) do click_button(button_name) end wait_for_ajax @@ -40,23 +39,23 @@ module TracksStepHelper end def submit_multiple_next_action_form - submit_form("form#todo-form-multi-new-action", "todo_multi_new_action_submit") + submit_form("//form[@id='todo-form-multi-new-action']", "todo_multi_new_action_submit") end def submit_next_action_form - submit_form("#todo-form-new-action", "todo_new_action_submit") + submit_form("//form[@id='todo-form-new-action']", "todo_new_action_submit") end def submit_new_context_form - submit_form("form#context-form", "context_new_submit") + submit_form("//form[@id='context-form']", "context_new_submit") end def submit_new_project_form - submit_form("form#project_form", "project_new_project_submit") + submit_form("//form[@id='project_form']", "project_new_project_submit") end def submit_edit_todo_form (todo) - submit_form("div#edit_todo_#{todo.id}", "submit_todo_#{todo.id}") + submit_form("//div[@id='edit_todo_#{todo.id}']", "submit_todo_#{todo.id}") wait_for_todo_form_to_go_away(todo) end @@ -81,7 +80,9 @@ module TracksStepHelper def edit_project(project) open_project_edit_form(project) - yield + within "form#edit_form_project_#{project.id}" do + yield + end submit_project_edit_form(project) wait_for_ajax diff --git a/lib/tracks/done_todos.rb b/lib/tracks/done_todos.rb index 7d4572b0..c1692b6b 100644 --- a/lib/tracks/done_todos.rb +++ b/lib/tracks/done_todos.rb @@ -10,10 +10,16 @@ class DoneTodos end def self.done_this_week(todos, includes = {:include => Todo::DEFAULT_INCLUDES}) - todos.completed_before(Time.zone.now.beginning_of_day).completed_after(Time.zone.now.beginning_of_week).all(includes) + done_between(todos, Time.zone.now.beginning_of_day, Time.zone.now.beginning_of_week) end def self.done_this_month(todos, includes = {:include => Todo::DEFAULT_INCLUDES}) - todos.completed_before(Time.zone.now.beginning_of_week).completed_after(Time.zone.now.beginning_of_month).all(includes) + done_between(todos, includes, Time.zone.now.beginning_of_week, Time.zone.now.beginning_of_month) + end + + private + + def self.done_between(todos, includes, start_date, end_date) + todos.completed_before(start_date).completed_after(end_date).all(includes) end end