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

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

399 lines
12 KiB
Ruby
Raw Normal View History

2020-11-24 15:15:51 +05:30
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe 'Related issues', :js do
2022-11-25 23:54:43 +05:30
let_it_be(:user) { create(:user) }
let_it_be(:project) { create(:project_empty_repo, :public) }
let_it_be(:project_b) { create(:project_empty_repo, :public) }
let_it_be(:project_unauthorized) { create(:project_empty_repo, :public) }
let_it_be(:internal_project) { create(:project_empty_repo, :internal) }
let_it_be(:private_project) { create(:project_empty_repo, :private) }
let_it_be(:public_project) { create(:project_empty_repo, :public) }
let_it_be(:issue_a) { create(:issue, project: project) }
let_it_be(:issue_b) { create(:issue, project: project) }
let_it_be(:issue_c) { create(:issue, project: project) }
let_it_be(:issue_d) { create(:issue, project: project) }
let_it_be(:issue_project_b_a) { create(:issue, project: project_b) }
let_it_be(:issue_project_unauthorized_a) { create(:issue, project: project_unauthorized) }
let_it_be(:internal_issue) { create(:issue, project: internal_project) }
let_it_be(:private_issue) { create(:issue, project: private_project) }
let_it_be(:public_issue) { create(:issue, project: public_project) }
2020-11-24 15:15:51 +05:30
context 'widget visibility' do
context 'when not logged in' do
it 'does not show widget when internal project' do
2022-11-25 23:54:43 +05:30
visit project_issue_path(internal_project, internal_issue)
2020-11-24 15:15:51 +05:30
expect(page).not_to have_css('.related-issues-block')
end
it 'does not show widget when private project' do
2022-11-25 23:54:43 +05:30
visit project_issue_path(private_project, private_issue)
2020-11-24 15:15:51 +05:30
expect(page).not_to have_css('.related-issues-block')
end
it 'shows widget when public project' do
2022-11-25 23:54:43 +05:30
visit project_issue_path(public_project, public_issue)
2020-11-24 15:15:51 +05:30
expect(page).to have_css('.related-issues-block')
2021-11-18 22:05:49 +05:30
expect(page).not_to have_button 'Add a related issue'
2020-11-24 15:15:51 +05:30
end
end
context 'when logged in but not a member' do
before do
2021-11-18 22:05:49 +05:30
sign_in(user)
2020-11-24 15:15:51 +05:30
end
it 'shows widget when internal project' do
2022-11-25 23:54:43 +05:30
visit project_issue_path(internal_project, internal_issue)
2020-11-24 15:15:51 +05:30
expect(page).to have_css('.related-issues-block')
2021-11-18 22:05:49 +05:30
expect(page).not_to have_button 'Add a related issue'
2020-11-24 15:15:51 +05:30
end
it 'does not show widget when private project' do
2022-11-25 23:54:43 +05:30
visit project_issue_path(private_project, private_issue)
2020-11-24 15:15:51 +05:30
expect(page).not_to have_css('.related-issues-block')
end
it 'shows widget when public project' do
2022-11-25 23:54:43 +05:30
visit project_issue_path(public_project, public_issue)
2020-11-24 15:15:51 +05:30
expect(page).to have_css('.related-issues-block')
2021-11-18 22:05:49 +05:30
expect(page).not_to have_button 'Add a related issue'
2020-11-24 15:15:51 +05:30
end
it 'shows widget on their own public issue' do
2022-11-25 23:54:43 +05:30
issue = create :issue, project: public_project, author: user
2020-11-24 15:15:51 +05:30
2022-11-25 23:54:43 +05:30
visit project_issue_path(public_project, issue)
2020-11-24 15:15:51 +05:30
expect(page).to have_css('.related-issues-block')
2021-11-18 22:05:49 +05:30
expect(page).not_to have_button 'Add a related issue'
2020-11-24 15:15:51 +05:30
end
end
context 'when logged in and a guest' do
before do
2021-11-18 22:05:49 +05:30
sign_in(user)
2020-11-24 15:15:51 +05:30
end
it 'shows widget when internal project' do
2022-11-25 23:54:43 +05:30
internal_project.add_guest(user)
2020-11-24 15:15:51 +05:30
2022-11-25 23:54:43 +05:30
visit project_issue_path(internal_project, internal_issue)
2020-11-24 15:15:51 +05:30
expect(page).to have_css('.related-issues-block')
2021-11-18 22:05:49 +05:30
expect(page).not_to have_button 'Add a related issue'
2020-11-24 15:15:51 +05:30
end
it 'shows widget when private project' do
2022-11-25 23:54:43 +05:30
private_project.add_guest(user)
2020-11-24 15:15:51 +05:30
2022-11-25 23:54:43 +05:30
visit project_issue_path(private_project, private_issue)
2020-11-24 15:15:51 +05:30
expect(page).to have_css('.related-issues-block')
2021-11-18 22:05:49 +05:30
expect(page).not_to have_button 'Add a related issue'
2020-11-24 15:15:51 +05:30
end
it 'shows widget when public project' do
2022-11-25 23:54:43 +05:30
public_project.add_guest(user)
2020-11-24 15:15:51 +05:30
2022-11-25 23:54:43 +05:30
visit project_issue_path(public_project, public_issue)
2020-11-24 15:15:51 +05:30
expect(page).to have_css('.related-issues-block')
2021-11-18 22:05:49 +05:30
expect(page).not_to have_button 'Add a related issue'
2020-11-24 15:15:51 +05:30
end
end
context 'when logged in and a reporter' do
before do
2021-11-18 22:05:49 +05:30
sign_in(user)
2020-11-24 15:15:51 +05:30
end
it 'shows widget when internal project' do
2022-11-25 23:54:43 +05:30
internal_project.add_reporter(user)
2020-11-24 15:15:51 +05:30
2022-11-25 23:54:43 +05:30
visit project_issue_path(internal_project, internal_issue)
2020-11-24 15:15:51 +05:30
expect(page).to have_css('.related-issues-block')
2021-11-18 22:05:49 +05:30
expect(page).to have_button 'Add a related issue'
2020-11-24 15:15:51 +05:30
end
it 'shows widget when private project' do
2022-11-25 23:54:43 +05:30
private_project.add_reporter(user)
2020-11-24 15:15:51 +05:30
2022-11-25 23:54:43 +05:30
visit project_issue_path(private_project, private_issue)
2020-11-24 15:15:51 +05:30
expect(page).to have_css('.related-issues-block')
2021-11-18 22:05:49 +05:30
expect(page).to have_button 'Add a related issue'
2020-11-24 15:15:51 +05:30
end
it 'shows widget when public project' do
2022-11-25 23:54:43 +05:30
public_project.add_reporter(user)
2020-11-24 15:15:51 +05:30
2022-11-25 23:54:43 +05:30
visit project_issue_path(public_project, public_issue)
2020-11-24 15:15:51 +05:30
expect(page).to have_css('.related-issues-block')
2021-11-18 22:05:49 +05:30
expect(page).to have_button 'Add a related issue'
2020-11-24 15:15:51 +05:30
end
it 'shows widget on their own public issue' do
2022-11-25 23:54:43 +05:30
issue = create :issue, project: public_project, author: user
public_project.add_reporter(user)
2020-11-24 15:15:51 +05:30
2022-11-25 23:54:43 +05:30
visit project_issue_path(public_project, issue)
2020-11-24 15:15:51 +05:30
expect(page).to have_css('.related-issues-block')
2021-11-18 22:05:49 +05:30
expect(page).to have_button 'Add a related issue'
2020-11-24 15:15:51 +05:30
end
end
end
context 'when user has no permission to manage related issues' do
let!(:issue_link_b) { create :issue_link, source: issue_a, target: issue_b }
let!(:issue_link_c) { create :issue_link, source: issue_a, target: issue_c }
2022-11-25 23:54:43 +05:30
before_all do
2020-11-24 15:15:51 +05:30
project.add_guest(user)
2022-11-25 23:54:43 +05:30
end
before do
2021-11-18 22:05:49 +05:30
sign_in(user)
2020-11-24 15:15:51 +05:30
end
context 'visiting some issue someone else created' do
before do
visit project_issue_path(project, issue_a)
wait_for_requests
end
it 'shows related issues count' do
expect(find('.js-related-issues-header-issue-count')).to have_content('2')
end
end
context 'visiting issue_b which was targeted by issue_a' do
before do
visit project_issue_path(project, issue_b)
wait_for_requests
end
it 'shows related issues count' do
expect(find('.js-related-issues-header-issue-count')).to have_content('1')
end
end
end
context 'when user has permission to manage related issues' do
2022-11-25 23:54:43 +05:30
before_all do
2020-11-24 15:15:51 +05:30
project.add_maintainer(user)
project_b.add_maintainer(user)
2022-11-25 23:54:43 +05:30
end
before do
2021-11-18 22:05:49 +05:30
sign_in(user)
2020-11-24 15:15:51 +05:30
end
context 'without existing related issues' do
before do
visit project_issue_path(project, issue_a)
wait_for_requests
end
it 'shows related issues count' do
expect(find('.js-related-issues-header-issue-count')).to have_content('0')
end
it 'add related issue' do
2021-11-18 22:05:49 +05:30
click_button 'Add a related issue'
fill_in 'Paste issue link', with: "#{issue_b.to_reference(project)} "
2022-08-27 11:52:29 +05:30
page.within('.linked-issues-card-body') do
click_button 'Add'
end
2020-11-24 15:15:51 +05:30
wait_for_requests
items = all('.item-title a')
# Form gets hidden after submission
expect(page).not_to have_selector('.js-add-related-issues-form-area')
# Check if related issues are present
expect(items.count).to eq(1)
expect(items[0].text).to eq(issue_b.title)
expect(find('.js-related-issues-header-issue-count')).to have_content('1')
end
it 'add cross-project related issue' do
2021-11-18 22:05:49 +05:30
click_button 'Add a related issue'
fill_in 'Paste issue link', with: "#{issue_project_b_a.to_reference(project)} "
2022-08-27 11:52:29 +05:30
page.within('.linked-issues-card-body') do
click_button 'Add'
end
2020-11-24 15:15:51 +05:30
wait_for_requests
items = all('.item-title a')
expect(items.count).to eq(1)
expect(items[0].text).to eq(issue_project_b_a.title)
expect(find('.js-related-issues-header-issue-count')).to have_content('1')
end
it 'pressing enter should submit the form' do
2021-11-18 22:05:49 +05:30
click_button 'Add a related issue'
fill_in 'Paste issue link', with: "#{issue_project_b_a.to_reference(project)} "
find_field('Paste issue link').native.send_key(:enter)
2020-11-24 15:15:51 +05:30
wait_for_requests
items = all('.item-title a')
expect(items.count).to eq(1)
expect(items[0].text).to eq(issue_project_b_a.title)
expect(find('.js-related-issues-header-issue-count')).to have_content('1')
end
it 'disallows duplicate entries' do
2021-11-18 22:05:49 +05:30
click_button 'Add a related issue'
fill_in 'Paste issue link', with: 'duplicate duplicate duplicate'
2020-11-24 15:15:51 +05:30
2021-11-18 22:05:49 +05:30
items = all('.issue-token')
2020-11-24 15:15:51 +05:30
expect(items.count).to eq(1)
expect(items[0].text).to eq('duplicate')
# Pending issues aren't counted towards the related issue count
expect(find('.js-related-issues-header-issue-count')).to have_content('0')
end
it 'allows us to remove pending issues' do
# Tests against https://gitlab.com/gitlab-org/gitlab/issues/11625
2021-11-18 22:05:49 +05:30
click_button 'Add a related issue'
fill_in 'Paste issue link', with: 'issue1 issue2 issue3 '
2020-11-24 15:15:51 +05:30
2021-11-18 22:05:49 +05:30
items = all('.issue-token')
2020-11-24 15:15:51 +05:30
expect(items.count).to eq(3)
expect(items[0].text).to eq('issue1')
expect(items[1].text).to eq('issue2')
expect(items[2].text).to eq('issue3')
# Remove pending issues left to right to make sure none get stuck
2021-11-18 22:05:49 +05:30
within items[0] do
click_button 'Remove'
end
items = all('.issue-token')
2020-11-24 15:15:51 +05:30
expect(items.count).to eq(2)
expect(items[0].text).to eq('issue2')
expect(items[1].text).to eq('issue3')
2021-11-18 22:05:49 +05:30
within items[0] do
click_button 'Remove'
end
items = all('.issue-token')
2020-11-24 15:15:51 +05:30
expect(items.count).to eq(1)
expect(items[0].text).to eq('issue3')
2021-11-18 22:05:49 +05:30
within items[0] do
click_button 'Remove'
end
items = all('.issue-token')
2020-11-24 15:15:51 +05:30
expect(items.count).to eq(0)
end
end
context 'with existing related issues' do
let!(:issue_link_b) { create :issue_link, source: issue_a, target: issue_b }
let!(:issue_link_c) { create :issue_link, source: issue_a, target: issue_c }
before do
visit project_issue_path(project, issue_a)
wait_for_requests
end
it 'shows related issues count' do
expect(find('.js-related-issues-header-issue-count')).to have_content('2')
end
it 'shows related issues' do
items = all('.item-title a')
expect(items.count).to eq(2)
expect(items[0].text).to eq(issue_b.title)
expect(items[1].text).to eq(issue_c.title)
end
it 'allows us to remove a related issues' do
items_before = all('.item-title a')
expect(items_before.count).to eq(2)
first('.js-issue-item-remove-button').click
wait_for_requests
items_after = all('.item-title a')
expect(items_after.count).to eq(1)
end
it 'add related issue' do
2021-11-18 22:05:49 +05:30
click_button 'Add a related issue'
fill_in 'Paste issue link', with: "##{issue_d.iid} "
2022-08-27 11:52:29 +05:30
page.within('.linked-issues-card-body') do
click_button 'Add'
end
2020-11-24 15:15:51 +05:30
wait_for_requests
items = all('.item-title a')
expect(items.count).to eq(3)
expect(items[0].text).to eq(issue_b.title)
expect(items[1].text).to eq(issue_c.title)
expect(items[2].text).to eq(issue_d.title)
expect(find('.js-related-issues-header-issue-count')).to have_content('3')
end
it 'add invalid related issue' do
2021-11-18 22:05:49 +05:30
click_button 'Add a related issue'
fill_in 'Paste issue link', with: '#9999999 '
2022-08-27 11:52:29 +05:30
page.within('.linked-issues-card-body') do
click_button 'Add'
end
2020-11-24 15:15:51 +05:30
wait_for_requests
items = all('.item-title a')
expect(items.count).to eq(2)
expect(items[0].text).to eq(issue_b.title)
expect(items[1].text).to eq(issue_c.title)
expect(find('.js-related-issues-header-issue-count')).to have_content('2')
end
it 'add unauthorized related issue' do
2021-11-18 22:05:49 +05:30
click_button 'Add a related issue'
fill_in 'Paste issue link', with: "#{issue_project_unauthorized_a.to_reference(project)} "
2022-08-27 11:52:29 +05:30
page.within('.linked-issues-card-body') do
click_button 'Add'
end
2020-11-24 15:15:51 +05:30
wait_for_requests
items = all('.item-title a')
expect(items.count).to eq(2)
expect(items[0].text).to eq(issue_b.title)
expect(items[1].text).to eq(issue_c.title)
expect(find('.js-related-issues-header-issue-count')).to have_content('2')
end
end
end
end