2017-08-17 22:00:37 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe PreviewMarkdownService do
|
|
|
|
let(:user) { create(:user) }
|
2017-09-10 17:25:29 +05:30
|
|
|
let(:project) { create(:project) }
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
before do
|
|
|
|
project.add_developer(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'user references' do
|
|
|
|
let(:params) { { text: "Take a look #{user.to_reference}" } }
|
|
|
|
let(:service) { described_class.new(project, user, params) }
|
|
|
|
|
|
|
|
it 'returns users referenced in text' do
|
|
|
|
result = service.execute
|
|
|
|
|
|
|
|
expect(result[:users]).to eq [user.username]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
context 'new note with quick actions' do
|
2017-08-17 22:00:37 +05:30
|
|
|
let(:issue) { create(:issue, project: project) }
|
|
|
|
let(:params) do
|
|
|
|
{
|
|
|
|
text: "Please do it\n/assign #{user.to_reference}",
|
2017-09-10 17:25:29 +05:30
|
|
|
quick_actions_target_type: 'Issue',
|
|
|
|
quick_actions_target_id: issue.id
|
2017-08-17 22:00:37 +05:30
|
|
|
}
|
|
|
|
end
|
|
|
|
let(:service) { described_class.new(project, user, params) }
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
it 'removes quick actions from text' do
|
2017-08-17 22:00:37 +05:30
|
|
|
result = service.execute
|
|
|
|
|
|
|
|
expect(result[:text]).to eq 'Please do it'
|
|
|
|
end
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
it 'explains quick actions effect' do
|
2017-08-17 22:00:37 +05:30
|
|
|
result = service.execute
|
|
|
|
|
|
|
|
expect(result[:commands]).to eq "Assigns #{user.to_reference}."
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'merge request description' do
|
|
|
|
let(:params) do
|
|
|
|
{
|
|
|
|
text: "My work\n/estimate 2y",
|
2017-09-10 17:25:29 +05:30
|
|
|
quick_actions_target_type: 'MergeRequest'
|
2017-08-17 22:00:37 +05:30
|
|
|
}
|
|
|
|
end
|
|
|
|
let(:service) { described_class.new(project, user, params) }
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
it 'removes quick actions from text' do
|
2017-08-17 22:00:37 +05:30
|
|
|
result = service.execute
|
|
|
|
|
|
|
|
expect(result[:text]).to eq 'My work'
|
|
|
|
end
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
it 'explains quick actions effect' do
|
2017-08-17 22:00:37 +05:30
|
|
|
result = service.execute
|
|
|
|
|
|
|
|
expect(result[:commands]).to eq 'Sets time estimate to 2y.'
|
2017-09-10 17:25:29 +05:30
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
end
|