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-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-02-22 11:35:00 +01:00
Given / ^"(.*)" depends on "(.*)"$ / do | successor_name , predecessor_name |
successor = Todo . find_by_description ( successor_name )
predecessor = Todo . find_by_description ( predecessor_name )
successor . add_predecessor ( predecessor )
successor . state = " pending "
successor . save!
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
2010-08-12 14:39:58 +02:00
end
end
2010-02-22 11:35:00 +01:00
When / ^I drag "(.*)" to "(.*)"$ / do | dragged , target |
drag_id = Todo . find_by_description ( dragged ) . id
drop_id = Todo . find_by_description ( target ) . id
drag_name = " xpath=//div[@id='line_todo_ #{ drag_id } ']//img[@class='grip'] "
2010-05-09 18:59:02 -04:00
drop_name = " xpath=//div[@id='line_todo_ #{ drop_id } ']//div[@class='description'] "
2010-02-22 11:35:00 +01:00
selenium . drag_and_drop_to_object ( drag_name , drop_name )
2010-03-02 11:14:45 +01:00
arrow = " xpath=//div[@id='line_todo_ #{ drop_id } ']/div/a[@class='show_successors']/img "
2010-10-22 20:46:06 +02:00
selenium . wait_for_element ( arrow , :timeout_in_seconds = > 5 )
2010-03-02 11:14:45 +01:00
end
When / ^I expand the dependencies of "([^ \ "]*)"$ / do | todo_name |
todo = Todo . find_by_description ( todo_name )
todo . should_not be_nil
expand_img_locator = " xpath=//div[@id='line_todo_ #{ todo . id } ']/div/a[@class='show_successors']/img "
selenium . click ( expand_img_locator )
2010-02-22 11:35:00 +01:00
end
2010-07-04 20:13:32 -07:00
When / I change the (.*) field of "([^ \ "]*)" to "([^ \ "]*)"$ / do | field , todo_name , new_value |
2010-10-22 11:55:54 +02:00
todo = @current_user . todos . find_by_description ( todo_name )
todo . should_not be_nil
selenium . click ( " //img[@id='edit_icon_todo_ #{ todo . id } '] " , :wait_for = > :ajax , :javascript_framework = > :jquery )
2010-07-04 20:13:32 -07:00
selenium . type ( " css=form.edit_todo_form input[name= #{ field } ] " , new_value )
selenium . click ( " css=button.positive " , :wait_for = > :ajax , :javascript_framework = > :jquery )
2010-11-10 23:48:56 +01:00
# TODO: change to a wait_for
2010-07-04 20:13:32 -07:00
sleep ( 5 )
end
2010-07-14 23:34:47 +02:00
When / ^I submit a new action with description "([^"]*)"$ / do | description |
fill_in " todo[description] " , :with = > description
2010-07-16 14:41:04 +02:00
submit_next_action_form
2010-07-14 23:34:47 +02:00
end
2011-01-08 09:12:37 +01:00
When / ^I submit a new action with description "([^"]*)" and the tags "([^"]*)" in the context "([^"]*)"$ / do | description , tags , context_name |
fill_in " todo[description] " , :with = > description
fill_in " tag_list " , :with = > tags
2011-01-08 19:50:19 +01:00
# fill_in does not seem to work when the field is prefilled with something. Empty the field first
clear_context_name_from_next_action_form
2011-01-08 09:12:37 +01:00
fill_in " todo_context_name " , :with = > context_name
submit_next_action_form
end
When / ^I submit a new deferred action with description "([^"]*)" and the tags "([^"]*)" in the context "([^"]*)"$ / do | description , tags , context_name |
fill_in " todo[description] " , :with = > description
2011-01-08 19:50:19 +01:00
clear_context_name_from_next_action_form
2011-02-08 17:37:14 +01:00
fill_in " todo_context_name " , :with = > context_name
2011-01-08 19:50:19 +01:00
2011-01-08 09:12:37 +01:00
fill_in " tag_list " , :with = > tags
fill_in " todo[show_from] " , :with = > format_date ( @current_user . time + 1 . week )
submit_next_action_form
2011-01-08 19:50:19 +01:00
end
When / ^I submit a new action with description "([^"]*)" to project "([^"]*)" with tags "([^"]*)" in the context "([^"]*)"$ / do | description , project_name , tags , context_name |
fill_in " todo[description] " , :with = > description
clear_project_name_from_next_action_form
clear_context_name_from_next_action_form
fill_in " todo_project_name " , :with = > project_name
2011-02-08 17:37:14 +01:00
fill_in " todo_context_name " , :with = > context_name
2011-01-08 19:50:19 +01:00
fill_in " tag_list " , :with = > tags
submit_next_action_form
end
When / ^I submit a new action with description "([^"]*)" in the context "([^"]*)"$ / do | description , context_name |
fill_in " todo[description] " , :with = > description
clear_context_name_from_next_action_form
2011-02-08 17:37:14 +01:00
fill_in " todo_context_name " , :with = > context_name
2011-01-08 19:50:19 +01:00
submit_next_action_form
2011-01-08 09:12:37 +01:00
end
2010-07-14 23:34:47 +02:00
When / ^I submit multiple actions with using$ / do | multiple_actions |
fill_in " todo[multiple_todos] " , :with = > multiple_actions
2010-07-16 14:41:04 +02:00
submit_multiple_next_action_form
2010-07-14 23:34:47 +02:00
end
2010-07-16 13:11:01 +02:00
When / ^I fill the multiple actions form with "([^"]*)", "([^"]*)", "([^"]*)", "([^"]*)"$ / do | descriptions , project_name , context_name , tags |
fill_in " todo[multiple_todos] " , :with = > descriptions
fill_in " multi_todo_project_name " , :with = > project_name
fill_in " multi_todo_context_name " , :with = > context_name
fill_in " multi_tag_list " , :with = > tags
end
When / ^I submit the new multiple actions form with "([^"]*)", "([^"]*)", "([^"]*)", "([^"]*)"$ / do | descriptions , project_name , context_name , tags |
When " I fill the multiple actions form with \" #{ descriptions } \" , \" #{ project_name } \" , \" #{ context_name } \" , \" #{ tags } \" "
2010-07-16 14:41:04 +02:00
submit_multiple_next_action_form
2010-07-16 13:11:01 +02:00
end
When / ^I submit the new multiple actions form with$ / do | multi_line_descriptions |
fill_in " todo[multiple_todos] " , :with = > multi_line_descriptions
2010-07-16 14:41:04 +02:00
submit_multiple_next_action_form
2010-07-16 13:11:01 +02:00
end
2011-02-03 16:59:59 +01:00
When / ^I edit the dependency of "([^"]*)" to "([^"]*)"$ / do | todo_name , deps |
2010-08-12 14:39:58 +02:00
todo = @dep_todo = @current_user . todos . find_by_description ( todo_name )
todo . should_not be_nil
2011-02-27 00:35:19 +01:00
open_edit_form_for ( todo )
2010-08-12 14:39:58 +02:00
fill_in " predecessor_list_todo_ #{ todo . id } " , :with = > deps
2011-02-03 16:59:59 +01:00
submit_edit_todo_form ( todo )
2011-02-27 00:35:19 +01:00
end
When / ^I edit the due date of "([^"]*)" to tomorrow$ / do | action_description |
todo = @current_user . todos . find_by_description ( action_description )
todo . should_not be_nil
open_edit_form_for ( todo )
fill_in " due_todo_ #{ todo . id } " , :with = > format_date ( todo . created_at + 1 . day )
submit_edit_todo_form ( todo )
end
When / ^I clear the due date of "([^"]*)"$ / do | action_description |
todo = @current_user . todos . find_by_description ( action_description )
todo . should_not be_nil
open_edit_form_for ( todo )
selenium . click ( " //div[@id='edit_todo_ #{ todo . id } ']//a[@id='due_x_todo_ #{ todo_id } ']/img " , :wait_for = > :ajax , :javascript_framework = > :jquery )
submit_edit_todo_form ( todo )
2010-08-12 14:39:58 +02:00
end
2011-01-08 09:12:37 +01:00
Then / ^I should see ([0-9]+) todos$ / do | count |
count . to_i . downto 1 do | i |
match_xpath " div[ "
end
end
2010-08-12 14:39:58 +02:00
Then / ^there should not be an error$ / do
2011-02-03 16:59:59 +01:00
sleep ( 5 )
# form should be gone and thus no errors visible
2010-08-12 14:39:58 +02:00
selenium . is_visible ( " edit_todo_ #{ @dep_todo . id } " ) . should == false
end
2011-02-03 16:59:59 +01:00
Then / ^the successors of "(.*)" should include "(.*)"$ / do | parent_name , child_name |
2010-03-02 11:14:45 +01:00
parent = @current_user . todos . find_by_description ( parent_name )
parent . should_not be_nil
child = parent . pending_successors . find_by_description ( child_name )
child . should_not be_nil
end
Then / ^I should see "([^ \ "]*)" within the dependencies of "([^ \ "]*)"$ / do | successor_description , todo_description |
todo = @current_user . todos . find_by_description ( todo_description )
todo . should_not be_nil
successor = @current_user . todos . find_by_description ( successor_description )
successor . should_not be_nil
# argh, webrat on selenium does not support within, so this won't work
# xpath = "//div[@id='line_todo_#{todo.id}'"
# Then "I should see \"#{successor_description}\" within \"xpath=#{xpath}\""
# let selenium look for the presence of the successor
xpath = " xpath=//div[@id='line_todo_ #{ todo . id } ']//div[@id='successor_line_todo_ #{ successor . id } ']//span "
2010-03-08 20:36:33 +01:00
selenium . wait_for_element ( xpath , :timeout_in_seconds = > 5 )
2010-03-02 11:14:45 +01:00
end
2010-07-04 20:13:32 -07:00
2011-02-03 16:59:59 +01:00
Then / ^I should not see "([^"]*)" within the dependencies of "([^"]*)"$ / do | successor_description , todo_description |
todo = @current_user . todos . find_by_description ( todo_description )
todo . should_not be_nil
successor = @current_user . todos . find_by_description ( successor_description )
successor . should_not be_nil
# let selenium look for the presence of the successor
xpath = " xpath=//div[@id='line_todo_ #{ todo . id } ']//div[@id='successor_line_todo_ #{ successor . id } ']//span "
selenium . is_element_present ( xpath ) . should be_false
end
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 / ^the container for the context "([^"]*)" should be visible$ / do | context_name |
context = @current_user . contexts . find_by_name ( context_name )
context . should_not be_nil
xpath = " xpath=//div[@id= \" c #{ context . id } \" ] "
selenium . wait_for_element ( xpath , :timeout_in_seconds = > 5 )
selenium . is_visible ( xpath ) . should be_true
end
Then / ^the container for the context "([^"]*)" should not be visible$ / do | context_name |
context = @current_user . contexts . find_by_name ( context_name )
context . should_not be_nil
xpath = " xpath=//div[@id= \" c #{ context . id } \" ] "
selenium . wait_for :wait_for = > :ajax , :javascript_framework = > :jquery
selenium . is_element_present ( xpath ) . should be_false
end
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 } '] "
selenium . is_element_present ( xpath ) . should be_true
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 } '] "
selenium . is_element_present ( xpath ) . should be_false
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