refactor done todos view and tests

This commit is contained in:
Reinier Balt 2013-03-18 12:24:42 +01:00
parent aac744e411
commit 85fc82d494
16 changed files with 141 additions and 116 deletions

View file

@ -158,8 +158,8 @@ class ContextsController < ApplicationController
@context = current_user.contexts.find(params[:id])
@page_title = t('contexts.completed_tasks_title', :context_name => @context.name)
@done_today, @done_this_week, @done_this_month = DoneTodos.done_todos_for_container(@context)
@count = @done_today.size + @done_this_week.size + @done_this_month.size
@done_today, @done_rest_of_week, @done_rest_of_month = DoneTodos.done_todos_for_container(@context)
@count = @done_today.size + @done_rest_of_week.size + @done_rest_of_month.size
render :template => 'todos/done'
end

View file

@ -307,8 +307,8 @@ class ProjectsController < ApplicationController
@project = current_user.projects.find(params[:id])
@page_title = t('projects.completed_tasks_title', :project_name => @project.name)
@done_today, @done_this_week, @done_this_month = DoneTodos.done_todos_for_container(@project)
@count = @done_today.size + @done_this_week.size + @done_this_month.size
@done_today, @done_rest_of_week, @done_rest_of_month = DoneTodos.done_todos_for_container(@project)
@count = @done_today.size + @done_rest_of_week.size + @done_rest_of_month.size
render :template => 'todos/done'
end

View file

@ -329,13 +329,16 @@ class TodosController < ApplicationController
def toggle_check
@todo = current_user.todos.find(params['id'])
@source_view = params['_source_view'] || 'todo'
@original_item_due = @todo.due
@original_item_was_deferred = @todo.deferred?
@original_item_was_pending = @todo.pending?
@original_item_was_hidden = @todo.hidden?
@original_item_context_id = @todo.context_id
@original_item_project_id = @todo.project_id
@original_completed_period = DoneTodos.completed_period(@todo.completed_at)
@todo_was_completed_from_deferred_or_blocked_state = @original_item_was_deferred || @original_item_was_pending
@saved = @todo.toggle_completion!
@todo_was_blocked_from_completed_state = @todo.pending? # since we toggled_completion the previous state was completed
@ -556,8 +559,8 @@ class TodosController < ApplicationController
@source_view = 'done'
@page_title = t('todos.completed_tasks_title')
@done_today, @done_this_week, @done_this_month = DoneTodos.done_todos_for_container(current_user)
@count = @done_today.size + @done_this_week.size + @done_this_month.size
@done_today, @done_rest_of_week, @done_rest_of_month = DoneTodos.done_todos_for_container(current_user)
@count = @done_today.size + @done_rest_of_week.size + @done_rest_of_month.size
respond_to do |format|
format.html
@ -697,9 +700,9 @@ class TodosController < ApplicationController
completed_todos = current_user.todos.completed.with_tag(@tag.id)
@done_today = get_done_today(completed_todos)
@done_this_week = get_done_this_week(completed_todos)
@done_this_month = get_done_this_month(completed_todos)
@count = @done_today.size + @done_this_week.size + @done_this_month.size
@done_rest_of_week = get_done_rest_of_week(completed_todos)
@done_rest_of_month = get_done_rest_of_month(completed_todos)
@count = @done_today.size + @done_rest_of_week.size + @done_rest_of_month.size
render :template => 'todos/done'
end
@ -1009,9 +1012,8 @@ class TodosController < ApplicationController
}
from.tag {
tag = Tag.where(:name => params['_tag_name']).first
if tag.nil?
tag = Tag.new(:name => params['tag'])
end
tag = Tag.new(:name => params['tag']) if tag.nil?
@remaining_deferred_or_pending_count = current_user.todos.with_tag(tag.id).deferred_or_blocked.count
@remaining_in_context = current_user.contexts.find(context_id).todos.active.not_hidden.with_tag(tag.id).count
@target_context_count = current_user.contexts.find(@todo.context_id).todos.active.not_hidden.with_tag(tag.id).count
@ -1048,9 +1050,12 @@ class TodosController < ApplicationController
end
@target_context_count = actions_in_target.count
}
from.done {
@remaining_in_context = DoneTodos.remaining_in_container(current_user, @original_completed_period)
}
end
@remaining_in_context = current_user.contexts.find(context_id).todos(true).active.not_hidden.count if !@remaining_in_context
@target_context_count = current_user.contexts.find(@todo.context_id).todos(true).active.not_hidden.count if !@target_context_count
@remaining_in_context = current_user.contexts.find(context_id).todos(true).active.not_hidden.count if @remaining_in_context.nil?
@target_context_count = current_user.contexts.find(@todo.context_id).todos(true).active.not_hidden.count if !@target_context_count.nil?
end
def determine_completed_count
@ -1334,14 +1339,14 @@ class TodosController < ApplicationController
end
# all completed todos [begin_of_week, start_of_today]
def get_done_this_week(completed_todos, includes = {:include => Todo::DEFAULT_INCLUDES})
def get_done_rest_of_week(completed_todos, includes = {:include => Todo::DEFAULT_INCLUDES})
start_of_this_week = Time.zone.now.beginning_of_week
start_of_this_day = Time.zone.now.beginning_of_day
completed_todos.completed_before(start_of_this_day).completed_after(start_of_this_week).all(includes)
end
# all completed todos [begin_of_month, begin_of_week]
def get_done_this_month(completed_todos, includes = {:include => Todo::DEFAULT_INCLUDES})
def get_done_rest_of_month(completed_todos, includes = {:include => Todo::DEFAULT_INCLUDES})
start_of_this_month = Time.zone.now.beginning_of_month
start_of_this_week = Time.zone.now.beginning_of_week
completed_todos.completed_before(start_of_this_week).completed_after(start_of_this_month).all(includes)

