From bed46847b3ad085dab58e3c947a5243dbf9068a9 Mon Sep 17 00:00:00 2001 From: Reinier Balt Date: Fri, 16 Sep 2011 12:38:35 +0200 Subject: [PATCH] make todos editable on the search page. Fix #716. --- app/helpers/todos_helper.rb | 2 + app/views/todos/toggle_check.js.erb | 31 ++++--- app/views/todos/update.js.erb | 9 ++- features/search.feature | 81 +++++++++++++++++++ features/step_definitions/search_steps.rb | 4 + .../step_definitions/todo_create_steps.rb | 6 ++ features/step_definitions/todo_steps.rb | 37 ++++++++- 7 files changed, 153 insertions(+), 17 deletions(-) create mode 100644 features/search.feature create mode 100644 features/step_definitions/search_steps.rb diff --git a/app/helpers/todos_helper.rb b/app/helpers/todos_helper.rb index 4f8b6cc8..f1873b34 100644 --- a/app/helpers/todos_helper.rb +++ b/app/helpers/todos_helper.rb @@ -308,6 +308,7 @@ module TodosHelper page.stats { return @todo.completed? } page.tag { return (@context_changed && !@todo.hidden?) || @tag_was_removed || @todo_hidden_state_changed || @todo_deferred_state_changed } page.todo { return @context_changed || @todo.hidden? || @todo.deferred? || @todo.pending?} + page.search { return false } end return false end @@ -321,6 +322,7 @@ module TodosHelper page.stats { return !@todo.completed? } page.tag { return !update_needs_to_remove_todo_from_container && !@tag_was_removed } page.todo { return !update_needs_to_remove_todo_from_container } + page.search { return true } end return false end diff --git a/app/views/todos/toggle_check.js.erb b/app/views/todos/toggle_check.js.erb index ed94e030..14bb168d 100644 --- a/app/views/todos/toggle_check.js.erb +++ b/app/views/todos/toggle_check.js.erb @@ -5,18 +5,22 @@ redirect_after_complete(); <% else animation = [] - animation << "remove_todo" - if @todo.completed? - animation << "add_to_completed_container" unless source_view_is_one_of(:calendar, :deferred) - animation << "add_new_recurring_todo" - animation << "activate_pending_todos" - animation << "remove_source_container" + unless source_view_is(:search) + animation << "remove_todo" + if @todo.completed? + animation << "add_to_completed_container" unless source_view_is_one_of(:calendar, :deferred) + animation << "add_new_recurring_todo" + animation << "activate_pending_todos" + animation << "remove_source_container" + else + animation << "add_todo_to_context" unless source_view_is(:done) + animation << "block_predecessors" + end + animation << "update_empty_container" if source_view_is_one_of(:tag, :todo) + animation << "regenerate_predecessor_family" else - animation << "add_todo_to_context" unless source_view_is(:done) - animation << "block_predecessors" - end - animation << "update_empty_container" if source_view_is_one_of(:tag, :todo) - animation << "regenerate_predecessor_family" -%> + animation << "replace_todo" + end -%> <%= render_animation(animation) %> TracksPages.set_page_badge(<%= @down_count %>); <% end -%> @@ -55,6 +59,11 @@ function add_to_completed_container(next_steps) { <% end -%> } +function replace_todo(next_steps) { + $('#<%= dom_id(@todo) %>').html(html_for_todo()); + next_steps.go(); +} + function add_todo_to_context(next_steps) { $('#<%= item_container_id(@todo) %>').append(html_for_todo()); <% if should_make_context_visible -%> diff --git a/app/views/todos/update.js.erb b/app/views/todos/update.js.erb index 62c3cc6a..d732662e 100644 --- a/app/views/todos/update.js.erb +++ b/app/views/todos/update.js.erb @@ -27,8 +27,8 @@ function remove_todo(next_steps) { $('#<%= dom_id(@todo) %>').fadeOut(400, function() { $('#<%= dom_id(@todo) %>').remove(); - <% if source_view_is :calendar - # in calendar view it is possible to have a todo twice on the page + <% if source_view_is :calendar + # in calendar view it is possible to have a todo twice on the page -%> $('#<%= dom_id(@todo) %>').remove(); <% end %> @@ -46,7 +46,7 @@ function add_to_existing_container(next_steps) { <% end -%> <% else -%> <% unless (@todo_hidden_state_changed && @todo.hidden?) || @todo_was_deferred_from_active_state -%> - $('#c<%= @todo.context_id %>').fadeIn(500, function() { + $('#c<%= @todo.context_id %>').fadeIn(500, function() { next_steps.go(); <% if @target_context_count==1 -%> $("#<%= empty_container_msg_div_id %>").slideUp(100); @@ -110,7 +110,7 @@ function html_for_error_messages() { return "<%= escape_javascript(error_messages_for('todo')) %>"; } -function update_predecessors() { +function update_predecessors(next_steps) { <% @todo.uncompleted_predecessors.each do |p| -%> if ($('#<%=item_container_id(p)%>')) { $('#<%=dom_id(p)%>').html('<%=escape_javascript(render(:partial => p, :locals => { :parent_container_type => parent_container_type }))%>'); @@ -123,4 +123,5 @@ function update_predecessors() { } <% end -%> <% end -%> + next_steps.go(); } \ No newline at end of file diff --git a/features/search.feature b/features/search.feature new file mode 100644 index 00000000..7609feb3 --- /dev/null +++ b/features/search.feature @@ -0,0 +1,81 @@ +Feature: Show all due actions in a calendar view + As a Tracks user + In order to keep overview of my due todos + I want to manage due todos in a calendar view + + Background: + Given the following user record + | login | password | is_admin | + | testuser | secret | false | + And I have logged in as "testuser" with password "secret" + + Scenario: I can search for todos by partial description + Given I have the following todos: + | description | context | + | tester of stuff | @home | + | testing search | @work | + | unrelated stuff | @home | + When I go to the search page + And I search for "test" + Then I should see "tester" + And I should see "testing search" + When I go to the search page + And I search for "stuff" + Then I should see "tester of stuff" + And I should see "unrelated stuff" + + @selenium + Scenario: I can edit found todos + Given I have the following todos: + | description | context | + | tester of stuff | @home | + | testing search | @work | + When I go to the search page + And I search for "test" + Then I should see "tester of stuff" + When I star the action "tester of stuff" + Then I should see a starred "tester of stuff" + When I edit the description of "tester of stuff" to "test 1-2-3" + Then I should not see "tester of stuff" + And I should see "test 1-2-3" + When I go to the search page + And I search for "test" + Then I should not see "tester of stuff" + And I should see "test 1-2-3" + + @selenium + Scenario: I can delete found todos + Given I have the following todos: + | description | context | + | tester of stuff | @home | + | testing search | @work | + When I go to the search page + And I search for "test" + Then I should see "tester of stuff" + When I delete the action "tester of stuff" + Then I should not see "tester of stuff" + When I go to the search page + And I search for "test" + Then I should not see "tester of stuff" + + @selenium @wip + Scenario: I can mark found todos complete and uncomplete + Given I have the following todos: + | description | context | + | tester of stuff | @home | + | testing search | @work | + When I go to the search page + And I search for "test" + Then I should see an active todo "tester of stuff" + When I mark "tester of stuff" as complete + Then I should see a completed todo "tester of stuff" + # the completed todo should show up on the next search too + When I go to the search page + And I search for "test" + Then I should see a completed todo "tester of stuff" + When I mark "tester of stuff" as uncompleted + Then I should see an active todo "tester of stuff" + # the active todo should show up on the next search too + When I go to the search page + And I search for "test" + Then I should see an active todo "tester of stuff" diff --git a/features/step_definitions/search_steps.rb b/features/step_definitions/search_steps.rb new file mode 100644 index 00000000..1c7327f8 --- /dev/null +++ b/features/step_definitions/search_steps.rb @@ -0,0 +1,4 @@ +When /^I search for "([^"]*)"$/ do |search_arg| + fill_in "search", :with => search_arg + click_button "Search" +end \ No newline at end of file diff --git a/features/step_definitions/todo_create_steps.rb b/features/step_definitions/todo_create_steps.rb index 5025f523..69b3cc88 100644 --- a/features/step_definitions/todo_create_steps.rb +++ b/features/step_definitions/todo_create_steps.rb @@ -40,6 +40,12 @@ Given /^I have a todo "([^"]*)"$/ do |description| Given "I have a todo \"#{description}\" in the context \"Context A\"" end +Given /^I have the following todos:$/ do |table| + table.hashes.each do | todo | + Given "I have a todo \"#{todo[:description]}\" in the context \"#{todo[:context]}\"" + end +end + Given /^I have a todo "([^"]*)" with notes "([^"]*)"$/ do |description, notes| Given "I have a todo \"#{description}\" in the context \"Context A\"" @todo.notes = notes diff --git a/features/step_definitions/todo_steps.rb b/features/step_definitions/todo_steps.rb index dfca38f2..5ddda5b8 100644 --- a/features/step_definitions/todo_steps.rb +++ b/features/step_definitions/todo_steps.rb @@ -71,13 +71,46 @@ Then /^I should see the todo "([^\"]*)"$/ do |todo_description| end Then /^I should not see the todo "([^\"]*)"$/ do |todo_description| - if selenium.is_element_present("//span[.=\"#{todo_description}\"]") + xpath = "//span[.=\"#{todo_description}\"]" + if selenium.is_element_present(xpath) wait_for :timeout => 5 do - !selenium.is_element_present("//span[.=\"#{todo_description}\"]") + !selenium.is_element_present(xpath) end end end +Then /^I should see a completed todo "([^"]*)"$/ do |todo_description| + todo = @current_user.todos.find_by_description(todo_description) + todo.should_not be_nil + + # only completed todos have a grey span with the completed_at date + xpath = "//div[@id='line_todo_#{todo.id}']/div/span[@class='grey']" + + unless selenium.is_element_present(xpath) + wait_for :timeout => 5 do + selenium.is_element_present(xpath) + end + end + selenium.is_visible(xpath).should be_true + +end + +Then /^I should see an active todo "([^"]*)"$/ do |todo_description| + todo = @current_user.todos.find_by_description(todo_description) + todo.should_not be_nil + + # only active todos have a grip div + + xpath = "//div[@id='line_todo_#{todo.id}']/img[@class='grip']" + + unless selenium.is_element_present(xpath) + wait_for :timeout => 5 do + selenium.is_element_present(xpath) + end + end + selenium.is_visible(xpath).should be_true +end + Then /^the number of actions should be (\d+)$/ do |count| @current_user.todos.count.should == count.to_i end