Add tests for WP top menu && limit visiblity rights

pull/4764/head
Henriette Dinger 8 years ago
parent 47f7d3e14d
commit 3388a64c9d
  1. 42
      config/initializers/menus.rb
  2. 3
      lib/redmine/menu_manager/top_menu_helper.rb
  3. 4
      spec/features/menu_items/top_menu_item_spec.rb
  4. 140
      spec/features/menu_items/work_packages_menu_item_spec.rb
  5. 2
      spec_legacy/unit/lib/redmine_spec.rb

@ -55,8 +55,17 @@ Redmine::MenuManager.map :top_menu do |menu|
User.current.allowed_to?(:view_time_entries, nil, global: true)
}
menu.push :help, OpenProject::Static::Links.help_link,
last: true,
caption: '',
html: { accesskey: OpenProject::AccessKeys.key_for(:help),
title: I18n.t('label_help'),
class: 'icon5 icon-help1',
target: '_blank' }
menu.push :new_work_packages,
{ controller: '/work_packages', action: 'new', project_id: @project },
{ controller: '/work_packages', action: 'new' },
context: :work_packages,
caption: I18n.t(:label_work_package_new),
html: {
@ -64,33 +73,48 @@ Redmine::MenuManager.map :top_menu do |menu|
accesskey: OpenProject::AccessKeys.key_for(:new_work_package)
},
if: Proc.new {
(User.current.logged? || !Setting.login_required?) &&
User.current.allowed_to?(:add_work_packages, @project, global: @project.nil?)
User.current.allowed_to?(:add_work_packages, nil, global: true)
}
menu.push :list_work_packages,
{ controller: '/work_packages', action: 'index' },
{ controller: '/work_packages', action: 'index', project_id: nil },
context: :work_packages,
caption: I18n.t(:label_all)
caption: I18n.t(:label_all),
if: Proc.new {
User.current.allowed_to?(:view_work_packages, nil, global: true)
}
menu.push :work_packages_filter_assigned_to_me,
:work_packages_assigned_to_me_path,
context: :work_packages,
caption: I18n.t(:label_assigned_to_me)
caption: I18n.t(:label_assigned_to_me),
if: Proc.new {
User.current.logged? && User.current.allowed_to?(:view_work_packages, nil, global: true)
}
menu.push :work_packages_filter_reported_by_me,
:work_packages_reported_by_me_path,
context: :work_packages,
caption: I18n.t(:label_reported_by_me)
caption: I18n.t(:label_reported_by_me),
if: Proc.new {
User.current.logged? && User.current.allowed_to?(:view_work_packages, nil, global: true)
}
menu.push :work_packages_filter_responsible_for,
:work_packages_responsible_for_path,
context: :work_packages,
caption: I18n.t(:label_responsible_for)
caption: I18n.t(:label_responsible_for),
if: Proc.new {
User.current.logged? && User.current.allowed_to?(:view_work_packages, nil, global: true)
}
menu.push :work_packages_filter_watched_by_me,
:work_packages_watched_path,
context: :work_packages,
caption: I18n.t(:label_watched_by_me)
caption: I18n.t(:label_watched_by_me),
if: Proc.new {
User.current.logged? && User.current.allowed_to?(:view_work_packages, nil, global: true)
}
end
Redmine::MenuManager.map :account_menu do |menu|

