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

202 lines
5.9 KiB
Ruby
Raw Normal View History

2019-12-21 20:55:43 +05:30
# frozen_string_literal: true
2015-04-26 12:48:37 +05:30
require 'spec_helper'
describe EventsHelper do
2016-11-03 12:29:30 +05:30
describe '#event_commit_title' do
2018-12-13 13:39:08 +05:30
let(:message) { 'foo & bar ' + 'A' * 70 + '\n' + 'B' * 80 }
2020-01-01 13:55:28 +05:30
2016-11-03 12:29:30 +05:30
subject { helper.event_commit_title(message) }
2018-12-13 13:39:08 +05:30
it 'returns the first line, truncated to 70 chars' do
2016-11-03 12:29:30 +05:30
is_expected.to eq(message[0..66] + "...")
end
2018-12-13 13:39:08 +05:30
it 'is not html-safe' do
2016-11-03 12:29:30 +05:30
is_expected.not_to be_a(ActiveSupport::SafeBuffer)
end
2018-12-13 13:39:08 +05:30
it 'handles empty strings' do
2016-11-03 12:29:30 +05:30
expect(helper.event_commit_title("")).to eq("")
end
2017-09-10 17:25:29 +05:30
it 'handles nil values' do
expect(helper.event_commit_title(nil)).to eq('')
end
2018-03-27 19:54:05 +05:30
it 'does not escape HTML entities' do
2018-12-13 13:39:08 +05:30
expect(helper.event_commit_title('foo & bar')).to eq('foo & bar')
2018-03-27 19:54:05 +05:30
end
2016-11-03 12:29:30 +05:30
end
2018-11-20 20:47:30 +05:30
describe '#event_feed_url' do
2019-12-04 20:38:33 +05:30
let(:event) { create(:event).present }
2018-11-20 20:47:30 +05:30
let(:project) { create(:project, :public, :repository) }
2018-12-13 13:39:08 +05:30
context 'issue' do
before do
event.target = create(:issue)
end
2018-11-20 20:47:30 +05:30
2018-12-13 13:39:08 +05:30
it 'returns the project issue url' do
expect(helper.event_feed_url(event)).to eq(project_issue_url(event.project, event.target))
end
it 'contains the project issue IID link' do
expect(helper.event_feed_title(event)).to include("##{event.target.iid}")
end
2018-11-20 20:47:30 +05:30
end
2018-12-13 13:39:08 +05:30
context 'merge request' do
before do
event.target = create(:merge_request)
end
it 'returns the project merge request url' do
expect(helper.event_feed_url(event)).to eq(project_merge_request_url(event.project, event.target))
end
2018-11-20 20:47:30 +05:30
2018-12-13 13:39:08 +05:30
it 'contains the project merge request IID link' do
expect(helper.event_feed_title(event)).to include("!#{event.target.iid}")
end
2018-11-20 20:47:30 +05:30
end
2018-12-13 13:39:08 +05:30
it 'returns project commit url' do
2018-11-20 20:47:30 +05:30
event.target = create(:note_on_commit, project: project)
expect(helper.event_feed_url(event)).to eq(project_commit_url(event.project, event.note_target))
end
2018-12-13 13:39:08 +05:30
it 'returns event note target url' do
2018-11-20 20:47:30 +05:30
event.target = create(:note)
expect(helper.event_feed_url(event)).to eq(event_note_target_url(event))
end
2018-12-13 13:39:08 +05:30
it 'returns project url' do
2018-11-20 20:47:30 +05:30
event.project = project
event.action = 1
expect(helper.event_feed_url(event)).to eq(project_url(event.project))
end
2018-12-13 13:39:08 +05:30
it 'returns push event feed url' do
2018-11-20 20:47:30 +05:30
event = create(:push_event)
create(:push_event_payload, event: event, action: :pushed)
expect(helper.event_feed_url(event)).to eq(push_event_feed_url(event))
end
end
2019-02-15 15:39:39 +05:30
2020-04-22 19:07:51 +05:30
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('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
context 'for milestone events' 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)
title = event.target_title
html = [
"<span class=\"event-target-type append-right-4\">wiki page</span>",
"<a title=\"#{title}\" class=\"has-tooltip event-target-link append-right-4\" href=\"#{url}\">",
title,
"</a>"
].join
expect(helper.event_wiki_title_html(event)).to eq(html)
end
end
2019-02-15 15:39:39 +05:30
describe '#event_note_target_url' do
let(:project) { create(:project, :public, :repository) }
let(:event) { create(:event, project: project) }
let(:project_base_url) { namespace_project_url(namespace_id: project.namespace, id: project) }
subject { helper.event_note_target_url(event) }
it 'returns a commit note url' do
event.target = create(:note_on_commit, note: '+1 from me')
2020-03-13 15:44:24 +05:30
expect(subject).to eq("#{project_base_url}/-/commit/#{event.target.commit_id}#note_#{event.target.id}")
2019-02-15 15:39:39 +05:30
end
it 'returns a project snippet note url' do
2020-04-22 19:07:51 +05:30
event.target = create(:note_on_project_snippet, note: 'keep going')
2019-02-15 15:39:39 +05:30
expect(subject).to eq("#{project_base_url}/snippets/#{event.note_target.id}#note_#{event.target.id}")
end
it 'returns a project issue url' do
event.target = create(:note_on_issue, note: 'nice work')
2020-04-08 14:13:33 +05:30
expect(subject).to eq("#{project_base_url}/-/issues/#{event.note_target.iid}#note_#{event.target.id}")
2019-02-15 15:39:39 +05:30
end
it 'returns a merge request url' do
event.target = create(:note_on_merge_request, note: 'LGTM!')
2020-03-13 15:44:24 +05:30
expect(subject).to eq("#{project_base_url}/-/merge_requests/#{event.note_target.iid}#note_#{event.target.id}")
2019-02-15 15:39:39 +05:30
end
end
2015-04-26 12:48:37 +05:30
end