2019-04-29 20:27:42 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-01-22 13:17:35 -05:00
|
|
|
require "rails_helper"
|
|
|
|
require "excerpt_parser"
|
|
|
|
|
|
|
|
describe ExcerptParser do
|
|
|
|
|
|
|
|
it "handles nested <details> blocks" do
|
2018-03-12 11:52:06 -04:00
|
|
|
html = <<~HTML.strip
|
2018-01-22 13:17:35 -05:00
|
|
|
<details>
|
2018-03-12 11:52:06 -04:00
|
|
|
<summary>
|
|
|
|
FOO</summary>
|
|
|
|
<details>
|
|
|
|
<summary>
|
|
|
|
BAR</summary>
|
|
|
|
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce ultrices, ex bibendum vestibulum vestibulum, mi velit pulvinar risus, sed consequat eros libero in eros. Fusce luctus mattis mauris, vitae semper lorem sodales quis. Donec pellentesque lacus ac ante aliquam, tincidunt iaculis risus interdum. In ullamcorper cursus massa ut lacinia. Donec quis diam finibus, rutrum odio eu, maximus leo. Nulla facilisi. Nullam suscipit quam et bibendum sagittis. Praesent sollicitudin neque at luctus ornare. Maecenas tristique dapibus risus, ac dictum ipsum gravida aliquam. Phasellus vehicula eu arcu sed imperdiet. Vestibulum ornare eros a nisi faucibus vehicula. Quisque congue placerat nulla, nec finibus nulla ultrices vitae. Quisque ac mi sem. Curabitur eu porttitor justo. Etiam dignissim in orci iaculis congue. Donec tempus cursus orci, a placerat elit varius nec.</p>
|
|
|
|
</details>
|
2018-01-22 13:17:35 -05:00
|
|
|
</details>
|
|
|
|
HTML
|
|
|
|
|
2018-03-12 11:52:06 -04:00
|
|
|
expect(ExcerptParser.get_excerpt(html, 50, {})).to match_html(<<~HTML)
|
|
|
|
<details><summary>FOO</summary>BAR
|
|
|
|
Lorem ipsum dolor sit amet, consectetur adi…</details>
|
|
|
|
HTML
|
|
|
|
|
|
|
|
expect(ExcerptParser.get_excerpt(html, 6, {})).to match_html('<details><summary>FOO</summary>BAR…</details>')
|
|
|
|
expect(ExcerptParser.get_excerpt(html, 3, {})).to match_html('<details class="disabled"><summary>FOO</summary></details>')
|
2018-01-22 13:17:35 -05:00
|
|
|
end
|
|
|
|
|
2018-03-12 11:52:06 -04:00
|
|
|
it "respects length parameter for <details> block" do
|
|
|
|
html = '<details><summary>foo</summary><p>bar</p></details>'
|
|
|
|
expect(ExcerptParser.get_excerpt(html, 100, {})).to match_html('<details><summary>foo</summary>bar</details>')
|
|
|
|
expect(ExcerptParser.get_excerpt(html, 5, {})).to match_html('<details><summary>foo</summary>ba…</details>')
|
|
|
|
expect(ExcerptParser.get_excerpt(html, 3, {})).to match_html('<details class="disabled"><summary>foo</summary></details>')
|
|
|
|
expect(ExcerptParser.get_excerpt(html, 2, {})).to match_html('<details class="disabled"><summary>fo…</summary></details>')
|
|
|
|
end
|
2018-01-22 13:17:35 -05:00
|
|
|
end
|