From 983bf49b3802e1aae539591264dc07dde3d0dfbf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Mon, 3 Aug 2020 12:17:25 +0200 Subject: [PATCH] Simplify code related to Foundation's sticky In the past we had huge problems trying to make it work with Turbolinks. However, after updating foundation-rails in commit 58071fd6, these hacks aren't necessary anymore. We're adding a test for the scenario of visiting a page using Turbolinks, which was missing, so we're sure we aren't breaking anything. Note the sticky will still not work after using the browser back button. We haven't been able to make it work with turbolinks-classic; we'll fix this issue when upgrading turbolinks. --- app/assets/javascripts/foundation_extras.js | 21 --------------------- spec/system/proposals_spec.rb | 17 +++++++++++++++-- 2 files changed, 15 insertions(+), 23 deletions(-) diff --git a/app/assets/javascripts/foundation_extras.js b/app/assets/javascripts/foundation_extras.js index c6e344684..de709505d 100644 --- a/app/assets/javascripts/foundation_extras.js +++ b/app/assets/javascripts/foundation_extras.js @@ -1,29 +1,8 @@ (function() { "use strict"; App.FoundationExtras = { - clearSticky: function() { - if ($("[data-sticky]").length) { - $("[data-sticky]").foundation("destroy"); - } - }, - mobile_ui_init: function() { - $(window).trigger("load.zf.sticky"); - }, - desktop_ui_init: function() { - $(window).trigger("init.zf.sticky"); - }, initialize: function() { $(document).foundation(); - $(window).trigger("resize"); - $(document).on("page:before-unload", this.clearSticky); - window.addEventListener("popstate", this.clearSticky, false); - $(function() { - if ($(window).width() < 620) { - App.FoundationExtras.mobile_ui_init(); - } else { - App.FoundationExtras.desktop_ui_init(); - } - }); } }; }).call(this); diff --git a/spec/system/proposals_spec.rb b/spec/system/proposals_spec.rb index 6374057cf..986fb7daf 100644 --- a/spec/system/proposals_spec.rb +++ b/spec/system/proposals_spec.rb @@ -200,7 +200,7 @@ describe "Proposals" do end end - context "Show on mobile screens" do + describe "Show sticky support button on mobile screens", :js do let!(:window_size) { Capybara.current_window.size } before do @@ -211,7 +211,7 @@ describe "Proposals" do Capybara.current_window.resize_to(*window_size) end - scenario "Show support button sticky at bottom", :js do + scenario "On a first visit" do proposal = create(:proposal) visit proposal_path(proposal) @@ -220,6 +220,19 @@ describe "Proposals" do expect(page).not_to have_css(".is-anchored") end end + + scenario "After visiting another page" do + proposal = create(:proposal) + + visit proposal_path(proposal) + click_link "Go back" + click_link proposal.title + + within("#proposal_sticky") do + expect(page).to have_css(".is-stuck") + expect(page).not_to have_css(".is-anchored") + end + end end context "Embedded video" do