# frozen_string_literal: true require 'rails_helper' require 'email' describe Email::Styles do def basic_fragment(html) styler = Email::Styles.new(html) styler.format_basic Nokogiri::HTML5.fragment(styler.to_html) end def html_fragment(html) styler = Email::Styles.new(html) styler.format_basic styler.format_html Nokogiri::HTML5.fragment(styler.to_html) end context "basic formatter" do it "works with an empty string" do style = Email::Styles.new("") style.format_basic expect(style.to_html).to be_blank end it "adds a max-width to large images" do frag = basic_fragment("") expect(frag.at("img")["style"]).to match("max-width") end it "adds a width and height to emojis" do frag = basic_fragment("") expect(frag.at("img")["width"]).to eq("20") expect(frag.at("img")["height"]).to eq("20") end it "adds a width and height to custom emojis" do frag = basic_fragment("") expect(frag.at("img")["width"]).to eq("20") expect(frag.at("img")["height"]).to eq("20") end it "converts relative paths to absolute paths" do frag = basic_fragment("") expect(frag.at("img")["src"]).to eq("#{Discourse.base_url}/some-image.png") end it "strips classes and ids" do frag = basic_fragment("
" do fragment = html_fragment('') expect(fragment.to_s.squish).to match(/^$/) end end context "replace_relative_urls" do it "replaces secure media within a link with a placeholder" do frag = html_fragment("") expect(frag.at('p.secure-media-notice')).to be_present expect(frag.at('img')).not_to be_present expect(frag.at('a')).not_to be_present end it "replaces secure images with a placeholder" do frag = html_fragment("") expect(frag.at('p.secure-media-notice')).to be_present expect(frag.at('img')).not_to be_present end it "does not replace topic links with secure-media-uploads in the name" do frag = html_fragment("Visit Topic") expect(frag.at('p.secure-media-notice')).not_to be_present end end end