Read about our upcoming Code of Conduct on this issue

Commit 959e6d22 authored by Ashley Dumaine's avatar Ashley Dumaine Committed by Sean McGivern
Browse files

add unit tests for new collapse_outdated_diff_comments toggle

parent bac58c105294
require 'spec_helper'
feature 'Collapse outdated diff comments', js: true do
let(:merge_request) { create(:merge_request, importing: true) }
let(:project) { merge_request.source_project }
let!(:outdated_discussion) { create(:diff_note_on_merge_request, project: project, noteable: merge_request, position: outdated_position).to_discussion }
let!(:active_discussion) { create(:diff_note_on_merge_request, noteable: merge_request, project: project).to_discussion }
let(:outdated_position) do
Gitlab::Diff::Position.new(
old_path: "files/ruby/popen.rb",
new_path: "files/ruby/popen.rb",
old_line: nil,
new_line: 9,
diff_refs: outdated_diff_refs
)
end
let(:outdated_diff_refs) { project.commit("874797c3a73b60d2187ed6e2fcabd289ff75171e").diff_refs }
before do
sign_in(create(:admin))
end
context 'when project.collapse_outdated_diff_comments == true' do
before do
project.update_column(:collapse_outdated_diff_comments, true)
end
context 'with unresolved outdated discussions' do
it 'does not show outdated discussion' do
visit_merge_request(merge_request)
within(".discussion[data-discussion-id='#{outdated_discussion.id}']") do
expect(page).to have_css('.discussion-body .hide .js-toggle-content', visible: false)
end
end
end
context 'with unresolved active discussions' do
it 'shows active discussion' do
visit_merge_request(merge_request)
within(".discussion[data-discussion-id='#{active_discussion.id}']") do
expect(page).to have_css('.discussion-body .hide .js-toggle-content', visible: true)
end
end
end
end
context 'when project.collapse_outdated_diff_comments == false' do
before do
project.update_column(:collapse_outdated_diff_comments, false)
end
context 'with unresolved outdated discussions' do
it 'shows outdated discussion' do
visit_merge_request(merge_request)
within(".discussion[data-discussion-id='#{outdated_discussion.id}']") do
expect(page).to have_css('.discussion-body .hide .js-toggle-content', visible: true)
end
end
end
context 'with unresolved active discussions' do
it 'shows active discussion' do
visit_merge_request(merge_request)
within(".discussion[data-discussion-id='#{active_discussion.id}']") do
expect(page).to have_css('.discussion-body .hide .js-toggle-content', visible: true)
end
end
end
end
def visit_merge_request(merge_request)
visit project_merge_request_path(project, merge_request)
end
end
......@@ -414,6 +414,7 @@
jobs_enabled: false,
merge_requests_enabled: false,
wiki_enabled: false,
collapse_outdated_diff_comments: false,
only_allow_merge_if_pipeline_succeeds: false,
request_access_enabled: true,
only_allow_merge_if_all_discussions_are_resolved: false,
......@@ -477,6 +478,18 @@
expect(json_response['avatar_url']).to eq("http://localhost/uploads/-/system/project/avatar/#{project_id}/banana_sample.gif")
end
it 'sets a project as allowing outdated diff comments to collapse regardless of discussion resolution' do
project = attributes_for(:project, { collapse_outdated_diff_comments: false })
post api('/projects', user), project
expect(json_response['collapse_outdated_diff_comments']).to be_falsey
end
it 'sets a project as allowing outdated diff comments to collapse if collapse_outdated_diff_comments' do
project = attributes_for(:project, { collapse_outdated_diff_comments: true })
post api('/projects', user), project
expect(json_response['collapse_outdated_diff_comments']).to be_truthy
end
it 'sets a project as allowing merge even if build fails' do
project = attributes_for(:project, { only_allow_merge_if_pipeline_succeeds: false })
post api('/projects', user), project
......@@ -642,6 +655,22 @@
expect(json_response['visibility']).to eq('private')
end
it 'sets a project as allowing outdated diff comments to collapse regardless of discussion resolution' do
project = attributes_for(:project, { collapse_outdated_diff_comments: false })
post api("/projects/user/#{user.id}", admin), project
expect(json_response['collapse_outdated_diff_comments']).to be_falsey
end
it 'sets a project as allowing outdated diff comments to collapse only if collapse_outdated_diff_comments' do
project = attributes_for(:project, { collapse_outdated_diff_comments: true })
post api("/projects/user/#{user.id}", admin), project
expect(json_response['collapse_outdated_diff_comments']).to be_truthy
end
it 'sets a project as allowing merge even if build fails' do
project = attributes_for(:project, { only_allow_merge_if_pipeline_succeeds: false })
post api("/projects/user/#{user.id}", admin), project
......@@ -732,6 +761,7 @@
expect(json_response['wiki_enabled']).to be_present
expect(json_response['jobs_enabled']).to be_present
expect(json_response['snippets_enabled']).to be_present
expect(json_response['collapse_outdated_diff_comments']).to eq(project.collapse_outdated_diff_comments)
expect(json_response['container_registry_enabled']).to be_present
expect(json_response['created_at']).to be_present
expect(json_response['last_activity_at']).to be_present
......
......@@ -394,6 +394,7 @@
issues_enabled: false,
merge_requests_enabled: false,
wiki_enabled: false,
collapse_outdated_diff_comments: false,
only_allow_merge_if_build_succeeds: false,
request_access_enabled: true,
only_allow_merge_if_all_discussions_are_resolved: false
......@@ -455,6 +456,18 @@
expect(json_response['visibility_level']).to eq(Gitlab::VisibilityLevel::PRIVATE)
end
it 'sets a project as allowing outdated diff comments to collapse regardless of discussion resolution' do
project = attributes_for(:project, { collapse_outdated_diff_comments: false })
post v3_api('/projects', user), project
expect(json_response['collapse_outdated_diff_comments']).to be_falsey
end
it 'sets a project as allowing outdated diff comments to collapse if collapse_outdated_diff_comments' do
project = attributes_for(:project, { collapse_outdated_diff_comments: true })
post v3_api('/projects', user), project
expect(json_response['collapse_outdated_diff_comments']).to be_truthy
end
it 'sets a project as allowing merge even if build fails' do
project = attributes_for(:project, { only_allow_merge_if_build_succeeds: false })
post v3_api('/projects', user), project
......@@ -599,6 +612,18 @@
expect(json_response['visibility_level']).to eq(Gitlab::VisibilityLevel::PRIVATE)
end
it 'sets a project as allowing outdated diff comments to collapse regardless of discussion resolution' do
project = attributes_for(:project, { collapse_outdated_diff_comments: false })
post v3_api("/projects/user/#{user.id}", admin), project
expect(json_response['collapse_outdated_diff_comments']).to be_falsey
end
it 'sets a project as allowing outdated diff comments to collapse only if collapse_outdated_diff_comments' do
project = attributes_for(:project, { collapse_outdated_diff_comments: true })
post v3_api("/projects/user/#{user.id}", admin), project
expect(json_response['collapse_outdated_diff_comments']).to be_truthy
end
it 'sets a project as allowing merge even if build fails' do
project = attributes_for(:project, { only_allow_merge_if_build_succeeds: false })
post v3_api("/projects/user/#{user.id}", admin), project
......@@ -687,6 +712,7 @@
expect(json_response['wiki_enabled']).to be_present
expect(json_response['builds_enabled']).to be_present
expect(json_response['snippets_enabled']).to be_present
expect(json_response['collapse_outdated_diff_comments']).to eq(project.collapse_outdated_diff_comments)
expect(json_response['container_registry_enabled']).to be_present
expect(json_response['created_at']).to be_present
expect(json_response['last_activity_at']).to be_present
......
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