1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
|
require "spec_helper"
describe "Compare", :js do
let(:user) { create(:user) }
let(:project) { create(:project, :repository) }
before do
project.add_maintainer(user)
sign_in user
end
describe "branches" do
it "pre-populates fields" do
visit project_compare_index_path(project, from: "master", to: "master")
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")
end
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
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
end
it "filters branches" do
visit project_compare_index_path(project, from: "master", to: "master")
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
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)
allow_any_instance_of(DiffHelper).to receive(:render_overflow_warning?).and_return(true)
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
end
describe "tags" do
it "compares tags" do
visit project_compare_index_path(project, from: "master", to: "master")
select_using_dropdown "from", "v1.0.0"
expect(find(".js-compare-from-dropdown .dropdown-toggle-text")).to have_content("v1.0.0")
select_using_dropdown "to", "v1.1.0"
expect(find(".js-compare-to-dropdown .dropdown-toggle-text")).to have_content("v1.1.0")
click_button "Compare"
expect(page).to have_content "Commits"
end
end
def select_using_dropdown(dropdown_type, selection, commit: false)
dropdown = find(".js-compare-#{dropdown_type}-dropdown")
dropdown.find(".compare-dropdown-toggle").click
# find input before using to wait for the inputs visiblity
dropdown.find('.dropdown-menu')
dropdown.fill_in("Filter by Git revision", with: selection)
wait_for_requests
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
end
end
|