debian-mirror-gitlab/spec/features/issues/user_bulk_edits_issues_labels_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

472 lines
14 KiB
Ruby
Raw Normal View History

2019-10-12 21:52:04 +05:30
# frozen_string_literal: true
2019-12-04 20:38:33 +05:30
require 'spec_helper'
2020-06-23 00:09:42 +05:30
RSpec.describe 'Issues > Labels bulk assignment' do
let(:user) { create(:user) }
let!(:project) { create(:project) }
let!(:bug) { create(:label, project: project, title: 'bug') }
let!(:feature) { create(:label, project: project, title: 'feature') }
2020-07-28 23:09:34 +05:30
let!(:frontend) { create(:label, project: project, title: 'frontend') }
2017-08-17 22:00:37 +05:30
let!(:wontfix) { create(:label, project: project, title: 'wontfix') }
2020-07-28 23:09:34 +05:30
let!(:issue1) { create(:issue, project: project, title: "Issue 1", labels: [frontend]) }
let!(:issue2) { create(:issue, project: project, title: "Issue 2") }
2022-07-16 23:28:13 +05:30
let(:issue_1_selector) { "#issuable_#{issue1.id}" }
let(:issue_2_selector) { "#issuable_#{issue2.id}" }
2018-03-17 18:26:18 +05:30
context 'as an allowed user', :js do
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
end
context 'sidebar' do
it 'is present when bulk edit is enabled' do
2021-06-08 01:23:25 +05:30
enable_bulk_update
expect(page).to have_css 'aside[aria-label="Bulk update"]'
2017-09-10 17:25:29 +05:30
end
it 'is not present when bulk edit is disabled' do
2021-06-08 01:23:25 +05:30
expect(page).not_to have_css 'aside[aria-label="Bulk update"]'
2017-09-10 17:25:29 +05:30
end
end
context 'can bulk assign' do
before do
2017-09-10 17:25:29 +05:30
enable_bulk_update
end
context 'a label' do
context 'to all issues' do
before do
2021-06-08 01:23:25 +05:30
check 'Select all'
open_labels_dropdown ['bug']
update_issues
end
it do
2022-01-26 12:08:38 +05:30
expect(find(issue_1_selector)).to have_content 'bug'
expect(find(issue_1_selector)).to have_content 'frontend'
expect(find(issue_2_selector)).to have_content 'bug'
expect(find(issue_2_selector)).not_to have_content 'frontend'
end
end
2020-07-28 23:09:34 +05:30
context 'to some issues' do
before do
2021-06-08 01:23:25 +05:30
check issue1.title
check issue2.title
2020-07-28 23:09:34 +05:30
open_labels_dropdown ['bug']
update_issues
end
it do
2022-01-26 12:08:38 +05:30
expect(find(issue_1_selector)).to have_content 'bug'
expect(find(issue_1_selector)).to have_content 'frontend'
expect(find(issue_2_selector)).to have_content 'bug'
expect(find(issue_2_selector)).not_to have_content 'frontend'
2020-07-28 23:09:34 +05:30
end
end
context 'to an issue' do
before do
2021-06-08 01:23:25 +05:30
check issue1.title
open_labels_dropdown ['bug']
update_issues
end
it do
2022-01-26 12:08:38 +05:30
expect(find(issue_1_selector)).to have_content 'bug'
expect(find(issue_1_selector)).to have_content 'frontend'
expect(find(issue_2_selector)).not_to have_content 'bug'
expect(find(issue_2_selector)).not_to have_content 'frontend'
2020-07-28 23:09:34 +05:30
end
end
context 'to an issue by selecting the label first' do
before do
open_labels_dropdown ['bug']
2021-06-08 01:23:25 +05:30
check issue1.title
2020-07-28 23:09:34 +05:30
update_issues
end
it do
2022-01-26 12:08:38 +05:30
expect(find(issue_1_selector)).to have_content 'bug'
expect(find(issue_1_selector)).to have_content 'frontend'
expect(find(issue_2_selector)).not_to have_content 'bug'
expect(find(issue_2_selector)).not_to have_content 'frontend'
end
end
end
context 'multiple labels' do
context 'to all issues' do
before do
2021-06-08 01:23:25 +05:30
check 'Select all'
2017-08-17 22:00:37 +05:30
open_labels_dropdown %w(bug feature)
update_issues
end
it do
2022-01-26 12:08:38 +05:30
expect(find(issue_1_selector)).to have_content 'bug'
expect(find(issue_1_selector)).to have_content 'feature'
expect(find(issue_2_selector)).to have_content 'bug'
expect(find(issue_2_selector)).to have_content 'feature'
end
end
context 'to a issue' do
before do
2021-06-08 01:23:25 +05:30
check issue1.title
2017-08-17 22:00:37 +05:30
open_labels_dropdown %w(bug feature)
update_issues
end
it do
2022-01-26 12:08:38 +05:30
expect(find(issue_1_selector)).to have_content 'bug'
expect(find(issue_1_selector)).to have_content 'feature'
expect(find(issue_2_selector)).not_to have_content 'bug'
expect(find(issue_2_selector)).not_to have_content 'feature'
end
end
end
end
context 'can assign a label to all issues when label is present' do
before do
issue2.labels << bug
issue2.labels << feature
2017-09-10 17:25:29 +05:30
enable_bulk_update
2021-06-08 01:23:25 +05:30
check 'Select all'
2017-09-10 17:25:29 +05:30
open_labels_dropdown ['bug']
update_issues
end
it do
2022-01-26 12:08:38 +05:30
expect(find(issue_1_selector)).to have_content 'bug'
expect(find(issue_2_selector)).to have_content 'bug'
end
end
context 'can bulk un-assign' do
context 'all labels to all issues' do
before do
issue1.labels << bug
issue1.labels << feature
issue2.labels << bug
issue2.labels << feature
2017-09-10 17:25:29 +05:30
enable_bulk_update
2021-06-08 01:23:25 +05:30
check 'Select all'
2017-08-17 22:00:37 +05:30
unmark_labels_in_dropdown %w(bug feature)
update_issues
end
it do
2022-01-26 12:08:38 +05:30
expect(find(issue_1_selector)).not_to have_content 'bug'
expect(find(issue_1_selector)).not_to have_content 'feature'
expect(find(issue_2_selector)).not_to have_content 'bug'
expect(find(issue_2_selector)).not_to have_content 'feature'
end
end
context 'a label to a issue' do
before do
issue1.labels << bug
issue2.labels << feature
2017-09-10 17:25:29 +05:30
enable_bulk_update
check_issue issue1
unmark_labels_in_dropdown ['bug']
update_issues
end
it do
2022-01-26 12:08:38 +05:30
expect(find(issue_1_selector)).not_to have_content 'bug'
expect(find(issue_2_selector)).to have_content 'feature'
end
end
context 'a label and keep the others label' do
before do
issue1.labels << bug
issue1.labels << feature
issue2.labels << bug
issue2.labels << feature
2017-09-10 17:25:29 +05:30
enable_bulk_update
check_issue issue1
check_issue issue2
unmark_labels_in_dropdown ['bug']
update_issues
end
it do
2022-01-26 12:08:38 +05:30
expect(find(issue_1_selector)).not_to have_content 'bug'
expect(find(issue_1_selector)).to have_content 'feature'
expect(find(issue_2_selector)).not_to have_content 'bug'
expect(find(issue_2_selector)).to have_content 'feature'
end
end
end
2016-08-24 12:49:21 +05:30
context 'toggling a milestone' do
let!(:milestone) { create(:milestone, project: project, title: 'First Release') }
context 'setting a milestone' do
before do
issue1.labels << bug
issue2.labels << feature
2017-09-10 17:25:29 +05:30
enable_bulk_update
2016-08-24 12:49:21 +05:30
end
2016-09-13 17:45:13 +05:30
it 'keeps labels' do
2022-01-26 12:08:38 +05:30
expect(find(issue_1_selector)).to have_content 'bug'
expect(find(issue_2_selector)).to have_content 'feature'
2016-08-24 12:49:21 +05:30
2021-06-08 01:23:25 +05:30
check 'Select all'
2017-09-10 17:25:29 +05:30
2016-08-24 12:49:21 +05:30
open_milestone_dropdown(['First Release'])
update_issues
2022-01-26 12:08:38 +05:30
expect(find(issue_1_selector)).to have_content 'bug'
expect(find(issue_1_selector)).to have_content 'First Release'
expect(find(issue_2_selector)).to have_content 'feature'
expect(find(issue_2_selector)).to have_content 'First Release'
2016-08-24 12:49:21 +05:30
end
end
context 'setting a milestone and adding another label' do
before do
issue1.labels << bug
2017-09-10 17:25:29 +05:30
enable_bulk_update
2016-08-24 12:49:21 +05:30
end
2016-09-13 17:45:13 +05:30
it 'keeps existing label and new label is present' do
2022-01-26 12:08:38 +05:30
expect(find(issue_1_selector)).to have_content 'bug'
2016-08-24 12:49:21 +05:30
2021-06-08 01:23:25 +05:30
check 'Select all'
2016-08-24 12:49:21 +05:30
open_milestone_dropdown ['First Release']
open_labels_dropdown ['feature']
update_issues
2022-01-26 12:08:38 +05:30
expect(find(issue_1_selector)).to have_content 'bug'
expect(find(issue_1_selector)).to have_content 'feature'
expect(find(issue_1_selector)).to have_content 'First Release'
expect(find(issue_2_selector)).to have_content 'feature'
expect(find(issue_2_selector)).to have_content 'First Release'
2016-08-24 12:49:21 +05:30
end
end
context 'setting a milestone and removing existing label' do
before do
issue1.labels << bug
issue1.labels << feature
issue2.labels << feature
2017-09-10 17:25:29 +05:30
enable_bulk_update
2016-08-24 12:49:21 +05:30
end
2016-09-13 17:45:13 +05:30
it 'keeps existing label and new label is present' do
2022-01-26 12:08:38 +05:30
expect(find(issue_1_selector)).to have_content 'bug'
expect(find(issue_1_selector)).to have_content 'bug'
expect(find(issue_2_selector)).to have_content 'feature'
2016-08-24 12:49:21 +05:30
2021-06-08 01:23:25 +05:30
check 'Select all'
2017-09-10 17:25:29 +05:30
2016-08-24 12:49:21 +05:30
open_milestone_dropdown ['First Release']
unmark_labels_in_dropdown ['feature']
update_issues
2022-01-26 12:08:38 +05:30
expect(find(issue_1_selector)).to have_content 'bug'
expect(find(issue_1_selector)).not_to have_content 'feature'
expect(find(issue_1_selector)).to have_content 'First Release'
expect(find(issue_2_selector)).not_to have_content 'feature'
expect(find(issue_2_selector)).to have_content 'First Release'
2016-08-24 12:49:21 +05:30
end
end
context 'unsetting a milestone' do
before do
issue1.milestone = milestone
issue2.milestone = milestone
2021-04-29 21:17:54 +05:30
issue1.save!
issue2.save!
2016-08-24 12:49:21 +05:30
issue1.labels << bug
issue2.labels << feature
2017-09-10 17:25:29 +05:30
enable_bulk_update
2016-08-24 12:49:21 +05:30
end
2016-09-13 17:45:13 +05:30
it 'keeps labels' do
2022-01-26 12:08:38 +05:30
expect(find(issue_1_selector)).to have_content 'bug'
expect(find(issue_1_selector)).to have_content 'First Release'
expect(find(issue_2_selector)).to have_content 'feature'
expect(find(issue_2_selector)).to have_content 'First Release'
2016-08-24 12:49:21 +05:30
2021-06-08 01:23:25 +05:30
check 'Select all'
2020-05-24 23:13:21 +05:30
open_milestone_dropdown(['No milestone'])
2016-08-24 12:49:21 +05:30
update_issues
2022-01-26 12:08:38 +05:30
expect(find(issue_1_selector)).to have_content 'bug'
expect(find(issue_1_selector)).not_to have_content 'First Release'
expect(find(issue_2_selector)).to have_content 'feature'
expect(find(issue_2_selector)).not_to have_content 'First Release'
2016-08-24 12:49:21 +05:30
end
end
end
context 'toggling checked issues' do
before do
issue1.labels << bug
2017-09-10 17:25:29 +05:30
enable_bulk_update
2016-08-24 12:49:21 +05:30
end
it do
2022-01-26 12:08:38 +05:30
expect(find(issue_1_selector)).to have_content 'bug'
2016-08-24 12:49:21 +05:30
check_issue issue1
open_labels_dropdown ['feature']
uncheck_issue issue1
check_issue issue1
update_issues
sleep 1 # needed
2022-01-26 12:08:38 +05:30
expect(find(issue_1_selector)).to have_content 'bug'
expect(find(issue_1_selector)).to have_content 'feature'
2020-06-23 00:09:42 +05:30
end
end
context 'mark previously toggled label' do
before do
enable_bulk_update
end
it do
open_labels_dropdown ['feature']
check_issue issue1
update_issues
2022-01-26 12:08:38 +05:30
expect(find(issue_1_selector)).to have_content 'feature'
2016-08-24 12:49:21 +05:30
end
end
2017-08-17 22:00:37 +05:30
2019-12-04 20:38:33 +05:30
# Special case https://gitlab.com/gitlab-org/gitlab-foss/issues/24877
2017-08-17 22:00:37 +05:30
context 'unmarking common label' do
before do
issue1.labels << bug
issue1.labels << feature
issue2.labels << bug
2017-09-10 17:25:29 +05:30
enable_bulk_update
2017-08-17 22:00:37 +05:30
end
it 'applies label from filtered results' do
2021-06-08 01:23:25 +05:30
check 'Select all'
2017-08-17 22:00:37 +05:30
2021-06-08 01:23:25 +05:30
within('aside[aria-label="Bulk update"]') do
2017-09-10 17:25:29 +05:30
click_button 'Select labels'
wait_for_requests
2017-08-17 22:00:37 +05:30
2021-06-08 01:23:25 +05:30
expect(page).to have_link 'bug', class: 'is-active'
expect(page).to have_link 'feature', class: 'is-indeterminate'
2017-08-17 22:00:37 +05:30
click_link 'bug'
2021-06-08 01:23:25 +05:30
fill_in 'Search', with: 'wontfix'
2017-08-17 22:00:37 +05:30
click_link 'wontfix'
end
update_issues
2022-01-26 12:08:38 +05:30
first_issue = find(issue_1_selector)
2021-06-08 01:23:25 +05:30
expect(first_issue).not_to have_content 'bug'
expect(first_issue).to have_content 'feature'
expect(first_issue).to have_content 'wontfix'
2017-08-17 22:00:37 +05:30
2022-01-26 12:08:38 +05:30
second_issue = find(issue_2_selector)
2021-06-08 01:23:25 +05:30
expect(second_issue).not_to have_content 'bug'
expect(second_issue).not_to have_content 'feature'
expect(second_issue).to have_content 'wontfix'
2017-08-17 22:00:37 +05:30
end
end
end
context 'as a guest' do
before do
2017-09-10 17:25:29 +05:30
sign_in user
2017-09-10 17:25:29 +05:30
visit project_issues_path(project)
end
context 'cannot bulk assign labels' do
it do
2018-03-17 18:26:18 +05:30
expect(page).not_to have_button 'Edit issues'
2021-06-08 01:23:25 +05:30
expect(page).not_to have_unchecked_field 'Select all'
expect(page).not_to have_unchecked_field issue1.title
end
end
end
2016-08-24 12:49:21 +05:30
def open_milestone_dropdown(items = [])
2021-06-08 01:23:25 +05:30
click_button 'Select milestone'
wait_for_requests
items.map do |item|
2023-01-13 00:05:48 +05:30
click_button item
2016-08-24 12:49:21 +05:30
end
end
def open_labels_dropdown(items = [], unmark = false)
2021-06-08 01:23:25 +05:30
within('aside[aria-label="Bulk update"]') do
2017-09-10 17:25:29 +05:30
click_button 'Select labels'
wait_for_requests
items.map do |item|
click_link item
end
2018-03-17 18:26:18 +05:30
if unmark
items.map do |item|
2016-06-22 15:30:34 +05:30
# Make sure we are unmarking the item no matter the state it has currently
2019-09-30 21:07:59 +05:30
click_link item until find('a', text: item)[:class].include? 'label-item'
end
end
end
end
def unmark_labels_in_dropdown(items = [])
open_labels_dropdown(items, true)
end
2016-08-24 12:49:21 +05:30
def check_issue(issue, uncheck = false)
2021-06-08 01:23:25 +05:30
if uncheck
uncheck issue.title
else
check issue.title
end
end
2016-08-24 12:49:21 +05:30
def uncheck_issue(issue)
check_issue(issue, true)
end
def update_issues
2021-06-08 01:23:25 +05:30
click_button 'Update all'
2017-09-10 17:25:29 +05:30
wait_for_requests
end
def enable_bulk_update
visit project_issues_path(project)
2021-06-08 01:23:25 +05:30
wait_for_requests
2018-03-17 18:26:18 +05:30
click_button 'Edit issues'
2017-09-10 17:25:29 +05:30
end
def disable_bulk_update
click_button 'Cancel'
end
end