2019-07-31 22:56:46 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2023-04-23 21:23:45 +05:30
|
|
|
RSpec.describe DashboardController, feature_category: :code_review_workflow do
|
2018-11-29 20:51:05 +05:30
|
|
|
context 'signed in' do
|
2022-11-25 23:54:43 +05:30
|
|
|
let_it_be(:user) { create(:user) }
|
|
|
|
let_it_be(:project) { create(:project) }
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2022-11-25 23:54:43 +05:30
|
|
|
before_all do
|
2018-11-29 20:51:05 +05:30
|
|
|
project.add_maintainer(user)
|
2022-11-25 23:54:43 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
before do
|
2018-11-29 20:51:05 +05:30
|
|
|
sign_in(user)
|
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2018-11-29 20:51:05 +05:30
|
|
|
describe 'GET issues' do
|
2022-05-07 20:08:51 +05:30
|
|
|
context 'when issues_full_text_search is disabled' do
|
|
|
|
before do
|
|
|
|
stub_feature_flags(issues_full_text_search: false)
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'issuables list meta-data', :issue, :issues
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when issues_full_text_search is enabled' do
|
|
|
|
before do
|
|
|
|
stub_feature_flags(issues_full_text_search: true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'issuables list meta-data', :issue, :issues
|
|
|
|
end
|
|
|
|
|
2018-11-29 20:51:05 +05:30
|
|
|
it_behaves_like 'issuables requiring filter', :issues
|
2022-11-25 23:54:43 +05:30
|
|
|
|
|
|
|
it 'includes tasks in issue list' do
|
|
|
|
task = create(:work_item, :task, project: project, author: user)
|
|
|
|
|
|
|
|
get :issues, params: { author_id: user.id }
|
|
|
|
|
|
|
|
expect(assigns[:issues].map(&:id)).to include(task.id)
|
|
|
|
end
|
2018-11-29 20:51:05 +05:30
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2018-11-29 20:51:05 +05:30
|
|
|
describe 'GET merge requests' do
|
|
|
|
it_behaves_like 'issuables list meta-data', :merge_request, :merge_requests
|
|
|
|
it_behaves_like 'issuables requiring filter', :merge_requests
|
2023-04-23 21:23:45 +05:30
|
|
|
|
|
|
|
context 'when an ActiveRecord::QueryCanceled is raised' do
|
|
|
|
before do
|
|
|
|
allow_next_instance_of(Gitlab::IssuableMetadata) do |instance|
|
|
|
|
allow(instance).to receive(:data).and_raise(ActiveRecord::QueryCanceled)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'sets :search_timeout_occurred' do
|
|
|
|
get :merge_requests, params: { author_id: user.id }
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
|
|
|
expect(assigns(:search_timeout_occurred)).to eq(true)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'rendering views' do
|
|
|
|
render_views
|
|
|
|
|
|
|
|
it 'shows error message' do
|
|
|
|
get :merge_requests, params: { author_id: user.id }
|
|
|
|
|
|
|
|
expect(response.body).to have_content('Too many results to display. Edit your search or add a filter.')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not display MR counts in nav' do
|
|
|
|
get :merge_requests, params: { author_id: user.id }
|
|
|
|
|
|
|
|
expect(response.body).to have_content('Open Merged Closed All')
|
|
|
|
expect(response.body).not_to have_content('Open 0 Merged 0 Closed 0 All 0')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'logs the exception' do
|
|
|
|
expect(Gitlab::ErrorTracking).to receive(:track_exception).and_call_original
|
|
|
|
|
|
|
|
get :merge_requests, params: { author_id: user.id }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when an ActiveRecord::QueryCanceled is not raised' do
|
|
|
|
it 'does not set :search_timeout_occurred' do
|
|
|
|
get :merge_requests, params: { author_id: user.id }
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
|
|
|
expect(assigns(:search_timeout_occurred)).to eq(nil)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'rendering views' do
|
|
|
|
render_views
|
|
|
|
|
|
|
|
it 'displays MR counts in nav' do
|
|
|
|
get :merge_requests, params: { author_id: user.id }
|
|
|
|
|
|
|
|
expect(response.body).to have_content('Open 0 Merged 0 Closed 0 All 0')
|
|
|
|
expect(response.body).not_to have_content('Open Merged Closed All')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2018-11-29 20:51:05 +05:30
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
2018-11-29 20:51:05 +05:30
|
|
|
|
2020-02-01 01:16:34 +05:30
|
|
|
describe "GET activity as JSON" do
|
2020-07-28 23:09:34 +05:30
|
|
|
include DesignManagementTestHelpers
|
2020-02-01 01:16:34 +05:30
|
|
|
render_views
|
|
|
|
|
2023-04-23 21:23:45 +05:30
|
|
|
let_it_be(:user) { create(:user) }
|
|
|
|
let_it_be(:project) { create(:project, :public, issues_access_level: ProjectFeature::PRIVATE) }
|
|
|
|
let_it_be(:other_project) { create(:project, :public) }
|
2020-02-01 01:16:34 +05:30
|
|
|
|
|
|
|
before do
|
2020-07-28 23:09:34 +05:30
|
|
|
enable_design_management
|
2020-02-01 01:16:34 +05:30
|
|
|
create(:event, :created, project: project, target: create(:issue))
|
2020-04-22 19:07:51 +05:30
|
|
|
create(:wiki_page_event, :created, project: project)
|
|
|
|
create(:wiki_page_event, :updated, project: project)
|
2020-07-28 23:09:34 +05:30
|
|
|
create(:design_event, project: project)
|
|
|
|
create(:design_event, author: user, project: other_project)
|
2020-02-01 01:16:34 +05:30
|
|
|
|
|
|
|
sign_in(user)
|
|
|
|
|
|
|
|
request.cookies[:event_filter] = 'all'
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user has permission to see the event' do
|
|
|
|
before do
|
|
|
|
project.add_developer(user)
|
2020-07-28 23:09:34 +05:30
|
|
|
other_project.add_developer(user)
|
2020-02-01 01:16:34 +05:30
|
|
|
end
|
|
|
|
|
2023-04-23 21:23:45 +05:30
|
|
|
context 'without filter param' do
|
|
|
|
it 'returns only events of the user' do
|
|
|
|
get :activity, params: { format: :json }
|
|
|
|
|
|
|
|
expect(json_response['count']).to eq(3)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with "projects" filter' do
|
|
|
|
it 'returns events of the user\'s projects' do
|
|
|
|
get :activity, params: { format: :json, filter: :projects }
|
2020-02-01 01:16:34 +05:30
|
|
|
|
2023-04-23 21:23:45 +05:30
|
|
|
expect(json_response['count']).to eq(6)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with "followed" filter' do
|
|
|
|
let_it_be(:followed_user) { create(:user) }
|
|
|
|
let_it_be(:followed_user_private_project) { create(:project, :private) }
|
|
|
|
let_it_be(:followed_user_public_project) { create(:project, :public) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
followed_user_private_project.add_developer(followed_user)
|
|
|
|
followed_user_public_project.add_developer(followed_user)
|
|
|
|
user.follow(followed_user)
|
|
|
|
create(:event, :created, project: followed_user_private_project, target: create(:issue),
|
|
|
|
author: followed_user)
|
|
|
|
create(:event, :created, project: followed_user_public_project, target: create(:issue), author: followed_user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns public events of the user\'s followed users' do
|
|
|
|
get :activity, params: { format: :json, filter: :followed }
|
|
|
|
|
|
|
|
expect(json_response['count']).to eq(1)
|
|
|
|
end
|
2020-02-01 01:16:34 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user has no permission to see the event' do
|
|
|
|
it 'filters out invisible event' do
|
2023-04-23 21:23:45 +05:30
|
|
|
get :activity, params: { format: :json, filter: :projects }
|
2020-02-01 01:16:34 +05:30
|
|
|
|
|
|
|
expect(json_response['html']).to include(_('No activities found'))
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'filters out invisible event when calculating the count' do
|
2023-04-23 21:23:45 +05:30
|
|
|
get :activity, params: { format: :json, filter: :projects }
|
2020-02-01 01:16:34 +05:30
|
|
|
|
|
|
|
expect(json_response['count']).to eq(0)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-07-07 11:18:12 +05:30
|
|
|
describe "#check_filters_presence!" do
|
|
|
|
let(:user) { create(:user) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
sign_in(user)
|
|
|
|
get :merge_requests, params: params
|
|
|
|
end
|
|
|
|
|
|
|
|
context "no filters" do
|
|
|
|
let(:params) { {} }
|
|
|
|
|
2022-05-07 20:08:51 +05:30
|
|
|
shared_examples_for 'no filters are set' do
|
|
|
|
it 'sets @no_filters_set to true' do
|
|
|
|
expect(assigns[:no_filters_set]).to eq(true)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'no filters are set'
|
|
|
|
|
|
|
|
context 'when key is present but value is not' do
|
|
|
|
let(:params) { { author_username: nil } }
|
|
|
|
|
|
|
|
it_behaves_like 'no filters are set'
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when in param is set but no search' do
|
|
|
|
let(:params) { { in: 'title' } }
|
|
|
|
|
|
|
|
it_behaves_like 'no filters are set'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
shared_examples_for 'filters are set' do
|
2019-07-07 11:18:12 +05:30
|
|
|
it 'sets @no_filters_set to false' do
|
2022-05-07 20:08:51 +05:30
|
|
|
expect(assigns[:no_filters_set]).to eq(false)
|
2019-07-07 11:18:12 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "scalar filters" do
|
|
|
|
let(:params) { { author_id: user.id } }
|
|
|
|
|
2022-05-07 20:08:51 +05:30
|
|
|
it_behaves_like 'filters are set'
|
2019-07-07 11:18:12 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
context "array filters" do
|
|
|
|
let(:params) { { label_name: ['bug'] } }
|
|
|
|
|
2022-05-07 20:08:51 +05:30
|
|
|
it_behaves_like 'filters are set'
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'search' do
|
|
|
|
let(:params) { { search: 'test' } }
|
|
|
|
|
|
|
|
it_behaves_like 'filters are set'
|
2019-07-07 11:18:12 +05:30
|
|
|
end
|
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|