2019-04-30 10:27:42 +10:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-06-28 18:14:55 +10:00
|
|
|
require "category_badge"
|
|
|
|
|
2022-07-28 05:27:38 +03:00
|
|
|
RSpec.describe CategoryBadge do
|
2018-06-28 18:14:55 +10:00
|
|
|
it "escapes HTML in category names / descriptions" do
|
|
|
|
c = Fabricate(:category, name: "<b>name</b>", description: "<b>title</b>")
|
|
|
|
|
|
|
|
html = CategoryBadge.html_for(c)
|
|
|
|
|
|
|
|
expect(html).not_to include("<b>title</b>")
|
|
|
|
expect(html).not_to include("<b>name</b>")
|
2024-02-09 15:29:11 -05:00
|
|
|
expect(html).to include("<b>name</b>")
|
2018-06-28 18:14:55 +10:00
|
|
|
expect(html).to include("title='title'")
|
|
|
|
end
|
2019-10-01 18:04:40 +02:00
|
|
|
|
|
|
|
it "escapes code block contents" do
|
|
|
|
c = Fabricate(:category, description: '<code>\' <b id="x"></code>')
|
|
|
|
html = CategoryBadge.html_for(c)
|
|
|
|
|
2023-02-27 12:48:48 +11:00
|
|
|
expect(html).to include("title='' <b id="x">'")
|
2019-10-01 18:04:40 +02:00
|
|
|
end
|
2023-12-06 17:49:19 +00:00
|
|
|
|
|
|
|
it "includes color vars" do
|
|
|
|
c = Fabricate(:category, color: "123456", text_color: "654321")
|
|
|
|
html = CategoryBadge.html_for(c)
|
|
|
|
|
|
|
|
expect(html).to have_tag(
|
|
|
|
"span[data-category-id]",
|
|
|
|
with: {
|
|
|
|
style: "--category-badge-color: #123456; --category-badge-text-color: #654321;",
|
|
|
|
},
|
|
|
|
)
|
|
|
|
end
|
2024-02-09 15:29:11 -05:00
|
|
|
|
|
|
|
it "includes inline color style when inline_style is true" do
|
2024-02-13 10:18:36 -05:00
|
|
|
c = Fabricate(:category, color: "123456")
|
2024-02-09 15:29:11 -05:00
|
|
|
|
|
|
|
html = CategoryBadge.html_for(c, inline_style: true)
|
|
|
|
|
|
|
|
expect(html).to include("background-color: #123456;")
|
|
|
|
end
|
2018-06-28 18:14:55 +10:00
|
|
|
end
|