2019-07-25 01:24:42 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-09-18 03:52:28 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-03 14:08:28 -04:00
|
|
|
RSpec.describe 'Projects > Snippets > User views snippets' do
|
2020-01-31 13:09:11 -05:00
|
|
|
let_it_be(:project) { create(:project) }
|
2021-04-21 02:09:28 -04:00
|
|
|
|
2017-09-18 03:52:28 -04:00
|
|
|
let(:user) { create(:user) }
|
|
|
|
|
2020-01-31 13:09:11 -05:00
|
|
|
def visit_project_snippets
|
2017-09-18 03:52:28 -04:00
|
|
|
visit(project_snippets_path(project))
|
|
|
|
end
|
|
|
|
|
2020-01-31 13:09:11 -05:00
|
|
|
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
|
|
|
|
|
2018-04-06 08:40:33 -04:00
|
|
|
before do
|
2020-01-31 13:09:11 -05:00
|
|
|
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)
|
2018-04-06 08:40:33 -04:00
|
|
|
|
2020-01-31 13:09:11 -05:00
|
|
|
visit_project_snippets
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'paginated snippets'
|
2018-04-06 08:40:33 -04:00
|
|
|
end
|
|
|
|
|
2020-02-05 04:08:43 -05:00
|
|
|
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
|
|
|
|
|
2020-01-31 13:09:11 -05:00
|
|
|
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
|
2018-04-06 08:40:33 -04:00
|
|
|
end
|
|
|
|
|
2020-01-31 13:09:11 -05:00
|
|
|
context 'when current user is a guest' do
|
|
|
|
before do
|
|
|
|
project.add_guest(user)
|
|
|
|
sign_in(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
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
|
|
|
|
end
|
|
|
|
|
|
|
|
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
|
|
|
|
end
|
|
|
|
|
|
|
|
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
|
2017-09-18 03:52:28 -04:00
|
|
|
end
|
|
|
|
end
|