Skip to content

Commit

Permalink
Order module menu items in tandem with the global sidebar
Browse files Browse the repository at this point in the history
**NOTE**: The specs for the top_menu_items and the menu_manager
for the top_menu were out of sync with the current state of modules
so for completeness, added some specs to better cover these
features.
  • Loading branch information
aaron-contreras committed Jul 17, 2023
1 parent 7cdc930 commit 439d694
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 25 deletions.
6 changes: 6 additions & 0 deletions config/initializers/menus.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@
if: Proc.new {
(User.current.logged? || !Setting.login_required?)
}

menu.push :activity,
{ controller: '/activities', action: 'index' },
context: :modules,
icon: 'checkmark'

menu.push :work_packages,
{ controller: '/work_packages', project_id: nil, state: nil, action: 'index' },
context: :modules,
Expand Down
2 changes: 2 additions & 0 deletions modules/boards/lib/open_project/boards/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ class Engine < ::Rails::Engine
{ controller: '/boards/boards', action: 'overview' },
context: :modules,
caption: :project_module_board_view,
before: :news,
after: :team_planners,
icon: 'boards',
if: should_render_global_menu_item

Expand Down
1 change: 1 addition & 0 deletions modules/meeting/lib/open_project/meeting/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ class Engine < ::Rails::Engine
:meetings, { controller: '/meetings', action: 'index', project_id: nil },
context: :modules,
caption: :label_meeting_plural,
last: true,
icon: 'meetings',
if: should_render_global_menu_item

Expand Down
2 changes: 2 additions & 0 deletions modules/team_planner/lib/open_project/team_planner/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ class Engine < ::Rails::Engine
:team_planners, { controller: '/team_planner/team_planner', action: :overview },
context: :modules,
caption: :'team_planner.label_team_planner_plural',
before: :boards,
after: :calendar_view,
icon: 'team-planner',
if: should_render_global_menu_item,
enterprise_feature: 'team_planner_view'
Expand Down
77 changes: 53 additions & 24 deletions spec/features/menu_items/top_menu_item_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,29 +28,26 @@

require 'spec_helper'

RSpec.describe 'Top menu items', js: true, with_cuprite: true do
RSpec.describe 'Top menu items', :js, :with_cuprite do
let(:user) { create(:user) }
let(:open_menu) { true }

def has_menu_items?(*labels)
def has_menu_items?(*items)
within '.op-app-header' do
labels.each do |l|
expect(page).to have_link(l)
items.each do |item|
expect(page).to have_link(item.label)
end
(all_items - labels).each do |l|
expect(page).not_to have_link(l)
(all_items - items).each do |item|
expect(page).not_to have_link(item.label)
end
end
end

def click_link_in_open_menu(title)
# if the menu is not completely expanded (e.g. if the frontend thread is too fast),
# the click might be ignored

within '.op-app-menu--dropdown[aria-expanded=true]' do
expect(page).not_to have_selector('[style~=overflow]')

page.click_link(title)
click_link(title)
end
end

Expand All @@ -64,48 +61,80 @@ def click_link_in_open_menu(title)
end

visit root_path
wait_for_reload
top_menu.click if open_menu
end

describe 'Modules' do
describe 'Modules', with_flag: { more_global_index_pages_active: true } do
let!(:top_menu) { find("[title=#{I18n.t('label_modules')}]") }

let(:news_item) { I18n.t('label_news_plural') }
let(:project_item) { I18n.t('label_projects_menu') }
let(:reporting_item) { I18n.t('cost_reports_title') }
shared_let(:menu_link_item) { Struct.new(:label, :path) }

shared_let(:project_item) { menu_link_item.new(I18n.t(:label_projects_menu), projects_path) }
shared_let(:activity_item) { menu_link_item.new(I18n.t(:label_activity), activity_index_path) }
shared_let(:work_packages_item) { menu_link_item.new(I18n.t(:label_work_package_plural), work_packages_path) }
shared_let(:calendar_item) { menu_link_item.new(I18n.t(:label_calendar_plural), calendars_path) }
shared_let(:team_planners_item) { menu_link_item.new(I18n.t('team_planner.label_team_planner_plural'), team_planners_path) }
shared_let(:boards_item) { menu_link_item.new(I18n.t(:project_module_board_view), boards_all_path) }
shared_let(:news_item) { menu_link_item.new(I18n.t(:label_news_plural), news_index_path) }
shared_let(:reporting_item) { menu_link_item.new(I18n.t(:cost_reports_title), '/cost_reports') }
shared_let(:meetings_item) { menu_link_item.new(I18n.t(:label_meeting_plural), '/meetings') }

shared_let(:all_items) do
[
project_item,
activity_item,
work_packages_item,
calendar_item,
team_planners_item,
boards_item,
news_item,
reporting_item,
meetings_item
]
end

let!(:all_items) { [news_item, project_item, reporting_item] }
shared_examples 'visits the global index page' do |item:|
it "visits the #{item.label} page" do
click_link_in_open_menu item.label
expect(page).to have_current_path item.path
end
end

context 'as an admin' do
let(:user) { create(:admin) }

it 'displays all items' do
has_menu_items?(reporting_item, news_item, project_item)
has_menu_items?(*all_items)
end

it 'visits the news page' do
click_link_in_open_menu(news_item)
expect(page).to have_current_path(news_index_path)
it 'visits all module pages', :aggregate_failures, with_ee: %i[team_planner_view] do
all_items.each do |item|
click_link_in_open_menu item.label
expect(page).to have_current_path(item.path)

top_menu.click if open_menu
end
end
end

context 'as a regular user' do
it 'displays news and projects only' do
has_menu_items? news_item, project_item
it 'only displays projects, activity and news' do
has_menu_items? project_item, activity_item, news_item
end
end

context 'as a user with permissions', allowed_to: true do
it 'displays all options' do
has_menu_items?(reporting_item, news_item, project_item)
has_menu_items?(*all_items)
end
end

context 'as an anonymous user' do
let(:user) { create(:anonymous) }

it 'displays only news and projects' do
has_menu_items? news_item, project_item
it 'displays only projects, activity and news' do
has_menu_items? project_item, activity_item, news_item
end
end
end
Expand Down
11 changes: 10 additions & 1 deletion spec/lib/redmine/menu_manager_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,16 @@
context 'for the top_menu' do
it 'includes the expected items' do
expect(described_class.items(:top_menu).map(&:name))
.to include(:work_packages, :news, :help)
.to include(:projects,
:activity,
:work_packages,
:calendar_view,
:team_planners,
:boards,
:news,
:cost_reports_global,
:meetings,
:help)
end
end

Expand Down

0 comments on commit 439d694

Please sign in to comment.