# frozen_string_literal: true require "category_badge" RSpec.describe CategoryBadge do it "escapes HTML in category names / descriptions" do c = Fabricate(:category, name: "name", description: "title") html = CategoryBadge.html_for(c) expect(html).not_to include("title") expect(html).not_to include("name") expect(html).to include("<b>name</b>") expect(html).to include("title='title'") end it "escapes code block contents" do c = Fabricate(:category, description: '\' <b id="x">') html = CategoryBadge.html_for(c) expect(html).to include("title='' <b id="x">'") end 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 it "includes inline color style when inline_style is true" do c = Fabricate(:category, color: "123456", text_color: "654321") html = CategoryBadge.html_for(c, inline_style: true) expect(html).to include("color: #654321;") expect(html).to include("background-color: #123456;") end end