add some project grouping scenarios to edit_a_todo and fix failures

also refactor step definitions
This commit is contained in:
Reinier Balt 2013-04-17 22:11:24 +02:00
parent 5f8f2eefa9
commit 8641ecfc4e
16 changed files with 487 additions and 422 deletions

View file

@ -1,19 +1,11 @@
When /^I collapse the context container of "([^"]*)"$/ do |context_name|
context = @current_user.contexts.where(:name => context_name).first
context.should_not be_nil
xpath = "//a[@id='toggle_c#{context.id}']"
toggle = page.find(:xpath, xpath)
When(/^I collapse the context container of "([^"]*)"$/) do |context_name|
toggle = page.find(:xpath, toggle_context_container_xpath(find_context(context_name)))
toggle.should be_visible
toggle.click
end
When(/^I collapse the project container of "(.*?)"$/) do |project_name|
project = @current_user.projects.where(:name => project_name).first
project.should_not be_nil
xpath = "//a[@id='toggle_p#{project.id}']"
toggle = page.find(:xpath, xpath)
toggle = page.find(:xpath, toggle_project_container_xpath(find_project(project_name)))
toggle.should be_visible
toggle.click
end
@ -24,97 +16,61 @@ end
####### Context #######
Then /^I should not see the context "([^"]*)"$/ do |context_name|
context = @current_user.contexts.where(:name => context_name).first
context.should_not be_nil
xpath = "//div[@id='c#{context.id}']"
page.should_not have_xpath(xpath, :visible => true)
Then(/^I should (see|not see) the context "([^"]*)"$/) do |visible, context_name|
check_xpath_visibility(visible, context_container_xpath(find_context(context_name)))
end
Then /^I should not see the container for context "([^"]*)"$/ do |context_name|
step "I should not see the context \"#{context_name}\""
Then /^I should (see|not see) the container for context "([^"]*)"$/ do |visible, context_name|
step("I should #{visible} the context \"#{context_name}\"")
end
Then /^I should not see the context container for "([^"]*)"$/ do |context_name|
step "I should not see the context \"#{context_name}\""
Then /^I should (see|not see) the context container for "([^"]*)"$/ do |visible, context_name|
step "I should #{visible} the context \"#{context_name}\""
end
Then /^the container for the context "([^"]*)" should not be visible$/ do |context_name|
step "I should not see the context \"#{context_name}\""
end
Then /^I should see the container for context "([^"]*)"$/ do |context_name|
context = @current_user.contexts.where(:name => context_name).first
context.should_not be_nil
xpath = "//div[@id='c#{context.id}']"
page.should have_xpath(xpath)
end
Then /^the container for the context "([^"]*)" should be visible$/ do |context_name|
step "I should see the container for context \"#{context_name}\""
Then(/^the container for the context "([^"]*)" should (be|not be) visible$/) do |context_name, visible|
mapping = {"be" => "see", "not be" => "not see"}
step "I should #{mapping[visible]} the context \"#{context_name}\""
end
Then /^I should (see|not see) "([^"]*)" in the context container for "([^"]*)"$/ do |visible, todo_description, context_name|
context = @current_user.contexts.where(:name => context_name).first
context.should_not be_nil
todo = @current_user.todos.where(:description => todo_description).first
todo.should_not be_nil
check_xpath_visibility(visible, todo_in_context_container_xpath(find_todo(todo_description), find_context(context_name)))
end
xpath = "//div[@id=\"c#{context.id}\"]//div[@id='line_todo_#{todo.id}']"
page.send( visible=='see' ? :should : :should_not, have_xpath(xpath))
Then /^I should (see|not see) "([^"]*)" in the container for context "([^"]*)"$/ do |visible, todo_description, context_name|
step "I should #{visible} \"#{todo_description}\" in the context container for \"#{context_name}\""
end
####### Deferred #######
Then /^I should see "([^"]*)" in the deferred container$/ do |todo_description|
todo = @current_user.todos.where(:description => todo_description).first
todo.should_not be_nil
page.should have_xpath("//div[@id='deferred_pending_container']//div[@id='line_todo_#{todo.id}']")
Then(/^I should (not see|see) "([^"]*)" in the deferred container$/) do |visible, todo_description|
check_xpath_visibility(visible, todo_in_deferred_container_xpath(find_todo(todo_description)))
end
Then /^I should not see "([^"]*)" in the deferred container$/ do |todo_description|
todo = @current_user.todos.where(:description => todo_description).first
todo.should_not be_nil
page.should_not have_xpath("//div[@id='deferred_pending_container']//div[@id='line_todo_#{todo.id}']")
end
Then /^I should (not see|see) "([^"]*)" in the action container$/ do |visible, todo_description|
todo = @current_user.todos.where(:description => todo_description).first
todo.should_not be_nil
id = @source_view=="project" ? "p#{todo.project_id}_items" : "c#{todo.context_id}_items"
xpath = "//div[@id='#{id}']//div[@id='line_todo_#{todo.id}']"
page.send(visible=="see" ? :should : :should_not, have_xpath(xpath))
end
Then /^I should not see "([^"]*)" in the context container of "([^"]*)"$/ do |todo_description, context_name|
step "I should not see \"#{todo_description}\" in the action container"
Then(/^I should (not see|see) "([^"]*)" in the action container$/) do |visible, todo_description|
check_xpath_visibility(visible, todo_in_container_xpath(@source_view.to_s, find_todo(todo_description)))
end
####### Project #######
Then /^I should (see|not see) "([^"]*)" in the project container of "([^"]*)"$/ do |visible, todo_description, project_name|
todo = @current_user.todos.where(:description => todo_description).first
todo.should_not be_nil
check_xpath_visibility(visible, todo_in_project_container_xpath(find_todo(todo_description), find_project(project_name)))
end
project = @current_user.projects.where(:name => project_name).first
project.should_not be_nil
Then(/^I should (see|not see) "(.*?)" in the container for project "(.*?)"$/) do |visible, todo_description, project_name|
step "I should #{visible} \"#{todo_description}\" in the project container of \"#{project_name}\""
end
xpath = "//div[@id='p#{todo.project.id}_items']//div[@id='line_todo_#{todo.id}']"
page.send( visible=='see' ? :should : :should_not, have_xpath(xpath))
Then(/^I should (see|not see) "(.*?)" in the project container for "(.*?)"$/) do |visible, todo_description, project_name|
step "I should #{visible} \"#{todo_description}\" in the project container of \"#{project_name}\""
end
Then(/^I should (see|not see) the project container for "([^"]*)"$/) do |visible, project_name|
project = @current_user.projects.where(:name => project_name).first
project.should_not be_nil
check_xpath_visibility(visible, project_container_xpath(find_project(project_name)))
end
xpath = "//div[@id='p#{project.id}']"
page.send( visible=='see' ? :should : :should_not, have_xpath(xpath, :visible => true))
Then(/^I should (see|not see) the container for project "(.*?)"$/) do |visible, project_name|
step "I should #{visible} the project container for \"#{project_name}\""
end
Then(/^the container for the project "(.*?)" should (be visible|not be visible)$/) do |project_name, visible|
@ -124,37 +80,28 @@ end
####### Completed #######
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
Then(/^I should (not see|see) "([^"]*)" in the (completed|done today|done this week|done this month) container$/) do |visible, todo_description, container|
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'
xpath = "//div[@id='#{id}']//div[@id='line_todo_#{todo.id}']"
page.send( visible=='see' ? :should : :should_not, have_xpath(xpath))
xpath = "//div[@id='#{id}']//div[@id='line_todo_#{find_todo(todo_description).id}']"
check_xpath_visibility(visible, xpath)
end
####### Hidden #######
Then /^I should see "([^"]*)" in the hidden container$/ do |todo_description|
todo = @current_user.todos.where(:description => todo_description).first
todo.should_not be_nil
xpath = "//div[@id='hidden_container']//div[@id='line_todo_#{todo.id}']"
page.should have_xpath(xpath)
Then /^I should (not see|see) "([^"]*)" in the hidden container$/ do |visible, todo_description|
xpath = "//div[@id='hidden_container']//div[@id='line_todo_#{find_todo(todo_description).id}']"
check_xpath_visibility(visible, xpath)
end
####### Calendar #######
Then /^I should see "([^"]*)" in the due next month container$/ do |todo_description|
todo = @current_user.todos.where(:description => todo_description).first
todo.should_not be_nil
within "div#due_after_this_month_container" do
page.should have_css("div#line_todo_#{todo.id}")
page.should have_css("div#line_todo_#{find_todo(todo_description).id}")
end
end
@ -165,20 +112,20 @@ Then /^I should (see|not see) "([^"]*)" in the active recurring todos container$
unless repeat.nil?
xpath = "//div[@id='active_recurring_todos_container']//div[@id='recurring_todo_#{repeat.id}']"
page.send(visibility == "see" ? "should" : "should_not", have_xpath(xpath, :visible => true))
check_xpath_visibility(visibility, xpath)
else
step "I should #{visibility} \"#{repeat_pattern}\""
end
end
Then /^I should not see "([^"]*)" in the completed recurring todos container$/ do |repeat_pattern|
Then /^I should (see|not see) "([^"]*)" in the completed recurring todos container$/ do |visible, repeat_pattern|
repeat = @current_user.todos.where(:description => repeat_pattern).first
unless repeat.nil?
xpath = "//div[@id='completed_recurring_todos_container']//div[@id='recurring_todo_#{repeat.id}']"
page.should_not have_xpath(xpath, :visible => true)
check_xpath_visibility(visible, xpath)
else
step "I should not see \"#{repeat_pattern}\""
step "I should #{visible} \"#{repeat_pattern}\""
end
end
@ -190,12 +137,13 @@ Then /^I should (see|not see) empty message for (done today|done this week|done
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_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)
check_elem_visibility(visible, elem)
end