View file

@ -44,6 +44,19 @@ module TodosHelper
:locals => {:settings => settings.reverse_merge!(default_collection_settings)}
end
def show_completed_todos_for(period, collection)
settings = {
:parent_container_type => "completed",
:container_name => "completed_#{period}",
:title => t("todos.completed_#{period}"),
:show_empty_containers => true
}
render :partial => "todos/collection",
:object => collection,
:locals => { :settings => settings}
end
def show_hidden_todos(hidden_todos, settings={})
settings[:container_name] = "hidden"
@ -410,7 +423,7 @@ module TodosHelper
(@remaining_in_context == 0 && @tag_was_removed) ||
(@remaining_in_context == 0 && @todo.completed? && !(@original_item_was_deferred || @original_item_was_hidden)) if source_view_is(:tag)
return false if source_view_is_one_of(:project, :calendar)
return false if source_view_is_one_of(:project, :calendar, :done)
return (@remaining_in_context == 0) && !source_view_is(:context)
end
@ -531,6 +544,7 @@ module TodosHelper
container_id = "completed_container-empty-d" if @completed_count && @completed_count == 0 && !@todo.completed?
}
page.todo { container_id = "c#{@original_item_context_id}-empty-d" if @remaining_in_context == 0 }
page.done { container_id = "completed_#{@original_completed_period}_container-empty-d" if @remaining_in_context == 0 }
end
return container_id.blank? ? "" : "$(\"##{container_id}\").slideDown(100);".html_safe
end

View file

@ -1,31 +1,13 @@
<div id="display_box_projects">
<div class="container">
<h2><%= t('todos.completed_today') %></h2>
<% if @done_today.empty? -%>
<div class="message"><p><%= t('todos.no_completed_actions') %></p></div>
<% else -%>
<%= render :partial => "todos/todo", :collection => @done_today, :locals => { :parent_container_type => "completed", :suppress_context => false, :suppress_project => false } %>
<% end -%>
</div>
<div class="container">
<h2><%= t('todos.completed_rest_of_week') %></h2>
<% if @done_this_week.empty? -%>
<div class="message"><p><%= t('todos.no_completed_actions') %></p></div>
<% else -%>
<%= render :partial => "todos/todo", :collection => @done_this_week, :locals => { :parent_container_type => "completed", :suppress_context => false, :suppress_project => false } %>
<% end -%>
</div>
<%= show_completed_todos_for("today", @done_today) %>
<%= show_completed_todos_for("rest_of_week", @done_rest_of_week) %>
<%= show_completed_todos_for("rest_of_month", @done_rest_of_month) %>
<div class="container">
<h2><%= t('todos.completed_rest_of_month') %></h2>
<% if @done_this_month.empty? -%>
<div class="message"><p><%= t('todos.no_completed_actions') %></p></div>
<% else -%>
<%= render :partial => "todos/todo", :collection => @done_this_month, :locals => { :parent_container_type => "completed", :suppress_context => false, :suppress_project => false } %>
<% end -%>
</div>
<p><%= raw t('todos.see_all_completed', :link => link_to(t("todos.all_completed_here"), determine_all_done_path)) %></p>
<p>
<%= raw t('todos.see_all_completed',
:link => link_to(t("todos.all_completed_here"), determine_all_done_path))
%>
</p>
</div>

