From 5496b846422f4acc2bef36b6ce6de54a670561e2 Mon Sep 17 00:00:00 2001 From: Reinier Balt Date: Fri, 17 Jun 2011 20:17:01 +0200 Subject: [PATCH] add cucumber scenarios for the new done pages --- app/controllers/contexts_controller.rb | 2 + app/controllers/projects_controller.rb | 6 +- app/controllers/stats_controller.rb | 6 +- config/locales/en.yml | 1 + features/step_definitions/container_steps.rb | 1 - features/step_definitions/todo_steps.rb | 40 +++++++++++- features/support/paths.rb | 12 ++++ features/view_done.feature | 66 ++++++++++++++++++-- 8 files changed, 123 insertions(+), 11 deletions(-) diff --git a/app/controllers/contexts_controller.rb b/app/controllers/contexts_controller.rb index 38c464e8..cf46a942 100644 --- a/app/controllers/contexts_controller.rb +++ b/app/controllers/contexts_controller.rb @@ -19,6 +19,8 @@ class ContextsController < ApplicationController @all_contexts = @active_contexts + @hidden_contexts @count = @all_contexts.size + init_not_done_counts(['context']) + respond_to do |format| format.html &render_contexts_html format.m &render_contexts_mobile diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 0224e335..ab41ef70 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -14,8 +14,10 @@ class ProjectsController < ApplicationController projects_and_actions else @contexts = current_user.contexts.all + init_not_done_counts(['project']) + init_project_hidden_todo_counts(['project']) if params[:only_active_with_no_next_actions] - @projects = current_user.projects.active.select { |p| p.todos.count == 0 } + @projects = current_user.projects.active.select { |p| count_undone_todos(p) == 0 } else @projects = current_user.projects.all end @@ -207,12 +209,14 @@ class ProjectsController < ApplicationController @state = params['state'] @projects = current_user.projects.alphabetize(:state => @state) if @state @contexts = current_user.contexts + init_not_done_counts(['project']) end def actionize @state = params['state'] @projects = current_user.projects.actionize(:state => @state) if @state @contexts = current_user.contexts + init_not_done_counts(['project']) end def done_todos diff --git a/app/controllers/stats_controller.rb b/app/controllers/stats_controller.rb index 25e125e0..fac58ec2 100644 --- a/app/controllers/stats_controller.rb +++ b/app/controllers/stats_controller.rb @@ -646,10 +646,12 @@ class StatsController < ApplicationController def done @source_view = 'done' - @done_recently = current_user.todos.completed.all(:limit => 10, :order => 'completed_at DESC', :include => [:project, :context, :tags, :taggings]) + init_not_done_counts + + @done_recently = current_user.todos.completed.all(:limit => 10, :order => 'completed_at DESC', :include => Todo::DEFAULT_INCLUDES) @last_completed_projects = current_user.projects.completed.all(:limit => 10, :order => 'completed_at DESC', :include => [:todos, :notes]) @last_completed_contexts = [] - @last_completed_recurring_todos = current_user.recurring_todos.completed.all(:limit => 10, :order => 'completed_at DESC') + @last_completed_recurring_todos = current_user.recurring_todos.completed.all(:limit => 10, :order => 'completed_at DESC', :include => [:tags, :taggings]) #TODO: @last_completed_contexts = current_user.contexts.completed.all(:limit => 10, :order => 'completed_at DESC') end diff --git a/config/locales/en.yml b/config/locales/en.yml index e978fa13..b83c08c6 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -108,6 +108,7 @@ en: months: months week: week weeks: weeks + recurring_todos: Repeating Actions errors: user_unauthorized: "401 Unauthorized: Only administrative users are allowed access to this function." footer: diff --git a/features/step_definitions/container_steps.rb b/features/step_definitions/container_steps.rb index ab70189d..a740c08a 100644 --- a/features/step_definitions/container_steps.rb +++ b/features/step_definitions/container_steps.rb @@ -60,7 +60,6 @@ Then /^I should not see "([^"]*)" in the context container for "([^"]*)"$/ do |t end end - Then /^I should see "([^"]*)" in project container for "([^"]*)"$/ do |todo_description, project_name| todo = @current_user.todos.find_by_description(todo_description) todo.should_not be_nil diff --git a/features/step_definitions/todo_steps.rb b/features/step_definitions/todo_steps.rb index f6123faa..c1634d5b 100644 --- a/features/step_definitions/todo_steps.rb +++ b/features/step_definitions/todo_steps.rb @@ -44,16 +44,35 @@ Given /^I have a deferred todo "([^"]*)" in the context "([^"]*)"$/ do |descript todo.save! end -Given /^I have ([0-9]+) completed todos$/ do |count| - context = @current_user.contexts.create!(:name => "context C") +Given /^I have ([0-9]+) completed todos in project "([^"]*)" in context "([^"]*)"$/ do |count, project_name, context_name| + context = @current_user.contexts.find_by_name(context_name) + context.should_not be_nil + + project = @current_user.projects.find_by_name(project_name) + project.should_not be_nil + + count.to_i.downto 1 do |i| + todo = @current_user.todos.create!(:context_id => context.id, :description => "todo #{i}", :project_id => project.id) + todo.complete! + end +end + +Given /^I have ([0-9]+) completed todos in context "([^"]*)"$/ do |count, context_name| + context = @current_user.contexts.find_by_name(context_name) + context.should_not be_nil + count.to_i.downto 1 do |i| todo = @current_user.todos.create!(:context_id => context.id, :description => "todo #{i}") todo.complete! end end +Given /^I have ([0-9]+) completed todos$/ do |count| + Given "I have #{count} completed todos in the context \"context D\"" +end + Given /^I have ([0-9]+) completed todos with a note$/ do |count| - context = @current_user.contexts.create!(:name => "context D") + context = @current_user.contexts.find_or_create(:name => "context D") count.to_i.downto 1 do |i| todo = @current_user.todos.create!(:context_id => context.id, :description => "todo #{i}", :notes => "note #{i}") todo.complete! @@ -275,3 +294,18 @@ Then /^the selected context should be "([^"]*)"$/ do |content| # Works for mobile. TODO: make it work for both mobile and non-mobile field_labeled("Context").element.search(".//option[@selected = 'selected']").inner_html.should =~ /#{content}/ end + + +Then /^I should see the page selector$/ do + page_selector_xpath = ".//a[@class='next_page']" + response.body.should have_xpath(page_selector_xpath) +end + +Then /^the page should be "([^"]*)"$/ do |page_number| + page_number_found = -1 + page_number_xpath = ".//span[@class='current']" + response.should have_xpath(page_number_xpath) do |node| + page_number_found = node.first.content.to_i + end + page_number_found.should == page_number.to_i +end diff --git a/features/support/paths.rb b/features/support/paths.rb index 8729ddc8..3eaea682 100644 --- a/features/support/paths.rb +++ b/features/support/paths.rb @@ -13,6 +13,18 @@ module NavigationHelpers when /the home\s?page/ @source_view = "todos" root_path(options) + when /the done page/ + done_overview_path(options) + when /the done actions page for context "([^"]*)"/i + context = @current_user.contexts.find_by_name($1) + done_todos_context_path(context) + when /the done actions page for project "([^"]*)"/i + project = @current_user.projects.find_by_name($1) + done_todos_project_path(project) + when /the done actions page/ + done_todos_path(options) + when /the all done actions page/ + all_done_todos_path(options) when /the statistics page/ @source_view = "stats" stats_path(options) diff --git a/features/view_done.feature b/features/view_done.feature index 248d106f..f34c0863 100644 --- a/features/view_done.feature +++ b/features/view_done.feature @@ -7,9 +7,67 @@ Feature: Show done Given the following user record | login | password | is_admin | | testuser | secret | false | - - Scenario: Visit done page - Given I have logged in as "testuser" with password "secret" + And I have logged in as "testuser" with password "secret" And I have 1 completed todos with a note + + Scenario: Visit done overview page When I go to the done page - Then I should see "Completed in the last 24 hours" + Then I should see "Last Completed Actions" + And I should see "Last Completed Projects" + And I should see "Last Completed Repeating Actions" + + Scenario: Home page links to show all completed todos + When I go to the home page + Then I should see "Completed actions" + And I should see "Show all" + When I follow "Show all" + Then I should be on the done actions page + + Scenario Outline: I can see all todos completed in the last timeperiod + Given I have a context called "@pc" + And I have a project called "test" + And I have 1 completed todos in project "test" in context "@pc" + When I go to the + Then I should see "todo 1" + And I should see "Completed today" + And I should see "Completed in the rest of this week" + And I should see "Completed in the rest of this month" + + Scenarios: + | page | + | done actions page | + | done actions page for context "@pc" | + | done actions page for project "test" | + + Scenario: I can see all todos completed + When I go to the done actions page + And I should see "You can see all completed actions here" + When I follow "here" + Then I should be on the all done actions page + + Scenario: I can browse all todos completed by page + Given I have 50 completed todos with a note + When I go to the all done actions page + Then I should see the page selector + When I follow "2" + Then I should be on the all done actions page + And the page should be "2" + + Scenario: The context page for a context shows a link to all completed actions + Given I have a context called "@pc" + And I have 1 completed todos in context "@pc" + When I go to the context page for "@pc" + Then I should see "Completed actions" + And I should see "Show all" + When I follow "Show all" + Then I should be on the done actions page for context "@pc" + + Scenario: The project page for a project shows a link to all completed actions + Given I have a context called "@pc" + And I have a project called "test" + And I have 1 completed todos in project "test" in context "@pc" + When I go to the "test" project + Then I should see "Completed actions" + And I should see "Show all" + When I follow "Show all" + Then I should be on the done actions page for project "test"