2019-05-03 08:17:27 +10:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-07-06 19:46:47 +02:00
|
|
|
require "pretty_text"
|
|
|
|
|
2022-07-28 05:27:38 +03:00
|
|
|
RSpec.describe PrettyText do
|
2019-05-24 18:57:03 +03:00
|
|
|
let(:post) { Fabricate(:post) }
|
|
|
|
|
2016-07-06 19:46:47 +02:00
|
|
|
it "supports details tag" do
|
2024-05-22 10:42:58 +02:00
|
|
|
cooked_html = PrettyText.cook <<~MARKDOWN
|
|
|
|
[details="foo"]
|
|
|
|
bar
|
|
|
|
[/details]
|
|
|
|
MARKDOWN
|
|
|
|
|
|
|
|
expect(cooked_html).to match_html <<~HTML
|
2017-07-18 14:44:49 -04:00
|
|
|
<details>
|
2024-05-22 10:42:58 +02:00
|
|
|
<summary>foo</summary>
|
|
|
|
<p>bar</p>
|
2017-07-18 14:44:49 -04:00
|
|
|
</details>
|
|
|
|
HTML
|
2018-02-08 00:01:11 +01:00
|
|
|
end
|
|
|
|
|
2024-10-08 11:13:44 +09:00
|
|
|
it "supports open attribute" do
|
|
|
|
cooked_html = PrettyText.cook <<~MARKDOWN
|
|
|
|
[details open]
|
|
|
|
bar
|
|
|
|
[/details]
|
|
|
|
MARKDOWN
|
|
|
|
|
|
|
|
expect(cooked_html).to match_html <<~HTML
|
|
|
|
<details open="">
|
|
|
|
<summary></summary>
|
|
|
|
<p>bar</p>
|
|
|
|
</details>
|
|
|
|
HTML
|
|
|
|
end
|
|
|
|
|
2018-02-08 00:01:11 +01:00
|
|
|
it "deletes elided content" do
|
2024-05-22 10:42:58 +02:00
|
|
|
cooked_html = PrettyText.cook <<~MARKDOWN
|
|
|
|
Hello World
|
2024-10-08 11:13:44 +09:00
|
|
|
|
2024-05-22 10:42:58 +02:00
|
|
|
<details class='elided'>42</details>
|
|
|
|
MARKDOWN
|
2018-02-08 00:01:11 +01:00
|
|
|
|
2024-05-22 10:42:58 +02:00
|
|
|
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
|
2016-07-06 19:46:47 +02:00
|
|
|
end
|
|
|
|
|
2019-05-24 18:57:03 +03:00
|
|
|
it "can replace spoilers in emails" do
|
2024-05-22 10:42:58 +02:00
|
|
|
cooked_html = PrettyText.cook <<~MARKDOWN
|
2019-05-24 18:57:03 +03:00
|
|
|
hello
|
|
|
|
|
|
|
|
[details="Summary"]
|
|
|
|
world
|
|
|
|
[/details]
|
2024-05-22 10:42:58 +02:00
|
|
|
MARKDOWN
|
|
|
|
|
|
|
|
email_html = PrettyText.format_for_email(cooked_html, post)
|
2019-05-24 18:57:03 +03:00
|
|
|
|
2024-05-22 10:42:58 +02:00
|
|
|
expect(email_html).to match_html <<~HTML
|
|
|
|
<p>hello</p>
|
|
|
|
Summary <a href="#{post.full_url}">#{I18n.t("details.excerpt_details")}</a>
|
|
|
|
HTML
|
2019-05-24 18:57:03 +03:00
|
|
|
end
|
|
|
|
|
2020-07-13 18:49:36 -07:00
|
|
|
it "properly handles multiple spoiler blocks in a post" do
|
2024-05-22 10:42:58 +02:00
|
|
|
cooked_html = PrettyText.cook <<~MARKDOWN
|
2020-07-13 18:49:36 -07:00
|
|
|
[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]
|
2024-05-22 10:42:58 +02:00
|
|
|
MARKDOWN
|
|
|
|
|
|
|
|
email_html = PrettyText.format_for_email(cooked_html, post)
|
2020-07-13 18:49:36 -07:00
|
|
|
|
2024-05-22 10:42:58 +02:00
|
|
|
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
|
2020-07-13 18:49:36 -07:00
|
|
|
end
|
|
|
|
|
2019-06-26 16:37:01 +03:00
|
|
|
it "escapes summary text" do
|
2024-05-22 10:42:58 +02:00
|
|
|
cooked_html = PrettyText.cook <<~MARKDOWN
|
2019-06-26 16:37:01 +03:00
|
|
|
<script>alert('hello')</script>
|
2024-05-22 10:42:58 +02:00
|
|
|
|
2019-06-26 16:37:01 +03:00
|
|
|
[details="<script>alert('hello')</script>"]
|
|
|
|
<script>alert('hello')</script>
|
|
|
|
[/details]
|
2024-05-22 10:42:58 +02:00
|
|
|
MARKDOWN
|
|
|
|
|
|
|
|
email_html = PrettyText.format_for_email(cooked_html, post)
|
2019-06-26 16:37:01 +03:00
|
|
|
|
2024-05-22 10:42:58 +02:00
|
|
|
expect(email_html).to match_html <<~HTML
|
|
|
|
<script>alert('hello')</script> <a href="#{post.full_url}">#{I18n.t("details.excerpt_details")}</a>
|
|
|
|
HTML
|
2019-06-26 16:37:01 +03:00
|
|
|
end
|
2016-07-06 19:46:47 +02:00
|
|
|
end
|