debian-mirror-gitlab/spec/features/milestones/user_views_milestone_spec.rb

133 lines
4 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'
2018-10-15 14:42:47 +05:30
2020-06-23 00:09:42 +05:30
RSpec.describe "User views milestone" do
2020-04-08 14:13:33 +05:30
let_it_be(:user) { create(:user) }
2021-01-03 14:25:43 +05:30
let_it_be(:group) { create(:group) }
let_it_be(:project) { create(:project, :repository, group: group) }
let_it_be(:milestone) { create(:milestone, project: project, description: '**Lorem** _ipsum_ dolor sit [amet](https://example.com)') }
2020-04-08 14:13:33 +05:30
let_it_be(:labels) { create_list(:label, 2, project: project) }
2018-10-15 14:42:47 +05:30
2021-01-03 14:25:43 +05:30
before_all do
2018-10-15 14:42:47 +05:30
project.add_developer(user)
2021-01-03 14:25:43 +05:30
end
before do
2018-10-15 14:42:47 +05:30
sign_in(user)
end
2021-01-03 14:25:43 +05:30
context 'page description' do
before do
visit(project_milestone_path(project, milestone))
end
it_behaves_like 'page meta description', 'Lorem ipsum dolor sit amet'
end
2018-10-15 14:42:47 +05:30
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
2021-01-03 14:25:43 +05:30
context 'issues list', :js do
2020-04-22 19:07:51 +05:30
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
2021-01-03 14:25:43 +05:30
context 'for a project milestone' do
it 'does not show the project name' do
visit(project_milestone_path(project, milestone))
wait_for_requests
expect(page.find('#tab-issues')).not_to have_text(project.name)
end
end
context 'for a group milestone' do
let(:group_milestone) { create(:milestone, group: group) }
it 'shows the project name' do
create(:issue, project: project, milestone: group_milestone)
visit(group_milestone_path(group, group_milestone))
expect(page.find('#tab-issues')).to have_text(project.name)
end
end
2020-04-22 19:07:51 +05:30
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
2021-01-03 14:25:43 +05:30
context 'merge requests list', :js do
context 'for a project milestone' do
it 'does not show the project name' do
create(:merge_request, source_project: project, milestone: milestone)
visit(project_milestone_path(project, milestone))
within('.js-milestone-tabs') do
click_link('Merge Requests')
end
wait_for_requests
expect(page.find('#tab-merge-requests')).not_to have_text(project.name)
end
end
context 'for a group milestone' do
let(:group_milestone) { create(:milestone, group: group) }
it 'shows the project name' do
create(:merge_request, source_project: project, milestone: group_milestone)
visit(group_milestone_path(group, group_milestone))
within('.js-milestone-tabs') do
click_link('Merge Requests')
end
expect(page.find('#tab-merge-requests')).to have_text(project.name)
end
end
end
2018-10-15 14:42:47 +05:30
private
def visit_milestone
visit(project_milestone_path(project, milestone))
end
end