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

124 lines
4 KiB
Ruby
Raw Normal View History

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
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
2016-09-13 17:45:13 +05:30
it "compares branches" 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", "feature"
expect(find(".js-compare-from-dropdown .dropdown-toggle-text")).to have_content("feature")
2016-08-24 12:49:21 +05:30
2016-11-03 12:29:30 +05:30
select_using_dropdown "to", "binary-encoding"
expect(find(".js-compare-to-dropdown .dropdown-toggle-text")).to have_content("binary-encoding")
2016-08-24 12:49:21 +05:30
click_button "Compare"
2017-09-10 17:25:29 +05:30
2016-08-24 12:49:21 +05:30
expect(page).to have_content "Commits"
2018-10-15 14:42:47 +05:30
expect(page).to have_link 'Create merge request'
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
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
2017-09-10 17:25:29 +05:30
# find input before using to wait for the inputs visiblity
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
# find before all to wait for the items visiblity
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