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