Add mutations observer to initialize user initials added through ajax

This commit is contained in:
Senén Rodero Rodríguez
2020-05-14 18:43:53 +02:00
parent 956f002738
commit 014fa6eb1c
2 changed files with 21 additions and 0 deletions

View File

@@ -2,7 +2,14 @@
"use strict"; "use strict";
App.Users = { App.Users = {
initialize: function() { initialize: function() {
var observer;
$(".initialjs-avatar").initial(); $(".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); }).call(this);

View File

@@ -515,4 +515,18 @@ describe "Users" do
end end
end 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 end