2013-04-17 22:11:24 +02:00
|
|
|
module TracksStepHelper
|
|
|
|
|
|
2014-09-09 22:52:45 -04:00
|
|
|
def wait_until(wait_time = Capybara.default_wait_time)
|
|
|
|
|
Timeout.timeout(wait_time) do
|
|
|
|
|
loop until yield
|
2013-04-17 22:11:24 +02:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def wait_for_animations_to_end
|
|
|
|
|
wait_until do
|
2014-09-09 22:52:45 -04:00
|
|
|
page.evaluate_script('$(":animated").length').zero?
|
2013-04-17 22:11:24 +02:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def wait_for_ajax
|
2014-09-09 22:52:45 -04:00
|
|
|
wait_until do
|
|
|
|
|
page.evaluate_script('jQuery.active').zero?
|
2013-04-17 22:11:24 +02:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def wait_for_auto_complete
|
2014-05-16 15:42:03 -04:00
|
|
|
expect(page).to have_css("a.ui-state-focus", :visible => true)
|
2013-04-17 22:11:24 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def click_first_line_of_auto_complete
|
|
|
|
|
page.find(:css, "ul li a.ui-state-focus").click
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def check_xpath_visibility(visible, xpath)
|
2014-06-25 17:27:33 -04:00
|
|
|
expect(page).send( (visible=="see" ? :to : :to_not), have_xpath(xpath, :visible => true))
|
2013-04-17 22:11:24 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def check_css_visibility(visible, css)
|
2014-06-25 17:27:33 -04:00
|
|
|
expect(page).send( (visible=="see" ? :to : :to_not), have_css(css, :visible => true))
|
2013-04-17 22:11:24 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def check_elem_visibility(visible, elem)
|
2014-06-25 17:27:33 -04:00
|
|
|
expect(elem).send( (visible=="see" ? :to : :to_not), be_visible)
|
2013-04-17 22:11:24 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def find_todo(description)
|
|
|
|
|
todo = @current_user.todos.where(:description => description).first
|
2014-05-16 15:42:03 -04:00
|
|
|
expect(todo).to_not be_nil
|
2013-04-17 22:11:24 +02:00
|
|
|
return todo
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def find_context(context_name)
|
|
|
|
|
context = @current_user.contexts.where(:name => context_name).first
|
2014-05-16 15:42:03 -04:00
|
|
|
expect(context).to_not be_nil
|
2013-04-17 22:11:24 +02:00
|
|
|
return context
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def find_project(project_name)
|
|
|
|
|
project = @current_user.projects.where(:name => project_name).first
|
2014-05-16 15:42:03 -04:00
|
|
|
expect(project).to_not be_nil
|
2013-04-17 22:11:24 +02:00
|
|
|
return project
|
2013-05-03 19:28:26 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def container_list_find_index(container, object)
|
|
|
|
|
div_id = "#{container}_#{object.id}"
|
|
|
|
|
containers = page.all("div.#{container}").map { |x| x[:id] }
|
|
|
|
|
return containers.find_index(div_id)
|
|
|
|
|
end
|
2013-04-17 22:11:24 +02:00
|
|
|
|
|
|
|
|
def context_list_find_index(context_name)
|
2013-05-03 19:28:26 +02:00
|
|
|
return container_list_find_index(:context, find_context(context_name))
|
2013-04-17 22:11:24 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def project_list_find_index(project_name)
|
2013-05-03 19:28:26 +02:00
|
|
|
return container_list_find_index(:project, find_project(project_name))
|
2013-04-17 22:11:24 +02:00
|
|
|
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
|
|
|
|
|
|
2013-04-19 22:55:54 +02:00
|
|
|
def context_drag_and_drop(drag_id, delta)
|
|
|
|
|
sortable_css = "div.ui-sortable div#container_context_#{drag_id}"
|
|
|
|
|
execute_javascript("$('#{sortable_css}').simulateDragSortable({move: #{delta}, handle: '.grip'});")
|
|
|
|
|
end
|
|
|
|
|
|
2013-06-11 16:13:46 +02:00
|
|
|
def open_view_menu
|
|
|
|
|
view_menu = "ul.sf-menu li#menu_view"
|
|
|
|
|
|
|
|
|
|
# click menu
|
|
|
|
|
view_menu_link = "#{view_menu} a#menu_view_link"
|
2014-05-16 15:42:03 -04:00
|
|
|
expect(page).to have_css(view_menu_link, :visible => true)
|
2013-06-11 16:13:46 +02:00
|
|
|
page.find(view_menu_link).click
|
|
|
|
|
|
|
|
|
|
# wait for menu to be visible
|
|
|
|
|
view_menu_item = "#{view_menu} li#menu_view_toggle_contexts"
|
2014-05-16 15:42:03 -04:00
|
|
|
expect(page).to have_css(view_menu_item)
|
2013-06-11 16:13:46 +02:00
|
|
|
|
|
|
|
|
within view_menu do
|
|
|
|
|
yield
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2013-04-17 22:11:24 +02:00
|
|
|
def open_submenu_for(todo)
|
2014-01-09 11:18:33 +01:00
|
|
|
wait_for_animations_to_end
|
|
|
|
|
|
2013-04-29 09:31:15 +02:00
|
|
|
submenu_css = "div#line_todo_#{todo.id} ul#ultodo_#{todo.id}"
|
2014-09-10 01:00:09 -04:00
|
|
|
|
|
|
|
|
execute_javascript "$('#{submenu_css}').parent().showSuperfishUl()"
|
|
|
|
|
|
2014-09-09 22:52:45 -04:00
|
|
|
expect(page).to have_css(submenu_css, visible: true)
|
2015-04-12 22:11:22 +02:00
|
|
|
submenu = page.first(submenu_css, visible: true)
|
2013-04-29 09:31:15 +02:00
|
|
|
|
|
|
|
|
within submenu do
|
2013-04-17 22:11:24 +02:00
|
|
|
yield
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def handle_js_confirm(accept=true)
|
2013-04-19 22:55:54 +02:00
|
|
|
execute_javascript "window.original_confirm_function = window.confirm"
|
|
|
|
|
execute_javascript "window.confirmMsg = null"
|
|
|
|
|
execute_javascript "window.confirm = function(msg) { window.confirmMsg = msg; return #{!!accept}; }"
|
2013-04-17 22:11:24 +02:00
|
|
|
yield
|
|
|
|
|
ensure
|
2013-04-19 22:55:54 +02:00
|
|
|
execute_javascript "window.confirm = window.original_confirm_function"
|
2013-04-17 22:11:24 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def get_confirm_text
|
|
|
|
|
page.evaluate_script "window.confirmMsg"
|
|
|
|
|
end
|
2013-04-29 09:31:15 +02:00
|
|
|
|
|
|
|
|
def execute_javascript(js)
|
|
|
|
|
page.execute_script(js)
|
|
|
|
|
end
|
2013-04-17 22:11:24 +02:00
|
|
|
|
2014-05-16 15:42:03 -04:00
|
|
|
end
|