# frozen_string_literal: true RSpec.describe PostStripper do it "strips mentions in quotes" do mention = '@andrei' cooked = "" fragment = Nokogiri::HTML5.fragment(cooked) PostStripper.strip(fragment) expect(fragment.to_s).to_not include(mention) end it "strips group mentions in quotes" do group_mention = '@moderators' cooked = "" fragment = Nokogiri::HTML5.fragment(cooked) PostStripper.strip(fragment) expect(fragment.to_s).to_not include(group_mention) end it "strips oneboxes" do onebox = '' cooked = "

#{onebox}

" fragment = Nokogiri::HTML5.fragment(cooked) PostStripper.strip(fragment) expect(fragment.to_s).to_not include(onebox) end context "with plugins" do after { DiscoursePluginRegistry.reset_register!(:post_strippers) } it "runs strippers registered by plugins" do plugin_element = '
' block = Proc.new { |nokogiri_fragment| nokogiri_fragment.css(".plugin_class").remove } plugin = OpenStruct.new(enabled?: true) DiscoursePluginRegistry.register_post_stripper({ block: block }, plugin) fragment = Nokogiri::HTML5.fragment("

#{plugin_element}

") PostStripper.strip(fragment) expect(fragment.to_s).to_not include(plugin_element) end end end