2010-07-16 14:41:04 +02:00
|
|
|
module TracksStepHelper
|
2012-03-19 14:05:54 +01:00
|
|
|
|
2012-12-23 23:16:22 +01:00
|
|
|
def wait_until(timeout = 5)
|
|
|
|
|
timeout(timeout) { yield }
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def timeout(seconds = 1, error_message = nil, &block)
|
|
|
|
|
start_time = Time.now
|
|
|
|
|
|
|
|
|
|
result = nil
|
|
|
|
|
|
|
|
|
|
until result
|
|
|
|
|
return result if result = yield
|
|
|
|
|
|
|
|
|
|
delay = seconds - (Time.now - start_time)
|
|
|
|
|
if delay <= 0
|
|
|
|
|
raise TimeoutError, error_message || "timed out"
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
sleep(0.05)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2012-03-19 14:05:54 +01:00
|
|
|
def open_edit_form_for(todo)
|
2013-01-01 17:38:59 +01:00
|
|
|
# on calendar page there can be more than 1 occurance of a todo, so we select the first here
|
|
|
|
|
all(:css, "div#line_todo_#{todo.id} a#icon_edit_todo_#{todo.id}")[0].click
|
2012-03-19 14:05:54 +01:00
|
|
|
wait_for_ajax
|
|
|
|
|
wait_for_animations_to_end
|
|
|
|
|
end
|
|
|
|
|
|
2013-01-01 17:38:59 +01:00
|
|
|
def submit_form(form_xpath, button_name)
|
2012-03-12 21:50:53 +01:00
|
|
|
handle_js_confirm do
|
2013-01-01 17:38:59 +01:00
|
|
|
within(:xpath, form_xpath) do
|
2012-03-19 14:05:54 +01:00
|
|
|
click_button(button_name)
|
2012-03-12 21:50:53 +01:00
|
|
|
end
|
|
|
|
|
wait_for_ajax
|
|
|
|
|
wait_for_animations_to_end
|
|
|
|
|
end
|
2010-07-16 14:41:04 +02:00
|
|
|
end
|
2012-03-19 14:05:54 +01:00
|
|
|
|
|
|
|
|
def submit_multiple_next_action_form
|
2013-01-01 17:38:59 +01:00
|
|
|
submit_form("//form[@id='todo-form-multi-new-action']", "todo_multi_new_action_submit")
|
2012-03-19 14:05:54 +01:00
|
|
|
end
|
2010-07-16 14:41:04 +02:00
|
|
|
|
|
|
|
|
def submit_next_action_form
|
2013-01-01 17:38:59 +01:00
|
|
|
submit_form("//form[@id='todo-form-new-action']", "todo_new_action_submit")
|
2010-07-16 14:41:04 +02:00
|
|
|
end
|
|
|
|
|
|
2010-07-29 18:06:30 +02:00
|
|
|
def submit_new_context_form
|
2013-01-01 17:38:59 +01:00
|
|
|
submit_form("//form[@id='context-form']", "context_new_submit")
|
2010-07-29 18:06:30 +02:00
|
|
|
end
|
|
|
|
|
|
2010-10-16 16:45:08 +02:00
|
|
|
def submit_new_project_form
|
2013-01-01 17:38:59 +01:00
|
|
|
submit_form("//form[@id='project_form']", "project_new_project_submit")
|
2012-01-30 03:42:47 +01:00
|
|
|
end
|
|
|
|
|
|
2011-02-03 16:59:59 +01:00
|
|
|
def submit_edit_todo_form (todo)
|
2013-01-01 17:38:59 +01:00
|
|
|
submit_form("//div[@id='edit_todo_#{todo.id}']", "submit_todo_#{todo.id}")
|
2012-03-19 14:05:54 +01:00
|
|
|
wait_for_todo_form_to_go_away(todo)
|
2011-02-03 16:59:59 +01:00
|
|
|
end
|
2012-03-19 14:05:54 +01:00
|
|
|
|
|
|
|
|
def wait_for_todo_form_to_go_away(todo)
|
|
|
|
|
page.should_not have_content("button#submit_todo_#{todo.id}")
|
2011-01-08 19:50:19 +01:00
|
|
|
end
|
2012-03-19 14:05:54 +01:00
|
|
|
|
|
|
|
|
def open_project_edit_form(project)
|
|
|
|
|
click_link "link_edit_project_#{project.id}"
|
|
|
|
|
page.should have_css("button#submit_project_#{project.id}")
|
2011-01-08 19:50:19 +01:00
|
|
|
end
|
2012-01-30 03:42:47 +01:00
|
|
|
|
2012-03-19 14:05:54 +01:00
|
|
|
def submit_project_edit_form(project)
|
|
|
|
|
page.find("button#submit_project_#{project.id}").click
|
2012-01-30 03:42:47 +01:00
|
|
|
end
|
|
|
|
|
|
2012-03-19 14:05:54 +01:00
|
|
|
def edit_project_no_wait(project)
|
|
|
|
|
open_project_edit_form(project)
|
|
|
|
|
yield
|
|
|
|
|
submit_project_edit_form(project)
|
2012-01-30 03:42:47 +01:00
|
|
|
end
|
2012-02-03 15:57:23 +01:00
|
|
|
|
2012-03-19 14:05:54 +01:00
|
|
|
def edit_project(project)
|
|
|
|
|
open_project_edit_form(project)
|
2013-01-01 17:38:59 +01:00
|
|
|
within "form#edit_form_project_#{project.id}" do
|
|
|
|
|
yield
|
|
|
|
|
end
|
2012-03-19 14:05:54 +01:00
|
|
|
submit_project_edit_form(project)
|
|
|
|
|
|
|
|
|
|
wait_for_ajax
|
|
|
|
|
wait_for_animations_to_end
|
|
|
|
|
|
|
|
|
|
page.should_not have_css("button#submit_project_#{project.id}", :visible => true)
|
2012-01-30 03:42:47 +01:00
|
|
|
end
|
|
|
|
|
|
2012-03-19 14:05:54 +01:00
|
|
|
def edit_project_settings(project)
|
|
|
|
|
edit_project(project) do
|
|
|
|
|
yield
|
|
|
|
|
end
|
2011-02-27 00:35:19 +01:00
|
|
|
end
|
2012-03-19 14:05:54 +01:00
|
|
|
|
2012-01-30 03:42:47 +01:00
|
|
|
def open_submenu_for(todo)
|
2012-02-15 21:42:06 +01:00
|
|
|
submenu_arrow = "div#line_todo_#{todo.id} img.todo-submenu"
|
2012-03-19 14:05:54 +01:00
|
|
|
page.should have_css(submenu_arrow, :visible=>true)
|
2012-02-15 21:42:06 +01:00
|
|
|
|
|
|
|
|
page.find(submenu_arrow).click
|
|
|
|
|
|
2012-03-19 14:05:54 +01:00
|
|
|
page.should have_css("div#line_todo_#{todo.id} ul#ultodo_#{todo.id}", :visible => true)
|
2011-03-08 23:28:48 +01:00
|
|
|
end
|
2011-09-13 11:15:14 +02:00
|
|
|
|
2012-01-31 16:51:20 +01:00
|
|
|
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
|
2012-03-01 20:31:16 +01:00
|
|
|
|
|
|
|
|
def project_list_find_index(project_name)
|
|
|
|
|
# TODO: refactor with context_list_find_index
|
|
|
|
|
div_id = "project_#{@current_user.projects.find_by_name(project_name).id}"
|
|
|
|
|
project = page.all("div.project").map { |x| x[:id] }
|
|
|
|
|
return project.find_index(div_id)
|
|
|
|
|
end
|
2012-03-19 14:05:54 +01:00
|
|
|
|
|
|
|
|
def wait_for_animations_to_end
|
|
|
|
|
wait_until do
|
|
|
|
|
page.evaluate_script('$(":animated").length') == 0
|
|
|
|
|
end
|
2012-03-01 20:31:16 +01:00
|
|
|
end
|
|
|
|
|
|
2012-03-19 14:05:54 +01:00
|
|
|
def wait_for_ajax
|
|
|
|
|
start_time = Time.now
|
|
|
|
|
page.evaluate_script('jQuery.isReady&&jQuery.active==0').class.should_not eql(String)
|
|
|
|
|
until(page.evaluate_script('jQuery.isReady&&jQuery.active==0') || (start_time + 5.seconds) < Time.now)
|
2013-01-06 16:01:53 +01:00
|
|
|
sleep 0.25
|
2012-03-19 14:05:54 +01:00
|
|
|
end
|
2012-03-01 20:31:16 +01:00
|
|
|
end
|
2012-03-19 14:05:54 +01:00
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
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('');")
|
2012-03-01 20:31:16 +01:00
|
|
|
end
|
|
|
|
|
|
2012-03-19 14:05:54 +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}; }"
|
2012-03-01 20:31:16 +01:00
|
|
|
yield
|
2012-03-19 14:05:54 +01:00
|
|
|
ensure
|
|
|
|
|
page.execute_script "window.confirm = window.original_confirm_function"
|
2012-03-01 20:31:16 +01:00
|
|
|
end
|
|
|
|
|
|
2012-03-19 14:05:54 +01:00
|
|
|
def get_confirm_text
|
|
|
|
|
page.evaluate_script "window.confirmMsg"
|
2012-03-01 20:31:16 +01:00
|
|
|
end
|
2012-01-31 16:51:20 +01:00
|
|
|
|
2010-07-16 14:41:04 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
World(TracksStepHelper)
|