2019-05-03 06:17:27 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-07-07 01:46:47 +08:00
|
|
|
require 'rails_helper'
|
|
|
|
require 'pretty_text'
|
|
|
|
|
|
|
|
describe PrettyText do
|
|
|
|
|
2019-05-24 23:57:03 +08:00
|
|
|
let(:post) { Fabricate(:post) }
|
|
|
|
|
2016-07-07 01:46:47 +08:00
|
|
|
it "supports details tag" do
|
2020-05-05 11:46:57 +08:00
|
|
|
cooked_html = <<~HTML.gsub("\n", "")
|
2017-07-19 02:44:49 +08:00
|
|
|
<details>
|
|
|
|
<summary>
|
|
|
|
foo</summary>
|
|
|
|
<p>bar</p>
|
|
|
|
</details>
|
|
|
|
HTML
|
2018-02-08 07:01:11 +08:00
|
|
|
|
|
|
|
expect(cooked_html).to match_html(cooked_html)
|
2020-05-05 11:46:57 +08:00
|
|
|
expect(PrettyText.cook("[details=foo]\nbar\n[/details]").gsub("\n", "")).to match_html(cooked_html)
|
2018-02-08 07:01:11 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
it "deletes elided content" do
|
|
|
|
cooked_html = PrettyText.cook("Hello World\n\n<details class='elided'>42</details>")
|
2019-05-24 23:57:03 +08:00
|
|
|
mail_html = "<p>Hello World</p>\n<a href=\"http://test.localhost\">(click for more details)</a>"
|
2018-02-08 07:01:11 +08:00
|
|
|
|
|
|
|
expect(PrettyText.format_for_email(cooked_html)).to match_html(mail_html)
|
2016-07-07 01:46:47 +08:00
|
|
|
end
|
|
|
|
|
2019-05-24 23:57:03 +08:00
|
|
|
it 'can replace spoilers in emails' do
|
|
|
|
md = PrettyText.cook(<<~EOF)
|
|
|
|
hello
|
|
|
|
|
|
|
|
[details="Summary"]
|
|
|
|
world
|
|
|
|
[/details]
|
|
|
|
EOF
|
|
|
|
md = PrettyText.format_for_email(md, post)
|
|
|
|
html = "<p>hello</p>\n\nSummary <a href=\"#{post.full_url}\">(click for more details)</a>"
|
|
|
|
|
|
|
|
expect(md).to eq(html)
|
|
|
|
end
|
|
|
|
|
2019-06-26 21:37:01 +08:00
|
|
|
it 'escapes summary text' do
|
|
|
|
md = PrettyText.cook(<<~EOF)
|
|
|
|
<script>alert('hello')</script>
|
|
|
|
[details="<script>alert('hello')</script>"]
|
|
|
|
<script>alert('hello')</script>
|
|
|
|
[/details]
|
|
|
|
EOF
|
|
|
|
md = PrettyText.format_for_email(md, post)
|
|
|
|
|
|
|
|
expect(md).not_to include('<script>')
|
|
|
|
end
|
|
|
|
|
2016-07-07 01:46:47 +08:00
|
|
|
end
|