replace legacy spec

pull/11402/head
ulferts 2 years ago
parent bf1328a909
commit 633b01abcc
No known key found for this signature in database
GPG Key ID: A205708DE1284017
  1. 86
      spec/lib/redmine/menu_manager/menu_item_spec.rb
  2. 7
      spec/lib/redmine/menu_manager_spec.rb
  3. 112
      spec_legacy/unit/lib/redmine/menu_manager/menu_item_spec.rb

@ -0,0 +1,86 @@
# OpenProject is an open source project management software.
# Copyright (C) 2010-2022 the OpenProject GmbH
#
# 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 COPYRIGHT and LICENSE files for more details.
require 'spec_helper'
describe Redmine::MenuManager::MenuItem do
describe '.new' do
it 'creates an item with all required parameters' do
expect(described_class.new(:test_good_menu, '/test', {}))
.to be_a described_class
end
it 'creates an item with an if condition' do
expect(described_class.new(:test_good_menu, '/test', if: ->(*) {}))
.to be_a described_class
end
it 'creates an item with extra html options' do
expect(described_class.new(:test_good_menu, '/test', html: { data: 'foo' }))
.to be_a described_class
end
it 'creates an item with a children proc' do
expect(described_class.new(:test_good_menu, '/test', children: ->(*) {}))
.to be_a described_class
end
it 'fails without a name' do
expect { described_class.new }
.to raise_error ArgumentError
end
it 'fails without a url' do
expect { described_class.new(:missing_url) }
.to raise_error ArgumentError
end
it 'fails without an options' do
expect { described_class.new(:missing_url, '/test') }
.to raise_error ArgumentError
end
it 'fails when setting the parent item to the current item' do
expect { described_class.new(:test_error, '/test', parent: :test_error) }
.to raise_error ArgumentError
end
it 'fails for an if condition without a proc' do
expect { described_class.new(:test_error, '/test', if: ['not_a_proc']) }
.to raise_error ArgumentError
end
it 'fails for an html condition without a hash' do
expect { described_class.new(:test_error, '/test', html: ['not_a_hash']) }
.to raise_error ArgumentError
end
it 'fails for an children optiono without a proc' do
expect { described_class.new(:test_error, '/test', children: ['not_a_proc']) }
.to raise_error ArgumentError
end
end
end

@ -81,6 +81,13 @@ describe Redmine::MenuManager do
:authentication,
:announcements)
end
it 'has children defined for the authentication item' do
expect(described_class.items(:admin_menu).find { |item| item.name == :authentication }.map(&:name))
.to include(:authentication_settings,
:ldap_authentication,
:oauth_applications)
end
end
end
end

@ -1,112 +0,0 @@
#-- copyright
# OpenProject is an open source project management software.
# Copyright (C) 2012-2022 the OpenProject GmbH
#
# 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 COPYRIGHT and LICENSE files for more details.
#++
require_relative '../../../../legacy_spec_helper'
module RedmineMenuTestHelper
# Helpers
def get_menu_item(menu_name, item_name)
Redmine::MenuManager.items(menu_name).find { |item| item.name == item_name.to_sym }
end
end
describe Redmine::MenuManager::MenuItem do
include RedmineMenuTestHelper
Redmine::MenuManager.map :test_menu do |menu|
menu.push(:parent, '/test', {})
menu.push(:child_menu, '/test', parent: :parent)
menu.push(:child2_menu, '/test', parent: :parent)
end
# context new menu item
it 'news menu item should require a name' do
assert_raises ArgumentError do
Redmine::MenuManager::MenuItem.new
end
end
it 'news menu item should require an url' do
assert_raises ArgumentError do
Redmine::MenuManager::MenuItem.new(:test_missing_url)
end
end
it 'news menu item should require the options' do
assert_raises ArgumentError do
Redmine::MenuManager::MenuItem.new(:test_missing_options, '/test')
end
end
it 'news menu item with all required parameters' do
assert Redmine::MenuManager::MenuItem.new(:test_good_menu, '/test', {})
end
it 'news menu item should require a proc to use for the if condition' do
assert_raises ArgumentError do
Redmine::MenuManager::MenuItem.new(:test_error, '/test',
if: ['not_a_proc'])
end
assert Redmine::MenuManager::MenuItem.new(:test_good_if, '/test',
if: Proc.new {})
end
it 'news menu item should allow a hash for extra html options' do
assert_raises ArgumentError do
Redmine::MenuManager::MenuItem.new(:test_error, '/test',
html: ['not_a_hash'])
end
assert Redmine::MenuManager::MenuItem.new(:test_good_html, '/test',
html: { data: 'foo' })
end
it 'news menu item should require a proc to use the children option' do
assert_raises ArgumentError do
Redmine::MenuManager::MenuItem.new(:test_error, '/test',
children: ['not_a_proc'])
end
assert Redmine::MenuManager::MenuItem.new(:test_good_children, '/test',
children: Proc.new {})
end
it 'news should not allow setting the parent item to the current item' do
assert_raises ArgumentError do
Redmine::MenuManager::MenuItem.new(:test_error, '/test', parent: :test_error)
end
end
it 'hases children' do
parent_item = get_menu_item(:test_menu, :parent)
assert parent_item.has_children?
assert_equal 2, parent_item.children.size
assert_equal get_menu_item(:test_menu, :child_menu).name, parent_item.children[0].name
assert_equal get_menu_item(:test_menu, :child2_menu).name, parent_item.children[1].name
end
end
Loading…
Cancel
Save