Add and refactor Wiki menu

In this commit we're refactoring the Wiki
menu in the group sidebar.

We're moving away from partial defined logic to object
contained one. Now menus are defined in objects that
will contain all the information instead of in partials.
parent 6292305b
- if group_sidebar_link?(:wiki)
= render 'layouts/nav/sidebar/wiki_link', wiki_url: @group.wiki.web_url
- if group_sidebar_link?(:settings)
= nav_link(path: group_settings_nav_link_paths) do
= link_to edit_group_path(@group), class: 'has-sub-items' do
......
= nav_link(controller: :wikis) do
= link_to wiki_url, class: 'shortcuts-wiki', data: { qa_selector: 'wiki_link' } do
.nav-icon-container
= sprite_icon('book')
%span.nav-item-name
= _('Wiki')
%ul.sidebar-sub-level-items.is-fly-out-only
= nav_link(controller: :wikis, html_options: { class: "fly-out-top-item" } ) do
= link_to wiki_url do
%strong.fly-out-top-item-name
= _('Wiki')
......@@ -15,6 +15,7 @@ module EE
insert_menu_after(::Sidebars::Groups::Menus::MergeRequestsMenu, ::Sidebars::Groups::Menus::SecurityComplianceMenu.new(context))
insert_menu_after(::Sidebars::Groups::Menus::SecurityComplianceMenu, ::Sidebars::Groups::Menus::PushRulesMenu.new(context))
insert_menu_after(::Sidebars::Groups::Menus::PackagesRegistriesMenu, ::Sidebars::Groups::Menus::AnalyticsMenu.new(context))
insert_menu_after(::Sidebars::Groups::Menus::AnalyticsMenu, ::Sidebars::Groups::Menus::WikiMenu.new(context))
end
end
end
......
# frozen_string_literal: true
module Sidebars
module Groups
module Menus
class WikiMenu < ::Sidebars::Menu
override :link
def link
context.group.wiki.web_url
end
override :extra_container_html_options
def extra_container_html_options
{
class: 'shortcuts-wiki'
}
end
override :title
def title
_('Wiki')
end
override :sprite_icon
def sprite_icon
'book'
end
override :render?
def render?
can?(context.current_user, :read_wiki, context.group)
end
override :active_routes
def active_routes
{ controller: :wikis }
end
end
end
end
end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Sidebars::Groups::Menus::WikiMenu do
let_it_be(:owner) { create(:user) }
let_it_be_with_refind(:group) do
build(:group, :private).tap do |g|
g.add_owner(owner)
end
end
let(:user) { owner }
let(:context) { Sidebars::Groups::Context.new(current_user: user, container: group) }
let(:menu) { described_class.new(context) }
describe '#render?' do
let(:wiki_enabled) { true }
subject { menu.render? }
before do
stub_licensed_features(group_wikis: wiki_enabled)
end
context 'when user can access group wiki' do
specify { is_expected.to be true }
context 'when feature is not enabled' do
let(:wiki_enabled) { false }
specify { is_expected.to be false }
end
end
context 'when user cannot access group wiki' do
let(:user) { nil }
specify { is_expected.to be false }
end
end
end
......@@ -584,16 +584,13 @@ RSpec.describe 'layouts/nav/sidebar/_group' do
end
end
describe 'wiki tab' do
let(:can_read_wiki) { true }
let_it_be(:current_user) { create(:user) }
describe 'Wiki Menu' do
let(:wiki_enabled) { true }
before do
group.add_guest(current_user)
stub_licensed_features(group_wikis: wiki_enabled)
allow(view).to receive(:current_user).and_return(current_user)
allow(view).to receive(:can?).with(current_user, :read_wiki, group).and_return(can_read_wiki)
allow(view).to receive(:current_user).and_return(user)
end
describe 'when wiki is available to user' do
......@@ -605,7 +602,7 @@ RSpec.describe 'layouts/nav/sidebar/_group' do
end
describe 'when wiki is unavailable to user' do
let(:can_read_wiki) { false }
let(:wiki_enabled) { false }
it 'does not show the wiki tab' do
render
......
......@@ -18,10 +18,6 @@ module QA
element :group_settings
end
view 'app/views/layouts/nav/sidebar/_wiki_link.html.haml' do
element :wiki_link
end
view 'ee/app/views/groups/ee/_administration_nav.html.haml' do
element :group_administration_link
element :group_sidebar_submenu_content
......@@ -123,7 +119,8 @@ module QA
def click_group_wiki_link
within_sidebar do
click_element(:wiki_link)
scroll_to_element(:sidebar_menu_link, menu_item: 'Wiki')
click_element(:sidebar_menu_link, menu_item: 'Wiki')
end
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment