2019-10-12 21:52:04 +05:30
# frozen_string_literal: true
2019-12-04 20:38:33 +05:30
require 'spec_helper'
2017-08-17 22:00:37 +05:30
2020-06-23 00:09:42 +05:30
RSpec . describe 'Resolving all open threads in a merge request from an issue' , :js do
2017-08-17 22:00:37 +05:30
let ( :user ) { create ( :user ) }
2017-09-10 17:25:29 +05:30
let ( :project ) { create ( :project , :repository ) }
2017-08-17 22:00:37 +05:30
let ( :merge_request ) { create ( :merge_request , source_project : project ) }
let! ( :discussion ) { create ( :diff_note_on_merge_request , noteable : merge_request , project : project ) . to_discussion }
2020-10-24 23:57:45 +05:30
def resolve_all_discussions_link_selector ( title : " " )
2018-11-08 19:23:39 +05:30
url = new_project_issue_path ( project , merge_request_to_resolve_discussions_of : merge_request . iid )
2020-10-24 23:57:45 +05:30
if title . empty?
%Q{ a[href=" #{ url } "] }
else
%Q{ a[title=" #{ title } "][href=" #{ url } "] }
end
2018-11-08 19:23:39 +05:30
end
2017-08-17 22:00:37 +05:30
describe 'as a user with access to the project' do
before do
2018-11-18 11:00:15 +05:30
project . add_maintainer ( user )
2017-09-10 17:25:29 +05:30
sign_in user
visit project_merge_request_path ( project , merge_request )
2017-08-17 22:00:37 +05:30
end
2019-09-30 21:07:59 +05:30
it 'shows a button to resolve all threads by creating a new issue' do
2018-11-08 19:23:39 +05:30
within ( '.line-resolve-all-container' ) do
2020-10-24 23:57:45 +05:30
expect ( page ) . to have_selector resolve_all_discussions_link_selector ( title : " Resolve all threads in new issue " )
2017-08-17 22:00:37 +05:30
end
end
2019-09-30 21:07:59 +05:30
context 'resolving the thread' do
2017-08-17 22:00:37 +05:30
before do
2021-04-29 21:17:54 +05:30
find ( 'button[data-qa-selector="resolve_discussion_button"]' ) . click
2017-08-17 22:00:37 +05:30
end
it 'hides the link for creating a new issue' do
2018-11-08 19:23:39 +05:30
expect ( page ) . not_to have_selector resolve_all_discussions_link_selector
2020-10-24 23:57:45 +05:30
expect ( page ) . not_to have_content " Resolve all threads in new issue "
2017-08-17 22:00:37 +05:30
end
end
2019-09-30 21:07:59 +05:30
context 'creating an issue for threads' do
2017-08-17 22:00:37 +05:30
before do
2018-11-08 19:23:39 +05:30
find ( resolve_all_discussions_link_selector ) . click
2017-08-17 22:00:37 +05:30
end
2019-09-30 21:07:59 +05:30
it_behaves_like 'creating an issue for a thread'
2017-08-17 22:00:37 +05:30
end
2019-09-30 21:07:59 +05:30
context 'for a project where all threads need to be resolved before merging' do
2017-08-17 22:00:37 +05:30
before do
project . update_attribute ( :only_allow_merge_if_all_discussions_are_resolved , true )
end
context 'with the internal tracker disabled' do
before do
project . project_feature . update_attribute ( :issues_access_level , ProjectFeature :: DISABLED )
2017-09-10 17:25:29 +05:30
visit project_merge_request_path ( project , merge_request )
2017-08-17 22:00:37 +05:30
end
it 'does not show a link to create a new issue' do
2020-10-24 23:57:45 +05:30
expect ( page ) . not_to have_link 'Resolve all threads in new issue'
2017-08-17 22:00:37 +05:30
end
end
2019-09-30 21:07:59 +05:30
context 'merge request has threads that need to be resolved' do
2017-08-17 22:00:37 +05:30
before do
2017-09-10 17:25:29 +05:30
visit project_merge_request_path ( project , merge_request )
2017-08-17 22:00:37 +05:30
end
2019-09-30 21:07:59 +05:30
it 'shows a warning that the merge request contains unresolved threads' do
2020-10-24 23:57:45 +05:30
expect ( page ) . to have_content 'Before this can be merged,'
2017-08-17 22:00:37 +05:30
end
2019-09-30 21:07:59 +05:30
it 'has a link to resolve all threads by creating an issue' do
2017-08-17 22:00:37 +05:30
page . within '.mr-widget-body' do
2020-10-24 23:57:45 +05:30
expect ( page ) . to have_link 'Resolve all threads in new issue' , href : new_project_issue_path ( project , merge_request_to_resolve_discussions_of : merge_request . iid )
2017-08-17 22:00:37 +05:30
end
end
2019-09-30 21:07:59 +05:30
context 'creating an issue for threads' do
2017-08-17 22:00:37 +05:30
before do
2020-10-24 23:57:45 +05:30
page . within '.mr-widget-body' do
page . click_link 'Resolve all threads in new issue' , href : new_project_issue_path ( project , merge_request_to_resolve_discussions_of : merge_request . iid )
2021-04-17 20:07:23 +05:30
wait_for_all_requests
2020-10-24 23:57:45 +05:30
end
2017-08-17 22:00:37 +05:30
end
2019-09-30 21:07:59 +05:30
it_behaves_like 'creating an issue for a thread'
2017-08-17 22:00:37 +05:30
end
end
end
end
describe 'as a reporter' do
before do
2018-03-17 18:26:18 +05:30
project . add_reporter ( user )
2017-09-10 17:25:29 +05:30
sign_in user
visit new_project_issue_path ( project , merge_request_to_resolve_discussions_of : merge_request . iid )
2017-08-17 22:00:37 +05:30
end
2021-02-22 17:27:13 +05:30
it 'shows a notice to ask someone else to resolve the threads' do
2019-09-30 21:07:59 +05:30
expect ( page ) . to have_content ( " The threads at #{ merge_request . to_reference } will stay unresolved. Ask someone with permission to resolve them. " )
2017-08-17 22:00:37 +05:30
end
end
end