Commit a3982c2e authored by Alex Kalderimis's avatar Alex Kalderimis

Improved test coverage for events helper

* Add specs for prepositions
* Add test for event_wiki_page_target_url
* Add test for event_wiki_title_html
parent 44caf4e2
......@@ -68,10 +68,10 @@ module EventsHelper
end
def event_preposition(event)
if event.push_action? || event.commented_action? || event.target
"at"
elsif event.wiki_page?
if event.wiki_page?
_("Events|in the wiki for")
elsif event.push_action? || event.commented_action? || event.target
"at"
elsif event.milestone?
"in"
end
......@@ -177,14 +177,14 @@ module EventsHelper
def event_wiki_title_html(event)
capture do
concat content_tag(:span, _('wiki page'), class: "event-target-type append-right-4")
concat link_to(event.wiki_page_title, event_wiki_page_target_url(event),
concat link_to(event.target_title, event_wiki_page_target_url(event),
title: event.target_title,
class: 'has-tooltip event-target-link append-right-4')
end
end
def event_wiki_page_target_url(event)
project_wiki_url(event.project, event.wiki_page_title)
project_wiki_url(event.project, event.target.canonical_slug)
end
def event_note_title_html(event)
......
......@@ -88,6 +88,85 @@ describe EventsHelper do
end
end
describe '#event_preposition' do
context 'for wiki page events' do
let(:event) { create(:wiki_page_event) }
it 'returns a suitable phrase' do
expect(helper.event_preposition(event)).to eq('Events|in the wiki for')
end
end
context 'for push action events' do
let(:event) { create(:push_event) }
it 'returns a suitable phrase' do
expect(helper.event_preposition(event)).to eq('at')
end
end
context 'for commented actions' do
let(:event) { create(:event, :commented) }
it 'returns a suitable phrase' do
expect(helper.event_preposition(event)).to eq('at')
end
end
context 'for any event with a target' do
let(:event) { create(:event, target: create(:issue)) }
it 'returns a suitable phrase' do
expect(helper.event_preposition(event)).to eq('at')
end
end
# This branch appears to be unreachable
context 'for milestone events', :pending do
let(:event) { create(:event, target: create(:milestone)) }
it 'returns a suitable phrase' do
expect(helper.event_preposition(event)).to eq('in')
end
end
context 'for non-matching events' do
let(:event) { create(:event, :created) }
it 'returns no preposition' do
expect(helper.event_preposition(event)).to be_nil
end
end
end
describe 'event_wiki_page_target_url' do
let(:project) { create(:project) }
let(:wiki_page) { create(:wiki_page, wiki: create(:project_wiki, project: project)) }
let(:event) { create(:wiki_page_event, project: project, wiki_page: wiki_page) }
it 'links to the wiki page' do
url = helper.project_wiki_url(project, wiki_page.slug)
expect(helper.event_wiki_page_target_url(event)).to eq(url)
end
end
describe '#event_wiki_title_html' do
let(:event) { create(:wiki_page_event) }
it 'produces a suitable title chunk' do
url = helper.event_wiki_page_target_url(event)
html = [
"<span class=\"event-target-type append-right-4\">wiki page</span>",
"<a title=\"Title.with.dot\" class=\"has-tooltip event-target-link append-right-4\" href=\"#{url}\">",
event.target.title,
"</a>"
].join
expect(helper.event_wiki_title_html(event)).to eq(html)
end
end
describe '#event_note_target_url' do
let(:project) { create(:project, :public, :repository) }
let(:event) { create(:event, project: project) }
......
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