mirror of
https://github.com/discourse/discourse.git
synced 2024-12-28 12:23:50 +08:00
d4af30f26d
Not 100% sure why the changes in `PrettyText.format_for_email` raised this issue, but we were missing adding a link to the Discourse instance whenever we are replacing the elided part of a post with a link to either the post or the Discourse instance in the email. Also reformated the specs using better variable names (sometimes a variable named `md` would contain some html) and used the `match_html` helper for all the tests.
97 lines
2.4 KiB
Ruby
97 lines
2.4 KiB
Ruby
# 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
|
|
<details>
|
|
<summary>foo</summary>
|
|
<p>bar</p>
|
|
</details>
|
|
HTML
|
|
end
|
|
|
|
it "deletes elided content" do
|
|
cooked_html = PrettyText.cook <<~MARKDOWN
|
|
Hello World
|
|
|
|
<details class='elided'>42</details>
|
|
MARKDOWN
|
|
|
|
email_html = PrettyText.format_for_email(cooked_html)
|
|
|
|
expect(email_html).to match_html <<~HTML
|
|
<p>Hello World</p>
|
|
<a href="#{Discourse.base_url}">#{I18n.t("details.excerpt_details")}</a>
|
|
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
|
|
<p>hello</p>
|
|
Summary <a href="#{post.full_url}">#{I18n.t("details.excerpt_details")}</a>
|
|
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 <a href="#{post.full_url}">#{I18n.t("details.excerpt_details")}</a>
|
|
Second <a href="#{post.full_url}">#{I18n.t("details.excerpt_details")}</a>
|
|
<p>Hey there.</p>
|
|
Third <a href="#{post.full_url}">#{I18n.t("details.excerpt_details")}</a>
|
|
HTML
|
|
end
|
|
|
|
it "escapes summary text" do
|
|
cooked_html = PrettyText.cook <<~MARKDOWN
|
|
<script>alert('hello')</script>
|
|
|
|
[details="<script>alert('hello')</script>"]
|
|
<script>alert('hello')</script>
|
|
[/details]
|
|
MARKDOWN
|
|
|
|
email_html = PrettyText.format_for_email(cooked_html, post)
|
|
|
|
expect(email_html).to match_html <<~HTML
|
|
<script>alert('hello')</script> <a href="#{post.full_url}">#{I18n.t("details.excerpt_details")}</a>
|
|
HTML
|
|
end
|
|
end
|