Improve stability for manages_aspects.feature:79

page.execute_scripts looks to be asynchronous, .synced is already set
by default, so the previous expectation would be fulfilled before
the script got to run, running into the page reload in the next step
which then aborts or hasen't seen the to be triggered request yet.

The fix is to use Capybaras drag_to instead
This commit is contained in:
Jonne Haß 2015-06-08 14:28:00 +02:00 committed by Dennis Schubert
parent caf565681c
commit a2d894cb39
6 changed files with 11 additions and 31 deletions

View file

@ -265,11 +265,6 @@ group :test do
gem "database_cleaner" , "1.4.1"
gem "selenium-webdriver", "2.45.0"
source "https://rails-assets.org" do
gem "rails-assets-jquery-simulate", "1.0.1"
gem "rails-assets-jquery-simulate-ext", "1.3.0"
end
# General helpers
gem "factory_girl_rails", "4.5.0"

View file

@ -535,9 +535,6 @@ GEM
rails-assets-jquery-idletimer (1.0.1)
rails-assets-jquery-placeholder (2.1.1)
rails-assets-jquery (>= 1.6)
rails-assets-jquery-simulate (1.0.1)
rails-assets-jquery-simulate-ext (1.3.0)
rails-assets-jquery (>= 1.7.0)
rails-assets-jquery-textchange (0.2.3)
rails-assets-jquery
rails-assets-jquery-ui (1.10.4)
@ -826,8 +823,6 @@ DEPENDENCIES
rails-assets-jquery (= 1.11.2)!
rails-assets-jquery-idletimer (= 1.0.1)!
rails-assets-jquery-placeholder (= 2.1.1)!
rails-assets-jquery-simulate (= 1.0.1)!
rails-assets-jquery-simulate-ext (= 1.3.0)!
rails-assets-jquery-textchange (= 0.2.3)!
rails-assets-markdown-it (= 4.2.2)!
rails-assets-markdown-it--markdown-it-for-inline (= 0.1.1)!

View file

@ -81,11 +81,11 @@ app.pages.Contacts = Backbone.View.extend({
$("#aspect_nav .list-group").sortable({
items: "a.aspect[data-aspect-id]",
update: function() {
$("#aspect_nav .ui-sortable").removeClass("synced");
$("#aspect_nav .ui-sortable").addClass("syncing");
var data = JSON.stringify({ ordered_aspect_ids: $(this).sortable("toArray", { attribute: "data-aspect-id" }) });
$.ajax(Routes.orderAspects(),
{ type: "put", dataType: "text", contentType: "application/json", data: data })
.done(function() { $("#aspect_nav .ui-sortable").addClass("synced"); });
.done(function() { $("#aspect_nav .ui-sortable").removeClass("syncing"); });
},
revert: true,
helper: "clone"

View file

@ -1,5 +1,5 @@
#aspect_nav
%ul.list-group.synced.ui-sortable
%ul.list-group.ui-sortable
%a.list-group-item.ui-sortable-handle.all_contacts{class: ("active" if params["set"] == "all"), href: contacts_path(set: "all")}
= t('contacts.index.all_contacts')
.badge.badge-default.pull-right

View file

@ -81,7 +81,7 @@ Feature: User manages contacts
And I have an aspect called "People"
And I have an aspect called "Cat People"
When I am on the contacts page
And I drag "Cat People" up 40 pixels
And I drag "Cat People" up
And I go to the contacts page
Then I should see "Cat People" as 2. aspect
And I should see "People" as 3. aspect

View file

@ -88,23 +88,13 @@ When /^(.*) in the aspect creation modal$/ do |action|
end
end
When /^I drag "([^"]*)" (up|down) (\d+) pixels?$/ do |aspect_name, direction, distance|
distance = distance.to_i * -1 if direction == "up"
page.execute_script %{
function drag() {
$("a.aspect:contains('#{aspect_name}')")
.simulate("drag-n-drop", { dy: #{distance}, interpolation: { stepWidth: 10, stepDelay: 5 } });
}
function loadScripts() {
$.getScript("/assets/jquery-simulate/jquery.simulate.js", function(){
$.getScript("/assets/jquery-simulate-ext/src/jquery.simulate.ext.js", function(){
$.getScript("/assets/jquery-simulate-ext/src/jquery.simulate.drag-n-drop.js", drag);
});
});
}
if (!$.simulate) { loadScripts(); } else { drag(); }
}
expect(find("#aspect_nav")).to have_css ".synced"
When /^I drag "([^"]*)" (up|down)$/ do |aspect_name, direction|
aspect_id = @me.aspects.where(name: aspect_name).first.id
aspect = find(:xpath, "//div[@id='aspect_nav']/ul/a[@data-aspect-id='#{aspect_id}']")
target = direction == "up" ? aspect.all(:xpath, "./preceding-sibling::a").last :
aspect.all(:xpath, "./following-sibling::a").first
aspect.drag_to(target)
expect(page).to have_no_css "#aspect_nav .ui-sortable.syncing"
end
And /^I toggle the aspect "([^"]*)"$/ do |name|