tracks/features/support/world.rb

93 lines
2.6 KiB
Ruby
Raw Normal View History

2010-07-16 14:41:04 +02:00
module TracksStepHelper
def submit_multiple_next_action_form
selenium.click("xpath=//form[@id='todo-form-multi-new-action']//button[@id='todo_multi_new_action_submit']", :wait_for => :ajax, :javascript_framework => :jquery)
end
def submit_next_action_form
2012-01-30 03:42:47 +01:00
within("#todo-form-new-action") do
click_button("todo_new_action_submit")
end
2011-03-02 08:44:34 +01:00
sleep(1)
2010-07-16 14:41:04 +02:00
end
2010-07-29 18:06:30 +02:00
def submit_new_context_form
within "form#context-form" do
find("button#context_new_submit").click
end
wait_for_animations_to_end
2010-07-29 18:06:30 +02:00
end
2010-10-16 16:45:08 +02:00
def submit_new_project_form
selenium.click("xpath=//form[@id='project_form']//button[@id='project_new_project_submit']", :wait_for => :ajax, :javascript_framework => :jquery)
end
2012-01-30 03:42:47 +01:00
def wait_for_form_to_go_away(todo)
page.should_not have_content("button#submit_todo_#{todo.id}")
end
def submit_edit_todo_form (todo)
2012-01-30 03:42:47 +01:00
within "div#edit_todo_#{todo.id}" do
click_button "submit_todo_#{todo.id}"
2011-03-02 08:44:34 +01:00
end
2012-01-30 03:42:47 +01:00
wait_for_form_to_go_away(todo)
wait_for_animations_to_end
end
def format_date(date)
# copy-and-past from ApplicationController::format_date
return date ? date.in_time_zone(@current_user.prefs.time_zone).strftime("#{@current_user.prefs.date_format}") : ''
end
def execute_javascript(js)
2012-01-30 03:42:47 +01:00
page.execute_script(js)
end
def clear_context_name_from_next_action_form
execute_javascript("$('#todo_context_name').val('');")
end
def clear_project_name_from_next_action_form
execute_javascript("$('#todo_project_name').val('');")
end
2012-01-30 03:42:47 +01:00
2011-02-27 00:35:19 +01:00
def open_edit_form_for(todo)
2012-01-30 03:42:47 +01:00
within "div#line_todo_#{todo.id}" do
find("a#icon_edit_todo_#{todo.id}").click
2011-03-10 16:50:19 +01:00
end
2012-01-30 03:42:47 +01:00
wait_for_animations_to_end
end
def wait_for_animations_to_end
wait_until do
page.evaluate_script('$(":animated").length') == 0
end
end
2012-01-30 03:42:47 +01:00
def handle_js_confirm(accept=true)
page.execute_script "window.original_confirm_function = window.confirm"
page.execute_script "window.confirmMsg = null"
page.execute_script "window.confirm = function(msg) { window.confirmMsg = msg; return #{!!accept}; }"
yield
ensure
page.execute_script "window.confirm = window.original_confirm_function"
end
def get_confirm_text
page.evaluate_script "window.confirmMsg"
2011-02-27 00:35:19 +01:00
end
2012-01-30 03:42:47 +01:00
def open_submenu_for(todo)
within "div#line_todo_#{todo.id}" do
find("img#todo-submenu").click
end
end
def context_list_find_index(context_name)
div_id = "context_#{@current_user.contexts.find_by_name(context_name).id}"
contexts = page.all("div.context").map { |x| x[:id] }
return contexts.find_index(div_id)
end
2010-07-16 14:41:04 +02:00
end
World(TracksStepHelper)