summaryrefslogtreecommitdiff
path: root/spec/services/preview_markdown_service_spec.rb
diff options
context:
space:
mode:
authorRares Sfirlogea <rrr.junior@gmail.com>2016-11-16 12:09:09 +0100
committerAdam Niedzielski <adamsunday@gmail.com>2017-05-04 17:02:25 +0200
commit45e4c665653cd511b0d96119d3973652c43238bb (patch)
treeb614bb895b59dfb2f27d1408d0ed7594c4182c73 /spec/services/preview_markdown_service_spec.rb
parent2d43f8a2f4b1352067755609c9e3110d382d06c6 (diff)
downloadgitlab-ce-45e4c665653cd511b0d96119d3973652c43238bb.tar.gz
Display slash commands outcome when previewing Markdownadam-separate-slash-commands
Remove slash commands from Markdown preview and display their outcome next to the text field. Introduce new "explanation" block to our slash commands DSL. Introduce optional "parse_params" block to slash commands DSL that allows to process a parameter before it is passed to "explanation" or "command" blocks. Pass path for previewing Markdown as "data" attribute instead of setting a variable on "window".
Diffstat (limited to 'spec/services/preview_markdown_service_spec.rb')
-rw-r--r--spec/services/preview_markdown_service_spec.rb67
1 files changed, 67 insertions, 0 deletions
diff --git a/spec/services/preview_markdown_service_spec.rb b/spec/services/preview_markdown_service_spec.rb
new file mode 100644
index 00000000000..b2fb5c91313
--- /dev/null
+++ b/spec/services/preview_markdown_service_spec.rb
@@ -0,0 +1,67 @@
+require 'spec_helper'
+
+describe PreviewMarkdownService do
+ let(:user) { create(:user) }
+ let(:project) { create(:empty_project) }
+
+ 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
+
+ context 'new note with slash commands' do
+ let(:issue) { create(:issue, project: project) }
+ let(:params) do
+ {
+ text: "Please do it\n/assign #{user.to_reference}",
+ slash_commands_target_type: 'Issue',
+ slash_commands_target_id: issue.id
+ }
+ end
+ let(:service) { described_class.new(project, user, params) }
+
+ it 'removes slash commands from text' do
+ result = service.execute
+
+ expect(result[:text]).to eq 'Please do it'
+ end
+
+ it 'explains slash commands effect' do
+ 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",
+ slash_commands_target_type: 'MergeRequest'
+ }
+ end
+ let(:service) { described_class.new(project, user, params) }
+
+ it 'removes slash commands from text' do
+ result = service.execute
+
+ expect(result[:text]).to eq 'My work'
+ end
+
+ it 'explains slash commands effect' do
+ result = service.execute
+
+ expect(result[:commands]).to eq 'Sets time estimate to 2y.'
+ end
+ end
+end