tracks/features/step_definitions/dependencies_steps.rb

122 lines
4.4 KiB
Ruby
Raw Normal View History

Given /^"([^"]*)" depends on "([^"]*)"$/ do |successor_name, predecessor_name|
successor = Todo.where(:description => successor_name).first
predecessor = Todo.where(:description => predecessor_name).first
successor.add_predecessor(predecessor)
successor.state = "pending"
successor.save!
end
When /^I drag "(.*)" to "(.*)"$/ do |dragged, target|
drag_id = Todo.where(:description => dragged).first.id
drop_id = Todo.where(:description => target).first.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.where(:description=>todo_name).first
2014-05-16 15:42:03 -04:00
expect(todo).to_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.where(:description => todo_description).first
2014-05-16 15:42:03 -04:00
expect(todo).to_not be_nil
predecessor = @current_user.todos.where(:description => predecessor_description).first
2014-05-16 15:42:03 -04:00
expect(predecessor).to_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
2014-05-16 15:42:03 -04:00
expect(page).to have_css("a.ui-state-focus")
# click first line
2012-12-25 15:46:26 +01:00
page.find(:css, "ul li a.ui-state-focus").click
2012-02-03 15:57:23 +01:00
# wait for the new dependency to be added to the list
2014-05-16 15:42:03 -04:00
expect(page).to 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.where(:description => todo_description).first
2014-05-16 15:42:03 -04:00
expect(todo).to_not be_nil
predecessor = @current_user.todos.where(:description => predecessor_description).first
2014-05-16 15:42:03 -04:00
expect(predecessor).to_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
2014-05-16 15:42:03 -04:00
expect(page).to_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.where(:description => todo_name).first
2014-05-16 15:42:03 -04:00
expect(todo).to_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.where(:description => parent_name).first
2014-05-16 15:42:03 -04:00
expect(parent).to_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.where(:description => child_name).first.nil?
2012-03-19 14:05:54 +01:00
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.where(:description => todo_description).first
2014-05-16 15:42:03 -04:00
expect(todo).to_not be_nil
2012-12-25 15:46:26 +01:00
# open successors
within "div#line_todo_#{todo.id}" do
if !find(:css, "div#successors_todo_#{todo.id}").visible?
find(:css, "a.show_successors").click
end
end
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.where(:description => todo_description).first
2014-05-16 15:42:03 -04:00
expect(todo).to_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.where(:description => todo_description).first
2014-05-16 15:42:03 -04:00
expect(todo).to_not be_nil
dependencies_icon = "//div[@id='line_todo_#{todo.id}']/div/a[@class='show_successors']/img"
2014-05-16 15:42:03 -04:00
expect(page).to_not have_xpath(dependencies_icon)
end