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 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441
|
# frozen_string_literal: true
require "spec_helper"
RSpec.describe "Issues > User edits issue", :js, feature_category: :team_planning do
let_it_be(:project) { create(:project_empty_repo, :public) }
let_it_be(:project_with_milestones) { create(:project_empty_repo, :public) }
let_it_be(:user) { create(:user) }
let_it_be(:label_assigned) { create(:label, project: project, title: 'verisimilitude') }
let_it_be(:label_unassigned) { create(:label, project: project, title: 'syzygy') }
let_it_be(:issue) { create(:issue, project: project, author: user, assignees: [user], labels: [label_assigned]) }
let_it_be(:issue_with_milestones) { create(:issue, project: project_with_milestones, author: user, assignees: [user]) }
let_it_be(:milestone) { create(:milestone, project: project) }
let_it_be(:milestones) { create_list(:milestone, 25, project: project_with_milestones) }
context 'with authorized user' do
before do
project.add_developer(user)
project_with_milestones.add_developer(user)
sign_in(user)
end
context "from edit page" do
before do
stub_licensed_features(multiple_issue_assignees: false)
visit edit_project_issue_path(project, issue)
end
it_behaves_like 'rich text editor - common'
it "previews content", quarantine: 'https://gitlab.com/gitlab-org/gitlab/-/issues/391757' do
form = first(".gfm-form")
page.within(form) do
fill_in("Description", with: "Bug fixed :smile:")
click_button("Preview")
end
click_button("Continue editing")
fill_in("Description", with: "/confidential")
click_button("Preview")
expect(form).to have_content('Makes this issue confidential.')
end
it 'allows user to select unassigned' do
visit edit_project_issue_path(project, issue)
expect(page).to have_content "Assignee #{user.name}"
first('.js-user-search').click
click_link 'Unassigned'
click_button _('Save changes')
page.within('.assignee') do
expect(page).to have_content 'None - assign yourself'
end
end
context 'with due date' do
before do
visit edit_project_issue_path(project, issue)
end
it 'saves with due date' do
date = Date.today.at_beginning_of_month.tomorrow
fill_in 'issue_title', with: 'bug 345'
fill_in 'issue_description', with: 'bug description'
find('#issuable-due-date').click
page.within '.pika-single' do
click_button date.day
end
expect(find('#issuable-due-date').value).to eq date.to_s
click_button _('Save changes')
page.within '.issuable-sidebar' do
expect(page).to have_content date.to_fs(:medium)
end
end
it 'warns about version conflict' do
issue.update!(title: "New title")
fill_in 'issue_title', with: 'bug 345'
fill_in 'issue_description', with: 'bug description'
click_button _('Save changes')
expect(page).to have_content(
format(
_("Someone edited this %{model_name} at the same time you did. Please check out the %{link_to_model} and make sure your changes will not unintentionally remove theirs."),
model_name: _('issue'),
link_to_model: _('issue')
)
)
end
end
end
context "from issue#show" do
before do
visit project_issue_path(project, issue)
end
describe 'edit description' do
def click_edit_issue_description
click_on 'Edit title and description'
end
it 'places focus on the web editor' do
content_editor_focused_selector = '[data-testid="content-editor"].is-focused'
markdown_field_focused_selector = 'textarea:focus'
click_edit_issue_description
issuable_form = find_by_testid('issuable-form')
expect(issuable_form).to have_selector(markdown_field_focused_selector)
page.within issuable_form do
click_button("Switch to rich text editing")
end
expect(issuable_form).to have_selector(content_editor_focused_selector)
stub_feature_flags(rich_text_editor_as_default: true)
refresh
click_edit_issue_description
expect(issuable_form).to have_selector(content_editor_focused_selector)
page.within issuable_form do
click_button("Switch to plain text editing")
end
expect(issuable_form).to have_selector(markdown_field_focused_selector)
end
end
describe 'update labels', quarantine: 'https://gitlab.com/gitlab-org/gitlab/-/issues/345229' do
it 'will not send ajax request when no data is changed' do
page.within '.labels' do
click_on 'Edit'
find('.dropdown-title button').click
expect(page).not_to have_selector('.block-loading')
expect(page).not_to have_selector('.gl-spinner')
end
end
it 'can add label to issue' do
page.within '.block.labels' do
expect(page).to have_text('verisimilitude')
expect(page).not_to have_text('syzygy')
click_on 'Edit'
wait_for_requests
click_on 'syzygy'
find('.dropdown-header-button').click
wait_for_requests
expect(page).to have_text('verisimilitude')
expect(page).to have_text('syzygy')
end
end
it 'can remove label from issue by clicking on the label `x` button' do
page.within '.block.labels' do
expect(page).to have_text('verisimilitude')
within '.gl-label' do
click_button
end
wait_for_requests
expect(page).not_to have_text('verisimilitude')
end
end
it 'can remove label without removing label added via quick action', :aggregate_failures do
# Add `syzygy` label with a quick action
fill_in 'Comment', with: '/label ~syzygy'
click_button 'Comment'
expect(page).to have_text('added syzygy label just now')
page.within '.block.labels' do
# Remove `verisimilitude` label
within '.gl-label', text: 'verisimilitude' do
click_button 'Remove label'
end
expect(page).to have_text('syzygy')
expect(page).not_to have_text('verisimilitude')
end
expect(page).to have_text('removed verisimilitude label')
expect(page).not_to have_text('removed syzygy verisimilitude labels')
expect(issue.reload.labels.map(&:title)).to contain_exactly('syzygy')
end
end
describe 'update assignee' do
context 'by authorized user' do
it 'allows user to select unassigned' do
visit project_issue_path(project, issue)
page.within('.assignee') do
expect(page).to have_content user.name.to_s
click_button('Edit')
wait_for_requests
find_by_testid('unassign').click
find_by_testid('title').click
wait_for_requests
expect(page).to have_content 'None - assign yourself'
end
end
it 'allows user to select an assignee' do
issue2 = create(:issue, project: project, author: user)
visit project_issue_path(project, issue2)
page.within('.assignee') do
expect(page).to have_content "None"
click_button('Edit')
wait_for_requests
end
page.within '.dropdown-menu-user' do
click_button user.name
end
page.within('.assignee') do
find_by_testid('title').click
wait_for_requests
expect(page).to have_content user.name
end
end
it 'allows user to unselect themselves' do
issue2 = create(:issue, project: project, author: user, assignees: [user])
visit project_issue_path(project, issue2)
page.within '.assignee' do
expect(page).to have_content user.name
click_button('Edit')
wait_for_requests
click_button user.name
find_by_testid('title').click
wait_for_requests
expect(page).to have_content "None"
end
end
end
context 'by unauthorized user' do
let(:guest) { create(:user) }
before do
project.add_guest(guest)
end
it 'shows assignee text' do
sign_out(:user)
sign_in(guest)
visit project_issue_path(project, issue)
expect(page).to have_content issue.assignees.first.name
end
end
end
describe 'update milestone' do
context 'by authorized user' do
it 'allows user to select no milestone' do
visit project_issue_path(project, issue)
wait_for_requests
page.within('.block.milestone') do
expect(page).to have_content 'None'
click_button 'Edit'
wait_for_requests
click_button 'No milestone'
wait_for_requests
expect(page).to have_content 'None'
end
end
it 'allows user to de-select milestone' do
visit project_issue_path(project, issue)
wait_for_requests
page.within('.milestone') do
click_button 'Edit'
wait_for_requests
click_button milestone.title
within_testid('select-milestone') do
expect(page).to have_content milestone.title
end
click_button 'Edit'
wait_for_requests
click_button 'No milestone'
within_testid('select-milestone') do
expect(page).to have_content 'None'
end
end
end
it 'allows user to search milestone' do
visit project_issue_path(project_with_milestones, issue_with_milestones)
wait_for_requests
page.within('.milestone') do
click_button 'Edit'
wait_for_requests
# We need to enclose search string in quotes for exact match as all the milestone titles
# within tests are prefixed with `My title`.
find('.gl-form-input', visible: true).send_keys "\"#{milestones[0].title}\""
wait_for_requests
page.within '.gl-dropdown-contents' do
expect(page).to have_content milestones[0].title
end
end
end
end
context 'by unauthorized user' do
let(:guest) { create(:user) }
before do
project.add_guest(guest)
issue.milestone = milestone
issue.save!
end
it 'shows milestone text', quarantine: 'https://gitlab.com/gitlab-org/gitlab/-/issues/389287' do
sign_out(:user)
sign_in(guest)
visit project_issue_path(project, issue)
expect(page).to have_content milestone.title
end
end
end
context 'update due date' do
before do
# Due date widget uses GraphQL and needs to wait for requests to come back
# The date picker won't be rendered before requests complete
wait_for_requests
end
it 'adds due date to issue' do
date = Date.today.at_beginning_of_month + 2.days
within_testid('sidebar-due-date') do
click_button 'Edit'
page.within '.pika-single' do
click_button date.day
end
wait_for_requests
expect(find_by_testid('sidebar-date-value').text).to have_content date.strftime('%b %-d, %Y')
end
end
it 'removes due date from issue' do
date = Date.today.at_beginning_of_month + 2.days
within_testid('sidebar-due-date') do
click_button 'Edit'
page.within '.pika-single' do
click_button date.day
end
wait_for_requests
expect(page).to have_no_content 'None'
click_button 'remove due date'
expect(page).to have_content 'None'
end
end
end
end
end
context 'with unauthorized user' do
before do
sign_in(user)
end
context "from issue#show" do
before do
visit project_issue_path(project, issue)
end
describe 'updating labels' do
it 'cannot edit labels' do
page.within '.block.labels' do
expect(page).not_to have_button('Edit')
end
end
it 'cannot remove label with a click as it has no `x` button' do
page.within '.block.labels' do
within '.gl-label' do
expect(page).not_to have_button
end
end
end
end
end
end
end
|