Commit 05bbad58 authored by Robert Speicher's avatar Robert Speicher

Clean up EventsHelper spec

parent 459af7ff
require 'spec_helper' require 'spec_helper'
describe EventsHelper do describe EventsHelper do
include ApplicationHelper describe '#event_note' do
include GitlabMarkdownHelper before do
allow(helper).to receive(:current_user).and_return(double)
end
let(:current_user) { create(:user, email: "current@email.com") } it 'should display one line of plain text without alteration' do
input = 'A short, plain note'
expect(helper.event_note(input)).to match(input)
expect(helper.event_note(input)).not_to match(/\.\.\.\z/)
end
it 'should display one line of plain text without alteration' do it 'should display inline code' do
input = 'A short, plain note' input = 'A note with `inline code`'
expect(event_note(input)).to match(input) expected = 'A note with <code>inline code</code>'
expect(event_note(input)).not_to match(/\.\.\.\z/)
end
it 'should display inline code' do expect(helper.event_note(input)).to match(expected)
input = 'A note with `inline code`' end
expected = 'A note with <code>inline code</code>'
expect(event_note(input)).to match(expected) it 'should truncate a note with multiple paragraphs' do
end input = "Paragraph 1\n\nParagraph 2"
expected = 'Paragraph 1...'
it 'should truncate a note with multiple paragraphs' do expect(helper.event_note(input)).to match(expected)
input = "Paragraph 1\n\nParagraph 2" end
expected = 'Paragraph 1...'
expect(event_note(input)).to match(expected) it 'should display the first line of a code block' do
end input = "```\nCode block\nwith two lines\n```"
expected = %r{<pre.+><code>Code block\.\.\.</code></pre>}
it 'should display the first line of a code block' do expect(helper.event_note(input)).to match(expected)
input = "```\nCode block\nwith two lines\n```" end
expected = %r{<pre.+><code>Code block\.\.\.</code></pre>}
expect(event_note(input)).to match(expected) it 'should truncate a single long line of text' do
end text = 'The quick brown fox jumped over the lazy dog twice' # 50 chars
input = text * 4
expected = (text * 2).sub(/.{3}/, '...')
it 'should truncate a single long line of text' do expect(helper.event_note(input)).to match(expected)
text = 'The quick brown fox jumped over the lazy dog twice' # 50 chars end
input = "#{text}#{text}#{text}#{text}" # 200 chars
expected = "#{text}#{text}".sub(/.{3}/, '...')
expect(event_note(input)).to match(expected) it 'should preserve a link href when link text is truncated' do
end text = 'The quick brown fox jumped over the lazy dog' # 44 chars
input = "#{text}#{text}#{text} " # 133 chars
it 'should preserve a link href when link text is truncated' do link_url = 'http://example.com/foo/bar/baz' # 30 chars
text = 'The quick brown fox jumped over the lazy dog' # 44 chars input << link_url
input = "#{text}#{text}#{text} " # 133 chars expected_link_text = 'http://example...</a>'
link_url = 'http://example.com/foo/bar/baz' # 30 chars
input << link_url
expected_link_text = 'http://example...</a>'
expect(event_note(input)).to match(link_url) expect(helper.event_note(input)).to match(link_url)
expect(event_note(input)).to match(expected_link_text) expect(helper.event_note(input)).to match(expected_link_text)
end end
it 'should preserve code color scheme' do it 'should preserve code color scheme' do
input = "```ruby\ndef test\n 'hello world'\nend\n```" input = "```ruby\ndef test\n 'hello world'\nend\n```"
expected = '<pre class="code highlight js-syntax-highlight ruby">' \ expected = '<pre class="code highlight js-syntax-highlight ruby">' \
"<code><span class=\"k\">def</span> <span class=\"nf\">test</span>\n" \ "<code><span class=\"k\">def</span> <span class=\"nf\">test</span>\n" \
" <span class=\"s1\">\'hello world\'</span>\n" \ " <span class=\"s1\">\'hello world\'</span>\n" \
"<span class=\"k\">end</span>" \ "<span class=\"k\">end</span>" \
'</code></pre>' '</code></pre>'
expect(event_note(input)).to eq(expected) expect(helper.event_note(input)).to eq(expected)
end
end 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