Commit cfef4b5b authored by Fatih Acet's avatar Fatih Acet

Merge branch '11194-fix-approvals-groups-all-available' into 'master'

Fetch all available groups in MR approval rule form

Closes #11194

See merge request gitlab-org/gitlab-ee!12096
parents 265dffb0 dc09d1be
...@@ -128,6 +128,7 @@ export default { ...@@ -128,6 +128,7 @@ export default {
fetchGroups(term) { fetchGroups(term) {
return Api.groups(term, { return Api.groups(term, {
skip_groups: this.skipGroupIds, skip_groups: this.skipGroupIds,
all_available: true,
}); });
}, },
fetchUsers(term) { fetchUsers(term) {
......
---
title: Fetch all available groups when creating MR approval rule
merge_request: 12096
author:
type: changed
...@@ -3,7 +3,10 @@ ...@@ -3,7 +3,10 @@
require 'spec_helper' require 'spec_helper'
describe 'Merge request > User edits MR with approval rules', :js do describe 'Merge request > User edits MR with approval rules', :js do
include Select2Helper
include_context 'project with approval rules' include_context 'project with approval rules'
let(:merge_request) { create(:merge_request, source_project: project) } let(:merge_request) { create(:merge_request, source_project: project) }
let(:mr_rule_names) { %w[foo lorem ipsum] } let(:mr_rule_names) { %w[foo lorem ipsum] }
...@@ -30,4 +33,33 @@ describe 'Merge request > User edits MR with approval rules', :js do ...@@ -30,4 +33,33 @@ describe 'Merge request > User edits MR with approval rules', :js do
expect(names).to eq(mr_rule_names) expect(names).to eq(mr_rule_names)
end end
context "with public group" do
let!(:group) { create(:group, :public) }
before do
group.add_developer create(:user)
end
it "can be added by non member" do
members_selector = '#mr-edit-approvals-create-modal input[name=members]'
rule_name = "Custom Approval Rule"
click_button "Add approvers"
fill_in "Name", with: rule_name
open_select2 members_selector
find('.select2-result-label .group-result', text: group.name).click
close_select2 members_selector
find('#mr-edit-approvals-create-modal button', text: 'Add', exact_text: true).click
find('#mr-edit-approvals-create-modal button', text: 'Add approvers').click
wait_for_requests
expect(page_rule_names.last).to have_text(rule_name)
end
end
end end
...@@ -116,7 +116,7 @@ describe('Approvals ApproversSelect', () => { ...@@ -116,7 +116,7 @@ describe('Approvals ApproversSelect', () => {
waitForEvent($input, 'select2-loaded') waitForEvent($input, 'select2-loaded')
.then(() => { .then(() => {
expect(Api.groups).toHaveBeenCalledWith(term, { skip_groups: [] }); expect(Api.groups).toHaveBeenCalledWith(term, { skip_groups: [], all_available: true });
expect(Api.approverUsers).toHaveBeenCalledWith(term, { expect(Api.approverUsers).toHaveBeenCalledWith(term, {
skip_users: [], skip_users: [],
project_id: TEST_PROJECT_ID, project_id: TEST_PROJECT_ID,
...@@ -141,7 +141,11 @@ describe('Approvals ApproversSelect', () => { ...@@ -141,7 +141,11 @@ describe('Approvals ApproversSelect', () => {
waitForEvent($input, 'select2-loaded') waitForEvent($input, 'select2-loaded')
.then(() => { .then(() => {
expect(Api.groups).toHaveBeenCalledWith('', { skip_groups: skipGroupIds }); expect(Api.groups).toHaveBeenCalledWith('', {
skip_groups: skipGroupIds,
all_available: true,
});
expect(Api.approverUsers).toHaveBeenCalledWith('', { expect(Api.approverUsers).toHaveBeenCalledWith('', {
skip_users: skipUserIds, skip_users: skipUserIds,
project_id: TEST_PROJECT_ID, project_id: TEST_PROJECT_ID,
......
...@@ -35,6 +35,10 @@ module Select2Helper ...@@ -35,6 +35,10 @@ module Select2Helper
execute_script("$('#{selector}').select2('open');") execute_script("$('#{selector}').select2('open');")
end end
def close_select2(selector)
execute_script("$('#{selector}').select2('close');")
end
def scroll_select2_to_bottom(selector) def scroll_select2_to_bottom(selector)
evaluate_script "$('#{selector}').scrollTop($('#{selector}')[0].scrollHeight); $('#{selector}');" evaluate_script "$('#{selector}').scrollTop($('#{selector}')[0].scrollHeight); $('#{selector}');"
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment