Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I test JQuery UI Sortable with Cucumber

I'm tryting to write a cucumber/capybara test to reorder some items and then save them back. Any thoughts on how to best do this?

like image 661
smcdrc Avatar asked Oct 28 '10 15:10

smcdrc


People also ask

How to create a sortable widget using jQuery UI sortable update?

It can be used to build highly interactive web applications or can be used to add widgets easily. The jQuery UI Sortable update event is used to trigger when the user stopped sorting and the DOM position has changed. Initialize the sortable widget with the update callback function. Bind an event listener to the sortable update event.

How to reorder elements in a list or grid using jQuery UI?

Description: Reorder elements in a list or grid using the mouse. The jQuery UI Sortable plugin makes selected elements sortable by dragging with the mouse. Note: In order to sort table rows, the tbody must be made sortable, not the table. The sortable widget uses the jQuery UI CSS framework to style its look and feel.

How to connect two sortable elements in a list?

A selector of other sortable elements that the items from this list should be connected to. This is a one-way relationship, if you want the items to be connected in both directions, the connectWith option must be set on both sortable elements. Initialize the sortable with the connectWith option specified:

How do I sort a sortable using cursorat?

Defines the cursor that is being shown while sorting. Moves the sorting element or helper so the cursor always appears to drag from the same position. Coordinates can be given as a hash using a combination of one or two keys: { top, left, right, bottom }. Initialize the sortable with the cursorAt option specified:


2 Answers

I have developed a JQuery plugin to solve this problem, check out jquery.simulate.drag-sortable.js which includes a plugin along with a suite of tests and examples.

Hope you find this useful! Feedback is welcome.

Matt

like image 142
Matthew O'Riordan Avatar answered Sep 30 '22 14:09

Matthew O'Riordan


the drag_to method did not work for me. But I was able to cause the first element in my list to be dragged to the last position by including the following in my capybara selenium test using jquery.simulate.js :

page.execute_script %Q{
  $.getScript("/javascripts/jquery.simulate.js", function(){ 
    distance_between_elements = $('.task:nth-child(2)').offset().top - $('.task:nth-child(1)').offset().top;
    height_of_elements = $('.task:nth-child(1)').height();
    dy = (distance_between_elements * ( $('.task').size() - 1 )) + height_of_elements/2;

    first = $('.task:first');
    first.simulate('drag', {dx:0, dy:dy});
  });
}                 
like image 40
Francois Avatar answered Sep 30 '22 14:09

Francois