测试rails 3中的拖放功能

时间:2011-09-20 11:18:11

标签: jquery selenium capybara

如何从rspec请求规范中模拟拖放功能?

我有#divItem元素我在#divContainer元素(jquery)中拖放。在页面刷新时,我想确保#divItem元素在#divContainer元素中。

2 个答案:

答案 0 :(得分:7)

it "should drag item to new list", :js => true do
  item = Item.create!(:title => "title 1", :group => "group 1")

  # verify that item is withing group 1
  visit items_path
  within("#group 1") do # id of a div element (or ul element)
    page.should have_content("title 1")
  end    

  item_element = find("##{item.id}")     
  new_group_element = find("#group 2")
  item_element.drag_to new_group_element

  # verify that after page reload item is withing the new group
  visit items_path
  within("#group 2") do 
    page.should have_content("title 1")
  end

end

答案 1 :(得分:2)