replace wiki menu item cukes

pull/6568/head
Jens Ulferts 6 years ago
parent 16cdf98519
commit 71703432d9
No known key found for this signature in database
GPG Key ID: 3CAA4B1182CF5308
  1. 23
      app/controllers/wiki_menu_items_controller.rb
  2. 132
      features/menu_items/wiki_menu_items.feature
  3. 2
      features/step_definitions/project_steps.rb
  4. 114
      spec/features/menu_items/wiki_menu_item_spec.rb

@ -112,11 +112,15 @@ class WikiMenuItemsController < ApplicationController
def select_main_menu_item
@page = WikiPage.find params[:id]
@possible_wiki_pages = @project.wiki.pages.includes(:parent)
.reject { |page|
page != @page && page.menu_item.present? &&
page.menu_item.is_main_item?
}
@possible_wiki_pages = @project
.wiki
.pages
.includes(:parent)
.reject do |page|
page != @page &&
page.menu_item.present? &&
page.menu_item.is_main_item?
end
end
def replace_main_menu_item
@ -141,11 +145,10 @@ class WikiMenuItemsController < ApplicationController
@page = wiki.find_page(params[:id])
@page_title = @page.title
@wiki_menu_item = MenuItems::WikiMenuItem.find_or_initialize_by(
navigatable_id: wiki.id,
name: @page.slug
)
@wiki_menu_item.title ||= @page_title
@wiki_menu_item = MenuItems::WikiMenuItem
.where(navigatable_id: wiki.id, name: @page.slug)
.first_or_initialize(title: @page_title)
possible_parent_menu_items = MenuItems::WikiMenuItem.main_items(wiki.id) - [@wiki_menu_item]
@parent_menu_item_options = possible_parent_menu_items.map { |item| [item.name, item.id] }

@ -1,132 +0,0 @@
#-- copyright
# OpenProject is a project management system.
# Copyright (C) 2012-2018 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-2017 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 docs/COPYRIGHT.rdoc for more details.
#++
Feature: Wiki menu items
Background:
Given there is 1 project with the following:
| name | Awesome Project |
| identifier | awesome-project |
And there is a role "member"
And the role "member" may have the following rights:
| view_wiki_pages |
| edit_wiki_pages |
| delete_wiki_pages |
| manage_wiki_menu |
And there is 1 user with the following:
| login | bob |
And the user "bob" is a "member" in the project "Awesome Project"
And the project "Awesome Project" has 1 wiki page with the following:
| Title | Wiki |
And the project "Awesome Project" has 1 wiki page with the following:
| Title | AwesomePage |
And I am already logged in as "bob"
@javascript
Scenario: Adding a main menu entry without index and toc links
When I go to the wiki page "AwesomePage" for the project called "Awesome Project"
And I click on "More"
And I click on "Configure menu item"
And I fill in "Avocado Wuaärst" for "menu_items_wiki_menu_item_title"
And I choose "Show as menu item in project navigation"
And I press "Save"
And I should see "Avocado Wuaärst" within "#main-menu"
@javascript
Scenario: Adding a main menu entry with index and toc links
When I go to the wiki page "AwesomePage" for the project called "Awesome Project"
And I click on "More"
And I click on "Configure menu item"
And I fill in "Avocado Wuaärst" for "menu_items_wiki_menu_item_title"
And I choose "Show as menu item in project navigation"
And I press "Save"
When I go to the wiki page "AwesomePage" for the project called "Awesome Project"
Then I should see "Avocado Wuaärst" within "#main-menu"
@javascript
Scenario: Change existing entry
When I go to the wiki page "Wiki" for the project called "Awesome Project"
When I click on "More"
And I click on "Configure menu item"
And I fill in "Wikikiki" for "menu_items_wiki_menu_item_title"
And I press "Save"
When I go to the wiki page "Wiki" for the project called "Awesome Project"
Then I should see "Wikikiki" within "#main-menu"
@javascript
Scenario: Do not change existing entry, but saving nonetheless
When I go to the wiki page "Wiki" for the project called "Awesome Project"
When I click on "More"
And I click on "Configure menu item"
And I press "Save"
Then I should not see "Successful update."
@javascript
Scenario: Adding a sub menu entry
Given the project "Awesome Project" has a wiki menu item with the following:
| title | SelectMe |
| name | SelectMe |
Given the project "Awesome Project" has a wiki menu item with the following:
| title | AwesomePage |
| name | RichtigGeil |
When I go to the wiki page "Wiki" for the project called "Awesome Project"
When I click on "More"
And I click on "Configure menu item"
And I choose "Show as submenu item of"
When I select "SelectMe" from "parent_wiki_menu_item"
When I select "RichtigGeil" from "parent_wiki_menu_item"
And I press "Save"
When I go to the wiki page "Wiki" for the project called "Awesome Project"
Then I should see "Wiki" within ".main-menu--children"
@javascript
Scenario: Removing a menu item
Given the project "Awesome Project" has a wiki menu item with the following:
| title | DontKillMe |
| name | DontKillMe |
When I go to the wiki page "Wiki" for the project called "Awesome Project"
When I click on "More"
And I click on "Configure menu item"
And I choose "Do not show this wikipage in project navigation"
And I press "Save"
Then I should see "DontKillMe" within ".main-menu--children-menu-header"
@javascript
Scenario: When I delete the last wiki page with a menu item I can select a new menu item and the menu item is replaced
Given the project "Awesome Project" has a wiki menu item with the following:
| title | AwesomePage |
| name | awesomepage |
And the wiki menu item of the wiki page "Wiki" of project "Awesome Project" has been deleted
When I go to the wiki page "awesomepage" for the project called "Awesome Project"
And I click on "More"
And I click on "Configure menu item"
And I choose "Do not show this wikipage in project navigation"
And I press "Save"
And I select "Wiki" from "main-menu-item-select"
And I press "Save"
Then I should not see "AwesomePage" within ".main-menu--children-menu-header"
Then I should see "Wiki" within ".main-menu--children-menu-header"

