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

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

135 lines
4 KiB
Ruby
Raw Normal View History

2019-10-12 21:52:04 +05:30
# frozen_string_literal: true
2016-10-01 15:18:49 +05:30
require 'spec_helper'
2023-03-04 22:38:38 +05:30
RSpec.describe 'Dashboard snippets', feature_category: :source_code_management do
2020-04-22 19:07:51 +05:30
let_it_be(:user) { create(:user) }
2023-06-20 00:43:36 +05:30
it_behaves_like 'a "Your work" page with sidebar and breadcrumbs', :dashboard_snippets_path, :snippets
2023-03-17 16:20:25 +05:30
2023-05-27 22:25:52 +05:30
it 'links to the "Explore snippets" page' do
sign_in(user)
visit dashboard_snippets_path
expect(page).to have_link("Explore snippets", href: explore_snippets_path)
end
2016-10-01 15:18:49 +05:30
context 'when the project has snippets' do
2020-04-22 19:07:51 +05:30
let(:project) { create(:project, :public, creator: user) }
2022-04-04 11:22:00 +05:30
let!(:snippets) { create_list(:project_snippet, 2, :public, author: project.first_owner, project: project) }
2020-01-01 13:55:28 +05:30
2016-10-01 15:18:49 +05:30
before do
allow(Snippet).to receive(:default_per_page).and_return(1)
2022-04-04 11:22:00 +05:30
sign_in(project.first_owner)
2016-10-01 15:18:49 +05:30
visit dashboard_snippets_path
end
it_behaves_like 'paginated snippets'
2020-01-01 13:55:28 +05:30
it 'shows new snippet button in header' do
parent_element = page.find('.page-title-controls')
expect(parent_element).to have_link('New snippet')
end
2016-10-01 15:18:49 +05:30
end
2017-08-17 22:00:37 +05:30
2019-07-07 11:18:12 +05:30
context 'when there are no project snippets', :js do
2020-04-22 19:07:51 +05:30
let(:project) { create(:project, :public, creator: user) }
2020-01-01 13:55:28 +05:30
2019-07-07 11:18:12 +05:30
before do
2022-04-04 11:22:00 +05:30
sign_in(project.first_owner)
2019-07-07 11:18:12 +05:30
visit dashboard_snippets_path
end
it 'shows the empty state when there are no snippets' do
element = page.find('.row.empty-state')
2020-03-13 15:44:24 +05:30
expect(element).to have_content("Code snippets")
2023-06-20 00:43:36 +05:30
expect(element.find('.svg-content img.js-lazy-loaded')['src'])
.to have_content('illustrations/empty-state/empty-snippets-md')
2019-07-07 11:18:12 +05:30
end
2020-01-01 13:55:28 +05:30
it 'shows new snippet button in main content area' do
parent_element = page.find('.row.empty-state')
expect(parent_element).to have_link('New snippet')
end
2020-03-13 15:44:24 +05:30
it 'shows documentation button in main comment area' do
parent_element = page.find('.row.empty-state')
expect(parent_element).to have_link('Documentation', href: help_page_path('user/snippets.md'))
end
2019-07-07 11:18:12 +05:30
end
2017-08-17 22:00:37 +05:30
context 'filtering by visibility' do
2020-04-22 19:07:51 +05:30
let_it_be(:snippets) do
2017-08-17 22:00:37 +05:30
[
create(:personal_snippet, :public, author: user),
create(:personal_snippet, :internal, author: user),
create(:personal_snippet, :private, author: user),
create(:personal_snippet, :public)
]
end
before do
2017-09-10 17:25:29 +05:30
sign_in(user)
2017-08-17 22:00:37 +05:30
visit dashboard_snippets_path
end
2020-03-13 15:44:24 +05:30
it_behaves_like 'tabs with counts' do
let_it_be(:counts) { { all: '3', public: '1', private: '1', internal: '1' } }
end
2017-08-17 22:00:37 +05:30
it 'contains all snippets of logged user' do
expect(page).to have_selector('.snippet-row', count: 3)
expect(page).to have_content(snippets[0].title)
expect(page).to have_content(snippets[1].title)
expect(page).to have_content(snippets[2].title)
end
it 'contains all private snippets of logged user when clicking on private' do
click_link('Private')
expect(page).to have_selector('.snippet-row', count: 1)
expect(page).to have_content(snippets[2].title)
end
it 'contains all internal snippets of logged user when clicking on internal' do
click_link('Internal')
expect(page).to have_selector('.snippet-row', count: 1)
expect(page).to have_content(snippets[1].title)
end
it 'contains all public snippets of logged user when clicking on public' do
click_link('Public')
expect(page).to have_selector('.snippet-row', count: 1)
expect(page).to have_content(snippets[0].title)
end
end
2020-01-01 13:55:28 +05:30
context 'as an external user' do
2020-04-22 19:07:51 +05:30
let_it_be(:user) { create(:user, :external) }
2020-03-13 15:44:24 +05:30
2020-01-01 13:55:28 +05:30
before do
sign_in(user)
visit dashboard_snippets_path
end
context 'without snippets' do
it 'hides new snippet button' do
expect(page).not_to have_link('New snippet')
end
end
context 'with snippets' do
let!(:snippets) { create(:personal_snippet, author: user) }
it 'hides new snippet button' do
expect(page).not_to have_link('New snippet')
end
end
end
2016-10-01 15:18:49 +05:30
end