diff --git a/app/assets/javascripts/users.js b/app/assets/javascripts/users.js index 8f8f8ccfa..8608f4d30 100644 --- a/app/assets/javascripts/users.js +++ b/app/assets/javascripts/users.js @@ -2,7 +2,14 @@ "use strict"; App.Users = { initialize: function() { + var observer; $(".initialjs-avatar").initial(); + observer = new MutationObserver(function(mutations) { + $.each(mutations, function(index, mutation) { + $(mutation.addedNodes).find(".initialjs-avatar").initial(); + }); + }); + observer.observe(document.body, { childList: true, subtree: true }); } }; }).call(this); diff --git a/spec/system/users_spec.rb b/spec/system/users_spec.rb index 778ecdb7b..d15cb7330 100644 --- a/spec/system/users_spec.rb +++ b/spec/system/users_spec.rb @@ -515,4 +515,18 @@ describe "Users" do end end end + + describe "Initials" do + scenario "display SVG avatars when loaded into the DOM", :js do + login_as(create(:user)) + visit debate_path(create(:debate)) + + fill_in "Leave your comment", with: "I'm awesome" + click_button "Publish comment" + + within ".comment", text: "I'm awesome" do + expect(page).to have_css "img.initialjs-avatar[src^='data:image/svg']" + end + end + end end