@ -27,7 +27,7 @@
# See docs/COPYRIGHT.rdoc for more details.
#++
Given /^there is a project named "([^"]*)?$/ do |name|
Given /^there is a project named "([^"]*)"?$/ do |name|
attributes = { name: name,
identifier: name.downcase.gsub(' ', '_') }

@ -32,10 +32,27 @@ require 'features/work_packages/shared_contexts'
require 'features/work_packages/work_packages_page'
feature 'Wiki menu items' do
let(:user) { FactoryBot.create :admin }
let(:user) do
FactoryBot.create :user,
member_in_project: project,
member_with_permissions: %w[view_wiki_pages
manage_wiki_menu
delete_wiki_pages]
end
let(:project) { FactoryBot.create :project, enabled_module_names: %w[wiki] }
let(:wiki) { project.wiki }
let(:parent_menu) { wiki.wiki_menu_items.find_by(name: 'wiki') }
let(:wiki_page) { FactoryBot.create :wiki_page_with_content, wiki: wiki }
let(:other_wiki_page) do
FactoryBot.create(:wiki_page_with_content, wiki: wiki).tap do |page|
MenuItems::WikiMenuItem.create!(navigatable_id: page.id,
title: page.title,
name: page.slug)
end
end
let(:another_wiki_page) do
FactoryBot.create(:wiki_page_with_content, wiki: wiki)
end
before do
allow(User).to receive(:current).and_return user
@ -67,4 +84,99 @@ feature 'Wiki menu items' do
expect(wiki.wiki_menu_items.pluck(:name).sort).to eq(%w(slug wiki))
end
end
it 'allows managing the menu item of a wiki page', js: true do
other_wiki_page
another_wiki_page
visit project_wiki_path(project, wiki_page)
# creating the menu item with the pages name for the menu item
click_link 'More'
click_link 'Configure menu item'
choose "Show as menu item in project navigation"
click_button "Save"
expect(page)
.to have_selector('.main-menu--children-menu-header', text: wiki_page.title)
find('.main-menu--arrow-left-to-project').click
expect(page)
.to have_selector('.main-item-wrapper', text: wiki_page.title)
# clicking the menu item leads to the page
click_link wiki_page.title
expect(page)
.to have_current_path(project_wiki_path(project, wiki_page))
# modifying the menu item to a different name and to be a subpage
click_link 'More'
click_link 'Configure menu item'
fill_in 'Name of menu item', with: 'Custom page name'
choose "Show as submenu item of"
select other_wiki_page.slug, from: 'parent_wiki_menu_item'
click_button "Save"
# the other page is now the main heading
expect(page)
.to have_selector('.main-menu--children-menu-header', text: other_wiki_page.title)
expect(page)
.to have_selector('.wiki-menu--sub-item', text: 'Custom page name')
click_link 'Custom page name'
expect(page)
.to have_current_path(project_wiki_path(project, wiki_page))
# the submenu item is not visible on top level
find('.main-menu--arrow-left-to-project').click
expect(page)
.to have_no_selector('.main-item-wrapper', text: 'Custom page name')
# deleting the page will remove the menu item
visit project_wiki_path(project, wiki_page)
click_link 'More'
click_link 'Delete'
page.driver.browser.switch_to.alert.accept
within '#menu-sidebar' do
expect(page).to have_no_content('Custom page name')
end
# removing the menu item which is also the last wiki menu item
# removing the default wiki menu item programatically first
MenuItems::WikiMenuItem.where(name: "wiki").delete_all
visit project_wiki_path(project, other_wiki_page)
click_link 'More'
click_link 'Configure menu item'
choose 'Do not show this wikipage in project navigation'
click_button 'Save'
# Because it is the last wiki menu item, the user is prompted to select another menu item
select another_wiki_page.title, from: 'main-menu-item-select'
click_button 'Save'
expect(page)
.to have_no_selector('.main-menu--children-menu-header', text: other_wiki_page.title)
expect(page)
.to have_selector('.main-menu--children-menu-header', text: another_wiki_page.title)
end
end

Loading…
Cancel
Save