1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
|
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe 'shared/wikis/_sidebar.html.haml' do
let_it_be(:project) { create(:project) }
let_it_be(:wiki) { Wiki.for_container(project, project.first_owner) }
before do
assign(:wiki, wiki)
assign(:project, project)
end
context 'The sidebar comes from a custom page' do
before do
assign(:sidebar_page, double('WikiPage', path: 'sidebar.md', slug: 'sidebar', content: 'Some sidebar content', wiki: wiki))
end
it 'does not show an alert' do
render
expect(rendered).not_to include('The sidebar failed to load')
expect(rendered).not_to have_css('.gl-alert.gl-alert-info')
end
it 'renders the wiki content' do
render
expect(rendered).to include('Some sidebar content')
end
end
describe 'link to edit the sidebar' do
context 'when the user has edit permission and there are wiki pages' do
before do
create(:wiki_page, wiki: wiki, title: 'home', content: 'Home page')
assign(:wiki_pages_count, 3)
allow(view).to receive(:can?).with(anything, :create_wiki, anything).and_return(can_edit)
render
end
let(:can_edit) { true }
it 'renders the link' do
expect(rendered).to have_link('Add custom sidebar', href: wiki_page_path(wiki, Wiki::SIDEBAR, action: :edit))
end
end
context 'when the user does not have edit permission and there are no wiki pages' do
before do
allow(view).to receive(:can?).with(anything, :create_wiki, anything).and_return(can_edit)
render
end
let(:can_edit) { false }
it 'does not render the link' do
expect(rendered).not_to have_link('Add custom sidebar')
end
end
end
end
|