View file

@ -431,6 +431,9 @@ en:
not_done: Currently there are no incomplete actions
project: Currently there are no incomplete actions in this project
context: Currently there are no incomplete actions in this context
completed_today: No actions were completed today
completed_rest_of_week: No actions were completed in the rest of this week
completed_rest_of_month: No actions were completed in the rest of this month
actions:
completed: Completed actions
home_completed: Completed actions
@ -443,6 +446,9 @@ en:
project_completed: Completed actions in this project
context_completed: Completed actions in this context
tag_hidden: "Hidden actions tagged with '%{param}'"
completed_today: Completed today
completed_rest_of_week: Completed in the rest of this week
completed_rest_of_month: Completed in the rest of this month
show_from: Show from
error_starring_recurring: "Could not toggle the star of recurring todo \'%{description}\'"
recurring_action_deleted: Action was deleted. Because this action is recurring, a new action was added
@ -556,10 +562,8 @@ en:
one: One tickler item is now due - refresh the page to see it.
other: "%{count} tickler items are now due - refresh the page to see them."
action_marked_complete: "The action <strong>'%{description}'</strong> was marked as <strong>%{completed}</strong>"
completed_today: Completed today
added_new_next_action_plural: Added new next actions
new_related_todo_not_created_short: did not create todo
completed_rest_of_week: Completed in the rest of this week
error_starring: "Could not toggle the star of this todo '%{description}'"
calendar:
get_in_ical_format: Get this calendar in iCal format
@ -647,7 +651,6 @@ en:
yearly: Yearly
added_dependency: Added %{dependency} as dependency.
all_completed_tagged_page_title: TRACKS::All completed tasks with tag %{tag_name}
completed_rest_of_month: Completed in the rest of this month
recurrence_completed: There is no next action after the recurring action you just finished. The recurrence is completed
error_toggle_complete: Could not mark this todo complete
in_pending_state: in pending state

View file

@ -122,20 +122,17 @@ end
####### Completed #######
Then /^I should see "([^"]*)" in the completed container$/ do |todo_description|
Then /^I should (not see|see) "([^"]*)" in the (completed|done today|done this week|done this month) container$/ do |visible, todo_description, container|
todo = @current_user.todos.where(:description => todo_description).first
todo.should_not be_nil
xpath = "//div[@id='completed_container']//div[@id='line_todo_#{todo.id}']"
page.should have_xpath(xpath)
end
id = 'completed_container' if container == 'completed'
id = 'completed_today_container' if container == 'done today'
id = 'completed_rest_of_week_container' if container == 'done this week'
id = 'completed_rest_of_month_container' if container == 'done this month'
Then /^I should not see "([^"]*)" in the completed container$/ do |todo_description|
todo = @current_user.todos.where(:description => todo_description).first
todo.should_not be_nil
xpath = "//div[@id='completed_container']//div[@id='line_todo_#{todo.id}']"
page.should_not have_xpath(xpath)
xpath = "//div[@id='#{id}']//div[@id='line_todo_#{todo.id}']"
page.send( visible=='see' ? :should : :should_not, have_xpath(xpath))
end
####### Hidden #######
@ -182,3 +179,21 @@ Then /^I should not see "([^"]*)" in the completed recurring todos container$/ d
step "I should not see \"#{repeat_pattern}\""
end
end
####### Empty message patterns #######
Then /^I should (see|not see) empty message for (done today|done this week|done this month|completed todos|deferred todos|todos) (of done actions|of context|of project|of home|of tag)/ do |visible, state, type|
css = "error: wrong state"
css = "div#c#{@context.id}-empty-d" if state == "todos" && type == "of context"
css = "div#p#{@project.id}-empty-d" if state == "todos" && type == "of project"
css = "div#no_todos_in_view" if state == "todos" && (type == "of home" || type == "of tag")
css = "div#completed_today_container" if state == "done today"
css = "div#completed_rest_of_week_container" if state == "done this week"
css = "div#completed_rest_of_month_container" if state == "done this month"
css = "div#completed_container-empty-d" if state == "completed todos"
css = "div#deferred_pending_container-empty-d" if state == "deferred todos"
elem = find(css)
elem.should_not be_nil
elem.send(visible=="see" ? :should : :should_not, be_visible)
end

