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
Add specs for calendar move
Oliver Günther45ad10a43f90
diff --git a/frontend/src/app/features/calendar/op-calendar.service.ts b/frontend/src/app/features/calendar/op-calendar.service.tsindex 6c3bfad99d3..5915e1c1bf8 100644--- a/frontend/src/app/features/calendar/op-calendar.service.ts+++ b/frontend/src/app/features/calendar/op-calendar.service.ts@@ -43,6 +43,7 @@ import { HalResourceEditFieldHandler } from 'core-app/shared/components/fields/eimport { HalResourceEditingService } from 'core-app/shared/components/fields/edit/services/hal-resource-editing.service';import { HalResourceNotificationService } from 'core-app/features/hal/services/hal-resource-notification.service';import { ResourceChangeset } from 'core-app/shared/components/fields/changeset/resource-changeset';+import * as moment from 'moment';export interface CalendarViewEvent {el:HTMLElement;@@ -235,8 +236,7 @@ export class OpCalendarService extends UntilDestroyedMixin {public eventDurationEditable(wp:WorkPackageResource):boolean {const schema = this.schemaCache.of(wp);- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access- const schemaEditable = !!schema.startDate.writable && !!schema.dueDate.writable && schema.isAttributeEditable('startDate');+ const schemaEditable = schema.isAttributeEditable('startDate') && schema.isAttributeEditable('dueDate');return (wp.isLeaf || wp.scheduleManually) && schemaEditable && !this.isMilestone(wp);}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.tsindex 74da415cd6d..fcf06c132f8 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@@ -24,6 +24,7 @@ import { OpTitleService } from 'core-app/core/html/op-title.service';import dayGridPlugin from '@fullcalendar/daygrid';import {CalendarOptions,+ DateSelectArg,EventDropArg,EventInput,} from '@fullcalendar/core';@@ -37,6 +38,7 @@ import { CurrentProjectService } from 'core-app/core/current-project/current-proimport interactionPlugin, { EventResizeDoneArg } from '@fullcalendar/interaction';import { HalResourceEditingService } from 'core-app/shared/components/fields/edit/services/hal-resource-editing.service';import { HalResourceNotificationService } from 'core-app/features/hal/services/hal-resource-notification.service';+import { splitViewRoute } from 'core-app/features/work-packages/routing/split-view-routes.helper';@Component({templateUrl: './wp-calendar.template.html',@@ -134,6 +136,8 @@ export class WorkPackagesCalendarComponent extends UntilDestroyedMixin implementinteractionPlugin,],// DnD configuration+ selectable: true,+ select: this.handleDateClicked.bind(this) as unknown,editable: true,eventResize: (resizeInfo:EventResizeDoneArg) => this.updateEvent(resizeInfo),eventDrop: (dropInfo:EventDropArg) => this.updateEvent(dropInfo),@@ -206,8 +210,23 @@ export class WorkPackagesCalendarComponent extends UntilDestroyedMixin implementconst result = await this.halEditing.save(changeset);this.halNotification.showSave(result.resource, result.wasNew);} catch (e) {- this.halNotification.showError(e, changeset.projectedResource);+ this.halNotification.handleRawError(e, changeset.projectedResource);info.revert();}}++ private handleDateClicked(info:DateSelectArg) {+ const defaults = {+ startDate: info.startStr,+ dueDate: this.calendar.getEndDateFromTimestamp(info.end),+ };++ void this.$state.go(+ splitViewRoute(this.$state, 'new'),+ {+ defaults,+ tabIdentifier: 'overview',+ },+ );+ }}diff --git a/frontend/src/app/features/team-planner/team-planner/planner/team-planner.component.ts b/frontend/src/app/features/team-planner/team-planner/planner/team-planner.component.tsindex 7b2d45ac693..c10c08512d4 100644--- a/frontend/src/app/features/team-planner/team-planner/planner/team-planner.component.ts+++ b/frontend/src/app/features/team-planner/team-planner/planner/team-planner.component.ts@@ -388,7 +388,7 @@ export class TeamPlannerComponent extends UntilDestroyedMixin implements OnInit,this.openNewSplitCreate(info.startStr,// end date is exclusive- moment(info.end).subtract(1, 'd').format('YYYY-MM-DD'),+ this.calendar.getEndDateFromTimestamp(info.end),info.resource?.id || '',);}diff --git a/modules/calendar/spec/features/calendar_create_work_package_spec.rb b/modules/calendar/spec/features/calendar_create_work_package_spec.rbnew file mode 100644index 00000000000..77892c4efae--- /dev/null+++ b/modules/calendar/spec/features/calendar_create_work_package_spec.rb@@ -0,0 +1,71 @@+#-- 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 './shared_context'++describe 'Calendar create new work package', type: :feature, js: true do+ include_context 'with calendar full access'++ let(:type_task) { FactoryBot.create :type_task }+ let!(:status) { FactoryBot.create :default_status }+ let!(:priority) { FactoryBot.create :default_priority }++ before do+ login_as current_user+ project.types << type_task+ end++ it 'can create a new work package' do+ calendar.visit!++ start_of_week = Time.zone.today.beginning_of_week(:sunday)+ split_create = calendar.add_item start_of_week.iso8601,+ (start_of_week + 1.day).iso8601++ subject = split_create.edit_field(:subject)+ subject.set_value 'Newly planned task'++ split_create.save!++ split_create.expect_and_dismiss_toaster(message: I18n.t('js.notice_successful_create'))++ split_create.expect_attributes(+ combinedDate: "#{start_of_week.strftime('%m/%d/%Y')} - #{(start_of_week + 1.day).strftime('%m/%d/%Y')}"+ )++ wp = WorkPackage.last+ expect(wp.subject).to eq 'Newly planned task'+ expect(wp.start_date).to eq start_of_week+ expect(wp.due_date).to eq (start_of_week + 1.day)++ calendar.expect_event wp+ end+enddiff --git a/modules/calendar/spec/features/calendar_user_interaction_spec.rb b/modules/calendar/spec/features/calendar_user_interaction_spec.rbnew file mode 100644index 00000000000..8017d714beb--- /dev/null+++ b/modules/calendar/spec/features/calendar_user_interaction_spec.rb@@ -0,0 +1,98 @@+#-- 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 './shared_context'++describe 'Calendar drag&dop and resizing', type: :feature, js: true do+ include_context 'with calendar full access'++ let!(:other_user) do+ FactoryBot.create :user,+ firstname: 'Bernd',+ member_in_project: project,+ member_with_permissions: %w[+ view_work_packages view_calendar+ ]+ end++ let!(:work_package) do+ FactoryBot.create :work_package,+ project: project,+ start_date: Time.zone.today.beginning_of_week.next_occurring(:tuesday),+ due_date: Time.zone.today.beginning_of_week.next_occurring(:thursday)+ end++ before do+ login_as current_user+ calendar.visit!+ calendar.expect_event work_package+ end++ context 'with full permissions' do+ it 'allows to resize to change the dates of a wp' do+ target = work_package.due_date + 1.day+ retry_block do+ calendar.resize_end_date(work_package, target)+ end++ calendar.expect_and_dismiss_toaster(message: I18n.t('js.notice_successful_update'))++ work_package.reload+ expect(work_package.due_date).to eq target+ end++ it 'allows to drag the work package to another date' do+ target = Time.zone.today.beginning_of_week++ retry_block do+ calendar.drag_event(work_package, target)+ end++ calendar.expect_and_dismiss_toaster(message: I18n.t('js.notice_successful_update'))++ work_package.reload++ # The date is being dragged in the middle section+ expect(work_package.start_date).to eq(target - 1.day)+ expect(work_package.due_date).to eq(target + 1.day)+ end+ end++ context 'without permission to edit' do+ let(:current_user) { other_user }++ it 'allows neither dragging nor resizing any wp' do+ calendar.expect_event work_package+ calendar.expect_wp_not_resizable(work_package)+ calendar.expect_wp_not_draggable(work_package)+ end+ end+enddiff --git a/modules/calendar/spec/features/shared_context.rb b/modules/calendar/spec/features/shared_context.rbnew file mode 100644index 00000000000..5a8c5dd06ff--- /dev/null+++ b/modules/calendar/spec/features/shared_context.rb@@ -0,0 +1,52 @@+#-- 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'++shared_context 'with calendar full access' do+ shared_let(:project) do+ FactoryBot.create(:project, enabled_module_names: %w[work_package_tracking calendar_view])+ end++ shared_let(:user) do+ FactoryBot.create :user,+ member_in_project: project,+ member_with_permissions: %w[+ view_work_packages edit_work_packages add_work_packages+ view_calendar+ ]+ end++ let(:calendar) { ::Pages::Calendar.new project }+ let(:filters) { calendar.filters }++ let(:current_user) { user }+enddiff --git a/modules/calendar/spec/support/pages/calendar.rb b/modules/calendar/spec/support/pages/calendar.rbindex db5af98738b..09cd52d8bf2 100644--- a/modules/calendar/spec/support/pages/calendar.rb+++ b/modules/calendar/spec/support/pages/calendar.rb@@ -44,12 +44,49 @@ module Pagesproject_calendar_path(project)end+ def add_item(start_date, end_date)+ start_container = date_container start_date+ end_container = date_container end_date++ drag_n_drop_element(from: start_container, to: end_container)++ ::Pages::SplitWorkPackageCreate.new project: project+ end++ def resize_end_date(work_package, end_date)+ wp_strip = event(work_package)++ page+ .driver+ .browser+ .action+ .move_to(wp_strip.native)+ .perform++ resizer = wp_strip.find('.fc-event-resizer-end')+ end_container = date_container end_date++ drag_n_drop_element(from: resizer, to: end_container)+ end++ def drag_event(work_package, target)+ start_container = event(work_package)+ end_container = date_container target++ drag_n_drop_element(from: start_container, to: end_container)+ end++ def date_container(date)+ str = date.respond_to?(:iso8601) ? date.iso8601 : date.to_s+ page.find(".fc-day[data-date='#{str}'] .fc-daygrid-day-frame")+ end+def expect_title(title = 'Unnamed calendar')expect(page).to have_selector '.editable-toolbar-title--fixed', text: titleenddef expect_event(work_package, present: true)- expect(page).to have_conditional_selector(present, '.fc-event', text: work_package.subject)+ expect(page).to have_conditional_selector(present, '.fc-event', text: work_package.subject, wait: 10)enddef open_split_view(work_package)@@ -59,5 +96,17 @@ module Pages::Pages::SplitWorkPackage.new(work_package, project)end++ def event(work_package)+ page.find('.fc-event', text: work_package.subject)+ end++ def expect_wp_not_resizable(work_package)+ expect(page).to have_selector('.fc-event:not(.fc-event-resizable)', text: work_package.subject)+ end++ def expect_wp_not_draggable(work_package)+ expect(page).to have_selector('.fc-event:not(.fc-event-draggable)', text: work_package.subject)+ endendend