debian-mirror-gitlab/spec/features/projects/compare_spec.rb

155 lines
4.9 KiB
Ruby
Raw Normal View History

2019-10-12 21:52:04 +05:30
# frozen_string_literal: true
2016-08-24 12:49:21 +05:30
require "spec_helper"
2018-03-17 18:26:18 +05:30
describe "Compare", :js do
2016-08-24 12:49:21 +05:30
let(:user) { create(:user) }
2017-09-10 17:25:29 +05:30
let(:project) { create(:project, :repository) }
2016-08-24 12:49:21 +05:30
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
2016-08-24 12:49:21 +05:30
end
describe "branches" do
2019-12-21 20:55:43 +05:30
shared_examples 'compares branches' do
it 'compares branches' do
visit project_compare_index_path(project, from: 'master', to: 'master')
select_using_dropdown 'from', 'feature'
expect(find('.js-compare-from-dropdown .dropdown-toggle-text')).to have_content('feature')
select_using_dropdown 'to', 'binary-encoding'
expect(find('.js-compare-to-dropdown .dropdown-toggle-text')).to have_content('binary-encoding')
click_button 'Compare'
expect(page).to have_content 'Commits'
expect(page).to have_link 'Create merge request'
end
end
2016-09-13 17:45:13 +05:30
it "pre-populates fields" do
2018-10-15 14:42:47 +05:30
visit project_compare_index_path(project, from: "master", to: "master")
2016-11-03 12:29:30 +05:30
expect(find(".js-compare-from-dropdown .dropdown-toggle-text")).to have_content("master")
expect(find(".js-compare-to-dropdown .dropdown-toggle-text")).to have_content("master")
2016-08-24 12:49:21 +05:30
end
2019-12-21 20:55:43 +05:30
it_behaves_like 'compares branches'
2016-08-24 12:49:21 +05:30
2019-12-21 20:55:43 +05:30
context 'on a read-only instance' do
before do
allow(Gitlab::Database).to receive(:read_only?).and_return(true)
end
2017-09-10 17:25:29 +05:30
2019-12-21 20:55:43 +05:30
it_behaves_like 'compares branches'
2018-10-15 14:42:47 +05:30
end
it 'renders additions info when click unfold diff' do
visit project_compare_index_path(project)
select_using_dropdown('from', RepoHelpers.sample_commit.parent_id, commit: true)
select_using_dropdown('to', RepoHelpers.sample_commit.id, commit: true)
click_button 'Compare'
expect(page).to have_content 'Commits (1)'
expect(page).to have_content "Showing 2 changed files"
diff = first('.js-unfold')
diff.click
wait_for_requests
page.within diff.query_scope do
expect(first('.new_line').text).not_to have_content "..."
end
end
context 'when project have an open merge request' do
let!(:merge_request) do
create(
:merge_request,
title: 'Feature',
source_project: project,
source_branch: 'feature',
target_branch: 'master',
author: project.users.first
)
end
it 'compares branches' do
visit project_compare_index_path(project)
select_using_dropdown('from', 'master')
select_using_dropdown('to', 'feature')
click_button 'Compare'
expect(page).to have_content 'Commits (1)'
expect(page).to have_content 'Showing 1 changed file with 5 additions and 0 deletions'
expect(page).to have_link 'View open merge request', href: project_merge_request_path(project, merge_request)
expect(page).not_to have_link 'Create merge request'
end
2016-08-24 12:49:21 +05:30
end
2017-08-17 22:00:37 +05:30
it "filters branches" do
2018-10-15 14:42:47 +05:30
visit project_compare_index_path(project, from: "master", to: "master")
2017-08-17 22:00:37 +05:30
select_using_dropdown("from", "wip")
find(".js-compare-from-dropdown .compare-dropdown-toggle").click
expect(find(".js-compare-from-dropdown .dropdown-content")).to have_selector("li", count: 3)
end
2019-02-15 15:39:39 +05:30
context 'when commit has overflow', :js do
it 'displays warning' do
visit project_compare_index_path(project, from: "feature", to: "master")
allow(Commit).to receive(:max_diff_options).and_return(max_files: 3)
2019-12-26 22:10:19 +05:30
allow_next_instance_of(DiffHelper) do |instance|
allow(instance).to receive(:render_overflow_warning?).and_return(true)
end
2019-02-15 15:39:39 +05:30
click_button('Compare')
page.within('.alert') do
expect(page).to have_text("Too many changes to show. To preserve performance only 3 of 3+ files are displayed.")
end
end
end
2016-08-24 12:49:21 +05:30
end
describe "tags" do
2016-09-13 17:45:13 +05:30
it "compares tags" do
2018-10-15 14:42:47 +05:30
visit project_compare_index_path(project, from: "master", to: "master")
2016-11-03 12:29:30 +05:30
select_using_dropdown "from", "v1.0.0"
expect(find(".js-compare-from-dropdown .dropdown-toggle-text")).to have_content("v1.0.0")
2016-08-24 12:49:21 +05:30
2016-11-03 12:29:30 +05:30
select_using_dropdown "to", "v1.1.0"
expect(find(".js-compare-to-dropdown .dropdown-toggle-text")).to have_content("v1.1.0")
2016-08-24 12:49:21 +05:30
click_button "Compare"
expect(page).to have_content "Commits"
end
end
2016-11-03 12:29:30 +05:30
2018-10-15 14:42:47 +05:30
def select_using_dropdown(dropdown_type, selection, commit: false)
2016-11-03 12:29:30 +05:30
dropdown = find(".js-compare-#{dropdown_type}-dropdown")
dropdown.find(".compare-dropdown-toggle").click
2019-12-26 22:10:19 +05:30
# find input before using to wait for the inputs visibility
2017-09-10 17:25:29 +05:30
dropdown.find('.dropdown-menu')
2016-11-03 12:29:30 +05:30
dropdown.fill_in("Filter by Git revision", with: selection)
2017-09-10 17:25:29 +05:30
wait_for_requests
2018-10-15 14:42:47 +05:30
if commit
dropdown.find('input[type="search"]').send_keys(:return)
else
2019-12-26 22:10:19 +05:30
# find before all to wait for the items visibility
2018-10-15 14:42:47 +05:30
dropdown.find("a[data-ref=\"#{selection}\"]", match: :first)
dropdown.all("a[data-ref=\"#{selection}\"]").last.click
end
2016-11-03 12:29:30 +05:30
end
2016-08-24 12:49:21 +05:30
end