2019-10-12 21:52:04 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-12-04 20:38:33 +05:30
|
|
|
require 'spec_helper'
|
2018-10-15 14:42:47 +05:30
|
|
|
|
|
|
|
describe "User views milestone" do
|
2020-04-08 14:13:33 +05:30
|
|
|
let_it_be(:user) { create(:user) }
|
|
|
|
let_it_be(:project) { create(:project) }
|
|
|
|
let_it_be(:milestone) { create(:milestone, project: project) }
|
|
|
|
let_it_be(:labels) { create_list(:label, 2, project: project) }
|
2018-10-15 14:42:47 +05:30
|
|
|
|
|
|
|
before do
|
|
|
|
project.add_developer(user)
|
|
|
|
sign_in(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "avoids N+1 database queries" do
|
2020-05-24 23:13:21 +05:30
|
|
|
issue_params = { project: project, assignees: [user], author: user, milestone: milestone, labels: labels }.freeze
|
2018-10-15 14:42:47 +05:30
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
create(:labeled_issue, issue_params)
|
2018-10-15 14:42:47 +05:30
|
|
|
|
|
|
|
control = ActiveRecord::QueryRecorder.new { visit_milestone }
|
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
create(:labeled_issue, issue_params)
|
2018-10-15 14:42:47 +05:30
|
|
|
|
|
|
|
expect { visit_milestone }.not_to exceed_query_limit(control)
|
|
|
|
end
|
|
|
|
|
2020-04-22 19:07:51 +05:30
|
|
|
context 'limiting milestone issues' do
|
|
|
|
before_all do
|
|
|
|
2.times do
|
|
|
|
create(:issue, milestone: milestone, project: project)
|
|
|
|
create(:issue, milestone: milestone, project: project, assignees: [user])
|
|
|
|
create(:issue, milestone: milestone, project: project, state: :closed)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when issues on milestone are over DISPLAY_ISSUES_LIMIT' do
|
|
|
|
it "limits issues to display and shows warning" do
|
|
|
|
stub_const('Milestoneish::DISPLAY_ISSUES_LIMIT', 3)
|
|
|
|
|
|
|
|
visit(project_milestone_path(project, milestone))
|
|
|
|
|
|
|
|
expect(page).to have_selector('.issuable-row', count: 3)
|
|
|
|
expect(page).to have_selector('#milestone-issue-count-warning', text: 'Showing 3 of 6 issues. View all issues')
|
|
|
|
expect(page).to have_link('View all issues', href: project_issues_path(project, { milestone_title: milestone.title }))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when issues on milestone are below DISPLAY_ISSUES_LIMIT' do
|
|
|
|
it 'does not display warning' do
|
|
|
|
visit(project_milestone_path(project, milestone))
|
|
|
|
|
|
|
|
expect(page).not_to have_selector('#milestone-issue-count-warning', text: 'Showing 3 of 6 issues. View all issues')
|
|
|
|
expect(page).to have_selector('.issuable-row', count: 6)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-10-15 14:42:47 +05:30
|
|
|
private
|
|
|
|
|
|
|
|
def visit_milestone
|
|
|
|
visit(project_milestone_path(project, milestone))
|
|
|
|
end
|
|
|
|
end
|