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

@ -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 #######
@ -181,4 +178,22 @@ Then /^I should not see "([^"]*)" in the completed recurring todos container$/ d
else
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

@ -70,13 +70,4 @@ Then /^he should see that a context named "([^\"]*)" (is|is not) present$/ do |c
else
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

@ -6,4 +6,8 @@ end
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>