Skip to content

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

Add tests for query management in calendar module

Henriette Darge69a89936b28e
diff --git a/frontend/src/app/features/calendar/wp-calendar/wp-calendar.component.ts b/frontend/src/app/features/calendar/wp-calendar/wp-calendar.component.ts
index 4a7b565c6b3..ab410e1ad0c 100644
--- a/frontend/src/app/features/calendar/wp-calendar/wp-calendar.component.ts
+++ b/frontend/src/app/features/calendar/wp-calendar/wp-calendar.component.ts
@@ -124,6 +124,7 @@ export class WorkPackagesCalendarComponent extends UntilDestroyedMixin implement
this.calendar.calendarOptions({
height: '100%',
headerToolbar: this.buildHeader(),
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
events: this.calendarEventsFunction.bind(this),
plugins: [dayGridPlugin],
initialView: (() => {
diff --git a/modules/calendar/config/routes.rb b/modules/calendar/config/routes.rb
index 4c13c83eb95..eef5e976bba 100644
--- a/modules/calendar/config/routes.rb
+++ b/modules/calendar/config/routes.rb
@@ -1,7 +1,7 @@
OpenProject::Application.routes.draw do
scope 'projects/:project_id', as: 'project' do
- get '/calendar(/*state)', to: 'calendar/calendar#index', as: :index
+ get '/calendar(/*state)', to: 'calendar/calendar#index', as: :calendar
end
- get '/calendar(/*state)', to: 'calendar/calendar#index', as: :index
+ get '/calendar(/*state)', to: 'calendar/calendar#index', as: :calendar
end
diff --git a/modules/calendar/spec/features/query_handling_spec.rb b/modules/calendar/spec/features/query_handling_spec.rb
new file mode 100644
index 00000000000..4d082bec1f9
--- /dev/null
+++ b/modules/calendar/spec/features/query_handling_spec.rb
@@ -0,0 +1,143 @@
+#-- encoding: UTF-8
+
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2012-2021 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'
+require_relative '../support/pages/calendar'
+require_relative '../../../../spec/features/views/shared_examples'
+
+describe 'Calendar query handling', type: :feature, js: true do
+ shared_let(:type_task) { FactoryBot.create(:type_task) }
+ shared_let(:type_bug) { FactoryBot.create(:type_bug) }
+ shared_let(:project) do
+ FactoryBot.create(:project,
+ enabled_module_names: %w[work_package_tracking calendar_view],
+ types: [type_task, type_bug])
+ end
+
+ shared_let(:user) do
+ FactoryBot.create :user,
+ member_in_project: project,
+ member_with_permissions: %w[
+ view_work_packages
+ edit_work_packages
+ save_queries
+ save_public_queries
+ view_calendar
+ ]
+ end
+
+ shared_let(:task) do
+ FactoryBot.create :work_package,
+ project: project,
+ type: type_task,
+ assigned_to: user,
+ start_date: Time.zone.today - 1.day,
+ due_date: Time.zone.today + 1.day,
+ subject: 'A task for the user'
+ end
+ shared_let(:bug) do
+ FactoryBot.create :work_package,
+ project: project,
+ type: type_bug,
+ assigned_to: user,
+ start_date: Time.zone.today - 1.day,
+ due_date: Time.zone.today + 1.day,
+ subject: 'A bug for the user'
+ end
+
+ shared_let(:saved_query) do
+ FactoryBot.create(:query_with_view_work_packages_calendar,
+ project: project,
+ public: true)
+ end
+
+ let(:calendar_page) { ::Pages::Calendar.new project }
+ let(:work_package_page) { ::Pages::WorkPackagesTable.new project }
+ let(:query_title) { ::Components::WorkPackages::QueryTitle.new }
+ let(:query_menu) { ::Components::WorkPackages::QueryMenu.new }
+ let(:filters) { calendar_page.filters }
+
+ current_user { user }
+
+ before do
+ login_as user
+ calendar_page.visit!
+
+ loading_indicator_saveguard
+
+ calendar_page.expect_event task
+ calendar_page.expect_event bug
+ end
+
+ it 'allows saving the calendar' do
+ filters.expect_filter_count("1")
+ filters.open
+
+ filters.add_filter_by('Type', 'is', [type_bug.name])
+
+ filters.expect_filter_count("2")
+
+ calendar_page.expect_event bug
+ calendar_page.expect_event task, present: false
+
+ query_title.expect_changed
+ query_title.press_save_button
+
+ calendar_page.expect_and_dismiss_toaster(message: I18n.t('js.notice_successful_create'))
+ end
+
+ it 'shows only calendar queries' do
+ # Go to calendar where a query is already shown
+ query_menu.expect_menu_entry saved_query.name
+
+ # Change filter
+ filters.open
+ filters.add_filter_by('Type', 'is', [type_bug.name])
+ filters.expect_filter_count("2")
+
+ # Save current filters
+ query_title.expect_changed
+ query_title.rename 'I am your Query'
+ calendar_page.expect_and_dismiss_toaster(message: I18n.t('js.notice_successful_create'))
+
+ # The saved query appears in the side menu...
+ query_menu.expect_menu_entry 'I am your Query'
+ query_menu.expect_menu_entry saved_query.name
+
+ # .. but not in the work packages module
+ work_package_page.visit!
+ query_menu.expect_menu_entry_not_visible 'I am your Query'
+ end
+
+ it_behaves_like 'module specific query view management' do
+ let(:module_page) { calendar_page }
+ let(:default_name) { 'Unnamed calendar' }
+ end
+end
diff --git a/modules/calendar/spec/routing/calendar_routing_spec.rb b/modules/calendar/spec/routing/calendar_routing_spec.rb
index b74f40eea2f..8dc01715177 100644
--- a/modules/calendar/spec/routing/calendar_routing_spec.rb
+++ b/modules/calendar/spec/routing/calendar_routing_spec.rb
@@ -29,12 +29,12 @@
require 'spec_helper'
describe Calendar::CalendarController, type: :routing do
- it 'should connect GET /calendar to calendar#index' do
+ it 'connects GET /calendar to calendar#index' do
expect(get('/calendar')).to route_to(controller: 'calendar/calendar',
action: 'index')
end
- it 'should connect GET /project/1/calendar to calendar#index' do
+ it 'connects GET /project/1/calendar to calendar#index' do
expect(get('/projects/1/calendar')).to route_to(controller: 'calendar/calendar',
action: 'index',
project_id: '1')
diff --git a/modules/calendar/spec/support/pages/calendar.rb b/modules/calendar/spec/support/pages/calendar.rb
new file mode 100644
index 00000000000..db5af98738b
--- /dev/null
+++ b/modules/calendar/spec/support/pages/calendar.rb
@@ -0,0 +1,63 @@
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2012-2021 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 'support/pages/page'
+
+module Pages
+ class Calendar < ::Pages::Page
+ attr_reader :project,
+ :filters
+
+ def initialize(project)
+ super()
+
+ @project = project
+ @filters = ::Components::WorkPackages::Filters.new
+ end
+
+ def path
+ project_calendar_path(project)
+ end
+
+ def expect_title(title = 'Unnamed calendar')
+ expect(page).to have_selector '.editable-toolbar-title--fixed', text: title
+ end
+
+ def expect_event(work_package, present: true)
+ expect(page).to have_conditional_selector(present, '.fc-event', text: work_package.subject)
+ end
+
+ def open_split_view(work_package)
+ page
+ .find('.fc-event', text: work_package.subject)
+ .click
+
+ ::Pages::SplitWorkPackage.new(work_package, project)
+ end
+ end
+end
diff --git a/spec/factories/query_factory.rb b/spec/factories/query_factory.rb
index fb2b0bd1b43..7b579f13cc8 100644
--- a/spec/factories/query_factory.rb
+++ b/spec/factories/query_factory.rb
@@ -64,6 +64,14 @@ FactoryBot.define do
end
end
+ factory :query_with_view_work_packages_calendar do
+ sequence(:name) { |n| "Calendar query #{n}" }
+
+ callback(:after_create) do |query|
+ FactoryBot.create(:view_work_packages_calendar, query: query)
+ end
+ end
+
callback(:after_build) { |query| query.add_default_filter }
end
end
diff --git a/spec/factories/view_factory.rb b/spec/factories/view_factory.rb
index aca32b9e4bd..75768dd209e 100644
--- a/spec/factories/view_factory.rb
+++ b/spec/factories/view_factory.rb
@@ -37,4 +37,8 @@ FactoryBot.define do
factory :view_team_planner, parent: :view do
type { 'team_planner' }
end
+
+ factory :view_work_packages_calendar, parent: :view do
+ type { 'work_packages_calendar' }
+ end
end
diff --git a/spec_legacy/unit/lib/redmine_spec.rb b/spec_legacy/unit/lib/redmine_spec.rb
index b031a02c074..4359fd54fde 100644
--- a/spec_legacy/unit/lib/redmine_spec.rb
+++ b/spec_legacy/unit/lib/redmine_spec.rb
@@ -74,12 +74,11 @@ describe Redmine do
end
it 'should project_menu' do
- assert_number_of_items_in_menu :project_menu, 13
+ assert_number_of_items_in_menu :project_menu, 12
assert_menu_contains_item_named :project_menu, :overview
assert_menu_contains_item_named :project_menu, :activity
assert_menu_contains_item_named :project_menu, :roadmap
assert_menu_contains_item_named :project_menu, :work_packages
- assert_menu_contains_item_named :project_menu, :calendar
assert_menu_contains_item_named :project_menu, :news
assert_menu_contains_item_named :project_menu, :forums
assert_menu_contains_item_named :project_menu, :repository