summaryrefslogtreecommitdiff
path: root/spec/helpers/events_helper_spec.rb
diff options
context:
space:
mode:
authorVinnie Okada <vokada@mrvinn.com>2014-10-12 23:07:18 -0500
committerVinnie Okada <vokada@mrvinn.com>2014-10-12 23:56:56 -0500
commitb3c70d001d7371e8952cd7be879e727b5ee4155a (patch)
treeef3731d109df59f9786c1fe25aea70a1d08b89cb /spec/helpers/events_helper_spec.rb
parent5b2a42a091b2300ae1962b158b1496ac160c9e0f (diff)
downloadgitlab-ce-b3c70d001d7371e8952cd7be879e727b5ee4155a.tar.gz
Improve dashboard note view and add tests
Update the `#first_line_in_markdown` method so that the first line of parsed text is displayed more reliably, and the continuation indicators ("...") are displayed in all cases where the note is truncated. Also add Rspec tests for `EventsHelper#event_note`.
Diffstat (limited to 'spec/helpers/events_helper_spec.rb')
-rw-r--r--spec/helpers/events_helper_spec.rb52
1 files changed, 52 insertions, 0 deletions
diff --git a/spec/helpers/events_helper_spec.rb b/spec/helpers/events_helper_spec.rb
new file mode 100644
index 00000000000..4de54d291f2
--- /dev/null
+++ b/spec/helpers/events_helper_spec.rb
@@ -0,0 +1,52 @@
+require 'spec_helper'
+
+describe EventsHelper do
+ include ApplicationHelper
+ include GitlabMarkdownHelper
+
+ 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/)
+ 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)
+ 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)
+ end
+
+ it 'should display the first line of a code block' do
+ input = "```\nCode block\nwith two lines\n```"
+ expected = '<pre><code class="">Code block...</code></pre>'
+
+ expect(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}/, '...')
+
+ expect(event_note(input)).to match(expected)
+ end
+
+ it 'should preserve a link href when link text is truncated' do
+ 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>'
+
+ expect(event_note(input)).to match(link_url)
+ expect(event_note(input)).to match(expected_link_text)
+ end
+end