# frozen_string_literal: true require "rails_helper" require "excerpt_parser" describe ExcerptParser do it "handles nested
blocks" do html = <<~HTML.strip
FOO
BAR

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.

HTML expect(ExcerptParser.get_excerpt(html, 50, {})).to match_html <<~HTML
FOOBAR Lorem ipsum dolor sit amet, consectetur adi…
HTML expect(ExcerptParser.get_excerpt(html, 6, {})).to match_html('
FOOBAR…
') expect(ExcerptParser.get_excerpt(html, 3, {})).to match_html('
FOO
') end it "respects length parameter for
block" do html = '
foo

bar

' expect(ExcerptParser.get_excerpt(html, 100, {})).to match_html('
foobar
') expect(ExcerptParser.get_excerpt(html, 5, {})).to match_html('
fooba…
') expect(ExcerptParser.get_excerpt(html, 3, {})).to match_html('
foo
') expect(ExcerptParser.get_excerpt(html, 2, {})).to match_html('
fo…
') end describe "keep_onebox_body parameter" do it "keeps the body content for external oneboxes" do html = <<~HTML.strip HTML expect(ExcerptParser.get_excerpt(html, 100, keep_onebox_body: true)).to eq(<<~HTML.strip) [image] discourse/discourse A platform for community discussion. Free, o… HTML end it "keeps the content for internal oneboxes" do html = <<~HTML.strip HTML expect(ExcerptParser.get_excerpt(html, 100, keep_onebox_body: true)).to eq(<<~HTML.strip) [image] Welcome to Discourse The first paragraph of this pinned topic will be … HTML end end describe "keep_quotes parameter" do it "should keep the quoted content in html" do html = <<~HTML.strip HTML expect(ExcerptParser.get_excerpt(html, 100, keep_quotes: true)).to eq("This is a quoted text.") end end end