2016-06-30 11:34:19 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2017-05-31 01:50:53 -04:00
|
|
|
describe Gitlab::QuickActions::Dsl do
|
2016-06-30 11:34:19 -04:00
|
|
|
before :all do
|
2016-08-11 12:51:37 -04:00
|
|
|
DummyClass = Struct.new(:project) do
|
2017-05-31 01:50:53 -04:00
|
|
|
include Gitlab::QuickActions::Dsl # rubocop:disable RSpec/DescribedClass
|
2016-06-30 11:34:19 -04:00
|
|
|
|
|
|
|
desc 'A command with no args'
|
|
|
|
command :no_args, :none do
|
|
|
|
"Hello World!"
|
|
|
|
end
|
|
|
|
|
|
|
|
params 'The first argument'
|
2016-11-16 06:09:09 -05:00
|
|
|
explanation 'Static explanation'
|
|
|
|
command :explanation_with_aliases, :once, :first do |arg|
|
|
|
|
arg
|
2016-06-30 11:34:19 -04:00
|
|
|
end
|
|
|
|
|
2016-08-11 12:51:37 -04:00
|
|
|
desc do
|
|
|
|
"A dynamic description for #{noteable.upcase}"
|
|
|
|
end
|
2016-06-30 11:34:19 -04:00
|
|
|
params 'The first argument', 'The second argument'
|
2016-11-16 06:09:09 -05:00
|
|
|
command :dynamic_description do |args|
|
|
|
|
args.split
|
2016-06-30 11:34:19 -04:00
|
|
|
end
|
|
|
|
|
2016-08-13 12:58:51 -04:00
|
|
|
command :cc
|
2016-08-10 08:12:09 -04:00
|
|
|
|
2016-11-16 06:09:09 -05:00
|
|
|
explanation do |arg|
|
|
|
|
"Action does something with #{arg}"
|
|
|
|
end
|
2016-08-11 12:51:37 -04:00
|
|
|
condition do
|
|
|
|
project == 'foo'
|
|
|
|
end
|
|
|
|
command :cond_action do |arg|
|
|
|
|
arg
|
2016-08-10 11:51:01 -04:00
|
|
|
end
|
2016-11-16 06:09:09 -05:00
|
|
|
|
|
|
|
parse_params do |raw_arg|
|
|
|
|
raw_arg.strip
|
|
|
|
end
|
|
|
|
command :with_params_parsing do |parsed|
|
|
|
|
parsed
|
|
|
|
end
|
2017-07-24 23:11:22 -04:00
|
|
|
|
|
|
|
params '<Comment>'
|
|
|
|
substitution :something do |text|
|
|
|
|
"#{text} Some complicated thing you want in here"
|
|
|
|
end
|
2016-06-30 11:34:19 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '.command_definitions' do
|
2016-08-10 11:51:01 -04:00
|
|
|
it 'returns an array with commands definitions' do
|
2016-11-16 06:09:09 -05:00
|
|
|
no_args_def, explanation_with_aliases_def, dynamic_description_def,
|
2017-07-24 23:11:22 -04:00
|
|
|
cc_def, cond_action_def, with_params_parsing_def, substitution_def =
|
2016-11-16 06:09:09 -05:00
|
|
|
DummyClass.command_definitions
|
2016-08-13 12:58:51 -04:00
|
|
|
|
|
|
|
expect(no_args_def.name).to eq(:no_args)
|
|
|
|
expect(no_args_def.aliases).to eq([:none])
|
|
|
|
expect(no_args_def.description).to eq('A command with no args')
|
2016-11-16 06:09:09 -05:00
|
|
|
expect(no_args_def.explanation).to eq('')
|
2016-08-13 12:58:51 -04:00
|
|
|
expect(no_args_def.params).to eq([])
|
|
|
|
expect(no_args_def.condition_block).to be_nil
|
|
|
|
expect(no_args_def.action_block).to be_a_kind_of(Proc)
|
2016-11-16 06:09:09 -05:00
|
|
|
expect(no_args_def.parse_params_block).to be_nil
|
2016-08-13 12:58:51 -04:00
|
|
|
|
2016-11-16 06:09:09 -05:00
|
|
|
expect(explanation_with_aliases_def.name).to eq(:explanation_with_aliases)
|
|
|
|
expect(explanation_with_aliases_def.aliases).to eq([:once, :first])
|
|
|
|
expect(explanation_with_aliases_def.description).to eq('')
|
|
|
|
expect(explanation_with_aliases_def.explanation).to eq('Static explanation')
|
|
|
|
expect(explanation_with_aliases_def.params).to eq(['The first argument'])
|
|
|
|
expect(explanation_with_aliases_def.condition_block).to be_nil
|
|
|
|
expect(explanation_with_aliases_def.action_block).to be_a_kind_of(Proc)
|
|
|
|
expect(explanation_with_aliases_def.parse_params_block).to be_nil
|
2016-08-13 12:58:51 -04:00
|
|
|
|
2016-11-16 06:09:09 -05:00
|
|
|
expect(dynamic_description_def.name).to eq(:dynamic_description)
|
|
|
|
expect(dynamic_description_def.aliases).to eq([])
|
|
|
|
expect(dynamic_description_def.to_h(noteable: 'issue')[:description]).to eq('A dynamic description for ISSUE')
|
|
|
|
expect(dynamic_description_def.explanation).to eq('')
|
|
|
|
expect(dynamic_description_def.params).to eq(['The first argument', 'The second argument'])
|
|
|
|
expect(dynamic_description_def.condition_block).to be_nil
|
|
|
|
expect(dynamic_description_def.action_block).to be_a_kind_of(Proc)
|
|
|
|
expect(dynamic_description_def.parse_params_block).to be_nil
|
2016-08-16 20:59:55 -04:00
|
|
|
|
2016-08-13 12:58:51 -04:00
|
|
|
expect(cc_def.name).to eq(:cc)
|
|
|
|
expect(cc_def.aliases).to eq([])
|
|
|
|
expect(cc_def.description).to eq('')
|
2016-11-16 06:09:09 -05:00
|
|
|
expect(cc_def.explanation).to eq('')
|
2016-08-13 12:58:51 -04:00
|
|
|
expect(cc_def.params).to eq([])
|
|
|
|
expect(cc_def.condition_block).to be_nil
|
|
|
|
expect(cc_def.action_block).to be_nil
|
2016-11-16 06:09:09 -05:00
|
|
|
expect(cc_def.parse_params_block).to be_nil
|
2016-08-13 12:58:51 -04:00
|
|
|
|
2016-08-16 20:59:55 -04:00
|
|
|
expect(cond_action_def.name).to eq(:cond_action)
|
|
|
|
expect(cond_action_def.aliases).to eq([])
|
|
|
|
expect(cond_action_def.description).to eq('')
|
2016-11-16 06:09:09 -05:00
|
|
|
expect(cond_action_def.explanation).to be_a_kind_of(Proc)
|
2016-08-16 20:59:55 -04:00
|
|
|
expect(cond_action_def.params).to eq([])
|
|
|
|
expect(cond_action_def.condition_block).to be_a_kind_of(Proc)
|
|
|
|
expect(cond_action_def.action_block).to be_a_kind_of(Proc)
|
2016-11-16 06:09:09 -05:00
|
|
|
expect(cond_action_def.parse_params_block).to be_nil
|
|
|
|
|
|
|
|
expect(with_params_parsing_def.name).to eq(:with_params_parsing)
|
|
|
|
expect(with_params_parsing_def.aliases).to eq([])
|
|
|
|
expect(with_params_parsing_def.description).to eq('')
|
|
|
|
expect(with_params_parsing_def.explanation).to eq('')
|
|
|
|
expect(with_params_parsing_def.params).to eq([])
|
|
|
|
expect(with_params_parsing_def.condition_block).to be_nil
|
|
|
|
expect(with_params_parsing_def.action_block).to be_a_kind_of(Proc)
|
|
|
|
expect(with_params_parsing_def.parse_params_block).to be_a_kind_of(Proc)
|
2017-07-24 23:11:22 -04:00
|
|
|
|
|
|
|
expect(substitution_def.name).to eq(:something)
|
|
|
|
expect(substitution_def.aliases).to eq([])
|
|
|
|
expect(substitution_def.description).to eq('')
|
|
|
|
expect(substitution_def.explanation).to eq('')
|
|
|
|
expect(substitution_def.params).to eq(['<Comment>'])
|
|
|
|
expect(substitution_def.condition_block).to be_nil
|
|
|
|
expect(substitution_def.action_block.call('text')).to eq('text Some complicated thing you want in here')
|
|
|
|
expect(substitution_def.parse_params_block).to be_nil
|
2016-06-30 11:34:19 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|