2019-07-25 05:24:42 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-08-29 07:56:52 +00:00
|
|
|
require 'spec_helper'
|
2017-01-23 20:40:25 +00:00
|
|
|
|
2020-06-29 03:09:01 +00:00
|
|
|
RSpec.describe 'issuable list', :js do
|
2017-08-02 19:55:11 +00:00
|
|
|
let(:project) { create(:project) }
|
2017-01-23 20:40:25 +00:00
|
|
|
let(:user) { create(:user) }
|
|
|
|
|
|
|
|
issuable_types = [:issue, :merge_request]
|
|
|
|
|
|
|
|
before do
|
|
|
|
project.add_user(user, :developer)
|
2017-06-21 23:44:10 +00:00
|
|
|
sign_in(user)
|
2017-01-23 20:40:25 +00:00
|
|
|
issuable_types.each { |type| create_issuables(type) }
|
|
|
|
end
|
|
|
|
|
|
|
|
issuable_types.each do |issuable_type|
|
2020-08-11 12:09:55 +00:00
|
|
|
it "avoids N+1 database queries for #{issuable_type.to_s.humanize.pluralize}", quarantine: { issue: 'https://gitlab.com/gitlab-org/gitlab/-/issues/231426' } do
|
2017-01-23 20:40:25 +00:00
|
|
|
control_count = ActiveRecord::QueryRecorder.new { visit_issuable_list(issuable_type) }.count
|
|
|
|
|
|
|
|
create_issuables(issuable_type)
|
|
|
|
|
|
|
|
expect { visit_issuable_list(issuable_type) }.not_to exceed_query_limit(control_count)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "counts upvotes, downvotes and notes count for each #{issuable_type.to_s.humanize}" do
|
|
|
|
visit_issuable_list(issuable_type)
|
|
|
|
|
2020-07-08 06:09:13 +00:00
|
|
|
expect(first('.issuable-upvotes')).to have_content(1)
|
|
|
|
expect(first('.issuable-downvotes')).to have_content(1)
|
2020-07-10 09:09:01 +00:00
|
|
|
expect(first('.issuable-comments')).to have_content(2)
|
2017-01-23 20:40:25 +00:00
|
|
|
end
|
2019-02-21 16:06:14 +00:00
|
|
|
|
|
|
|
it 'sorts labels alphabetically' do
|
|
|
|
label1 = create(:label, project: project, title: 'a')
|
|
|
|
label2 = create(:label, project: project, title: 'z')
|
|
|
|
label3 = create(:label, project: project, title: 'X')
|
|
|
|
label4 = create(:label, project: project, title: 'B')
|
|
|
|
issuable = create_issuable(issuable_type)
|
|
|
|
issuable.labels << [label1, label2, label3, label4]
|
|
|
|
|
|
|
|
visit_issuable_list(issuable_type)
|
|
|
|
|
2020-02-25 15:08:50 +00:00
|
|
|
expect(all('.gl-label-text')[0].text).to have_content('B')
|
|
|
|
expect(all('.gl-label-text')[1].text).to have_content('X')
|
|
|
|
expect(all('.gl-label-text')[2].text).to have_content('a')
|
|
|
|
expect(all('.gl-label-text')[3].text).to have_content('z')
|
2019-02-21 16:06:14 +00:00
|
|
|
end
|
2017-01-23 20:40:25 +00:00
|
|
|
end
|
|
|
|
|
2020-10-14 18:08:47 +00:00
|
|
|
it 'displays a warning if counting the number of issues times out' do
|
|
|
|
allow_any_instance_of(IssuesFinder).to receive(:count_by_state).and_raise(ActiveRecord::QueryCanceled)
|
|
|
|
|
|
|
|
visit_issuable_list(:issue)
|
|
|
|
|
2021-02-02 15:09:06 +00:00
|
|
|
expect(page).to have_text('Open Closed All')
|
2020-10-14 18:08:47 +00:00
|
|
|
end
|
|
|
|
|
2017-02-18 01:58:24 +00:00
|
|
|
it "counts merge requests closing issues icons for each issue" do
|
|
|
|
visit_issuable_list(:issue)
|
2017-02-18 00:47:56 +00:00
|
|
|
|
2020-09-02 12:10:35 +00:00
|
|
|
expect(page).to have_selector('[data-testid="merge-requests"]', count: 1)
|
|
|
|
expect(first('[data-testid="merge-requests"]').find(:xpath, '..')).to have_content(1)
|
2017-02-18 01:58:24 +00:00
|
|
|
end
|
2017-02-18 00:47:56 +00:00
|
|
|
|
2017-01-23 20:40:25 +00:00
|
|
|
def visit_issuable_list(issuable_type)
|
|
|
|
if issuable_type == :issue
|
2017-07-06 16:20:50 +00:00
|
|
|
visit project_issues_path(project)
|
2017-01-23 20:40:25 +00:00
|
|
|
else
|
2017-07-06 16:20:50 +00:00
|
|
|
visit project_merge_requests_path(project)
|
2017-01-23 20:40:25 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-02-21 16:06:14 +00:00
|
|
|
def create_issuable(issuable_type)
|
|
|
|
if issuable_type == :issue
|
|
|
|
create(:issue, project: project)
|
|
|
|
else
|
|
|
|
create(:merge_request, source_project: project)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-01-23 20:40:25 +00:00
|
|
|
def create_issuables(issuable_type)
|
2017-03-23 13:08:39 +00:00
|
|
|
3.times do |n|
|
2017-02-22 15:10:32 +00:00
|
|
|
issuable =
|
|
|
|
if issuable_type == :issue
|
|
|
|
create(:issue, project: project, author: user)
|
|
|
|
else
|
2017-03-23 16:37:14 +00:00
|
|
|
create(:merge_request, source_project: project, source_branch: generate(:branch))
|
2019-04-10 03:39:45 +00:00
|
|
|
source_branch = FFaker::Lorem.characters(8)
|
2017-03-22 19:36:14 +00:00
|
|
|
pipeline = create(:ci_empty_pipeline, project: project, ref: source_branch, status: %w(running failed success).sample, sha: 'any')
|
|
|
|
create(:merge_request, title: FFaker::Lorem.sentence, source_project: project, source_branch: source_branch, head_pipeline: pipeline)
|
2017-02-22 15:10:32 +00:00
|
|
|
end
|
2017-01-23 20:40:25 +00:00
|
|
|
|
2020-01-09 18:07:52 +00:00
|
|
|
create_list(:note_on_issue, 2, noteable: issuable, project: project)
|
2017-01-23 20:40:25 +00:00
|
|
|
|
|
|
|
create(:award_emoji, :downvote, awardable: issuable)
|
|
|
|
create(:award_emoji, :upvote, awardable: issuable)
|
2017-02-21 22:08:20 +00:00
|
|
|
end
|
2017-02-21 01:07:50 +00:00
|
|
|
|
2017-02-21 22:00:03 +00:00
|
|
|
if issuable_type == :issue
|
|
|
|
issue = Issue.reorder(:iid).first
|
|
|
|
merge_request = create(:merge_request,
|
|
|
|
source_project: project,
|
2017-03-23 16:37:14 +00:00
|
|
|
source_branch: generate(:branch))
|
2017-02-21 01:07:50 +00:00
|
|
|
|
2017-04-12 11:38:00 +00:00
|
|
|
create(:merge_requests_closing_issues, issue: issue, merge_request: merge_request)
|
2017-01-23 20:40:25 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|