From 5d2e2677c0c11655db6efb4739034d31fb024bbc Mon Sep 17 00:00:00 2001 From: Alan Guo Xiang Tan Date: Wed, 14 Dec 2022 07:14:01 +0800 Subject: [PATCH] FIX: Invalid route path for staff info warnings link (#19461) This regressed in 4da2e3fef4102e0d3d2f24a4b0c54d4431755391 --- .../discourse/app/templates/user.hbs | 4 ++-- spec/system/page_objects/pages/user.rb | 15 ++++++++++++ spec/system/user_page/staff_info_spec.rb | 24 +++++++++++++++++++ 3 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 spec/system/user_page/staff_info_spec.rb diff --git a/app/assets/javascripts/discourse/app/templates/user.hbs b/app/assets/javascripts/discourse/app/templates/user.hbs index 80b308b0132..47c2ecaa401 100644 --- a/app/assets/javascripts/discourse/app/templates/user.hbs +++ b/app/assets/javascripts/discourse/app/templates/user.hbs @@ -39,8 +39,8 @@ {{/if}} {{#if this.model.warnings_received_count}}
- - {{this.model.warnings_received_count}}{{i18n "user.staff_counters.warnings_received"}} + + {{this.model.warnings_received_count}} {{i18n "user.staff_counters.warnings_received"}}
{{/if}} diff --git a/spec/system/page_objects/pages/user.rb b/spec/system/page_objects/pages/user.rb index 82115d893b9..a5062bafe5f 100644 --- a/spec/system/page_objects/pages/user.rb +++ b/spec/system/page_objects/pages/user.rb @@ -3,6 +3,11 @@ module PageObjects module Pages class User < PageObjects::Pages::Base + def visit(user) + page.visit("/u/#{user.username}") + self + end + def find(selector) page.find(".user-content-wrapper #{selector}") end @@ -14,6 +19,16 @@ module PageObjects def active_user_secondary_navigation find(".user-secondary-navigation li a.active") end + + def has_warning_messages_path?(user) + page.has_current_path?("/u/#{user.username}/messages/warnings") + end + + def click_staff_info_warnings_link(warnings_count: 0) + staff_counters = page.find(".staff-counters") + staff_counters.click_link("#{warnings_count} #{I18n.t("js.user.staff_counters.warnings_received")}") + self + end end end end diff --git a/spec/system/user_page/staff_info_spec.rb b/spec/system/user_page/staff_info_spec.rb new file mode 100644 index 00000000000..ef58f4adf14 --- /dev/null +++ b/spec/system/user_page/staff_info_spec.rb @@ -0,0 +1,24 @@ +# frozen_string_literal: true + +describe 'Viewing user staff info as an admin', type: :system, js: true do + fab!(:user) { Fabricate(:user) } + fab!(:admin) { Fabricate(:admin) } + let(:user_page) { PageObjects::Pages::User.new } + + before do + sign_in(admin) + end + + context 'for warnings' do + fab!(:topic) { Fabricate(:private_message_topic, user: admin, recipient: user) } + fab!(:user_warning) { UserWarning.create!(user: user, created_by: admin, topic: topic) } + + it "should display the right link to user's warnings with the right count in text" do + user_page + .visit(user) + .click_staff_info_warnings_link(warnings_count: 1) + + expect(user_page).to have_warning_messages_path(user) + end + end +end