A platform for community discussion. Free, open, simple.
UX: add filter button to user card of deactivated account (#36024)
Yuriy Kurant4793193c0b7b
diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rbindex 45f707873dd..d88e12ff1f7 100644--- a/app/controllers/users_controller.rb+++ b/app/controllers/users_controller.rb@@ -126,6 +126,7 @@ class UsersController < ApplicationControlleruser_serializer = nilif !current_user&.staff? && [email protected]?user_serializer = InactiveUserSerializer.new(@user, scope: guardian, root: "user")+ assign_topic_post_count(user_serializer) if for_cardelsif !guardian.can_see_profile?(@user)user_serializer = HiddenProfileSerializer.new(@user, scope: guardian, root: "user")assign_topic_post_count(user_serializer) if for_carddiff --git a/app/serializers/inactive_user_serializer.rb b/app/serializers/inactive_user_serializer.rbindex f76a02e6cf7..e3b13bd4d4e 100644--- a/app/serializers/inactive_user_serializer.rb+++ b/app/serializers/inactive_user_serializer.rb@@ -1,9 +1,15 @@# frozen_string_literal: trueclass InactiveUserSerializer < BasicUserSerializer- attributes :inactive+ attr_accessor :topic_post_count++ attributes :inactive, :topic_post_countdef inactive!object.active?end++ def include_topic_post_count?+ topic_post_count.present?+ endenddiff --git a/spec/system/page_objects/components/user_card.rb b/spec/system/page_objects/components/user_card.rbindex e655f5a5829..f1ddd0941a0 100644--- a/spec/system/page_objects/components/user_card.rb+++ b/spec/system/page_objects/components/user_card.rb@@ -3,28 +3,39 @@module PageObjectsmodule Componentsclass UserCard < PageObjects::Components::Base+ USER_CARD_SELECTOR = ".user-card"+ FILTER_BUTTON_SELECTOR = "#{USER_CARD_SELECTOR} .usercard-controls .d-icon-filter"+def visible?- has_css?("#user-card")+ has_css?(USER_CARD_SELECTOR)enddef showing_user?(username)- has_css?("#user-card.user-card-#{username}")+ has_css?("#{USER_CARD_SELECTOR}.user-card-#{username}")enddef has_filter_button?- has_css?("#user-card .usercard-controls .d-icon-filter")+ has_css?(FILTER_BUTTON_SELECTOR)enddef has_no_filter_button?- has_no_css?("#user-card .usercard-controls .d-icon-filter")+ has_no_css?(FILTER_BUTTON_SELECTOR)enddef filter_button_text- find("#user-card .usercard-controls .d-icon-filter + .d-button-label").text+ find("#{FILTER_BUTTON_SELECTOR} + .d-button-label").text+ end++ def click_filter_button+ find("#{FILTER_BUTTON_SELECTOR} + .d-button-label").clickenddef has_profile_hidden?- has_css?("#user-card .profile-hidden", visible: true)+ has_css?("#{USER_CARD_SELECTOR} .profile-hidden", visible: true)+ end++ def has_inactive_user?+ has_css?("#{USER_CARD_SELECTOR} .inactive-user", visible: true)endendenddiff --git a/spec/system/page_objects/pages/topic.rb b/spec/system/page_objects/pages/topic.rbindex e1db87a13ca..f4a76b46626 100644--- a/spec/system/page_objects/pages/topic.rb+++ b/spec/system/page_objects/pages/topic.rb@@ -337,6 +337,10 @@ module PageObjectswithin(post_by_number(post)) { yield }end+ def has_filtered_notice_text?(text)+ find(".posts-filtered-notice").has_text?(text, exact: false)+ end+privatedef within_topic_footer_buttonsdiff --git a/spec/system/user_card_spec.rb b/spec/system/user_card_spec.rbindex 268a4bb9abe..4477f263761 100644--- a/spec/system/user_card_spec.rb+++ b/spec/system/user_card_spec.rb@@ -74,6 +74,34 @@ describe "User Card", type: :system doexpect(user_card).to have_profile_hiddenexpect(user_card).to have_filter_buttonexpect(user_card.filter_button_text).to match(I18n.t("js.topic.filter_to", count: 2))++ user_card.click_filter_button+ expect(topic_page).to have_filtered_notice_text(+ I18n.t("js.post.filtered_replies.viewing_posts_by", post_count: 2),+ )+ end+ end++ context "when user is deactivated" do+ before do+ another_user.update!(active: false)+ # Sign in as regular user (not admin) to see deactivated user behavior+ sign_in(user)+ end++ it "shows filter button with post count for deactivated user" do+ topic_page.visit_topic(topic)+ topic_page.click_post_author_avatar(first_post_by_another_user)++ expect(user_card).to be_showing_user(another_user.username)+ expect(user_card).to have_inactive_user+ expect(user_card).to have_filter_button+ expect(user_card.filter_button_text).to match(I18n.t("js.topic.filter_to", count: 2))++ user_card.click_filter_button+ expect(topic_page).to have_filtered_notice_text(+ I18n.t("js.post.filtered_replies.viewing_posts_by", post_count: 2),+ )endendend