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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
|
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe 'User views an open merge request', feature_category: :code_review_workflow do
include ContentEditorHelpers
let(:merge_request) do
create(:merge_request, source_project: project, target_project: project, description: '# Description header')
end
context 'feature flags' do
let_it_be(:project) { create(:project, :public, :repository) }
it 'pushes content_editor_on_issues feature flag to frontend' do
stub_feature_flags(content_editor_on_issues: true)
visit merge_request_path(merge_request)
expect(page).to have_pushed_frontend_feature_flags(contentEditorOnIssues: true)
end
end
context 'when a merge request does not have repository' do
let(:project) { create(:project, :public, :repository) }
before do
visit(merge_request_path(merge_request))
end
it 'renders both the title and the description' do
node = find('.md h1 a#user-content-description-header')
expect(node[:href]).to end_with('#description-header')
# Work around a weird Capybara behavior where calling `parent` on a node
# returns the whole document, not the node's actual parent element
expect(find(:xpath, "#{node.path}/..").text).to eq(merge_request.description[2..])
expect(page).to have_content(merge_request.title)
end
it 'has reviewers in sidebar' do
expect(page).to have_css('.reviewer')
end
end
context 'when a merge request has repository', :js do
let(:project) { create(:project, :public, :repository) }
context 'when rendering description preview' do
let(:user) { create(:user) }
before do
project.add_maintainer(user)
sign_in(user)
visit(edit_project_merge_request_path(project, merge_request))
close_rich_text_promo_popover_if_present
end
it 'renders empty description preview' do
fill_in(:merge_request_description, with: '')
page.within('.js-vue-markdown-field') do
click_button("Preview")
expect(find('.js-vue-md-preview')).to have_content('Nothing to preview.')
end
end
it 'renders description preview' do
fill_in(:merge_request_description, with: ':+1: Nice')
page.within('.js-vue-markdown-field') do
click_button("Preview")
expect(find('.js-vue-md-preview')).to have_css('gl-emoji')
end
expect(find('.js-vue-markdown-field')).to have_css('.js-md-preview-button')
expect(find('#merge_request_description', visible: false)).not_to be_visible
end
end
context 'when the branch is rebased on the target' do
let(:merge_request) { create(:merge_request, :rebased, source_project: project, target_project: project) }
before do
project.add_maintainer(project.creator)
sign_in(project.creator)
visit(merge_request_path(merge_request))
end
it 'does not show diverged commits count' do
expect(page).not_to have_content(/([0-9]+ commits? behind)/)
end
end
context 'when the branch is diverged on the target' do
let(:merge_request) { create(:merge_request, :diverged, source_project: project, target_project: project) }
before do
project.add_maintainer(project.creator)
sign_in(project.creator)
visit(merge_request_path(merge_request))
end
it 'shows diverged commits count', quarantine: 'https://gitlab.com/gitlab-org/gitlab/-/issues/408223' do
expect(page).not_to have_content(/([0-9]+ commits? behind)/)
end
end
context 'when the assignee\'s availability set' do
before do
merge_request.author.create_status(availability: 'busy')
merge_request.assignees << merge_request.author
visit(merge_request_path(merge_request))
end
it 'exposes the availability in the data-availability attribute' do
assignees_data = find_all("input[name='merge_request[assignee_ids][]']", visible: false)
expect(assignees_data.size).to eq(1)
expect(assignees_data.first['data-availability']).to eq('busy')
end
end
end
context 'XSS source branch' do
let(:project) { create(:project, :public, :repository) }
let(:source_branch) { "'><iframe/srcdoc=''></iframe>" }
before do
stub_feature_flags(moved_mr_sidebar: false)
project.repository.create_branch(source_branch, "master")
mr = create(:merge_request, source_project: project, target_project: project, source_branch: source_branch)
visit(merge_request_path(mr))
end
it 'encodes branch name' do
expect(find("[data-testid='ref-name']")[:title]).to eq(source_branch)
end
end
context 'when user preferred language has changed', :use_clean_rails_memory_store_fragment_caching do
let(:project) { create(:project, :public, :repository) }
let(:user) { create(:user) }
before do
project.add_maintainer(user)
sign_in(user)
end
it 'renders edit button in preferred language' do
visit(merge_request_path(merge_request))
page.within('.detail-page-header-actions') do
expect(page).to have_link('Edit')
end
user.update!(preferred_language: 'de')
visit(merge_request_path(merge_request))
page.within('.detail-page-header-actions') do
expect(page).to have_link('Bearbeiten')
end
end
end
end
|