@ -106,6 +106,9 @@ module Redmine::MenuManager::TopMenuHelper
end
def render_work_packages_top_menu_node(items = work_packages_menu_items)
if items.empty?
return nil
end
render_menu_dropdown_with_items(
label: l(:label_work_package_plural),
label_options: { id: 'work-packages-menu', class: 'icon5 icon-work-packages' },

@ -64,12 +64,14 @@ feature 'Top menu items', js: true, selenium: true do
end
it 'visits the time sheet page' do
expect(page).to have_content(time_entries_item)
click_link time_entries_item
expect(current_path).to eq(time_entries_path)
end
it 'visits the news page' do
modules.click_link news_item
expect(page).to have_content(news_item)
click_link news_item
expect(current_path).to eq(news_index_path)
end
end

@ -0,0 +1,140 @@
#-- copyright
# OpenProject is a project management system.
# Copyright (C) 2012-2015 the OpenProject Foundation (OPF)
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License version 3.
#
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
# Copyright (C) 2006-2013 Jean-Philippe Lang
# Copyright (C) 2010-2013 the ChiliProject Team
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# See doc/COPYRIGHT.rdoc for more details.
#++
require 'spec_helper'
feature 'Work packages top menu items', js: true, selenium: true do
include WorkPackagesFilterHelper
let(:user) { FactoryGirl.create :user }
let(:new_wp_item) { I18n.t('label_work_package_new') }
let(:all_wp_item) { I18n.t('label_all') }
let(:assigned_wp_item) { I18n.t('label_assigned_to_me') }
let(:reported_wp_item) { I18n.t('label_reported_by_me') }
let(:responsible_wp_item) { I18n.t('label_responsible_for') }
let(:watched_wp_item) { I18n.t('label_watched_by_me') }
let(:all_items) { [new_wp_item, all_wp_item, assigned_wp_item, reported_wp_item, responsible_wp_item, watched_wp_item] }
def has_menu_items(*labels)
labels.each do |l|
expect(page).to have_link(l)
end
(all_items - labels).each do |l|
expect(page).not_to have_link(l)
end
end
before do |ex|
allow(User).to receive(:current).and_return user
if ex.metadata.key?(:allowed_to)
allow(user).to receive(:allowed_to?).and_return(ex.metadata[:allowed_to])
end
visit root_path
end
context 'as an admin' do
let(:work_packages) { find(:css, '#work-packages-menu') }
let(:user) { FactoryGirl.create :admin }
before do
work_packages.click
end
it 'displays all items' do
has_menu_items(new_wp_item, all_wp_item, assigned_wp_item, reported_wp_item, responsible_wp_item, watched_wp_item)
end
it 'visits the new work package page' do
expect(page).to have_content(new_wp_item)
click_link new_wp_item
expect(page).to have_current_path(new_work_packages_path)
end
it 'visits the all work packages page' do
expect(page).to have_content(all_wp_item)
click_link all_wp_item
expect(page).to have_current_path(index_work_packages_path)
end
it 'visits the work packages assigned to me page' do
expect(page).to have_content(assigned_wp_item)
click_link assigned_wp_item
expect(page).to have_current_path(work_packages_assigned_to_me_path)
end
it 'visits the work packages reported by me page' do
expect(page).to have_content(reported_wp_item)
click_link reported_wp_item
expect(page).to have_current_path(work_packages_reported_by_me_path)
end
it 'visits the work packages I am responsible for page' do
expect(page).to have_content(responsible_wp_item)
click_link responsible_wp_item
expect(page).to have_current_path(work_packages_responsible_for_path)
end
it 'visits the work packages watched by me page' do
expect(page).to have_content(watched_wp_item)
click_link watched_wp_item
expect(page).to have_current_path(work_packages_watched_path)
end
end
context 'as a user with permissions', allowed_to: true do
let(:work_packages) { find(:css, '#work-packages-menu') }
before do
work_packages.click
end
it 'displays all options' do
has_menu_items(new_wp_item, all_wp_item, assigned_wp_item, reported_wp_item, responsible_wp_item, watched_wp_item)
end
end
context 'as a user without any permission', allowed_to: false do
it 'shows no top menu entry Work packages' do
has_menu_items()
expect(page).not_to have_css('#work-packages-menu')
end
end
context 'as an anonymous user' do
let(:work_packages) { find(:css, '#work-packages-menu') }
let(:user) { FactoryGirl.create :anonymous }
before do
work_packages.click
end
it 'displays only add new work package' do
has_menu_items(new_wp_item)
end
end
end

@ -50,7 +50,7 @@ describe Redmine do
it 'should top_menu' do
assert_number_of_items_in_menu :top_menu, 6
assert_menu_contains_item_named :top_menu, :my_page
assert_menu_contains_item_named :top_menu, :work_packages
assert_menu_contains_item_named :top_menu, :list_work_packages
assert_menu_contains_item_named :top_menu, :news
assert_menu_contains_item_named :top_menu, :time_sheet
# do not test :projects here. it does not appear in the top_menu data structure, but will be generated by the TopMenuHelper

Loading…
Cancel
Save