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 spec

Oliver Günther2cbb85e2eeef
diff --git a/app/controllers/work_packages/dialogs_controller.rb b/app/controllers/work_packages/dialogs_controller.rb
index 06860cc3b27..2b59bbd5eaa 100644
--- a/app/controllers/work_packages/dialogs_controller.rb
+++ b/app/controllers/work_packages/dialogs_controller.rb
@@ -98,4 +98,6 @@ class WorkPackages::DialogsController < ApplicationController
project: @project
}
end
+
+ def default_breadcrumb; end
end
diff --git a/app/forms/work_packages/dialogs/create_form.rb b/app/forms/work_packages/dialogs/create_form.rb
index da7942fc3c7..bf30848b2b4 100644
--- a/app/forms/work_packages/dialogs/create_form.rb
+++ b/app/forms/work_packages/dialogs/create_form.rb
@@ -52,7 +52,8 @@ module WorkPackages::Dialogs
multiple: false,
decorated: true,
hiddenFieldAction: "change->work-packages--create-dialog#refreshForm",
- append_to: wrapper_id
+ append_to: wrapper_id,
+ data: { test_selector: "work_package_create_dialog_type" }
}
) do |select|
contract
diff --git a/spec/features/work_packages/tabs/relations_children_spec.rb b/spec/features/work_packages/tabs/relations_children_spec.rb
new file mode 100644
index 00000000000..a20b72cbb67
--- /dev/null
+++ b/spec/features/work_packages/tabs/relations_children_spec.rb
@@ -0,0 +1,80 @@
+require "spec_helper"
+
+require "support/edit_fields/edit_field"
+
+RSpec.describe "Relations children tab", :js, :with_cuprite do
+ shared_let(:normal_cf) { create(:string_wp_custom_field, is_required: false) }
+ shared_let(:required_cf) { create(:string_wp_custom_field, is_required: true) }
+ shared_let(:type_milestone) { create(:type_milestone) }
+ shared_let(:type_task) { create(:type, name: "Task", custom_fields: [normal_cf]) }
+ shared_let(:type_risk) { create(:type, name: "Risk", custom_fields: [required_cf]) }
+ shared_let(:default_status) { create(:default_status) }
+ shared_let(:default_priority) { create(:default_priority) }
+
+ shared_let(:project) do
+ create(:project,
+ types: [type_task, type_risk, type_milestone],
+ work_package_custom_fields: [normal_cf, required_cf])
+ end
+
+ shared_let(:work_package) { create(:work_package, type: type_task, project:, subject: "Parent") }
+
+ let(:relations_tab) { Components::WorkPackages::Relations.new(work_package) }
+ let(:create_dialog) { Components::WorkPackages::CreateDialog.new }
+ let(:wp_page) { Pages::FullWorkPackage.new(work_package, project) }
+
+ current_user { user }
+
+ context "with permissions to add children" do
+ let!(:user) do
+ create(:user, member_with_permissions: { project => %i[view_work_packages add_work_packages manage_subtasks] })
+ end
+
+ it "can add a new child" do
+ wp_page.visit_tab!("relations")
+ relations_tab.expect_add_relation_button
+ relations_tab.select_relation_type "New child"
+
+ create_dialog.select_type "Task"
+ create_dialog.set_subject "Hello there"
+ create_dialog.set_description "Some *markdown* content"
+ create_dialog.expect_no_custom_field(normal_cf)
+
+ create_dialog.select_type "Risk"
+ # Retains subject and description
+ create_dialog.expect_subject "Hello there"
+ create_dialog.expect_description "Some markdown content"
+
+ # Shows a custom field
+ create_dialog.set_custom_field(required_cf, "Custom value")
+ create_dialog.submit
+
+ wait_for_network_idle
+
+ page.within("#work-package-relations-tab-content") do
+ expect(page).to have_content("Hello there")
+ expect(page).to have_content("RISK")
+ end
+ end
+
+ context "when work package is a milestone" do
+ let(:work_package) { create(:work_package, type: type_milestone, project:, subject: "Parent") }
+
+ it "does not show the action" do
+ wp_page.visit_tab!("relations")
+ relations_tab.expect_no_add_relation_button
+ end
+ end
+ end
+
+ context "without permissions to add children" do
+ let!(:user) do
+ create(:user, member_with_permissions: { project => %i[view_work_packages] })
+ end
+
+ it "does not show the action" do
+ wp_page.visit_tab!("relations")
+ relations_tab.expect_no_add_relation_button
+ end
+ end
+end
diff --git a/spec/support/components/work_packages/create_dialog.rb b/spec/support/components/work_packages/create_dialog.rb
new file mode 100644
index 00000000000..4d363d4bbaf
--- /dev/null
+++ b/spec/support/components/work_packages/create_dialog.rb
@@ -0,0 +1,96 @@
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 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/components/autocompleter/ng_select_autocomplete_helpers"
+
+module Components
+ module WorkPackages
+ class CreateDialog
+ include Capybara::DSL
+ include Capybara::RSpecMatchers
+ include RSpec::Matchers
+ include RSpec::Wait
+ include ::Components::Autocompleter::NgSelectAutocompleteHelpers
+
+ def initialize
+ @description = ::Components::WysiwygEditor.new("#create-work-package-dialog")
+ end
+
+ def select_type(value)
+ retry_block do
+ select_autocomplete page.find_test_selector("work_package_create_dialog_type"),
+ query: value,
+ select_text: value.upcase,
+ results_selector: "#create-work-package-dialog"
+ end
+ end
+
+ def set_subject(value)
+ in_dialog do
+ fill_in "Subject", with: value
+ end
+ end
+
+ def expect_subject(value)
+ in_dialog do
+ expect(page).to have_field "Subject", with: value
+ end
+ end
+
+ def set_description(value)
+ @description.set_markdown(value)
+ end
+
+ def expect_description(value)
+ @description.expect_value(value)
+ end
+
+ def expect_custom_field(custom_field, **args)
+ expect(page).to have_field "work_package_custom_field_values_#{custom_field.id}", **args
+ end
+
+ def expect_no_custom_field(custom_field)
+ expect(page).to have_no_field "work_package_custom_field_values_#{custom_field.id}"
+ end
+
+ def set_custom_field(custom_field, value)
+ fill_in "work_package_custom_field_values_#{custom_field.id}", with: value
+ end
+
+ def in_dialog(&)
+ page.within("#create-work-package-dialog", &)
+ end
+
+ def submit
+ page.within("#create-work-package-dialog") do
+ click_on "Create"
+ end
+ end
+ end
+ end
+end