2019-10-12 21:52:04 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-12-04 20:38:33 +05:30
|
|
|
require 'spec_helper'
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
RSpec.describe 'issuable list' do
|
2017-09-10 17:25:29 +05:30
|
|
|
let(:project) { create(:project) }
|
2017-08-17 22:00:37 +05:30
|
|
|
let(:user) { create(:user) }
|
|
|
|
|
|
|
|
issuable_types = [:issue, :merge_request]
|
|
|
|
|
|
|
|
before do
|
|
|
|
project.add_user(user, :developer)
|
2017-09-10 17:25:29 +05:30
|
|
|
sign_in(user)
|
2017-08-17 22:00:37 +05:30
|
|
|
issuable_types.each { |type| create_issuables(type) }
|
|
|
|
end
|
|
|
|
|
|
|
|
issuable_types.each do |issuable_type|
|
|
|
|
it "avoids N+1 database queries for #{issuable_type.to_s.humanize.pluralize}" do
|
|
|
|
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)
|
|
|
|
|
|
|
|
expect(first('.fa-thumbs-up').find(:xpath, '..')).to have_content(1)
|
|
|
|
expect(first('.fa-thumbs-down').find(:xpath, '..')).to have_content(1)
|
|
|
|
expect(first('.fa-comments').find(:xpath, '..')).to have_content(2)
|
|
|
|
end
|
2019-07-07 11:18:12 +05:30
|
|
|
|
|
|
|
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-04-08 14:13:33 +05:30
|
|
|
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-07-07 11:18:12 +05:30
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it "counts merge requests closing issues icons for each issue" do
|
|
|
|
visit_issuable_list(:issue)
|
|
|
|
|
|
|
|
expect(page).to have_selector('.icon-merge-request-unmerged', count: 1)
|
|
|
|
expect(first('.icon-merge-request-unmerged').find(:xpath, '..')).to have_content(1)
|
|
|
|
end
|
|
|
|
|
|
|
|
def visit_issuable_list(issuable_type)
|
|
|
|
if issuable_type == :issue
|
2017-09-10 17:25:29 +05:30
|
|
|
visit project_issues_path(project)
|
2017-08-17 22:00:37 +05:30
|
|
|
else
|
2017-09-10 17:25:29 +05:30
|
|
|
visit project_merge_requests_path(project)
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-07-07 11:18:12 +05:30
|
|
|
def create_issuable(issuable_type)
|
|
|
|
if issuable_type == :issue
|
|
|
|
create(:issue, project: project)
|
|
|
|
else
|
|
|
|
create(:merge_request, source_project: project)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
def create_issuables(issuable_type)
|
|
|
|
3.times do |n|
|
|
|
|
issuable =
|
|
|
|
if issuable_type == :issue
|
|
|
|
create(:issue, project: project, author: user)
|
|
|
|
else
|
|
|
|
create(:merge_request, source_project: project, source_branch: generate(:branch))
|
2019-06-05 12:25:43 +05:30
|
|
|
source_branch = FFaker::Lorem.characters(8)
|
2017-09-10 17:25:29 +05:30
|
|
|
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-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
create_list(:note_on_issue, 2, noteable: issuable, project: project)
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
create(:award_emoji, :downvote, awardable: issuable)
|
|
|
|
create(:award_emoji, :upvote, awardable: issuable)
|
|
|
|
end
|
|
|
|
|
|
|
|
if issuable_type == :issue
|
|
|
|
issue = Issue.reorder(:iid).first
|
|
|
|
merge_request = create(:merge_request,
|
|
|
|
source_project: project,
|
|
|
|
source_branch: generate(:branch))
|
|
|
|
|
|
|
|
create(:merge_requests_closing_issues, issue: issue, merge_request: merge_request)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|