View file

@ -71,12 +71,3 @@ Then /^he should see that a context named "([^\"]*)" (is|is not) present$/ do |c
page.should_not have_selector("div#context_#{context.id} div.context_description a", :visible => true) if context
end
end
Then /^I should (see|not see) empty message for (todo|completed todo|deferred todo)s of context/ do |visible, state|
css = "error"
css = "div#c#{@context.id}-empty-d" if state == "todo"
css = "div#completed_container-empty-d" if state == "completed todo"
css = "div#deferred_pending_container-empty-d" if state == "deferred todo"
page.send(visible=="see" ? :should : :should_not, have_css(css, :visible=>true))
end

View file

@ -10,6 +10,11 @@ Given /^I am working on the mobile interface$/ do
@mobile_interface = true
end
Given /^the date is "(.*?)"$/ do |date|
# remember to tag the scenario with @reset_time to reset this travel
Timecop.travel(date)
end
Then /the badge should show (.*)/ do |number|
badge = find("span#badge_count").text.to_i
badge.should == number.to_i

View file

@ -234,17 +234,6 @@ When /^I cancel adding a note to the project$/ do
click_link "neg_edit_form_note"
end
Then /^I should (see|not see) empty message for (todos|deferred todos|completed todos) of project/ do |visible, state|
css = "wrong state"
css = "div#p#{@project.id}-empty-d" if state == "todos"
css = "div#deferred_pending_container-empty-d" if state == "deferred todos"
css = "div#completed_container-empty-d" if state == "completed todos"
elem = find(css)
elem.should_not be_nil
elem.send(visible=="see" ? :should : :should_not, be_visible)
end
Then /^I edit the default tags to "([^"]*)"$/ do |default_tags|
edit_project(@project) do
fill_in "project[default_tags]", :with => default_tags

View file

@ -162,6 +162,15 @@ Given /^I have a completed todo with description "([^"]*)" in project "([^"]*)"
@todo.complete!
end
Given(/^I have a completed todo with description "([^"]*)" in context "(.*?)" completed (\d+) days ago$/) do |action_description, context_name, num_of_days|
step "I have a todo \"#{action_description}\" in the context \"#{context_name}\""
@todo.complete!
@todo.completed_at = Time.zone.now - num_of_days.to_i.days
@todo.save!
@todo.reload
end
####### PROJECT WITH TODOS ######
Given /^I have a project "([^"]*)" that has the following (todos|deferred todos)$/ do |project_name, kind_of_todo, todos|

View file

@ -152,19 +152,14 @@ Then /^I should see "([^"]*)" in the completed section of the mobile site$/ do |
page.should have_xpath(xpath)
end
Then /^I should (see|not see) empty message for (completed todos|todos) of home/ do |visible, kind_of_todo|
elem = find(kind_of_todo=="todos" ? "div#no_todos_in_view" : "div#completed_container-empty-d")
elem.send(visible=="see" ? "should" : "should_not", be_visible)
end
Then /^I should (see|not see) the empty tickler message$/ do |see|
elem = find("div#no_todos_in_view")
elem.send(see=="see" ? "should" : "should_not", be_visible)
end
Then /^I should (see|not see) the notes of "([^"]*)"$/ do |visible, todo_description|
todo = @current_user.todos.where(:description => todo_description).first
todo.should_not be_nil
page.find("div#notes_todo_#{todo.id}").send(visible=="see" ? "should" : "should_not", be_visible)
end
Then /^I should (see|not see) the empty tickler message$/ do |see|
elem = find("div#no_todos_in_view")
elem.send(see=="see" ? "should" : "should_not", be_visible)
end

