2019-05-02 18:17:27 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-07-06 13:46:47 -04:00
|
|
|
require 'rails_helper'
|
|
|
|
require 'pretty_text'
|
|
|
|
|
2022-07-27 22:27:38 -04:00
|
|
|
RSpec.describe PrettyText do
|
2016-07-06 13:46:47 -04:00
|
|
|
|
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
|
2020-05-04 23:46:57 -04:00
|
|
|
cooked_html = <<~HTML.gsub("\n", "")
|
2017-07-18 14:44:49 -04:00
|
|
|
<details>
|
|
|
|
<summary>
|
|
|
|
foo</summary>
|
|
|
|
<p>bar</p>
|
|
|
|
</details>
|
|
|
|
HTML
|
2018-02-07 18:01:11 -05:00
|
|
|
|
|
|
|
expect(cooked_html).to match_html(cooked_html)
|
2020-05-04 23:46:57 -04:00
|
|
|
expect(PrettyText.cook("[details=foo]\nbar\n[/details]").gsub("\n", "")).to match_html(cooked_html)
|
2018-02-07 18:01:11 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "deletes elided content" do
|
|
|
|
cooked_html = PrettyText.cook("Hello World\n\n<details class='elided'>42</details>")
|
2019-05-24 11:57:03 -04:00
|
|
|
mail_html = "<p>Hello World</p>\n<a href=\"http://test.localhost\">(click for more details)</a>"
|
2018-02-07 18:01:11 -05:00
|
|
|
|
|
|
|
expect(PrettyText.format_for_email(cooked_html)).to match_html(mail_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
|
DEV: Correctly tag heredocs (#16061)
This allows text editors to use correct syntax coloring for the heredoc sections.
Heredoc tag names we use:
languages: SQL, JS, RUBY, LUA, HTML, CSS, SCSS, SH, HBS, XML, YAML/YML, MF, ICS
other: MD, TEXT/TXT, RAW, EMAIL
2022-02-28 14:50:55 -05:00
|
|
|
md = PrettyText.cook(<<~MD)
|
2019-05-24 11:57:03 -04:00
|
|
|
hello
|
|
|
|
|
|
|
|
[details="Summary"]
|
|
|
|
world
|
|
|
|
[/details]
|
DEV: Correctly tag heredocs (#16061)
This allows text editors to use correct syntax coloring for the heredoc sections.
Heredoc tag names we use:
languages: SQL, JS, RUBY, LUA, HTML, CSS, SCSS, SH, HBS, XML, YAML/YML, MF, ICS
other: MD, TEXT/TXT, RAW, EMAIL
2022-02-28 14:50:55 -05:00
|
|
|
MD
|
2019-05-24 11:57:03 -04:00
|
|
|
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
|
|
|
|
|
2020-07-13 21:49:36 -04:00
|
|
|
it 'properly handles multiple spoiler blocks in a post' do
|
DEV: Correctly tag heredocs (#16061)
This allows text editors to use correct syntax coloring for the heredoc sections.
Heredoc tag names we use:
languages: SQL, JS, RUBY, LUA, HTML, CSS, SCSS, SH, HBS, XML, YAML/YML, MF, ICS
other: MD, TEXT/TXT, RAW, EMAIL
2022-02-28 14:50:55 -05:00
|
|
|
md = PrettyText.cook(<<~MD)
|
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]
|
DEV: Correctly tag heredocs (#16061)
This allows text editors to use correct syntax coloring for the heredoc sections.
Heredoc tag names we use:
languages: SQL, JS, RUBY, LUA, HTML, CSS, SCSS, SH, HBS, XML, YAML/YML, MF, ICS
other: MD, TEXT/TXT, RAW, EMAIL
2022-02-28 14:50:55 -05:00
|
|
|
MD
|
2020-07-13 21:49:36 -04:00
|
|
|
|
|
|
|
md = PrettyText.format_for_email(md, post)
|
|
|
|
expect(md).not_to include('secret stuff')
|
|
|
|
expect(md.scan(/First/).size).to eq(1)
|
|
|
|
expect(md.scan(/Third/).size).to eq(1)
|
|
|
|
expect(md.scan(I18n.t('details.excerpt_details')).size).to eq(3)
|
|
|
|
end
|
|
|
|
|
2019-06-26 09:37:01 -04:00
|
|
|
it 'escapes summary text' do
|
DEV: Correctly tag heredocs (#16061)
This allows text editors to use correct syntax coloring for the heredoc sections.
Heredoc tag names we use:
languages: SQL, JS, RUBY, LUA, HTML, CSS, SCSS, SH, HBS, XML, YAML/YML, MF, ICS
other: MD, TEXT/TXT, RAW, EMAIL
2022-02-28 14:50:55 -05:00
|
|
|
md = PrettyText.cook(<<~MD)
|
2019-06-26 09:37:01 -04:00
|
|
|
<script>alert('hello')</script>
|
|
|
|
[details="<script>alert('hello')</script>"]
|
|
|
|
<script>alert('hello')</script>
|
|
|
|
[/details]
|
DEV: Correctly tag heredocs (#16061)
This allows text editors to use correct syntax coloring for the heredoc sections.
Heredoc tag names we use:
languages: SQL, JS, RUBY, LUA, HTML, CSS, SCSS, SH, HBS, XML, YAML/YML, MF, ICS
other: MD, TEXT/TXT, RAW, EMAIL
2022-02-28 14:50:55 -05:00
|
|
|
MD
|
2019-06-26 09:37:01 -04:00
|
|
|
md = PrettyText.format_for_email(md, post)
|
|
|
|
|
|
|
|
expect(md).not_to include('<script>')
|
|
|
|
end
|
|
|
|
|
2016-07-06 13:46:47 -04:00
|
|
|
end
|