debian-mirror-gitlab/spec/helpers/events_helper_spec.rb

66 lines
2.1 KiB
Ruby
Raw Normal View History

2015-04-26 12:48:37 +05:30
require 'spec_helper'
describe EventsHelper do
2016-06-02 11:05:42 +05:30
describe '#event_note' do
before do
allow(helper).to receive(:current_user).and_return(double)
end
2015-04-26 12:48:37 +05:30
2016-09-13 17:45:13 +05:30
it 'displays one line of plain text without alteration' do
2016-06-02 11:05:42 +05:30
input = 'A short, plain note'
expect(helper.event_note(input)).to match(input)
expect(helper.event_note(input)).not_to match(/\.\.\.\z/)
end
2015-04-26 12:48:37 +05:30
2016-09-13 17:45:13 +05:30
it 'displays inline code' do
2016-06-02 11:05:42 +05:30
input = 'A note with `inline code`'
expected = 'A note with <code>inline code</code>'
2015-04-26 12:48:37 +05:30
2016-06-02 11:05:42 +05:30
expect(helper.event_note(input)).to match(expected)
end
2015-04-26 12:48:37 +05:30
2016-09-13 17:45:13 +05:30
it 'truncates a note with multiple paragraphs' do
2016-06-02 11:05:42 +05:30
input = "Paragraph 1\n\nParagraph 2"
expected = 'Paragraph 1...'
2015-04-26 12:48:37 +05:30
2016-06-02 11:05:42 +05:30
expect(helper.event_note(input)).to match(expected)
end
2015-04-26 12:48:37 +05:30
2016-09-13 17:45:13 +05:30
it 'displays the first line of a code block' do
2016-06-02 11:05:42 +05:30
input = "```\nCode block\nwith two lines\n```"
expected = %r{<pre.+><code>Code block\.\.\.</code></pre>}
2015-04-26 12:48:37 +05:30
2016-06-02 11:05:42 +05:30
expect(helper.event_note(input)).to match(expected)
end
2015-04-26 12:48:37 +05:30
2016-09-13 17:45:13 +05:30
it 'truncates a single long line of text' do
2016-06-02 11:05:42 +05:30
text = 'The quick brown fox jumped over the lazy dog twice' # 50 chars
input = text * 4
expected = (text * 2).sub(/.{3}/, '...')
2015-04-26 12:48:37 +05:30
2016-06-02 11:05:42 +05:30
expect(helper.event_note(input)).to match(expected)
end
2015-04-26 12:48:37 +05:30
2016-09-13 17:45:13 +05:30
it 'preserves a link href when link text is truncated' do
2016-06-02 11:05:42 +05:30
text = 'The quick brown fox jumped over the lazy dog' # 44 chars
input = "#{text}#{text}#{text} " # 133 chars
link_url = 'http://example.com/foo/bar/baz' # 30 chars
input << link_url
expected_link_text = 'http://example...</a>'
2015-04-26 12:48:37 +05:30
2016-06-02 11:05:42 +05:30
expect(helper.event_note(input)).to match(link_url)
expect(helper.event_note(input)).to match(expected_link_text)
end
2015-04-26 12:48:37 +05:30
2016-09-13 17:45:13 +05:30
it 'preserves code color scheme' do
2016-06-02 11:05:42 +05:30
input = "```ruby\ndef test\n 'hello world'\nend\n```"
expected = '<pre class="code highlight js-syntax-highlight ruby">' \
"<code><span class=\"k\">def</span> <span class=\"nf\">test</span>\n" \
" <span class=\"s1\">\'hello world\'</span>\n" \
2016-08-24 12:49:21 +05:30
"<span class=\"k\">end</span>\n" \
2016-06-02 11:05:42 +05:30
'</code></pre>'
expect(helper.event_note(input)).to eq(expected)
end
2015-04-26 12:48:37 +05:30
end
end