Commit d2fb451c authored by Douwe Maan's avatar Douwe Maan

Merge branch 'rs-cleanup-events_helper_spec' into 'master'

Clean up EventsHelper spec

Extracted from https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/4090

See merge request !4133
parents 4735a753 05bbad58
require 'spec_helper'
describe EventsHelper do
include ApplicationHelper
include GitlabMarkdownHelper
let(:current_user) { create(:user, email: "current@email.com") }
describe '#event_note' do
before do
allow(helper).to receive(:current_user).and_return(double)
end
it 'should display one line of plain text without alteration' do
input = 'A short, plain note'
expect(event_note(input)).to match(input)
expect(event_note(input)).not_to match(/\.\.\.\z/)
expect(helper.event_note(input)).to match(input)
expect(helper.event_note(input)).not_to match(/\.\.\.\z/)
end
it 'should display inline code' do
input = 'A note with `inline code`'
expected = 'A note with <code>inline code</code>'
expect(event_note(input)).to match(expected)
expect(helper.event_note(input)).to match(expected)
end
it 'should truncate a note with multiple paragraphs' do
input = "Paragraph 1\n\nParagraph 2"
expected = 'Paragraph 1...'
expect(event_note(input)).to match(expected)
expect(helper.event_note(input)).to match(expected)
end
it 'should display the first line of a code block' do
input = "```\nCode block\nwith two lines\n```"
expected = %r{<pre.+><code>Code block\.\.\.</code></pre>}
expect(event_note(input)).to match(expected)
expect(helper.event_note(input)).to match(expected)
end
it 'should truncate a single long line of text' do
text = 'The quick brown fox jumped over the lazy dog twice' # 50 chars
input = "#{text}#{text}#{text}#{text}" # 200 chars
expected = "#{text}#{text}".sub(/.{3}/, '...')
input = text * 4
expected = (text * 2).sub(/.{3}/, '...')
expect(event_note(input)).to match(expected)
expect(helper.event_note(input)).to match(expected)
end
it 'should preserve a link href when link text is truncated' do
......@@ -48,8 +48,8 @@ describe EventsHelper do
input << link_url
expected_link_text = 'http://example...</a>'
expect(event_note(input)).to match(link_url)
expect(event_note(input)).to match(expected_link_text)
expect(helper.event_note(input)).to match(link_url)
expect(helper.event_note(input)).to match(expected_link_text)
end
it 'should preserve code color scheme' do
......@@ -59,6 +59,7 @@ describe EventsHelper do
" <span class=\"s1\">\'hello world\'</span>\n" \
"<span class=\"k\">end</span>" \
'</code></pre>'
expect(event_note(input)).to eq(expected)
expect(helper.event_note(input)).to eq(expected)
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment