finish drag and drop for context list. Works even for webkit :-)

This commit is contained in:
Reinier Balt 2012-01-31 16:51:20 +01:00
parent 4a8fdbabc2
commit c8ab797924
5 changed files with 14 additions and 29 deletions

View file

@ -12,7 +12,7 @@
<%= javascript_include_tag 'hoverIntent','superfish','application',
'accesskey-hints','niftycube','swfobject',
:cache => 'tracks-cached' %>
<%= javascript_include_tag('jquery.simulate.drag-sortable') if ENV['RAILS_ENV']=='test' -%>
<%= javascript_include_tag('jquery.simulate.drag-sortable') if ENV['RAILS_ENV']=='cucumber' -%>
<%= javascript_tag "var AUTH_TOKEN = #{form_authenticity_token.inspect};" if protect_against_forgery? %>
<%= javascript_tag "var SOURCE_VIEW = '#{@source_view}';" %>
<%= javascript_tag "var TAG_NAME = '#{@tag_name}';" if @tag_name %>

View file

@ -42,37 +42,16 @@ end
When /^I drag context "([^"]*)" above context "([^"]*)"$/ do |context_drag, context_drop|
drag_id = @current_user.contexts.find_by_name(context_drag).id
drop_id = @current_user.contexts.find_by_name(context_drop).id
sortable_css = "div.ui-sortable div#container_context_#{drag_id}"
# container_height = page.driver.get_element_height("//div[@id='container_context_#{drag_id}']").to_i
# vertical_offset = container_height*2
# coord_string = "10,#{vertical_offset}"
drag_index = context_list_find_index(context_drag)
drop_index = context_list_find_index(context_drop)
drag_context_handle = find("div#context_#{drag_id} span.handle")
drag_context_handle.text.should == "DRAG"
drop_context_container = find("div#container_context_#{drop_id}")
drag_context_handle.drag_to(drop_context_container)
# TODO: omzetten naar volgende script
page.execute_script %Q{
$('.sortable-books li:last').simulateDragSortable({move: -4});
}
sleep(5)
# page.driver.mouse_down_at(drag_context_handle_xpath,"2,2")
# page.driver.mouse_move_at(drop_context_container_xpath,coord_string)
# # no need to simulate mouse_over for this test
# page.driver.mouse_up_at(drop_context_container_xpath,coord_string)
page.execute_script "$('#{sortable_css}').simulateDragSortable({move: #{drop_index-drag_index}, handle: '.handle'});"
end
Then /^context "([^"]*)" should be above context "([^"]*)"$/ do |context_high, context_low|
high_id = "context_#{@current_user.contexts.find_by_name(context_high).id}"
low_id = "context_#{@current_user.contexts.find_by_name(context_low).id}"
contexts = page.all("div.context").map { |x| x[:id] }
contexts.find_index(high_id).should < contexts.find_index(low_id)
context_list_find_index(context_high).should < context_list_find_index(context_low)
end
Then /^I should see that a context named "([^"]*)" is not present$/ do |context_name|

View file

@ -19,7 +19,7 @@ require 'capybara/session'
# BUG in this version of cucumber/capybara: require 'cucumber/rails/capybara_javascript_emulation' # Lets you click links with onclick javascript handlers without using @culerity or @javascript
Capybara.default_wait_time = 5
Capybara.javascript_driver = :selenium
Capybara.javascript_driver = :webkit
if Capybara.javascript_driver == :webkit
require 'capybara/webkit'

View file

@ -82,6 +82,12 @@ module TracksStepHelper
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
end
World(TracksStepHelper)