2009-04-13 22:26:20 +02:00
|
|
|
Given /^I have no todos$/ do
|
|
|
|
|
Todo.delete_all
|
|
|
|
|
end
|
|
|
|
|
|
2011-02-27 00:04:04 +01:00
|
|
|
Given /^I have a todo "([^"]*)" in the context "([^"]*)"$/ do |description, context_name|
|
|
|
|
|
context = @current_user.contexts.find_or_create(:name => context_name)
|
2011-01-08 09:12:37 +01:00
|
|
|
@current_user.todos.create!(:context_id => context.id, :description => description)
|
|
|
|
|
end
|
|
|
|
|
|
2011-03-10 16:50:19 +01:00
|
|
|
Given /^I have a todo "([^"]*)" in the context "([^"]*)" which is due tomorrow$/ do |description, context_name|
|
|
|
|
|
context = @current_user.contexts.find_or_create(:name => context_name)
|
|
|
|
|
@todo = @current_user.todos.create!(:context_id => context.id, :description => description)
|
|
|
|
|
@todo.due = @todo.created_at + 1.day
|
|
|
|
|
@todo.save!
|
|
|
|
|
end
|
|
|
|
|
|
2011-02-27 00:04:04 +01:00
|
|
|
Given /^I have a todo "([^"]*)"$/ do |description|
|
|
|
|
|
Given "I have a todo \"#{description}\" in the context \"Context A\""
|
|
|
|
|
end
|
|
|
|
|
|
2009-04-13 22:26:20 +02:00
|
|
|
Given /^I have ([0-9]+) todos$/ do |count|
|
|
|
|
|
count.to_i.downto 1 do |i|
|
2011-02-27 00:04:04 +01:00
|
|
|
Given "I have a todo \"todo #{i}\" in the context \"Context A\""
|
2009-04-13 22:26:20 +02:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
Given /^I have ([0-9]+) deferred todos$/ do |count|
|
|
|
|
|
context = @current_user.contexts.create!(:name => "context B")
|
|
|
|
|
count.to_i.downto 1 do |i|
|
|
|
|
|
@current_user.todos.create!(:context_id => context.id, :description => "todo #{i}", :show_from => @current_user.time + 1.week)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2011-01-08 09:12:37 +01:00
|
|
|
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
|
|
|
|
|
|
2009-04-13 22:26:20 +02:00
|
|
|
Given /^I have ([0-9]+) completed todos$/ do |count|
|
|
|
|
|
context = @current_user.contexts.create!(:name => "context C")
|
|
|
|
|
count.to_i.downto 1 do |i|
|
|
|
|
|
todo = @current_user.todos.create!(:context_id => context.id, :description => "todo #{i}")
|
|
|
|
|
todo.complete!
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2011-02-14 20:22:59 +01:00
|
|
|
Given /^I have ([0-9]+) completed todos with a note$/ do |count|
|
|
|
|
|
context = @current_user.contexts.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!
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2010-08-12 14:39:58 +02:00
|
|
|
Given /^I have a project "([^"]*)" that has the following todos$/ do |project_name, todos|
|
|
|
|
|
Given "I have a project called \"#{project_name}\""
|
|
|
|
|
@project.should_not be_nil
|
|
|
|
|
todos.hashes.each do |todo|
|
2011-02-27 00:04:04 +01:00
|
|
|
context = @current_user.contexts.find_by_name(todo[:context])
|
|
|
|
|
context.should_not be_nil
|
|
|
|
|
new_todo = @current_user.todos.create!(
|
2010-08-12 14:39:58 +02:00
|
|
|
:description => todo[:description],
|
2011-02-27 00:04:04 +01:00
|
|
|
:context_id => context.id,
|
2010-08-12 14:39:58 +02:00
|
|
|
:project_id=>@project.id)
|
2011-02-27 00:04:04 +01:00
|
|
|
unless todo[:tags].nil?
|
|
|
|
|
new_todo.tag_with(todo[:tags])
|
|
|
|
|
end
|
2011-03-11 21:01:24 +01:00
|
|
|
unless todo[:completed].nil?
|
|
|
|
|
new_todo.complete! if todo[:completed] == 'yes'
|
|
|
|
|
end
|
2010-08-12 14:39:58 +02:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2011-04-14 16:26:16 +02:00
|
|
|
When /^I mark "([^"]*)" as complete$/ do |action_description|
|
|
|
|
|
todo = @current_user.todos.find_by_description(action_description)
|
2010-10-22 11:55:54 +02:00
|
|
|
todo.should_not be_nil
|
|
|
|
|
|
2011-04-14 16:26:16 +02:00
|
|
|
check "mark_complete_#{todo.id}"
|
2010-07-16 13:11:01 +02:00
|
|
|
|
2011-04-14 16:26:16 +02:00
|
|
|
todo_container = "fail" # fail this test if @source_view is wrong
|
|
|
|
|
todo_container = "p#{todo.project_id}items" if @source_view=="project"
|
|
|
|
|
todo_container = "c#{todo.context_id}items" if @source_view=="context" || @source_view=="todos" || @source_view=="tag"
|
2010-07-16 13:11:01 +02:00
|
|
|
|
2011-04-14 16:26:16 +02:00
|
|
|
# container should be there
|
|
|
|
|
selenium.is_element_present("//div[@id='#{todo_container}']").should be_true
|
2011-02-27 00:35:19 +01:00
|
|
|
|
2011-04-14 16:26:16 +02:00
|
|
|
wait_for :timeout => 5 do
|
|
|
|
|
!selenium.is_element_present("//div[@id='#{todo_container}']//div[@id='line_todo_#{todo.id}']")
|
|
|
|
|
end
|
|
|
|
|
# note that animations could be running after finishing this
|
2011-03-10 16:50:19 +01:00
|
|
|
end
|
|
|
|
|
|
2011-04-14 16:26:16 +02:00
|
|
|
When /^I mark "([^"]*)" as uncompleted$/ do |action_description|
|
|
|
|
|
# TODO: generalize. this currently only works for context wrt xpath
|
2011-02-27 00:35:19 +01:00
|
|
|
todo = @current_user.todos.find_by_description(action_description)
|
|
|
|
|
todo.should_not be_nil
|
2010-08-12 14:39:58 +02:00
|
|
|
|
2011-03-08 23:28:48 +01:00
|
|
|
check "mark_complete_#{todo.id}"
|
2011-04-14 16:26:16 +02:00
|
|
|
|
|
|
|
|
xpath="//div[@id='c#{todo.context_id}items']//div[@id='line_todo_#{todo.id}']"
|
2011-03-08 23:28:48 +01:00
|
|
|
wait_for :timeout => 5 do
|
2011-04-14 16:26:16 +02:00
|
|
|
selenium.is_element_present(xpath)
|
2011-01-08 09:12:37 +01:00
|
|
|
end
|
2011-03-08 23:28:48 +01:00
|
|
|
# note that animations could be running after finishing this
|
2011-01-08 09:12:37 +01:00
|
|
|
end
|
|
|
|
|
|
2011-03-08 23:28:48 +01:00
|
|
|
When /^I delete the action "([^"]*)"$/ do |action_description|
|
|
|
|
|
todo = @current_user.todos.find_by_description(action_description)
|
2010-03-02 11:14:45 +01:00
|
|
|
todo.should_not be_nil
|
|
|
|
|
|
2011-03-08 23:28:48 +01:00
|
|
|
delete_todo_button = "xpath=//a[@id='delete_todo_#{todo.id}']/img"
|
|
|
|
|
selenium.click delete_todo_button
|
|
|
|
|
selenium.get_confirmation.should == "Are you sure that you want to delete the action '#{todo.description}'?"
|
2010-03-02 11:14:45 +01:00
|
|
|
|
2011-03-08 23:28:48 +01:00
|
|
|
wait_for :timeout => 5 do
|
|
|
|
|
!selenium.is_element_present("//div[@id='line_todo_#{todo.id}']")
|
|
|
|
|
end
|
2010-03-02 11:14:45 +01:00
|
|
|
end
|
2010-07-04 20:13:32 -07:00
|
|
|
|
2011-04-14 16:26:16 +02:00
|
|
|
When /^I delete the todo "([^"]*)"$/ do |action_description|
|
|
|
|
|
When "I delete the action \"#{action_description}\""
|
|
|
|
|
end
|
|
|
|
|
|
2011-03-08 23:28:48 +01:00
|
|
|
Then /^I should see ([0-9]+) todos$/ do |count|
|
|
|
|
|
count.to_i.downto 1 do |i|
|
|
|
|
|
match_xpath "div["
|
|
|
|
|
end
|
2011-02-03 16:59:59 +01:00
|
|
|
end
|
|
|
|
|
|
2011-03-08 23:28:48 +01:00
|
|
|
Then /^there should not be an error$/ do
|
|
|
|
|
sleep(5)
|
|
|
|
|
# form should be gone and thus no errors visible
|
|
|
|
|
wait_for :timeout => 5 do
|
|
|
|
|
!selenium.is_visible("edit_todo_#{@dep_todo.id}")
|
|
|
|
|
end
|
|
|
|
|
end
|
2011-02-03 16:59:59 +01:00
|
|
|
|
2010-07-04 20:13:32 -07:00
|
|
|
Then /^I should see the todo "([^\"]*)"$/ do |todo_description|
|
|
|
|
|
selenium.is_element_present("//span[.=\"#{todo_description}\"]").should be_true
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
Then /^I should not see the todo "([^\"]*)"$/ do |todo_description|
|
|
|
|
|
selenium.is_element_present("//span[.=\"#{todo_description}\"]").should be_false
|
|
|
|
|
end
|
2010-07-14 23:34:47 +02:00
|
|
|
|
|
|
|
|
Then /^the number of actions should be (\d+)$/ do |count|
|
|
|
|
|
@current_user.todos.count.should == count.to_i
|
|
|
|
|
end
|
2011-01-08 09:12:37 +01:00
|
|
|
|
|
|
|
|
Then /^a confirmation for adding a new context "([^"]*)" should be asked$/ do |context_name|
|
2011-02-09 20:41:34 +01:00
|
|
|
selenium.get_confirmation.should == "New context '#{context_name}' will be also created. Are you sure?"
|
2011-02-03 16:59:59 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
Then /^I should see "([^"]*)" in the deferred container$/ do |todo_description|
|
|
|
|
|
todo = @current_user.todos.find_by_description(todo_description)
|
|
|
|
|
todo.should_not be_nil
|
|
|
|
|
|
|
|
|
|
xpath = "//div[@id='tickler']//div[@id='line_todo_#{todo.id}']"
|
|
|
|
|
|
2011-03-08 23:28:48 +01:00
|
|
|
wait_for :timeout => 5 do
|
|
|
|
|
selenium.is_element_present(xpath)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
Then /^I should see "([^"]*)" in the action container$/ do |todo_description|
|
|
|
|
|
todo = @current_user.todos.find_by_description(todo_description)
|
|
|
|
|
todo.should_not be_nil
|
|
|
|
|
|
|
|
|
|
xpath = "//div[@id='p#{todo.project.id}items']//div[@id='line_todo_#{todo.id}']"
|
|
|
|
|
|
|
|
|
|
wait_for :timeout => 5 do
|
|
|
|
|
selenium.is_element_present(xpath)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
Then /^I should see "([^"]*)" in the completed container$/ do |todo_description|
|
|
|
|
|
todo = @current_user.todos.find_by_description(todo_description)
|
|
|
|
|
todo.should_not be_nil
|
|
|
|
|
|
|
|
|
|
xpath = "//div[@id='completed_container']//div[@id='line_todo_#{todo.id}']"
|
|
|
|
|
|
|
|
|
|
wait_for :timeout => 5 do
|
|
|
|
|
selenium.is_element_present(xpath)
|
|
|
|
|
end
|
2011-02-03 16:59:59 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
Then /^I should not see "([^"]*)" in the deferred container$/ do |todo_description|
|
|
|
|
|
todo = @current_user.todos.find_by_description(todo_description)
|
|
|
|
|
todo.should_not be_nil
|
|
|
|
|
|
|
|
|
|
xpath = "//div[@id='tickler']//div[@id='line_todo_#{todo.id}']"
|
|
|
|
|
|
2011-03-08 23:28:48 +01:00
|
|
|
wait_for :timeout => 5 do
|
|
|
|
|
!selenium.is_element_present(xpath)
|
|
|
|
|
end
|
2011-02-03 16:59:59 +01:00
|
|
|
end
|
2011-02-26 11:38:39 +01:00
|
|
|
|
2011-03-10 16:50:19 +01:00
|
|
|
Then /^I should see "([^"]*)" in the due next month container$/ do |todo_description|
|
|
|
|
|
todo = @current_user.todos.find_by_description(todo_description)
|
|
|
|
|
todo.should_not be_nil
|
|
|
|
|
|
2011-04-01 21:50:00 +02:00
|
|
|
xpath = "//div[@id='due_after_this_month']//div[@id='line_todo_#{todo.id}']"
|
2011-03-10 16:50:19 +01:00
|
|
|
|
|
|
|
|
wait_for :timeout => 5 do
|
2011-04-01 21:50:00 +02:00
|
|
|
selenium.is_element_present(xpath)
|
2011-03-10 16:50:19 +01:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2011-02-26 11:38:39 +01:00
|
|
|
Then /^the selected project should be "([^"]*)"$/ do |content|
|
|
|
|
|
# Works for mobile. TODO: make it work for both mobile and non-mobile
|
|
|
|
|
field_labeled("Project").element.search(".//option[@selected = 'selected']").inner_html.should =~ /#{content}/
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
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
|