2019-10-12 21:52:04 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-08-24 12:49:21 +05:30
|
|
|
require "spec_helper"
|
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
RSpec.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'
|
2021-03-11 19:13:27 +05:30
|
|
|
expect(find('.js-compare-from-dropdown .gl-new-dropdown-button-text')).to have_content('feature')
|
2019-12-21 20:55:43 +05:30
|
|
|
|
|
|
|
select_using_dropdown 'to', 'binary-encoding'
|
2021-03-11 19:13:27 +05:30
|
|
|
expect(find('.js-compare-to-dropdown .gl-new-dropdown-button-text')).to have_content('binary-encoding')
|
2019-12-21 20:55:43 +05:30
|
|
|
|
|
|
|
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")
|
|
|
|
|
2021-03-11 19:13:27 +05:30
|
|
|
expect(find(".js-compare-from-dropdown .gl-new-dropdown-button-text")).to have_content("master")
|
|
|
|
expect(find(".js-compare-to-dropdown .gl-new-dropdown-button-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
|
|
|
|
|
2021-03-11 19:13:27 +05:30
|
|
|
expect(find(".js-compare-from-dropdown .gl-new-dropdown-contents")).to have_selector('li.gl-new-dropdown-item', count: 1)
|
2017-08-17 22:00:37 +05:30
|
|
|
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')
|
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
page.within('.gl-alert') do
|
2019-02-15 15:39:39 +05:30
|
|
|
expect(page).to have_text("Too many changes to show. To preserve performance only 3 of 3+ files are displayed.")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2021-06-08 01:23:25 +05:30
|
|
|
|
|
|
|
context "pagination" do
|
|
|
|
before do
|
|
|
|
stub_const("Projects::CompareController::COMMIT_DIFFS_PER_PAGE", 1)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "shows an adjusted count for changed files on this page" do
|
|
|
|
visit project_compare_index_path(project, from: "feature", to: "master")
|
|
|
|
|
|
|
|
click_button('Compare')
|
|
|
|
|
|
|
|
expect(page).to have_content("Showing 1 changed file")
|
|
|
|
end
|
|
|
|
|
|
|
|
it "shows commits list only on the first page" do
|
|
|
|
visit project_compare_index_path(project, from: "feature", to: "master")
|
|
|
|
click_button('Compare')
|
|
|
|
|
|
|
|
expect(page).to have_content 'Commits (29)'
|
|
|
|
|
|
|
|
# go to the second page
|
|
|
|
within(".files .gl-pagination") do
|
|
|
|
click_on("2")
|
|
|
|
end
|
|
|
|
|
|
|
|
expect(page).not_to have_content 'Commits (29)'
|
|
|
|
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"
|
2021-03-11 19:13:27 +05:30
|
|
|
expect(find(".js-compare-from-dropdown .gl-new-dropdown-button-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"
|
2021-03-11 19:13:27 +05:30
|
|
|
expect(find(".js-compare-to-dropdown .gl-new-dropdown-button-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)
|
2021-03-11 19:13:27 +05:30
|
|
|
wait_for_requests
|
|
|
|
|
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)
|
2021-03-11 19:13:27 +05:30
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
wait_for_requests
|
2018-10-15 14:42:47 +05:30
|
|
|
|
|
|
|
if commit
|
2021-03-11 19:13:27 +05:30
|
|
|
dropdown.find('.gl-search-box-by-type-input').send_keys(:return)
|
2018-10-15 14:42:47 +05:30
|
|
|
else
|
2019-12-26 22:10:19 +05:30
|
|
|
# find before all to wait for the items visibility
|
2021-03-11 19:13:27 +05:30
|
|
|
dropdown.find(".js-compare-#{dropdown_type}-dropdown .dropdown-item", text: selection, match: :first)
|
|
|
|
dropdown.all(".js-compare-#{dropdown_type}-dropdown .dropdown-item", text: selection).first.click
|
2018-10-15 14:42:47 +05:30
|
|
|
end
|
2016-11-03 12:29:30 +05:30
|
|
|
end
|
2016-08-24 12:49:21 +05:30
|
|
|
end
|