OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
test projects menu
Ivan Kuchin5ddcb59b28bd
diff --git a/spec/helpers/menus/projects_spec.rb b/spec/helpers/menus/projects_spec.rbnew file mode 100644index 00000000000..71a2cdfe40c--- /dev/null+++ b/spec/helpers/menus/projects_spec.rb@@ -0,0 +1,184 @@+# frozen_string_literal: true++#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2024 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"++RSpec.describe Menus::Projects do+ let(:instance) { described_class.new(controller_path:, params:, current_user:) }+ let(:controller_path) { "foo" }+ let(:params) { {} }++ shared_let(:current_user) { build(:user) }++ shared_let(:current_user_query) do+ Queries::Projects::ProjectQuery.create!(name: "Current user query", user: current_user)+ end++ shared_let(:other_user_query) do+ Queries::Projects::ProjectQuery.create!(name: "Other user query", user: build(:user))+ end++ subject(:first_level_menu_items) { instance.first_level_menu_items }++ it "returns 3 menu groups" do+ expect(first_level_menu_items).to all(be_a(OpenProject::Menu::MenuGroup))+ expect(first_level_menu_items.length).to eq(3)+ end++ describe "children items" do+ subject(:children_menu_items) { first_level_menu_items.flat_map(&:children) }++ it "contains menu items" do+ expect(children_menu_items).to all(be_a(OpenProject::Menu::MenuItem))+ end++ it "contains item for current user query" do+ expect(children_menu_items).to include(have_attributes(title: "Current user query"))+ end++ it "doesn't contain item for other user query" do+ expect(children_menu_items).not_to include(have_attributes(title: "Other user query"))+ end+ end++ describe "selected children items" do+ subject(:selected_menu_items) { first_level_menu_items.flat_map(&:children).select(&:selected) }++ context "when on homescreen page" do+ let(:controller_path) { "homescreen" }++ context "without params" do+ it "has no selected items" do+ expect(selected_menu_items).to be_empty+ end+ end++ context "with query_id param" do+ let(:params) { { query_id: current_user_query.id.to_s } }++ it "has no selected items" do+ expect(selected_menu_items).to be_empty+ end+ end++ context "with id param" do+ let(:params) { { id: current_user_query.id.to_s } }++ it "has no selected items" do+ expect(selected_menu_items).to be_empty+ end+ end+ end++ context "when on projects page" do+ let(:controller_path) { "projects" }++ context "without params" do+ it "has default item selected" do+ expect(selected_menu_items).to contain_exactly(have_attributes(title: "Active projects"))+ end+ end++ context "with id param" do+ let(:params) { { id: current_user_query.id.to_s } }++ it "has default item selected" do+ expect(selected_menu_items).to contain_exactly(have_attributes(title: "Active projects"))+ end+ end++ context "with query_id param for active projects" do+ let(:params) { { query_id: "active" } }++ it "has active projects selected" do+ expect(selected_menu_items).to contain_exactly(have_attributes(title: "Active projects"))+ end+ end++ context "with query_id param for at_risk projects" do+ let(:params) { { query_id: "at_risk" } }++ it "has active projects selected" do+ expect(selected_menu_items).to contain_exactly(have_attributes(title: "At risk"))+ end+ end++ context "with query_id param for current user query" do+ let(:params) { { query_id: current_user_query.id.to_s } }++ it "has current user query selected" do+ expect(selected_menu_items).to contain_exactly(have_attributes(title: "Current user query"))+ end+ end++ context "with query_id param for active projects and modifications to query" do+ let(:params) { { query_id: "active", columns: "foo" } }++ it "has no selected items" do+ expect(selected_menu_items).to be_empty+ end+ end++ context "with query_id param for current user query and modifications to query" do+ let(:params) { { query_id: current_user_query.id.to_s, columns: "foo" } }++ it "has current user query selected" do+ expect(selected_menu_items).to contain_exactly(have_attributes(title: "Current user query"))+ end+ end+ end++ context "when on project queries page" do+ let(:controller_path) { "projects/queries" }++ context "without params" do+ it "has no selected items" do+ expect(selected_menu_items).to be_empty+ end+ end++ context "with query_id param" do+ let(:params) { { query_id: current_user_query.id.to_s } }++ it "has no selected items" do+ expect(selected_menu_items).to be_empty+ end+ end++ context "with id param for current user query" do+ let(:params) { { id: current_user_query.id.to_s } }++ it "has current user query selected" do+ expect(selected_menu_items).to contain_exactly(have_attributes(title: "Current user query"))+ end+ end+ end+ end+end