Commit f547d41b authored by Mark Chao's avatar Mark Chao

Migrate feature spec for approval rule

Comment out spec for suggested approver feature
which is broken.
parent 81eea88b
require 'rails_helper' require 'rails_helper'
describe 'Merge request > User approves', :js do # TODO: https://gitlab.com/gitlab-org/gitlab-ee/issues/9430
xdescribe 'Merge request > User approves', :js do
let(:user) { create(:user) } let(:user) { create(:user) }
let(:project) { create(:project, :public, :repository, approvals_before_merge: 1) } let(:project) { create(:project, :public, :repository, approvals_before_merge: 1) }
let(:merge_request) { create(:merge_request, source_project: project) } let(:merge_request) { create(:merge_request, source_project: project) }
before do
stub_feature_flags(approval_rules: false)
end
context 'Approving by approvers from groups' do context 'Approving by approvers from groups' do
let(:other_user) { create(:user) } let(:other_user) { create(:user) }
let(:group) { create :group } let(:group) { create :group }
...@@ -65,7 +62,6 @@ describe 'Merge request > User approves', :js do ...@@ -65,7 +62,6 @@ describe 'Merge request > User approves', :js do
context 'when CI is running but no approval given' do context 'when CI is running but no approval given' do
before do before do
stub_feature_flags(approval_rules: false) # TODO check in !9001 when feature enabled
create :approver_group, group: group, target: merge_request create :approver_group, group: group, target: merge_request
pipeline = create(:ci_empty_pipeline, project: project, sha: merge_request.diff_head_sha, ref: merge_request.source_branch) pipeline = create(:ci_empty_pipeline, project: project, sha: merge_request.diff_head_sha, ref: merge_request.source_branch)
merge_request.update(head_pipeline: pipeline) merge_request.update(head_pipeline: pipeline)
......
...@@ -18,14 +18,12 @@ describe "User creates a merge request", :js do ...@@ -18,14 +18,12 @@ describe "User creates a merge request", :js do
let(:user2) { create(:user) } let(:user2) { create(:user) }
before do before do
stub_feature_flags(approval_rules: false)
project.add_maintainer(user) project.add_maintainer(user)
project.add_maintainer(user2) project.add_maintainer(user2)
project.add_maintainer(approver) project.add_maintainer(approver)
sign_in(user) sign_in(user)
project.approvers.create(user_id: approver.id) create(:approval_project_rule, project: project, users: [approver])
visit(project_new_merge_request_path(project)) visit(project_new_merge_request_path(project))
end end
...@@ -43,10 +41,12 @@ describe "User creates a merge request", :js do ...@@ -43,10 +41,12 @@ describe "User creates a merge request", :js do
expect(find_field("merge_request_description").value).to eq(template_text) expect(find_field("merge_request_description").value).to eq(template_text)
page.within("ul .unsaved-approvers") do page.within('.js-approval-rules') do
expect(page).to have_content(approver.name) expect(page).to have_css("img[alt=\"#{approver.name}\"]")
end end
# TODO: Fix https://gitlab.com/gitlab-org/gitlab-ee/issues/11527
=begin
page.within(".suggested-approvers") do page.within(".suggested-approvers") do
expect(page).to have_content(user2.name) expect(page).to have_content(user2.name)
end end
...@@ -55,7 +55,8 @@ describe "User creates a merge request", :js do ...@@ -55,7 +55,8 @@ describe "User creates a merge request", :js do
page.within("ul.approver-list") do page.within("ul.approver-list") do
expect(page).to have_content(user2.name) expect(page).to have_content(user2.name)
end end
=end
fill_in("Title", with: title) fill_in("Title", with: title)
click_button("Submit merge request") click_button("Submit merge request")
...@@ -64,8 +65,10 @@ describe "User creates a merge request", :js do ...@@ -64,8 +65,10 @@ describe "User creates a merge request", :js do
click_link("Edit", match: :first) click_link("Edit", match: :first)
end end
=begin
page.within("ul.approver-list") do page.within("ul.approver-list") do
expect(page).to have_content(user2.name) expect(page).to have_content(user2.name)
end end
=end
end end
end end
...@@ -6,8 +6,6 @@ describe 'Merge request > User sees approval widget', :js do ...@@ -6,8 +6,6 @@ describe 'Merge request > User sees approval widget', :js do
let(:merge_request) { create(:merge_request, source_project: project) } let(:merge_request) { create(:merge_request, source_project: project) }
before do before do
stub_feature_flags(approval_rules: false)
sign_in(user) sign_in(user)
end end
...@@ -22,17 +20,14 @@ describe 'Merge request > User sees approval widget', :js do ...@@ -22,17 +20,14 @@ describe 'Merge request > User sees approval widget', :js do
visit project_merge_request_path(project, merge_request) visit project_merge_request_path(project, merge_request)
end end
it 'does not show checking ability text' do # TODO: https://gitlab.com/gitlab-org/gitlab-ee/issues/9430
xit 'does not show checking ability text' do
expect(find('.js-mr-approvals')).not_to have_text('Checking ability to merge automatically') expect(find('.js-mr-approvals')).not_to have_text('Checking ability to merge automatically')
expect(find('.js-mr-approvals')).to have_selector('.approvals-body') expect(find('.js-mr-approvals')).to have_selector('.approvals-body')
end end
end end
context 'when rules are enabled' do context 'when rules are enabled' do
before do
stub_feature_flags(approval_rules: true)
end
context 'merge request approvers enabled' do context 'merge request approvers enabled' do
let(:project) { create(:project, :public, :repository, approvals_before_merge: 3) } let(:project) { create(:project, :public, :repository, approvals_before_merge: 3) }
......
...@@ -14,7 +14,6 @@ describe 'User approves a merge request', :js do ...@@ -14,7 +14,6 @@ describe 'User approves a merge request', :js do
context 'when user can approve' do context 'when user can approve' do
before do before do
stub_feature_flags(approval_rules: false) # TODO check in !9001 when feature enabled
visit(merge_request_path(merge_request)) visit(merge_request_path(merge_request))
end end
...@@ -31,12 +30,12 @@ describe 'User approves a merge request', :js do ...@@ -31,12 +30,12 @@ describe 'User approves a merge request', :js do
context 'when a merge request is approved additionally' do context 'when a merge request is approved additionally' do
before do before do
stub_feature_flags(approval_rules: false) # TODO check in !9001 when feature enabled
project.add_developer(user2) project.add_developer(user2)
project.add_developer(user3) project.add_developer(user3)
end end
it 'shows multiple approvers beyond the needed count' do # TODO: https://gitlab.com/gitlab-org/gitlab-ee/issues/9430
xit 'shows multiple approvers beyond the needed count' do
visit(merge_request_path(merge_request)) visit(merge_request_path(merge_request))
click_button('Approve') click_button('Approve')
...@@ -47,7 +46,8 @@ describe 'User approves a merge request', :js do ...@@ -47,7 +46,8 @@ describe 'User approves a merge request', :js do
sign_in_visit_merge_request(user2, true) sign_in_visit_merge_request(user2, true)
sign_in_visit_merge_request(user3, true) sign_in_visit_merge_request(user3, true)
expect(all('.js-approver-list-member').count).to eq(3) widget = find('.js-mr-approvals').find(:xpath, '..')
expect(widget.all('.user-avatar-link').count).to eq(3)
end end
it "doesn't show the add approval when a merge request is closed" do it "doesn't show the add approval when a merge request is closed" do
...@@ -75,7 +75,6 @@ describe 'User approves a merge request', :js do ...@@ -75,7 +75,6 @@ describe 'User approves a merge request', :js do
context 'when user cannot approve' do context 'when user cannot approve' do
before do before do
stub_feature_flags(approval_rules: false) # TODO check in !9001 when feature enabled
merge_request.approvers.create(user_id: user2.id) merge_request.approvers.create(user_id: user2.id)
visit(merge_request_path(merge_request)) visit(merge_request_path(merge_request))
...@@ -85,7 +84,7 @@ describe 'User approves a merge request', :js do ...@@ -85,7 +84,7 @@ describe 'User approves a merge request', :js do
page.within('.mr-state-widget') do page.within('.mr-state-widget') do
expect(page).to have_button('Merge', disabled: true) expect(page).to have_button('Merge', disabled: true)
expect(page).not_to have_button('Approve') expect(page).not_to have_button('Approve')
expect(page).to have_content('Requires 1 more approval') expect(page).to have_content('Requires approval')
end end
end end
end end
......
...@@ -8,10 +8,49 @@ describe 'Project settings > [EE] Merge Requests', :js do ...@@ -8,10 +8,49 @@ describe 'Project settings > [EE] Merge Requests', :js do
let(:group) { create(:group) } let(:group) { create(:group) }
let(:group_member) { create(:user) } let(:group_member) { create(:user) }
let(:non_member) { create(:user) } let(:non_member) { create(:user) }
let!(:config_selector) { '.js-approval-rules' }
let!(:modal_selector) { '#project-settings-approvals-create-modal' }
before do def open_modal
stub_feature_flags(approval_rules: false) page.execute_script "document.querySelector('#{config_selector}').scrollIntoView()"
within(config_selector) do
click_on('Edit')
end
end
def open_approver_select
within(modal_selector) do
find('.select2-input').click
end
wait_for_requests
end
def close_approver_select
within(modal_selector) do
find('.select2-input').send_keys :escape
end
end
def remove_approver(name)
el = page.find("#{modal_selector} .content-list li", text: /#{name}/i)
el.find('button').click
end
def expect_avatar(container, users)
users = Array(users)
members = container.all('.js-members img.avatar').map do |member|
member['alt']
end
users.each do |user|
expect(members).to include(user.name)
end
expect(members.size).to eq(users.size)
end
before do
sign_in(user) sign_in(user)
project.add_maintainer(user) project.add_maintainer(user)
group.add_developer(user) group.add_developer(user)
...@@ -21,68 +60,68 @@ describe 'Project settings > [EE] Merge Requests', :js do ...@@ -21,68 +60,68 @@ describe 'Project settings > [EE] Merge Requests', :js do
it 'adds approver' do it 'adds approver' do
visit edit_project_path(project) visit edit_project_path(project)
find('#s2id_approver_user_and_group_ids .select2-input').click open_modal
open_approver_select
wait_for_requests
expect(find('.select2-results')).to have_content(user.name) expect(find('.select2-results')).to have_content(user.name)
expect(find('.select2-results')).not_to have_content(non_member.name)
find('.user-result', text: user.name).click find('.user-result', text: user.name).click
close_approver_select
click_button 'Add' click_button 'Add'
expect(find('.js-current-approvers')).to have_content(user.name) expect(find('.content-list')).to have_content(user.name)
find('.js-select-user-and-group').click open_approver_select
expect(find('.select2-results')).not_to have_content(user.name) expect(find('.select2-results')).not_to have_content(user.name)
end
it 'filter approvers' do close_approver_select
visit edit_project_path(project) click_button 'Update approvers'
find('.js-select-user-and-group').click wait_for_requests
expect(find('.select2-results')).to have_content(user.name) expect_avatar(find('.js-members'), user)
expect(find('.select2-results')).not_to have_content(non_member.name)
end end
it 'adds approver group' do it 'adds approver group' do
visit edit_project_path(project) visit edit_project_path(project)
find('#s2id_approver_user_and_group_ids .select2-input').click open_modal
open_approver_select
wait_for_requests
within('.js-current-approvers') do
expect(find('.card-header .badge')).to have_content('0')
end
expect(find('.select2-results')).to have_content(group.name) expect(find('.select2-results')).to have_content(group.name)
find('.select2-results .group-result').click
find('.user-result', text: group.name).click
close_approver_select
click_button 'Add' click_button 'Add'
expect(find('.approver-list-loader')).to be_visible expect(find('.content-list')).to have_content(group.name)
expect(page).to have_css('.js-current-approvers li.approver-group', count: 1)
expect(page).to have_css('.js-current-approvers li.approver-group', count: 1) click_button 'Update approvers'
within('.js-current-approvers') do wait_for_requests
expect(find('.card-header .badge')).to have_content('2')
end expect_avatar(find('.js-members'), group.users)
end end
context 'with an approver group' do context 'with an approver group' do
let(:non_group_approver) { create(:user) }
let!(:rule) { create(:approval_project_rule, project: project, groups: [group], users: [non_group_approver]) }
before do before do
create(:approver_group, group: group, target: project) project.add_developer(non_group_approver)
end end
it 'removes approver group' do it 'removes approver group' do
visit edit_project_path(project) visit edit_project_path(project)
expect(find('.js-current-approvers')).to have_content(group.name) expect_avatar(find('.js-members'), rule.approvers)
within('.js-current-approvers') do open_modal
accept_confirm { click_on "Remove" } remove_approver(group.name)
end click_button "Update approvers"
wait_for_requests
expect(find('.js-current-approvers')).not_to have_content(group.name) expect_avatar(find('.js-members'), [non_group_approver])
end end
end end
......
...@@ -22,8 +22,6 @@ describe Projects::MergeRequestsController, '(JavaScript fixtures)', type: :cont ...@@ -22,8 +22,6 @@ describe Projects::MergeRequestsController, '(JavaScript fixtures)', type: :cont
end end
before do before do
stub_feature_flags(approval_rules: false)
# Ensure some approver suggestions are displayed # Ensure some approver suggestions are displayed
service = double(:service) service = double(:service)
expect(::Gitlab::AuthorityAnalyzer).to receive(:new).and_return(service) expect(::Gitlab::AuthorityAnalyzer).to receive(:new).and_return(service)
...@@ -33,8 +31,6 @@ describe Projects::MergeRequestsController, '(JavaScript fixtures)', type: :cont ...@@ -33,8 +31,6 @@ describe Projects::MergeRequestsController, '(JavaScript fixtures)', type: :cont
approver_group = create(:approver_group, target: project) approver_group = create(:approver_group, target: project)
approver_group.group.add_owner(create(:owner)) approver_group.group.add_owner(create(:owner))
stub_feature_flags(approval_rules: false)
sign_in(admin) sign_in(admin)
end end
......
...@@ -8,8 +8,6 @@ describe "User creates a merge request", :js do ...@@ -8,8 +8,6 @@ describe "User creates a merge request", :js do
let(:user) { create(:user) } let(:user) { create(:user) }
before do before do
stub_feature_flags(approval_rules: false)
project.add_maintainer(user) project.add_maintainer(user)
sign_in(user) sign_in(user)
end end
......
...@@ -7,7 +7,6 @@ describe 'Projects > Settings > For a forked project', :js do ...@@ -7,7 +7,6 @@ describe 'Projects > Settings > For a forked project', :js do
let(:forked_project) { fork_project(original_project, user) } let(:forked_project) { fork_project(original_project, user) }
before do before do
stub_feature_flags(approval_rules: false)
original_project.add_maintainer(user) original_project.add_maintainer(user)
forked_project.add_maintainer(user) forked_project.add_maintainer(user)
sign_in(user) sign_in(user)
......
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