View file

@ -1,23 +0,0 @@
Then /^I should not see empty message for todos of tag$/ do
page.should_not have_css("div#no_todos_in_view", :visible => true)
end
Then /^I should see empty message for todos of tag$/ do
page.should have_css("div#no_todos_in_view", :visible => true)
end
Then /^I should not see empty message for completed todos of tag$/ do
page.should_not have_css("div#completed_container-empty-d", :visible=>true)
end
Then /^I should see empty message for completed todos of tag$/ do
page.should have_css("div#completed_container-empty-d", :visible=>true)
end
Then /^I should not see empty message for deferred todos of tag$/ do
page.should_not have_css("div#deferred_pending_container-empty-d", :visible=>true)
end
Then /^I should see empty message for deferred todos of tag$/ do
page.should have_css("div#deferred_pending_container-empty-d", :visible=>true)
end

View file

@ -7,3 +7,7 @@ Before('@aruba') do
@aruba_timeout_seconds = 5
# print "\nsetting timeout for aruba to #{@aruba_timeout_seconds}\n"
end
After('@reset_time') do
Timecop.return
end

View file

@ -35,7 +35,7 @@ Feature: Show done
Scenario Outline: I can see all todos completed in the last timeperiod
When I go to the <page>
Then I should see "todo 1"
And I should see "Completed today"
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"
@ -153,6 +153,25 @@ Feature: Show done
| all done actions page for project "test project"| "test project" project | |
| all done actions page for tag "starred" | home page | in the context container for "@pc" |
@javascript @reset_time
Scenario: Activating the last todo will show empty message
Given the date is "2013-03-11"
And I have a completed todo with description "todo 2" in context "@pc" completed 1 days ago
And I have a completed todo with description "todo 3" in context "@pc" completed 8 days ago
When I go to the done actions page
Then I should see "todo 1" in the done today container
And I should see "todo 2" in the done this week container
And I should see "todo 3" in the done this month container
When I mark the completed todo "todo 1" active
Then I should not see "todo 1"
And I should see empty message for done today of done actions
When I mark the completed todo "todo 2" active
Then I should not see "todo 2"
And I should see empty message for done this week of done actions
When I mark the completed todo "todo 3" active
Then I should not see "todo 3"
And I should see empty message for done this month of done actions
@javascript
Scenario Outline: I can toggle the star of a todo from the done pages
When I go to the <page>

View file

@ -1,7 +1,7 @@
class DoneTodos
def self.done_todos_for_container(container)
completed_todos = container.todos.completed
return done_today(completed_todos), done_this_week(completed_todos), done_this_month(completed_todos)
def self.done_todos_for_container(user)
completed_todos = user.todos.completed
return done_today(completed_todos), done_rest_of_week(completed_todos), done_rest_of_month(completed_todos)
end
def self.done_today(todos, includes = {:include => Todo::DEFAULT_INCLUDES})
@ -9,14 +9,31 @@ class DoneTodos
todos.completed_after(start_of_this_day).all(includes)
end
def self.done_this_week(todos, includes = {:include => Todo::DEFAULT_INCLUDES})
def self.done_rest_of_week(todos, includes = {:include => Todo::DEFAULT_INCLUDES})
done_between(todos, includes, Time.zone.now.beginning_of_day, Time.zone.now.beginning_of_week)
end
def self.done_this_month(todos, includes = {:include => Todo::DEFAULT_INCLUDES})
def self.done_rest_of_month(todos, includes = {:include => Todo::DEFAULT_INCLUDES})
done_between(todos, includes, Time.zone.now.beginning_of_week, Time.zone.now.beginning_of_month)
end
def self.completed_period(date)
return nil if date.nil?
period = nil
period = "rest_of_month" if date > Time.zone.now.beginning_of_month
period = "rest_of_week" if date > Time.zone.now.beginning_of_week
period = "today" if date > Time.zone.now.beginning_of_day
return period
end
def self.remaining_in_container(user, period)
count = self.send("done_#{period}", user.todos.completed, {}).count
return nil if period.nil?
return count
end
private
def self.done_between(todos, includes, start_date, end_date)