debian-mirror-gitlab/spec/features/projects/snippets/user_views_snippets_spec.rb

110 lines
2.7 KiB
Ruby
Raw Normal View History

2019-10-12 21:52:04 +05:30
# frozen_string_literal: true
2018-03-17 18:26:18 +05:30
require 'spec_helper'
2020-06-23 00:09:42 +05:30
RSpec.describe 'Projects > Snippets > User views snippets' do
2020-03-13 15:44:24 +05:30
let_it_be(:project) { create(:project) }
2018-03-17 18:26:18 +05:30
let(:user) { create(:user) }
2020-03-13 15:44:24 +05:30
def visit_project_snippets
2018-03-17 18:26:18 +05:30
visit(project_snippets_path(project))
end
2020-03-13 15:44:24 +05:30
context 'snippets list' do
let!(:project_snippet) { create(:project_snippet, project: project, author: user) }
let!(:snippet) { create(:snippet, author: user) }
let(:snippets) { [project_snippet, snippet] } # Used by the shared examples
before do
project.add_maintainer(user)
sign_in(user)
end
context 'pagination' do
before do
create(:project_snippet, project: project, author: user)
allow(Snippet).to receive(:default_per_page).and_return(1)
visit_project_snippets
end
it_behaves_like 'paginated snippets'
end
context 'filtering by visibility' do
before do
visit_project_snippets
end
it_behaves_like 'tabs with counts' do
let_it_be(:counts) { { all: '1', public: '0', private: '1', internal: '0' } }
end
end
it 'shows snippets' do
visit_project_snippets
expect(page).to have_link(project_snippet.title, href: project_snippet_path(project, project_snippet))
expect(page).not_to have_content(snippet.title)
end
end
context 'when current user is a guest' do
2018-10-15 14:42:47 +05:30
before do
2020-03-13 15:44:24 +05:30
project.add_guest(user)
sign_in(user)
end
2018-10-15 14:42:47 +05:30
2020-03-13 15:44:24 +05:30
context 'when snippets list is empty' do
it 'hides New Snippet button' do
visit_project_snippets
page.within(find('.empty-state')) do
expect(page).not_to have_link('New snippet')
end
end
2018-10-15 14:42:47 +05:30
end
2020-03-13 15:44:24 +05:30
context 'when project has snippets' do
let!(:project_snippet) { create(:project_snippet, project: project, author: user) }
it 'hides New Snippet button' do
visit_project_snippets
page.within(find('.top-area')) do
expect(page).not_to have_link('New snippet')
end
end
end
2018-10-15 14:42:47 +05:30
end
2020-03-13 15:44:24 +05:30
context 'when current user is not a guest' do
before do
project.add_developer(user)
sign_in(user)
end
context 'when snippets list is empty' do
it 'shows New Snippet button' do
visit_project_snippets
page.within(find('.empty-state')) do
expect(page).to have_link('New snippet')
end
end
end
context 'when project has snippets' do
let!(:project_snippet) { create(:project_snippet, project: project, author: user) }
it 'shows New Snippet button' do
visit_project_snippets
page.within(find('.top-area')) do
expect(page).to have_link('New snippet')
end
end
end
2018-03-17 18:26:18 +05:30
end
end