From df50df041a07d8272ccdab574a8f5de615ce5afc Mon Sep 17 00:00:00 2001 From: Joffrey JAFFEUX Date: Wed, 1 Feb 2023 16:42:39 +0100 Subject: [PATCH] FIX: corrects a regression hiding avatar in user selector (#20107) Due to the way templates work, the incorrect variable (user instead of item) was not causing any error, and just failing silently to display the avatar. This commit is also providing a basic spec for completion of users and groups. --- .../templates/user-selector-autocomplete.hbr | 2 +- spec/system/user_selector_spec.rb | 38 +++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 spec/system/user_selector_spec.rb diff --git a/app/assets/javascripts/discourse/app/templates/user-selector-autocomplete.hbr b/app/assets/javascripts/discourse/app/templates/user-selector-autocomplete.hbr index 78c9c02ca2b..24f7a18cd36 100644 --- a/app/assets/javascripts/discourse/app/templates/user-selector-autocomplete.hbr +++ b/app/assets/javascripts/discourse/app/templates/user-selector-autocomplete.hbr @@ -4,7 +4,7 @@ {{#if item.isUser}}
  • - {{avatar user imageSize="tiny"}} + {{avatar item imageSize="tiny"}} {{format-username item.username}} {{#if item.name}} {{item.name}} diff --git a/spec/system/user_selector_spec.rb b/spec/system/user_selector_spec.rb new file mode 100644 index 00000000000..5e90c29121c --- /dev/null +++ b/spec/system/user_selector_spec.rb @@ -0,0 +1,38 @@ +# frozen_string_literal: true + +describe "User selector", type: :system, js: true do + fab!(:topic) { Fabricate(:topic) } + fab!(:post) { Fabricate(:post, topic: topic) } + fab!(:current_user) { Fabricate(:admin) } + + before do + current_user.activate + sign_in(current_user) + end + + context "when autocompleting a username" do + it "correctly shows the user" do + visit("/t/-/#{topic.id}") + find(".btn-primary.create").click + find(".d-editor-input").fill_in(with: "Hello @dis") + + within(".autocomplete.ac-user") do |el| + expect(el).to have_selector(".selected .avatar[title=discobot]") + expect(el.find(".selected .username")).to have_content("discobot") + end + end + end + + context "when autocompleting a group" do + it "correctly shows the user" do + visit("/t/-/#{topic.id}") + find(".btn-primary.create").click + find(".d-editor-input").fill_in(with: "Hello @adm") + + within(".autocomplete.ac-user") do |el| + expect(el).to have_selector(".selected .d-icon-users") + expect(el.find(".selected .username")).to have_content("admins") + end + end + end +end