Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions javascripts/discourse/initializers/tag-icons.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,16 @@ function iconTagRenderer(tag, params) {
let tagIconList = settings.tag_icon_list.split("|");

params = params || {};
const visibleName = escapeExpression(tag);
// TODO(https://github.com/discourse/discourse/pull/36678): The string check can be
// removed using .discourse-compatibility once the PR is merged.
const tagStr = typeof tag === "string" ? tag : tag.name;
const visibleName = escapeExpression(tagStr);
tag = visibleName.toLowerCase();

const classes = ["discourse-tag"];
const tagName = params.tagName || "a";
const htmlTagName = params.tagName || "a";
let path;
if (tagName === "a" && !params.noHref) {
if (htmlTagName === "a" && !params.noHref) {
if ((params.isPrivateMessage || params.pmOnly) && currentUser) {
const username = params.tagsForUser
? params.tagsForUser
Expand Down Expand Up @@ -64,7 +67,7 @@ function iconTagRenderer(tag, params) {

let val =
"<" +
tagName +
htmlTagName +
href +
" data-tag-name=" +
tag +
Expand All @@ -75,7 +78,7 @@ function iconTagRenderer(tag, params) {
tagIconHTML + // inject tag Icon in html
(params.displayName ? escape(params.displayName) : visibleName) +
"</" +
tagName +
htmlTagName +
">";

if (params.count) {
Expand Down
19 changes: 19 additions & 0 deletions spec/system/page_objects/components/tag_icon.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# frozen_string_literal: true

module PageObjects
module Components
class TagIcon < PageObjects::Components::Base
def has_icon_for_tag?(tag_name:, icon:, color: nil)
selector = ".discourse-tag[data-tag-name='#{tag_name}'] .tag-icon"
selector += "[style*='color: #{color}']" if color
selector += " .d-icon-#{icon}"
page.has_css?(selector)
end

def has_no_icon_for_tag?(tag_name:)
page.has_css?(".discourse-tag[data-tag-name='#{tag_name}']") &&
page.has_no_css?(".discourse-tag[data-tag-name='#{tag_name}'] .tag-icon")
end
end
end
end
34 changes: 34 additions & 0 deletions spec/system/tag_icons_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# frozen_string_literal: true

require_relative "page_objects/components/tag_icon"

RSpec.describe "Tag icons", type: :system do
fab!(:tag) { Fabricate(:tag, name: "support") }
fab!(:topic) { Fabricate(:topic, tags: [tag]) }
fab!(:post) { Fabricate(:post, topic:) }
fab!(:user)

let(:topic_page) { PageObjects::Pages::Topic.new }
let(:tag_icon) { PageObjects::Components::TagIcon.new }
let!(:theme) { upload_theme_component }

before do
SiteSetting.tagging_enabled = true
theme.update_setting(:tag_icon_list, "support,question-circle,#ff0000")
theme.save!
sign_in(user)
end

it "displays tag with icon on topic page" do
topic_page.visit_topic(topic)
expect(tag_icon).to have_icon_for_tag(tag_name: "support", icon: "question-circle", color: "#ff0000")
end

it "displays tag without icon when not configured" do
theme.update_setting(:tag_icon_list, "")
theme.save!

topic_page.visit_topic(topic)
expect(tag_icon).to have_no_icon_for_tag(tag_name: "support")
end
end