2025-05-05 09:29:55 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
2013-10-17 13:48:50 +02:00
|
|
|
#-- copyright
|
2020-01-15 11:31:26 +01:00
|
|
|
# OpenProject is an open source project management software.
|
2024-07-30 13:42:36 +02:00
|
|
|
# Copyright (C) the OpenProject GmbH
|
2013-10-17 13:48:50 +02:00
|
|
|
#
|
|
|
|
|
# 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:
|
2021-01-13 17:47:45 +01:00
|
|
|
# Copyright (C) 2006-2013 Jean-Philippe Lang
|
2013-10-17 13:48:50 +02:00
|
|
|
# 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.
|
|
|
|
|
#
|
2021-09-02 21:49:06 +02:00
|
|
|
# See COPYRIGHT and LICENSE files for more details.
|
2013-10-17 13:48:50 +02:00
|
|
|
#++
|
|
|
|
|
|
|
|
|
|
require "spec_helper"
|
|
|
|
|
|
2023-05-31 12:15:15 +02:00
|
|
|
RSpec.describe WikiMenuItemsController do
|
2022-01-24 19:22:35 +01:00
|
|
|
let(:current_user) { create(:admin) }
|
2013-10-21 11:37:22 +02:00
|
|
|
|
|
|
|
|
# create project with wiki
|
2022-01-24 19:22:35 +01:00
|
|
|
let(:project) { create(:project).reload } # a wiki is created for project, but the object doesn't know of it (FIXME?)
|
2013-10-21 11:37:22 +02:00
|
|
|
let(:wiki) { project.wiki }
|
|
|
|
|
|
2022-01-24 19:22:35 +01:00
|
|
|
let(:wiki_page) { create(:wiki_page, wiki:) } # first wiki page without child pages
|
2021-02-11 16:02:18 +01:00
|
|
|
let!(:top_level_wiki_menu_item) do
|
2022-01-24 19:22:35 +01:00
|
|
|
create(:wiki_menu_item, :with_menu_item_options, wiki:, name: wiki_page.slug)
|
2021-02-11 16:02:18 +01:00
|
|
|
end
|
2014-05-29 22:54:55 +02:00
|
|
|
|
2013-10-17 13:48:50 +02:00
|
|
|
before do
|
|
|
|
|
# log in user
|
2014-03-29 14:50:29 +01:00
|
|
|
allow(User).to receive(:current).and_return current_user
|
2013-10-17 13:48:50 +02:00
|
|
|
end
|
|
|
|
|
|
2015-02-03 22:16:25 +01:00
|
|
|
describe "#edit" do
|
2013-10-29 08:44:19 +01:00
|
|
|
# more wiki pages with menu items
|
2022-01-24 19:22:35 +01:00
|
|
|
let(:another_wiki_page) { create(:wiki_page, wiki:) } # second wiki page with two child pages
|
2021-02-11 16:02:18 +01:00
|
|
|
let!(:another_wiki_page_top_level_wiki_menu_item) do
|
2022-01-24 19:22:35 +01:00
|
|
|
create(:wiki_menu_item, wiki:, name: another_wiki_page.slug)
|
2021-02-11 16:02:18 +01:00
|
|
|
end
|
2013-10-29 08:44:19 +01:00
|
|
|
|
|
|
|
|
# child pages of another_wiki_page
|
2022-01-24 19:22:35 +01:00
|
|
|
let(:child_page) { create(:wiki_page, parent: another_wiki_page, wiki:) }
|
|
|
|
|
let!(:child_page_wiki_menu_item) { create(:wiki_menu_item, wiki:, name: child_page.slug) }
|
|
|
|
|
let(:another_child_page) { create(:wiki_page, parent: another_wiki_page, wiki:) }
|
2021-02-11 16:02:18 +01:00
|
|
|
let!(:another_child_page_wiki_menu_item) do
|
2022-01-24 19:22:35 +01:00
|
|
|
create(:wiki_menu_item, wiki:, name: another_child_page.slug, parent: top_level_wiki_menu_item)
|
2021-02-11 16:02:18 +01:00
|
|
|
end
|
2013-10-29 08:44:19 +01:00
|
|
|
|
2022-01-24 19:22:35 +01:00
|
|
|
let(:grand_child_page) { create(:wiki_page, parent: child_page, wiki:) }
|
|
|
|
|
let!(:grand_child_page_wiki_menu_item) { create(:wiki_menu_item, wiki:, name: grand_child_page.slug) }
|
2013-10-29 08:44:19 +01:00
|
|
|
|
2013-10-17 13:48:50 +02:00
|
|
|
context "when no parent wiki menu item has been configured yet" do
|
2013-10-17 14:06:45 +02:00
|
|
|
context "and it is a child page" do
|
2021-02-11 16:02:18 +01:00
|
|
|
before { get :edit, params: { project_id: project.id, id: child_page.slug } }
|
2022-05-31 11:55:27 +02:00
|
|
|
|
2013-10-17 14:06:45 +02:00
|
|
|
subject { response }
|
|
|
|
|
|
|
|
|
|
it "preselects the wiki menu item of the parent page as parent wiki menu item option" do
|
2014-03-29 14:50:29 +01:00
|
|
|
expect(assigns["selected_parent_menu_item_id"]).to eq(another_wiki_page_top_level_wiki_menu_item.id)
|
2013-10-17 14:06:45 +02:00
|
|
|
# see FIXME in menu_helper.rb
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context "and it is a grand child page the parent of which is not a main item" do
|
|
|
|
|
before do
|
|
|
|
|
# ensure the parent page of grand_child_page is not a main item
|
2014-11-03 23:43:33 +01:00
|
|
|
child_page_wiki_menu_item.tap { |page| page.parent = top_level_wiki_menu_item }.save
|
2016-10-17 10:21:42 +02:00
|
|
|
get :edit, params: { project_id: project.id, id: grand_child_page.slug }
|
2013-10-17 14:06:45 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
subject { response }
|
2013-10-17 13:48:50 +02:00
|
|
|
|
2013-10-17 14:06:45 +02:00
|
|
|
it "preselects the wiki menu item of the grand parent page as parent wiki menu item option" do
|
2014-03-29 14:50:29 +01:00
|
|
|
expect(assigns["selected_parent_menu_item_id"]).to eq(another_wiki_page_top_level_wiki_menu_item.id)
|
2013-10-17 14:06:45 +02:00
|
|
|
end
|
2013-10-17 13:48:50 +02:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context "when a parent wiki menu item has already been configured" do
|
2021-02-11 16:02:18 +01:00
|
|
|
before { get :edit, params: { project_id: project.id, id: another_child_page.slug } }
|
2022-05-31 11:55:27 +02:00
|
|
|
|
2013-10-17 13:48:50 +02:00
|
|
|
subject { response }
|
|
|
|
|
|
|
|
|
|
it "preselects the parent wiki menu item that is already assigned" do
|
2014-03-29 14:50:29 +01:00
|
|
|
expect(assigns["selected_parent_menu_item_id"]).to eq(top_level_wiki_menu_item.id)
|
2013-10-17 13:48:50 +02:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
2013-10-29 08:44:19 +01:00
|
|
|
|
2013-10-29 09:19:04 +01:00
|
|
|
shared_context "when there is one more wiki page with a child page" do
|
2022-01-24 19:22:35 +01:00
|
|
|
let!(:child_page) { create(:wiki_page, parent: wiki_page, wiki:) }
|
2013-11-01 15:59:53 +01:00
|
|
|
|
2022-01-24 19:22:35 +01:00
|
|
|
let!(:another_wiki_page) { create(:wiki_page, wiki:) } # second wiki page with two child pages
|
|
|
|
|
let!(:another_child_page) { create(:wiki_page, parent: another_wiki_page, wiki:) }
|
2013-10-29 08:44:19 +01:00
|
|
|
end
|
|
|
|
|
|
2015-02-03 22:16:25 +01:00
|
|
|
describe "#select_main_menu_item" do
|
2013-10-29 09:19:04 +01:00
|
|
|
include_context "when there is one more wiki page with a child page"
|
2013-10-29 08:44:19 +01:00
|
|
|
|
2021-02-11 16:02:18 +01:00
|
|
|
before { get :select_main_menu_item, params: { project_id: project, id: wiki_page.id } }
|
2022-05-31 11:55:27 +02:00
|
|
|
|
2013-10-29 08:44:19 +01:00
|
|
|
subject { assigns["possible_wiki_pages"] }
|
|
|
|
|
|
|
|
|
|
context "when selecting a new wiki page to replace the current main menu item" do
|
2014-04-17 23:35:32 +02:00
|
|
|
it { is_expected.to include wiki_page }
|
|
|
|
|
it { is_expected.to include child_page }
|
|
|
|
|
it { is_expected.to include another_wiki_page }
|
|
|
|
|
it { is_expected.to include another_child_page }
|
2013-10-29 08:44:19 +01:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2015-02-03 22:16:25 +01:00
|
|
|
describe "#replace_main_menu_item" do
|
2013-10-29 09:19:04 +01:00
|
|
|
include_context "when there is one more wiki page with a child page"
|
2013-10-29 08:44:19 +01:00
|
|
|
|
2013-11-05 15:12:49 +01:00
|
|
|
context "when another wiki page is selected for replacement" do
|
|
|
|
|
let(:selected_page) { child_page }
|
|
|
|
|
let(:new_menu_item) { selected_page.menu_item }
|
|
|
|
|
|
|
|
|
|
before do
|
2016-10-17 10:21:42 +02:00
|
|
|
post :replace_main_menu_item,
|
|
|
|
|
params: {
|
2026-02-13 09:59:03 +01:00
|
|
|
project_id: project.id,
|
2016-10-17 10:21:42 +02:00
|
|
|
id: wiki_page.id,
|
|
|
|
|
wiki_page: { id: selected_page.id }
|
|
|
|
|
}
|
2013-11-05 15:12:49 +01:00
|
|
|
end
|
2013-10-29 08:44:19 +01:00
|
|
|
|
2013-11-05 15:12:49 +01:00
|
|
|
it "destroys the current wiki menu item" do
|
2014-03-29 14:50:29 +01:00
|
|
|
expect(wiki_page.menu_item).to be_nil
|
2013-11-05 15:12:49 +01:00
|
|
|
end
|
2013-10-29 08:44:19 +01:00
|
|
|
|
2013-11-05 15:12:49 +01:00
|
|
|
it "creates a new main menu item for the selected wiki page" do
|
2014-03-29 14:50:29 +01:00
|
|
|
expect(selected_page.menu_item).to be_present
|
|
|
|
|
expect(selected_page.menu_item.parent).to be_nil
|
2013-11-05 15:12:49 +01:00
|
|
|
end
|
2013-10-29 08:44:19 +01:00
|
|
|
|
2013-11-05 15:12:49 +01:00
|
|
|
it "transfers the menu item options to the selected wiki page" do
|
2014-11-03 23:43:33 +01:00
|
|
|
expect(new_menu_item.options).to eq(index_page: true, new_wiki_page: true)
|
2013-11-05 15:12:49 +01:00
|
|
|
end
|
2013-10-29 08:44:19 +01:00
|
|
|
end
|
2013-10-29 09:19:04 +01:00
|
|
|
|
2013-11-05 15:12:49 +01:00
|
|
|
context "when its own wiki page is selected for replacement" do
|
|
|
|
|
let!(:wiki_menu_item) { wiki_page.menu_item }
|
|
|
|
|
|
|
|
|
|
before do
|
2016-10-17 10:21:42 +02:00
|
|
|
post :replace_main_menu_item,
|
|
|
|
|
params: {
|
2026-02-13 09:59:03 +01:00
|
|
|
project_id: project.id,
|
2016-10-17 10:21:42 +02:00
|
|
|
id: wiki_page.id,
|
|
|
|
|
wiki_page: { id: wiki_page.id }
|
|
|
|
|
}
|
2013-11-05 15:12:49 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it "does not destroy the wiki menu item" do
|
2014-03-29 14:50:29 +01:00
|
|
|
expect(wiki_menu_item.reload).to be_present
|
2013-11-05 15:12:49 +01:00
|
|
|
end
|
2013-10-29 09:19:04 +01:00
|
|
|
end
|
2013-10-29 08:44:19 +01:00
|
|
|
end
|
2013-10-17 13:48:50 +02:00
|
|
|
end
|