debian-mirror-gitlab/spec/features/dashboard/projects_spec.rb

266 lines
8.8 KiB
Ruby
Raw Permalink Normal View History

2019-10-12 21:52:04 +05:30
# frozen_string_literal: true
2017-08-17 22:00:37 +05:30
require 'spec_helper'
2023-03-04 22:38:38 +05:30
RSpec.describe 'Dashboard Projects', feature_category: :projects do
2021-04-29 21:17:54 +05:30
let_it_be(:user) { create(:user) }
2023-05-27 22:25:52 +05:30
let_it_be(:project, reload: true) { create(:project, :repository, creator: build(:user)) } # ensure creator != owner to avoid N+1 false-positive
2021-04-29 21:17:54 +05:30
let_it_be(:project2) { create(:project, :public) }
2017-08-17 22:00:37 +05:30
before do
2018-03-17 18:26:18 +05:30
project.add_developer(user)
2017-09-10 17:25:29 +05:30
sign_in(user)
end
2018-11-08 19:23:39 +05:30
it_behaves_like "an autodiscoverable RSS feed with current_user's feed token" do
2017-09-10 17:25:29 +05:30
before do
visit dashboard_projects_path
end
2017-08-17 22:00:37 +05:30
end
2023-06-20 00:43:36 +05:30
it_behaves_like 'a "Your work" page with sidebar and breadcrumbs', :dashboard_projects_path, :projects
2023-03-17 16:20:25 +05:30
2023-05-27 22:25:52 +05:30
it 'links to the "Explore projects" page' do
visit dashboard_projects_path
expect(page).to have_link("Explore projects", href: explore_projects_path)
end
2018-11-08 19:23:39 +05:30
context 'when user has access to the project' do
it 'shows role badge' do
visit dashboard_projects_path
page.within '.user-access-role' do
expect(page).to have_content('Developer')
end
end
context 'when role changes', :use_clean_rails_memory_store_fragment_caching do
it 'displays the right role' do
visit dashboard_projects_path
page.within '.user-access-role' do
expect(page).to have_content('Developer')
end
2021-04-29 21:17:54 +05:30
project.members.last.update!(access_level: 40)
2018-11-08 19:23:39 +05:30
visit dashboard_projects_path
page.within '.user-access-role' do
expect(page).to have_content('Maintainer')
end
end
end
end
2017-09-10 17:25:29 +05:30
context 'when last_repository_updated_at, last_activity_at and update_at are present' do
it 'shows the last_repository_updated_at attribute as the update date' do
2022-05-07 20:08:51 +05:30
project.update!(last_repository_updated_at: Time.zone.now, last_activity_at: 1.hour.ago)
2017-09-10 17:25:29 +05:30
visit dashboard_projects_path
expect(page).to have_xpath("//time[@datetime='#{project.last_repository_updated_at.getutc.iso8601}']")
end
2018-03-27 19:54:05 +05:30
it 'shows the last_activity_at attribute as the update date' do
2022-05-07 20:08:51 +05:30
project.update!(last_repository_updated_at: 1.hour.ago, last_activity_at: Time.zone.now)
2018-03-27 19:54:05 +05:30
visit dashboard_projects_path
expect(page).to have_xpath("//time[@datetime='#{project.last_activity_at.getutc.iso8601}']")
end
2017-09-10 17:25:29 +05:30
end
context 'when last_repository_updated_at and last_activity_at are missing' do
it 'shows the updated_at attribute as the update date' do
2018-11-18 11:00:15 +05:30
project.update!(last_repository_updated_at: nil, last_activity_at: nil)
2017-09-10 17:25:29 +05:30
project.touch
visit dashboard_projects_path
expect(page).to have_xpath("//time[@datetime='#{project.updated_at.getutc.iso8601}']")
end
end
2018-03-17 18:26:18 +05:30
context 'when on Your projects tab' do
it 'shows all projects by default' do
visit dashboard_projects_path
expect(page).to have_content(project.name)
2021-12-11 22:18:48 +05:30
expect(find('.gl-tabs-nav li:nth-child(1) .badge-pill')).to have_content(1)
2018-03-17 18:26:18 +05:30
end
it 'shows personal projects on personal projects tab', :js do
project3 = create(:project, namespace: user.namespace)
visit dashboard_projects_path
click_link 'Personal'
expect(page).not_to have_content(project.name)
expect(page).to have_content(project3.name)
end
2018-12-05 23:21:45 +05:30
it 'sorts projects by most stars when sorting by most stars' do
project_with_most_stars = create(:project, namespace: user.namespace, star_count: 10)
visit dashboard_projects_path(sort: :stars_desc)
expect(first('.project-row')).to have_content(project_with_most_stars.title)
end
2018-03-17 18:26:18 +05:30
end
2019-07-07 11:18:12 +05:30
context 'when on Starred projects tab', :js do
2023-06-20 00:43:36 +05:30
it_behaves_like 'a "Your work" page with sidebar and breadcrumbs', :starred_dashboard_projects_path, :projects
2022-11-25 23:54:43 +05:30
it 'shows the empty state when there are no starred projects' do
2019-07-07 11:18:12 +05:30
visit(starred_dashboard_projects_path)
element = page.find('.row.empty-state')
expect(element).to have_content("You don't have starred projects yet.")
end
2017-09-10 17:25:29 +05:30
it 'shows only starred projects' do
user.toggle_star(project2)
visit(starred_dashboard_projects_path)
expect(page).not_to have_content(project.name)
expect(page).to have_content(project2.name)
2021-12-11 22:18:48 +05:30
expect(find('.gl-tabs-nav li:nth-child(1) .badge-pill')).to have_content(1)
expect(find('.gl-tabs-nav li:nth-child(2) .badge-pill')).to have_content(1)
2017-09-10 17:25:29 +05:30
end
2019-07-31 22:56:46 +05:30
it 'does not show tabs to filter by all projects or personal' do
visit(starred_dashboard_projects_path)
expect(page).not_to have_content '.filtered-search-nav'
end
2017-09-10 17:25:29 +05:30
end
2018-03-17 18:26:18 +05:30
describe 'with a pipeline', :clean_gitlab_redis_shared_state do
2023-01-13 00:05:48 +05:30
let!(:pipeline) { create(:ci_pipeline, project: project, sha: project.commit.sha, ref: project.default_branch) }
2017-08-17 22:00:37 +05:30
before do
# Since the cache isn't updated when a new pipeline is created
# we need the pipeline to advance in the pipeline since the cache was created
# by visiting the login page.
pipeline.succeed
end
it 'shows that the last pipeline passed' do
visit dashboard_projects_path
2023-01-13 00:05:48 +05:30
page.within('[data-testid="project_controls"]') do
2018-10-15 14:42:47 +05:30
expect(page).to have_xpath("//a[@href='#{pipelines_project_commit_path(project, project.commit, ref: pipeline.ref)}']")
2017-09-10 17:25:29 +05:30
expect(page).to have_css('.ci-status-link')
expect(page).to have_css('.ci-status-icon-success')
2019-12-04 20:38:33 +05:30
expect(page).to have_link('Pipeline: passed')
2017-09-10 17:25:29 +05:30
end
2019-02-02 18:00:53 +05:30
end
2020-03-13 15:44:24 +05:30
shared_examples 'hidden pipeline status' do
it 'does not show the pipeline status' do
visit dashboard_projects_path
2023-01-13 00:05:48 +05:30
page.within('[data-testid="project_controls"]') do
2020-03-13 15:44:24 +05:30
expect(page).not_to have_xpath("//a[@href='#{pipelines_project_commit_path(project, project.commit, ref: pipeline.ref)}']")
expect(page).not_to have_css('.ci-status-link')
expect(page).not_to have_css('.ci-status-icon-success')
expect(page).not_to have_link('Pipeline: passed')
end
end
end
2019-02-02 18:00:53 +05:30
context 'guest user of project and project has private pipelines' do
let(:guest_user) { create(:user) }
before do
2021-04-29 21:17:54 +05:30
project.update!(public_builds: false)
2019-02-02 18:00:53 +05:30
project.add_guest(guest_user)
sign_in(guest_user)
end
2020-03-13 15:44:24 +05:30
it_behaves_like 'hidden pipeline status'
end
2019-02-02 18:00:53 +05:30
2020-07-28 23:09:34 +05:30
context "when last_pipeline is missing" do
before do
project.last_pipeline.delete
end
2020-03-13 15:44:24 +05:30
it_behaves_like 'hidden pipeline status'
2017-08-17 22:00:37 +05:30
end
end
2021-10-27 15:23:28 +05:30
describe 'with topics' do
context 'when project has topics' do
before do
project.update_attribute(:topic_list, 'topic1')
end
it 'shows project topics if exist' do
visit dashboard_projects_path
expect(page).to have_selector('[data-testid="project_topic_list"]')
2021-12-11 22:18:48 +05:30
expect(page).to have_link('topic1', href: topic_explore_projects_path(topic_name: 'topic1'))
2021-10-27 15:23:28 +05:30
end
end
context 'when project does not have topics' do
it 'does not show project topics' do
visit dashboard_projects_path
expect(page).not_to have_selector('[data-testid="project_topic_list"]')
end
end
end
2018-03-17 18:26:18 +05:30
context 'last push widget', :use_clean_rails_memory_store_caching do
2017-09-10 17:25:29 +05:30
before do
2018-03-17 18:26:18 +05:30
event = create(:push_event, project: project, author: user)
create(:push_event_payload, event: event, ref: 'feature', action: :created)
Users::LastPushEventService.new(user).cache_last_push_event(event)
2017-09-10 17:25:29 +05:30
visit dashboard_projects_path
end
2018-11-08 19:23:39 +05:30
it 'shows "Create merge request" button' do
2017-09-10 17:25:29 +05:30
expect(page).to have_content 'You pushed to feature'
within('#content-body') do
find_link('Create merge request', visible: false).click
end
expect(page).to have_selector('.merge-request-form')
2022-05-07 20:08:51 +05:30
expect(page).to have_current_path project_new_merge_request_path(project), ignore_query: true
2018-03-17 18:26:18 +05:30
expect(find('#merge_request_target_project_id', visible: false).value).to eq project.id.to_s
2019-12-26 22:10:19 +05:30
expect(page).to have_content "From feature into master"
2017-09-10 17:25:29 +05:30
end
end
2019-12-04 20:38:33 +05:30
it 'avoids an N+1 query in dashboard index' do
create(:ci_pipeline, :with_job, status: :success, project: project, ref: project.default_branch, sha: project.commit.sha)
visit dashboard_projects_path
2023-05-27 22:25:52 +05:30
control = ActiveRecord::QueryRecorder.new { visit dashboard_projects_path }
2019-12-04 20:38:33 +05:30
new_project = create(:project, :repository, name: 'new project')
create(:ci_pipeline, :with_job, status: :success, project: new_project, ref: new_project.commit.sha)
new_project.add_developer(user)
ActiveRecord::QueryRecorder.new { visit dashboard_projects_path }.count
2023-05-27 22:25:52 +05:30
# There are a few known N+1 queries: https://gitlab.com/gitlab-org/gitlab/-/issues/214037
# - User#max_member_access_for_project_ids
# - ProjectsHelper#load_pipeline_status / Ci::CommitWithPipeline#last_pipeline
# - Ci::Pipeline#detailed_status
2020-04-22 19:07:51 +05:30
2023-05-27 22:25:52 +05:30
expect { visit dashboard_projects_path }.not_to exceed_query_limit(control).with_threshold(4)
2019-12-04 20:38:33 +05:30
end
2017-08-17 22:00:37 +05:30
end