View file

@ -13,6 +13,16 @@ Given /^I have a todo "([^"]*)" in context "([^"]*)" with tags "([^"]*)"$/ do |d
@todo.save!
end
Given(/^I have a todo "([^"]*)" in the context "([^"]*)" in the project "([^"]*)"$/) do |description, context_name, project_name|
step "I have a todo \"#{description}\" in the context \"#{context_name}\""
@project = @current_user.projects.where(:name => project_name).first_or_create
@project.should_not be_nil
@todo.project = @project
@todo.save!
end
Given /^I have a todo "([^"]*)" in the context "([^"]*)" which is due tomorrow$/ do |description, context_name|
context = @current_user.contexts.where(:name => context_name).first_or_create
@todo = @current_user.todos.create!(:context_id => context.id, :description => description)
@ -21,11 +31,8 @@ Given /^I have a todo "([^"]*)" in the context "([^"]*)" which is due tomorrow$/
end
Given /^I have (\d+) todos in project "([^"]*)" in context "([^"]*)" with tags "([^"]*)" prefixed by "([^"]*)"$/ do |number_of_todos, project_name, context_name, tag_names, prefix|
@context = @current_user.contexts.where(:name => context_name).first
@context.should_not be_nil
@project = @current_user.projects.where(:name => project_name).first
@project.should_not be_nil
@context = find_context(context_name)
@project = find_project(project_name)
@todos = []
number_of_todos.to_i.downto 1 do |i|
@ -76,6 +83,11 @@ Given /^I have a todo with description "([^"]*)" in project "([^"]*)" with tags
@todo.save!
end
Given(/^I have a todo "(.*?)" in context "(.*?)" in project "(.*?)" with tags "(.*?)"$/) do |action_description, context_name, project_name, tags|
step "I have a todo with description \"#{action_description}\" in project \"#{project_name}\" with tags \"#{tags}\" in the context \"#{context_name}\""
end
###### DEFERRED TODOS #######
Given /^I have ([0-9]+) deferred todos$/ do |count|
@ -107,11 +119,8 @@ end
####### COMPLETED TODOS #######
Given /^I have ([0-9]+) completed todos in project "([^"]*)" in context "([^"]*)"$/ do |count, project_name, context_name|
@context = @current_user.contexts.where(:name => context_name).first
@context.should_not be_nil
@project = @current_user.projects.where(:name => project_name).first
@project.should_not be_nil
@context = find_context(context_name)
@project = find_project(project_name)
@todos = []
count.to_i.downto 1 do |i|
@ -132,9 +141,8 @@ Given /^I have (\d+) completed todos in project "([^"]*)" in context "([^"]*)" w
@todos.each { |t| t.tag_with(tags); t.save! }
end
Given /^I have ([0-9]+) completed todos in context "([^"]*)"$/ do |count, context_name|
context = @current_user.contexts.where(:name => context_name).first
context.should_not be_nil
Given(/^I have ([0-9]+) completed todos in context "([^"]*)"$/) do |count, context_name|
find_context(context_name)
count.to_i.downto 1 do |i|
todo = @current_user.todos.create!(:context_id => context.id, :description => "todo #{i}")
@ -170,27 +178,21 @@ Given(/^I have a completed todo with description "([^"]*)" in context "(.*?)" co
@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|
step "I have a project called \"#{project_name}\""
@project.should_not be_nil
todos.hashes.each do |todo|
context = @current_user.contexts.where(:name => todo[:context]).first
context.should_not be_nil
new_todo = @current_user.todos.create!(
:description => todo[:description],
:context_id => context.id,
:project_id=>@project.id,
:notes => todo[:notes])
:context_id => find_context(todo[:context]).id,
:project_id => @project.id,
:notes => todo[:notes])
new_todo.show_from = Time.zone.now+1.week if kind_of_todo=="deferred todos"
unless todo[:tags].nil?
new_todo.tag_with(todo[:tags])
end
unless todo[:completed].nil?
new_todo.complete! if todo[:completed] == 'yes'
end
new_todo.tag_with(todo[:tags]) unless todo[:tags].nil?
new_todo.complete! if !todo[:completed].nil? && todo[:completed] == 'yes'
end
end
@ -221,19 +223,15 @@ When(/^I submit a new action with description "([^"]*)" to project "([^"]*)" wit
end
When /^I submit a new action with description "([^"]*)" with a dependency on "([^"]*)"$/ do |todo_description, predecessor_description|
predecessor = @current_user.todos.where(:description => predecessor_description).first
predecessor.should_not be_nil
predecessor = find_todo(predecessor_description)
within "form#todo-form-new-action" do
fill_in "todo[description]", :with => todo_description
fill_in "predecessor_input", :with => predecessor_description
end
# wait for auto complete
page.should have_css("a.ui-state-focus", :visible => true)
# click first line
page.find(:css, "ul li a.ui-state-focus").click
wait_for_auto_complete
click_first_line_of_auto_complete
new_dependency_line = "//li[@id='pred_#{predecessor.id}']"
page.should have_xpath(new_dependency_line, :visible => true)
@ -285,7 +283,7 @@ end
####### submitting using sidebar form: DEFERRED #######
When /^I submit a new deferred action with description "([^"]*)"$/ do |description|
When(/^I submit a new deferred action with description "([^"]*)"$/) do |description|
fill_in "todo[description]", :with => description
fill_in "todo[show_from]", :with => format_date(@current_user.time + 1.week)
submit_next_action_form