2014-10-13 00:07:18 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe EventsHelper do
|
2016-05-11 16:17:16 -04:00
|
|
|
describe '#event_note' do
|
|
|
|
before do
|
|
|
|
allow(helper).to receive(:current_user).and_return(double)
|
|
|
|
end
|
2014-10-13 00:07:18 -04:00
|
|
|
|
2016-07-25 14:16:19 -04:00
|
|
|
it 'displays one line of plain text without alteration' do
|
2016-05-11 16:17:16 -04:00
|
|
|
input = 'A short, plain note'
|
|
|
|
expect(helper.event_note(input)).to match(input)
|
|
|
|
expect(helper.event_note(input)).not_to match(/\.\.\.\z/)
|
|
|
|
end
|
2015-02-27 20:17:57 -05:00
|
|
|
|
2016-07-25 14:16:19 -04:00
|
|
|
it 'displays inline code' do
|
2016-05-11 16:17:16 -04:00
|
|
|
input = 'A note with `inline code`'
|
|
|
|
expected = 'A note with <code>inline code</code>'
|
2014-10-13 00:07:18 -04:00
|
|
|
|
2016-05-11 16:17:16 -04:00
|
|
|
expect(helper.event_note(input)).to match(expected)
|
|
|
|
end
|
2014-10-13 00:07:18 -04:00
|
|
|
|
2016-07-25 14:16:19 -04:00
|
|
|
it 'truncates a note with multiple paragraphs' do
|
2016-05-11 16:17:16 -04:00
|
|
|
input = "Paragraph 1\n\nParagraph 2"
|
|
|
|
expected = 'Paragraph 1...'
|
2014-10-13 00:07:18 -04:00
|
|
|
|
2016-05-11 16:17:16 -04:00
|
|
|
expect(helper.event_note(input)).to match(expected)
|
|
|
|
end
|
2014-10-13 00:07:18 -04:00
|
|
|
|
2016-07-25 14:16:19 -04:00
|
|
|
it 'displays the first line of a code block' do
|
2016-05-11 16:17:16 -04:00
|
|
|
input = "```\nCode block\nwith two lines\n```"
|
2017-03-13 18:39:22 -04:00
|
|
|
expected = %r{<pre.+><code><span class="line">Code block\.\.\.</span>\n</code></pre>}
|
2014-10-13 00:07:18 -04:00
|
|
|
|
2016-05-11 16:17:16 -04:00
|
|
|
expect(helper.event_note(input)).to match(expected)
|
|
|
|
end
|
2014-10-13 00:07:18 -04:00
|
|
|
|
2016-07-25 14:16:19 -04:00
|
|
|
it 'truncates a single long line of text' do
|
2016-05-11 16:17:16 -04:00
|
|
|
text = 'The quick brown fox jumped over the lazy dog twice' # 50 chars
|
|
|
|
input = text * 4
|
|
|
|
expected = (text * 2).sub(/.{3}/, '...')
|
2014-10-13 00:07:18 -04:00
|
|
|
|
2016-05-11 16:17:16 -04:00
|
|
|
expect(helper.event_note(input)).to match(expected)
|
|
|
|
end
|
2014-10-13 00:07:18 -04:00
|
|
|
|
2016-07-25 14:16:19 -04:00
|
|
|
it 'preserves a link href when link text is truncated' do
|
2016-05-11 16:17:16 -04:00
|
|
|
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>'
|
2014-10-13 00:07:18 -04:00
|
|
|
|
2016-05-11 16:17:16 -04:00
|
|
|
expect(helper.event_note(input)).to match(link_url)
|
|
|
|
expect(helper.event_note(input)).to match(expected_link_text)
|
|
|
|
end
|
2015-02-27 20:17:57 -05:00
|
|
|
|
2016-07-25 14:16:19 -04:00
|
|
|
it 'preserves code color scheme' do
|
2016-05-11 16:17:16 -04:00
|
|
|
input = "```ruby\ndef test\n 'hello world'\nend\n```"
|
|
|
|
expected = '<pre class="code highlight js-syntax-highlight ruby">' \
|
2017-03-13 18:39:22 -04:00
|
|
|
"<code><span class=\"line\"><span class=\"k\">def</span> <span class=\"nf\">test</span>...</span>\n" \
|
|
|
|
"</code></pre>"
|
2016-05-11 16:17:16 -04:00
|
|
|
expect(helper.event_note(input)).to eq(expected)
|
|
|
|
end
|
2017-03-07 05:08:59 -05:00
|
|
|
|
|
|
|
it 'preserves style attribute within a tag' do
|
|
|
|
input = '<span class="" style="background-color: #44ad8e; color: #FFFFFF;"></span>'
|
|
|
|
expected = '<p><span style="background-color: #44ad8e; color: #FFFFFF;"></span></p>'
|
|
|
|
|
|
|
|
expect(helper.event_note(input)).to eq(expected)
|
|
|
|
end
|
2015-02-27 20:17:57 -05:00
|
|
|
end
|
2016-10-17 06:07:44 -04:00
|
|
|
|
|
|
|
describe '#event_commit_title' do
|
|
|
|
let(:message) { "foo & bar " + "A" * 70 + "\n" + "B" * 80 }
|
|
|
|
subject { helper.event_commit_title(message) }
|
|
|
|
|
|
|
|
it "returns the first line, truncated to 70 chars" do
|
|
|
|
is_expected.to eq(message[0..66] + "...")
|
|
|
|
end
|
|
|
|
|
|
|
|
it "is not html-safe" do
|
|
|
|
is_expected.not_to be_a(ActiveSupport::SafeBuffer)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "handles empty strings" do
|
|
|
|
expect(helper.event_commit_title("")).to eq("")
|
|
|
|
end
|
|
|
|
end
|
2014-10-13 00:07:18 -04:00
|
|
|
end
|