tracks/features/step_definitions/dependencies_steps.rb

115 lines
4.1 KiB
Ruby
Raw Normal View History

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
When /^I drag "(.*)" to "(.*)"$/ do |dragged, target|
drag_id = Todo.find_by_description(dragged).id
drop_id = Todo.find_by_description(target).id
2012-02-03 15:57:23 +01:00
drag_elem = page.find(:xpath, "//div[@id='line_todo_#{drag_id}']//img[@class='grip']")
2012-03-19 14:05:54 +01:00
drop_elem = page.find(:xpath, "//div[@id='line_todo_#{drop_id}']")
2012-02-03 15:57:23 +01:00
drag_elem.drag_to(drop_elem)
end
When /^I expand the dependencies of "([^\"]*)"$/ do |todo_name|
todo = Todo.find_by_description(todo_name)
todo.should_not be_nil
2012-02-03 15:57:23 +01:00
expand_img_locator = "//div[@id='line_todo_#{todo.id}']/div/a[@class='show_successors']/img"
page.find(:xpath, expand_img_locator).click
wait_for_animations_to_end
end
When /^I edit the dependency of "([^"]*)" to add "([^"]*)" as predecessor$/ do |todo_description, predecessor_description|
todo = @current_user.todos.find_by_description(todo_description)
todo.should_not be_nil
predecessor = @current_user.todos.find_by_description(predecessor_description)
predecessor.should_not be_nil
open_edit_form_for(todo)
2012-02-03 15:57:23 +01:00
form_css = "form#form_todo_#{todo.id}"
within form_css do
fill_in 'predecessor_input', :with => predecessor_description
end
2012-02-03 15:57:23 +01:00
# in webkit, the autocompleter is not fired after fill_in
page.execute_script %Q{$("#{form_css}").find('input[id$="predecessor_input"]').autocomplete('search')} if Capybara.javascript_driver == :webkit
# wait for auto complete
2012-02-03 15:57:23 +01:00
page.should have_css("a#ui-active-menuitem")
# click first line
2012-02-03 15:57:23 +01:00
page.find(:xpath, "//ul/li[1]/a[@id='ui-active-menuitem']").click
2012-02-03 15:57:23 +01:00
# wait for the new dependency to be added to the list
page.should have_css("li#pred_#{predecessor.id}")
submit_edit_todo_form(todo)
end
When /^I edit the dependency of "([^"]*)" to remove "([^"]*)" as predecessor$/ do |todo_description, predecessor_description|
todo = @current_user.todos.find_by_description(todo_description)
todo.should_not be_nil
predecessor = @current_user.todos.find_by_description(predecessor_description)
predecessor.should_not be_nil
open_edit_form_for(todo)
2012-02-03 15:57:23 +01:00
delete_dep_button = "//form[@id='form_todo_#{todo.id}']//img[@id='delete_dep_#{predecessor.id}']"
page.find(:xpath, delete_dep_button).click
page.should_not have_xpath(delete_dep_button)
submit_edit_todo_form(todo)
2012-02-03 15:57:23 +01:00
wait_for_ajax
wait_for_animations_to_end
end
When /^I edit the dependency of "([^"]*)" to "([^"]*)"$/ do |todo_name, deps|
todo = @dep_todo = @current_user.todos.find_by_description(todo_name)
todo.should_not be_nil
open_edit_form_for(todo)
fill_in "predecessor_list_todo_#{todo.id}", :with => deps
submit_edit_todo_form(todo)
end
Then /^the successors of "(.*)" should include "(.*)"$/ do |parent_name, child_name|
parent = @current_user.todos.find_by_description(parent_name)
parent.should_not be_nil
2012-03-19 14:05:54 +01:00
# wait until the successor is added. TODO: make this not loop indefinitly
wait_until do
found = !parent.pending_successors.find_by_description(child_name).nil?
sleep 0.2 unless found
found
end
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
step "I should see \"#{successor_description}\" within \"div#line_todo_#{todo.id}\""
end
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
2012-02-03 15:57:23 +01:00
step "I should not see \"#{successor_description}\" within \"div#line_todo_#{todo.id}\""
end
Then /^I should see that "([^"]*)" does not have dependencies$/ do |todo_description|
todo = @current_user.todos.find_by_description(todo_description)
todo.should_not be_nil
dependencies_icon = "//div[@id='line_todo_#{todo.id}']/div/a[@class='show_successors']/img"
2012-02-03 15:57:23 +01:00
page.should_not have_xpath(dependencies_icon)
end