From ab2e51a51a02f6e4fbcf13711ac8eab88fec67e4 Mon Sep 17 00:00:00 2001 From: Reinier Balt Date: Sat, 8 Jan 2011 09:12:37 +0100 Subject: [PATCH] get selenium scenarios running again and add some scenarios for adding todos started --- app/controllers/todos_controller.rb | 28 +++++---- app/helpers/todos_helper.rb | 11 +++- app/models/todo.rb | 2 +- app/views/todos/create.js.erb | 15 +---- app/views/todos/destroy.js.erb | 4 ++ config/environments/cucumber.rb | 3 +- features/context_edit.feature | 10 ++-- features/dependencies.feature | 2 +- features/edit_a_todo.feature | 4 +- features/project_edit.feature | 10 ++-- features/shared_add_new_todo.feature | 17 +++++- features/show_statistics.feature | 4 +- features/step_definitions/todo_steps.rb | 60 +++++++++++++++++-- features/support/world.rb | 7 +++ features/tickler.feature | 13 +++- ...create_deferred_todo_with_new_context.rsel | 10 ---- test/selenium/tickler/see_all_deferred.rsel | 4 -- 17 files changed, 135 insertions(+), 69 deletions(-) delete mode 100644 test/selenium/tickler/create_deferred_todo_with_new_context.rsel delete mode 100644 test/selenium/tickler/see_all_deferred.rsel diff --git a/app/controllers/todos_controller.rb b/app/controllers/todos_controller.rb index 6a06600b..4aae18f4 100644 --- a/app/controllers/todos_controller.rb +++ b/app/controllers/todos_controller.rb @@ -116,18 +116,20 @@ class TodosController < ApplicationController end end format.js do - determine_down_count if @saved - @contexts = current_user.contexts.find(:all) if @new_context_created - @projects = current_user.projects.find(:all) if @new_project_created - @initial_context_name = params['default_context_name'] - @initial_project_name = params['default_project_name'] - @default_tags = @todo.project.default_tags unless @todo.project.nil? - @status_message = 'Added new next action' - @status_message += ' to tickler' if @todo.deferred? - @status_message += ' in pending state' if @todo.pending? - @status_message += ' in hidden state' if @todo.hidden? - @status_message = 'Added new project / ' + status_message if @new_project_created - @status_message = 'Added new context / ' + status_message if @new_context_created + if @saved + determine_down_count + @contexts = current_user.contexts.find(:all) if @new_context_created + @projects = current_user.projects.find(:all) if @new_project_created + @initial_context_name = params['default_context_name'] + @initial_project_name = params['default_project_name'] + @default_tags = @todo.project.default_tags unless @todo.project.nil? + @status_message = 'Added new next action' + @status_message += ' to tickler' if @todo.deferred? + @status_message += ' in pending state' if @todo.pending? + @status_message += ' in hidden state' if @todo.hidden? + @status_message = 'Added new project / ' + @status_message if @new_project_created + @status_message = 'Added new context / ' + @status_message if @new_context_created + end render :action => 'create' end format.xml do @@ -830,7 +832,7 @@ class TodosController < ApplicationController def determine_down_count source_view do |from| from.todo do - @down_count = current_user.todos.active.not_hidden.count(:all) + @down_count = current_user.todos.active.not_hidden.count end from.context do @down_count = current_user.contexts.find(@todo.context_id).todos.not_completed.count(:all) diff --git a/app/helpers/todos_helper.rb b/app/helpers/todos_helper.rb index 58cfbdff..86abd944 100644 --- a/app/helpers/todos_helper.rb +++ b/app/helpers/todos_helper.rb @@ -208,7 +208,11 @@ module TodosHelper return false if source_view_is(:todo) && @todo.hidden? return false if source_view_is(:context) && @todo.hidden? && !@todo.context.hidden? - return false if (source_view_is(:tag) && !@todo.tags.include?(@tag_name)) + return true if source_view_is(:tag) && ( + (@todo.pending? && @todo.tags.include?(@tag_name)) || + @todo.tags.include?(@tag_name) || + (@todo.starred? && @tag_name == Todo::STARRED_TAG_NAME)) + return false if (source_view_is(:context) && !(@todo.context_id==@default_context.id) ) return true if source_view_is(:deferred) && @todo.deferred? @@ -217,9 +221,12 @@ module TodosHelper return true if source_view_is(:project) && @todo.pending? return true if !source_view_is(:deferred) && @todo.active? - return true if source_view_is(:tag) && @todo.pending? return false end + + def should_add_new_context + return @new_context_created && !source_view_is(:project) + end def parent_container_type return 'tickler' if source_view_is :deferred diff --git a/app/models/todo.rb b/app/models/todo.rb index 383b063f..adc0a5de 100644 --- a/app/models/todo.rb +++ b/app/models/todo.rb @@ -32,7 +32,7 @@ class Todo < ActiveRecord::Base :conditions => ["todos.state = ? OR (contexts.hide = ? AND (todos.state = ? OR todos.state = ? OR todos.state = ?))", 'project_hidden', true, 'active', 'deferred', 'pending'] named_scope :not_hidden, - :joins => [:context, :project], + :joins => [:context], :conditions => ['NOT(todos.state = ? OR (contexts.hide = ? AND (todos.state = ? OR todos.state = ? OR todos.state = ?)))', 'project_hidden', true, 'active', 'deferred', 'pending'] diff --git a/app/views/todos/create.js.erb b/app/views/todos/create.js.erb index 0be68148..bb0de3d2 100644 --- a/app/views/todos/create.js.erb +++ b/app/views/todos/create.js.erb @@ -1,10 +1,9 @@ <% if @saved -%> TracksPages.page_notify('notice', "<%=@status_message%>", 5); - hide_empty_message(); TracksPages.hide_errors(); TracksPages.set_page_badge(<%= @down_count %>); <% if should_show_new_item -%> - <% if @new_context_created -%> + <% if should_add_new_context -%> insert_new_context_with_new_todo(); <% else -%> add_todo_to_existing_context(); @@ -16,15 +15,6 @@ TracksPages.show_errors(html_for_error_messages()); <% end -%> -function hide_empty_message() { - <% if @todo %> - $('#<%=empty_container_msg_div_id%>').hide(); - <% if (source_view_is :project and @todo.pending?) or (source_view_is :deferred) -%> - $('#tickler-empty-nd').hide(); - <% end -%> - <% end -%> -} - function clear_form() { $('#todo-form-new-action').clearForm(); TracksForm.set_context_name('<%=@initial_context_name%>'); @@ -34,14 +24,15 @@ function clear_form() { } function insert_new_context_with_new_todo() { + $('#no_todos_in_tag_view').slideUp(100); $('#display_box').prepend(html_for_new_context()); } function add_todo_to_existing_context() { <% if source_view_is_one_of(:todo, :deferred, :tag) -%> TodoItemsContainer.ensureVisibleWithEffectAppear("c<%=@todo.context_id%>"); - $('#<%=empty_container_msg_div_id%>').hide(); <% end -%> + $('#<%=empty_container_msg_div_id%>').hide(); $('#<%=item_container_id(@todo)%>').append(html_for_new_todo()); $('#<%= dom_id(@todo)%>').effect('highlight', {}, 2000 ); } diff --git a/app/views/todos/destroy.js.erb b/app/views/todos/destroy.js.erb index 2be9dd5d..b4948a35 100644 --- a/app/views/todos/destroy.js.erb +++ b/app/views/todos/destroy.js.erb @@ -21,6 +21,10 @@ function show_empty_messages() { <% if empty_container_msg_div_id && todo_container_is_empty -%> $('#<%=empty_container_msg_div_id%>').slideDown(1000); <% end -%> + + <% if source_view_is(:deferred) && @down_count==0 -%> + $('#tickler-empty-nd').slideDown(100); + <% end -%> } function remove_todo_from_page() { diff --git a/config/environments/cucumber.rb b/config/environments/cucumber.rb index 8517416d..38e54e4b 100644 --- a/config/environments/cucumber.rb +++ b/config/environments/cucumber.rb @@ -21,7 +21,8 @@ config.action_controller.allow_forgery_protection = false # ActionMailer::Base.deliveries array. config.action_mailer.delivery_method = :test -config.gem 'cucumber', :lib => false, :version => '=0.9.8' unless File.directory?(File.join(Rails.root, 'vendor/plugins/cucumber-rails')) +config.gem 'cucumber', :lib => false, :version => '<0.10.0' unless File.directory?(File.join(Rails.root, 'vendor/plugins/cucumber')) config.gem 'cucumber-rails', :lib => false, :version => '>=0.3.2' unless File.directory?(File.join(Rails.root, 'vendor/plugins/cucumber-rails')) +config.gem 'gherkin', :lib => false, :version => '2.2.9' unless File.directory?(File.join(Rails.root, 'vendor/plugins/gherkin')) config.gem 'database_cleaner', :lib => false, :version => '>=0.5.0' unless File.directory?(File.join(Rails.root, 'vendor/plugins/database_cleaner')) config.gem 'webrat', :lib => false, :version => '>=0.7.0' unless File.directory?(File.join(Rails.root, 'vendor/plugins/webrat')) \ No newline at end of file diff --git a/features/context_edit.feature b/features/context_edit.feature index f644596b..9f5abecc 100644 --- a/features/context_edit.feature +++ b/features/context_edit.feature @@ -20,16 +20,16 @@ Feature: Edit a context And he should see that a context named "OutAndAbout" is present Scenario: Editing the context of a todo will remove the todo - Given this scenario is pending + Given this is a pending scenario Scenario: Editing the description of a a todo will update that todo - Given this scenario is pending + Given this is a pending scenario Scenario: Editing the context of the last todo will remove the todo and show empty message - Given this scenario is pending + Given this is a pending scenario Scenario: Adding a todo to a hidden project will not show the todo - Given this scenario is pending + Given this is a pending scenario Scenario: Adding a todo to a hidden context will show that todo - Given this scenario is pending + Given this is a pending scenario diff --git a/features/dependencies.feature b/features/dependencies.feature index 6b5d2af0..78ce5696 100644 --- a/features/dependencies.feature +++ b/features/dependencies.feature @@ -37,4 +37,4 @@ Feature: dependencies Then there should not be an error Scenario: Deleting a predecessor will activate successors - Given this scenario is pending + Given this is a pending scenario diff --git a/features/edit_a_todo.feature b/features/edit_a_todo.feature index 40c29f41..43693ded 100644 --- a/features/edit_a_todo.feature +++ b/features/edit_a_todo.feature @@ -58,7 +58,7 @@ Feature: Edit a next action from every page Given this is a pending scenario Scenario: Editing the context of a todo to a new context will show new context - Given this scenario is pending # for home and tickler and tag + Given this is a pending scenario # for home and tickler and tag Scenario: Making an error when editing a todo will show error message - Given this scenario is pending \ No newline at end of file + Given this is a pending scenario diff --git a/features/project_edit.feature b/features/project_edit.feature index bd94e04d..86696224 100644 --- a/features/project_edit.feature +++ b/features/project_edit.feature @@ -83,19 +83,19 @@ Feature: Edit a project And I should see "12345678901234567890123456789012345678901234567890123456789012345678901234567890123456" Scenario: Cancelling editing a project will restore project settings - Given this scenario is pending + Given this is a pending scenario Scenario: Editing the description of a todo will update todo - Given this scenario is pending + Given this is a pending scenario Scenario: Moving the todo to the tickler will move todo to tickler container - Given this scenario is pending + Given this is a pending scenario Scenario: Moving the todo out of the tickler will move todo to active container - Given this scenario is pending + Given this is a pending scenario Scenario: Making all todos inactive will show empty message - Given this scenario is pending # empty message is in separate container + Given this is a pending scenario # empty message is in separate container # Ticket #1043 @selenium @wip diff --git a/features/shared_add_new_todo.feature b/features/shared_add_new_todo.feature index de7f9211..55dd87ad 100644 --- a/features/shared_add_new_todo.feature +++ b/features/shared_add_new_todo.feature @@ -125,8 +125,21 @@ Feature: Add new next action from every page Scenario: Adding a todo to a hidden project does not show the todo Given this is a pending scenario - Scenario: Adding a todo with a new context shows the new context - Given this is a pending scenario + @selenium @wip + Scenario Outline: Adding a todo with a new context shows the new context + When I the + And I submit a new with description "do at new context" and the tags "starred" in the context "New" + Then a confirmation for adding a new context "New" should be asked + And the container for the context "New" should + And the badge should show + + Scenarios: + | action | page | todo | badge | visible | + | go to | home page | action | 2 | be visible | + | go to | tickler page | deferred action | 1 | be visible | + | visit | project page for "test project" | action | 2 | not be visible | + | visit | context page for "test context" | action | 1 | not be visible | + | visit | tag page for "starred" | action | 1 | be visible | Scenario: Adding a todo to a hidden context does not show the todo Given this is a pending scenario diff --git a/features/show_statistics.feature b/features/show_statistics.feature index ae1eece2..023072c5 100644 --- a/features/show_statistics.feature +++ b/features/show_statistics.feature @@ -64,7 +64,7 @@ Feature: Show statistics And I should see "to show the actions from week 0 and further" Scenario: I can edit the todos selected from a chart - Given this scenario is pending + Given this is a pending scenario Scenario: Marking a todo selected from a chart as complete will remove it from the page - Given this scenario is pending + Given this is a pending scenario diff --git a/features/step_definitions/todo_steps.rb b/features/step_definitions/todo_steps.rb index 1ab0fe91..724de73f 100644 --- a/features/step_definitions/todo_steps.rb +++ b/features/step_definitions/todo_steps.rb @@ -2,6 +2,11 @@ Given /^I have no todos$/ do Todo.delete_all end +Given /^I have a todo "(.*)"$/ do |description| + context = @current_user.contexts.create!(:name => "context A") + @current_user.todos.create!(:context_id => context.id, :description => description) +end + Given /^I have ([0-9]+) todos$/ do |count| context = @current_user.contexts.create!(:name => "context A") count.to_i.downto 1 do |i| @@ -16,6 +21,11 @@ Given /^I have ([0-9]+) deferred todos$/ do |count| end end +Given /^I have a deferred todo "(.*)"$/ do |description| + context = @current_user.contexts.create!(:name => "context B") + @current_user.todos.create!(:context_id => context.id, :description => description, :show_from => @current_user.time + 1.week) +end + Given /^I have ([0-9]+) completed todos$/ do |count| context = @current_user.contexts.create!(:name => "context C") count.to_i.downto 1 do |i| @@ -66,12 +76,6 @@ When /^I expand the dependencies of "([^\"]*)"$/ do |todo_name| selenium.click(expand_img_locator) end -Then /^I should see ([0-9]+) todos$/ do |count| - count.to_i.downto 1 do |i| - match_xpath "div[" - end -end - When /I change the (.*) field of "([^\"]*)" to "([^\"]*)"$/ do |field, todo_name, new_value| todo = @current_user.todos.find_by_description(todo_name) todo.should_not be_nil @@ -88,6 +92,24 @@ When /^I submit a new action with description "([^"]*)"$/ do |description| submit_next_action_form end +When /^I submit a new action with description "([^"]*)" and the tags "([^"]*)" in the context "([^"]*)"$/ do |description, tags, context_name| + fill_in "todo[description]", :with => description + fill_in "tag_list", :with => tags + + js="$('#todo_context_name').val('');" + selenium.get_eval "(function() {with(this) {#{js}}}).call(selenium.browserbot.getCurrentWindow());" + fill_in "todo_context_name", :with => context_name + submit_next_action_form +end + +When /^I submit a new deferred action with description "([^"]*)" and the tags "([^"]*)" in the context "([^"]*)"$/ do |description, tags, context_name| + fill_in "todo[description]", :with => description + fill_in "context_name", :with => context_name + fill_in "tag_list", :with => tags + fill_in "todo[show_from]", :with => format_date(@current_user.time + 1.week) + submit_next_action_form +end + When /^I submit multiple actions with using$/ do |multiple_actions| fill_in "todo[multiple_todos]", :with => multiple_actions submit_multiple_next_action_form @@ -120,6 +142,12 @@ When /^I edit the dependency of "([^"]*)" to '([^'']*)'$/ do |todo_name, deps| selenium.click("//div[@id='edit_todo_#{todo.id}']//button[@id='submit_todo_#{todo.id}']", :wait_for => :ajax, :javascript_framework => :jquery) end +Then /^I should see ([0-9]+) todos$/ do |count| + count.to_i.downto 1 do |i| + match_xpath "div[" + end +end + Then /^there should not be an error$/ do # form should be gone and thus not errors visible selenium.is_visible("edit_todo_#{@dep_todo.id}").should == false @@ -159,3 +187,23 @@ end Then /^the number of actions should be (\d+)$/ do |count| @current_user.todos.count.should == count.to_i end + +Then /^the container for the context "([^"]*)" should be visible$/ do |context_name| + context = @current_user.contexts.find_by_name(context_name) + context.should_not be_nil + xpath = "xpath=//div[@id=\"c#{context.id}\"]" + selenium.wait_for_element(xpath, :timeout_in_seconds => 5) + selenium.is_visible(xpath).should be_true +end + +Then /^the container for the context "([^"]*)" should not be visible$/ do |context_name| + context = @current_user.contexts.find_by_name(context_name) + context.should_not be_nil + xpath = "xpath=//div[@id=\"c#{context.id}\"]" + selenium.wait_for :wait_for => :ajax, :javascript_framework => :jquery + selenium.is_element_present(xpath).should be_false +end + +Then /^a confirmation for adding a new context "([^"]*)" should be asked$/ do |context_name| + selenium.get_confirmation.should == "New context \"#{context_name}\" will be also created. Are you sure?" +end diff --git a/features/support/world.rb b/features/support/world.rb index e630381a..9d5aa5f3 100644 --- a/features/support/world.rb +++ b/features/support/world.rb @@ -14,6 +14,13 @@ module TracksStepHelper def submit_new_project_form selenium.click("xpath=//form[@id='project_form']//button[@id='project_new_project_submit']", :wait_for => :ajax, :javascript_framework => :jquery) end + + def format_date(date) + # copy-and-past from ApplicationController::format_date + return date ? date.in_time_zone(@current_user.prefs.time_zone).strftime("#{@current_user.prefs.date_format}") : '' + end + + end World(TracksStepHelper) \ No newline at end of file diff --git a/features/tickler.feature b/features/tickler.feature index 02121f64..45c1b3c1 100644 --- a/features/tickler.feature +++ b/features/tickler.feature @@ -11,10 +11,17 @@ Feature: Manage deferred todos And I have logged in as "testuser" with password "secret" Scenario: Editing the description of a todo updated the todo - Given this scenario is pending + Given this is a pending scenario Scenario: Editing the context of a todo moves it to the new context - Given this scenario is pending + Given this is a pending scenario Scenario: Removing the show from date from a todo removes it from the tickler - Given this scenario is pending + Given this is a pending scenario + + Scenario: Opening the tickler page shows me all deferred todos + Given I have a deferred todo "not yet now" + And I have a todo "now is a good time" + When I go to the tickler page + Then I should see "not yet now" + And I should not see "now is a good time" diff --git a/test/selenium/tickler/create_deferred_todo_with_new_context.rsel b/test/selenium/tickler/create_deferred_todo_with_new_context.rsel deleted file mode 100644 index 37cac4f1..00000000 --- a/test/selenium/tickler/create_deferred_todo_with_new_context.rsel +++ /dev/null @@ -1,10 +0,0 @@ -setup :fixtures => :all -login :as => 'admin' -open "/tickler" -assert_context_count_incremented do - type "todo_description", "a new action" - type "todo_context_name", "Brand new context" - type "todo_show_from", "1/1/2030" - click "css=#todo-form-new-action .submit_box button" - assert_confirmation "New context \"Brand new context\" will be also created. Are you sure?" -end diff --git a/test/selenium/tickler/see_all_deferred.rsel b/test/selenium/tickler/see_all_deferred.rsel deleted file mode 100644 index f68939fa..00000000 --- a/test/selenium/tickler/see_all_deferred.rsel +++ /dev/null @@ -1,4 +0,0 @@ -setup :fixtures => :all -login :as => 'admin' -open "/tickler/" -assert_element_present "todo_15"