From 137e0f5a64e11f2bc36dfdd641789e536a2fc666 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sen=C3=A9n=20Rodero=20Rodr=C3=ADguez?= Date: Mon, 27 Jul 2020 12:53:33 +0200 Subject: [PATCH] Remove description for screen readers It was being duplicated when restoring a page by using browser history. With this solution we will avoid to have screen readers descriptions more than once inside any sociual share button. --- app/assets/javascripts/application.js | 1 + app/assets/javascripts/social_share.js | 3 +++ spec/system/proposals_spec.rb | 12 ++++++++++++ 3 files changed, 16 insertions(+) diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index d9298762b..184fb3aa2 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -173,6 +173,7 @@ var destroy_non_idempotent_modules = function() { App.Datepicker.destroy(); App.HTMLEditor.destroy(); App.LegislationAnnotatable.destroy(); + App.SocialShare.destroy(); }; $(document).on("turbolinks:load", initialize_modules); diff --git a/app/assets/javascripts/social_share.js b/app/assets/javascripts/social_share.js index 34ae229ac..eb75fe479 100644 --- a/app/assets/javascripts/social_share.js +++ b/app/assets/javascripts/social_share.js @@ -5,6 +5,9 @@ $(".social-share-button a").each(function() { $(this).append("" + ($(this).data("site")) + ""); }); + }, + destroy: function() { + $(".social-share-button a .show-for-sr").remove(); } }; }).call(this); diff --git a/spec/system/proposals_spec.rb b/spec/system/proposals_spec.rb index d0978fa18..cd84e2c5b 100644 --- a/spec/system/proposals_spec.rb +++ b/spec/system/proposals_spec.rb @@ -198,6 +198,18 @@ describe "Proposals" do expect(page).not_to have_link("No comments", href: "#comments") end end + + scenario "After using the browser's back button, social buttons will have one screen reader", :js do + proposal = create(:proposal) + visit proposal_path(proposal) + click_link "Help" + + expect(page).to have_content "CONSUL is a platform for citizen participation" + + go_back + + expect(page).to have_css "span.show-for-sr", text: "twitter", count: 1 + end end describe "Show sticky support button on mobile screens", :js do