From a2d894cb391c0d2afbe6a22187990eb5a0ede8b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonne=20Ha=C3=9F?= Date: Mon, 8 Jun 2015 14:28:00 +0200 Subject: [PATCH] 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 --- Gemfile | 5 ---- Gemfile.lock | 5 ---- app/assets/javascripts/app/pages/contacts.js | 4 ++-- app/views/contacts/_aspect_listings.haml | 2 +- features/desktop/manages_aspects.feature | 2 +- features/step_definitions/aspects_steps.rb | 24 ++++++-------------- 6 files changed, 11 insertions(+), 31 deletions(-) diff --git a/Gemfile b/Gemfile index 48a069fd2..d49e1e543 100644 --- a/Gemfile +++ b/Gemfile @@ -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" diff --git a/Gemfile.lock b/Gemfile.lock index 46ca4e7aa..6f4db9d8b 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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)! diff --git a/app/assets/javascripts/app/pages/contacts.js b/app/assets/javascripts/app/pages/contacts.js index a0d01c8e6..6e31af66a 100644 --- a/app/assets/javascripts/app/pages/contacts.js +++ b/app/assets/javascripts/app/pages/contacts.js @@ -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" diff --git a/app/views/contacts/_aspect_listings.haml b/app/views/contacts/_aspect_listings.haml index f7c52d6bc..0c0ba5927 100644 --- a/app/views/contacts/_aspect_listings.haml +++ b/app/views/contacts/_aspect_listings.haml @@ -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 diff --git a/features/desktop/manages_aspects.feature b/features/desktop/manages_aspects.feature index be0f4bc3f..7df4f0f2a 100644 --- a/features/desktop/manages_aspects.feature +++ b/features/desktop/manages_aspects.feature @@ -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 diff --git a/features/step_definitions/aspects_steps.rb b/features/step_definitions/aspects_steps.rb index c56eeeddd..b29946ece 100644 --- a/features/step_definitions/aspects_steps.rb +++ b/features/step_definitions/aspects_steps.rb @@ -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|