# frozen_string_literal: true require "pretty_text" RSpec.describe PrettyText do let(:post) { Fabricate(:post) } it "supports details tag" do cooked_html = PrettyText.cook <<~MARKDOWN [details="foo"] bar [/details] MARKDOWN expect(cooked_html).to match_html <<~HTML
foo

bar

HTML end it "deletes elided content" do cooked_html = PrettyText.cook <<~MARKDOWN Hello World
42
MARKDOWN email_html = PrettyText.format_for_email(cooked_html) expect(email_html).to match_html <<~HTML

Hello World

#{I18n.t("details.excerpt_details")} HTML end it "can replace spoilers in emails" do cooked_html = PrettyText.cook <<~MARKDOWN hello [details="Summary"] world [/details] MARKDOWN email_html = PrettyText.format_for_email(cooked_html, post) expect(email_html).to match_html <<~HTML

hello

Summary #{I18n.t("details.excerpt_details")} HTML end it "properly handles multiple spoiler blocks in a post" do cooked_html = PrettyText.cook <<~MARKDOWN [details="First"] body secret stuff very long [/details] [details="Second"] body secret stuff very long [/details] Hey there. [details="Third"] body secret stuff very long [/details] MARKDOWN email_html = PrettyText.format_for_email(cooked_html, post) expect(email_html).to match_html <<~HTML First #{I18n.t("details.excerpt_details")} Second #{I18n.t("details.excerpt_details")}

Hey there.

Third #{I18n.t("details.excerpt_details")} HTML end it "escapes summary text" do cooked_html = PrettyText.cook <<~MARKDOWN [details=""] [/details] MARKDOWN email_html = PrettyText.format_for_email(cooked_html, post) expect(email_html).to match_html <<~HTML <script>alert('hello')</script> #{I18n.t("details.excerpt_details")} HTML end end