Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/services/quick_actions/interpret_service_spec.rb')
-rw-r--r--spec/services/quick_actions/interpret_service_spec.rb166
1 files changed, 125 insertions, 41 deletions
diff --git a/spec/services/quick_actions/interpret_service_spec.rb b/spec/services/quick_actions/interpret_service_spec.rb
index f7a22b1b92f..f7ed6006099 100644
--- a/spec/services/quick_actions/interpret_service_spec.rb
+++ b/spec/services/quick_actions/interpret_service_spec.rb
@@ -122,7 +122,7 @@ RSpec.describe QuickActions::InterpretService do
inprogress # populate the label
_, updates, _ = service.execute(content, issuable)
- expect(updates).to eq(add_label_ids: [bug.id, inprogress.id])
+ expect(updates).to match(add_label_ids: contain_exactly(bug.id, inprogress.id))
end
it 'returns the label message' do
@@ -130,7 +130,10 @@ RSpec.describe QuickActions::InterpretService do
inprogress # populate the label
_, _, message = service.execute(content, issuable)
- expect(message).to eq("Added #{bug.to_reference(format: :name)} #{inprogress.to_reference(format: :name)} labels.")
+ # Compare message without making assumptions about ordering.
+ expect(message).to match %r{Added ~".*" ~".*" labels.}
+ expect(message).to include(bug.to_reference(format: :name))
+ expect(message).to include(inprogress.to_reference(format: :name))
end
end
@@ -318,32 +321,40 @@ RSpec.describe QuickActions::InterpretService do
end
shared_examples 'draft command' do
- it 'returns wip_event: "wip" if content contains /draft' do
+ it 'returns wip_event: "draft"' do
_, updates, _ = service.execute(content, issuable)
- expect(updates).to eq(wip_event: 'wip')
+ expect(updates).to eq(wip_event: 'draft')
end
- it 'returns the wip message' do
+ it 'returns the draft message' do
_, _, message = service.execute(content, issuable)
expect(message).to eq("Marked this #{issuable.to_ability_name.humanize(capitalize: false)} as a draft.")
end
end
- shared_examples 'undraft command' do
- it 'returns wip_event: "unwip" if content contains /draft' do
- issuable.update!(title: issuable.wip_title)
+ shared_examples 'draft/ready command no action' do
+ it 'returns the no action message if there is no change to the status' do
+ _, _, message = service.execute(content, issuable)
+
+ expect(message).to eq("No change to this #{issuable.to_ability_name.humanize(capitalize: false)}'s draft status.")
+ end
+ end
+
+ shared_examples 'ready command' do
+ it 'returns wip_event: "ready"' do
+ issuable.update!(title: issuable.draft_title)
_, updates, _ = service.execute(content, issuable)
- expect(updates).to eq(wip_event: 'unwip')
+ expect(updates).to eq(wip_event: 'ready')
end
- it 'returns the unwip message' do
- issuable.update!(title: issuable.wip_title)
+ it 'returns the ready message' do
+ issuable.update!(title: issuable.draft_title)
_, _, message = service.execute(content, issuable)
- expect(message).to eq("Unmarked this #{issuable.to_ability_name.humanize(capitalize: false)} as a draft.")
+ expect(message).to eq("Marked this #{issuable.to_ability_name.humanize(capitalize: false)} as ready.")
end
end
@@ -1196,6 +1207,64 @@ RSpec.describe QuickActions::InterpretService do
let(:issuable) { merge_request }
end
+ context 'with a colon label' do
+ let(:bug) { create(:label, project: project, title: 'Category:Bug') }
+ let(:inprogress) { create(:label, project: project, title: 'status:in:progress') }
+
+ context 'when quoted' do
+ let(:content) { %(/label ~"#{inprogress.title}" ~"#{bug.title}" ~unknown) }
+
+ it_behaves_like 'label command' do
+ let(:issuable) { merge_request }
+ end
+
+ it_behaves_like 'label command' do
+ let(:issuable) { issue }
+ end
+ end
+
+ context 'when unquoted' do
+ let(:content) { %(/label ~#{inprogress.title} ~#{bug.title} ~unknown) }
+
+ it_behaves_like 'label command' do
+ let(:issuable) { merge_request }
+ end
+
+ it_behaves_like 'label command' do
+ let(:issuable) { issue }
+ end
+ end
+ end
+
+ context 'with a scoped label' do
+ let(:bug) { create(:label, :scoped, project: project) }
+ let(:inprogress) { create(:label, project: project, title: 'three::part::label') }
+
+ context 'when quoted' do
+ let(:content) { %(/label ~"#{inprogress.title}" ~"#{bug.title}" ~unknown) }
+
+ it_behaves_like 'label command' do
+ let(:issuable) { merge_request }
+ end
+
+ it_behaves_like 'label command' do
+ let(:issuable) { issue }
+ end
+ end
+
+ context 'when unquoted' do
+ let(:content) { %(/label ~#{inprogress.title} ~#{bug.title} ~unknown) }
+
+ it_behaves_like 'label command' do
+ let(:issuable) { merge_request }
+ end
+
+ it_behaves_like 'label command' do
+ let(:issuable) { issue }
+ end
+ end
+ end
+
it_behaves_like 'multiple label command' do
let(:content) { %(/label ~"#{inprogress.title}" \n/label ~#{bug.title}) }
let(:issuable) { issue }
@@ -1306,11 +1375,21 @@ RSpec.describe QuickActions::InterpretService do
let(:issuable) { merge_request }
end
- it_behaves_like 'undraft command' do
+ it_behaves_like 'ready command' do
let(:content) { '/draft' }
let(:issuable) { merge_request }
end
+ it_behaves_like 'draft/ready command no action' do
+ let(:content) { '/ready' }
+ let(:issuable) { merge_request }
+ end
+
+ it_behaves_like 'ready command' do
+ let(:content) { '/ready' }
+ let(:issuable) { merge_request }
+ end
+
it_behaves_like 'failed command', 'Could not apply remove_due_date command.' do
let(:content) { '/remove_due_date' }
let(:issuable) { merge_request }
@@ -2333,24 +2412,6 @@ RSpec.describe QuickActions::InterpretService do
create(:issue_customer_relations_contact, issue: issue, contact: existing_contact)
end
- context 'with feature flag disabled' do
- before do
- stub_feature_flags(customer_relations: false)
- end
-
- it 'add_contacts command does not add the contact' do
- _, updates, _ = add_command
-
- expect(updates).to be_empty
- end
-
- it 'remove_contacts command does not remove the contact' do
- _, updates, _ = remove_command
-
- expect(updates).to be_empty
- end
- end
-
it 'add_contacts command adds the contact' do
_, updates, message = add_command
@@ -2644,7 +2705,24 @@ RSpec.describe QuickActions::InterpretService do
it 'includes the new status' do
_, explanations = service.explain(content, merge_request)
- expect(explanations).to eq(['Marks this merge request as a draft.'])
+ expect(explanations).to match_array(['Marks this merge request as a draft.'])
+ end
+ end
+
+ describe 'ready command' do
+ let(:content) { '/ready' }
+
+ it 'includes the new status' do
+ merge_request.update!(title: merge_request.draft_title)
+ _, explanations = service.explain(content, merge_request)
+
+ expect(explanations).to match_array(['Marks this merge request as ready.'])
+ end
+
+ it 'includes the no change message when status unchanged' do
+ _, explanations = service.explain(content, merge_request)
+
+ expect(explanations).to match_array(["No change to this merge request's draft status."])
end
end
@@ -2805,12 +2883,6 @@ RSpec.describe QuickActions::InterpretService do
expect(explanations).to be_empty
end
-
- it '/remove_contacts is not available' do
- _, explanations = service.explain(remove_contacts, issue)
-
- expect(explanations).to be_empty
- end
end
context 'when group has contacts' do
@@ -2822,10 +2894,22 @@ RSpec.describe QuickActions::InterpretService do
expect(explanations).to contain_exactly("Add customer relation contact(s).")
end
- it '/remove_contacts is available' do
- _, explanations = service.explain(remove_contacts, issue)
+ context 'when issue has no contacts' do
+ it '/remove_contacts is not available' do
+ _, explanations = service.explain(remove_contacts, issue)
- expect(explanations).to contain_exactly("Remove customer relation contact(s).")
+ expect(explanations).to be_empty
+ end
+ end
+
+ context 'when issue has contacts' do
+ let!(:issue_contact) { create(:issue_customer_relations_contact, issue: issue, contact: contact) }
+
+ it '/remove_contacts is available' do
+ _, explanations = service.explain(remove_contacts, issue)
+
+ expect(explanations).to contain_exactly("Remove customer relation contact(s).")
+ end
end
end
end