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

[#61619] added component test

Eric Schubert27b9c4e5d646
diff --git a/spec/components/work_packages/types/subject_configuration_component_spec.rb b/spec/components/work_packages/types/subject_configuration_component_spec.rb
index 9274198ca9f..a8be84773d4 100644
--- a/spec/components/work_packages/types/subject_configuration_component_spec.rb
+++ b/spec/components/work_packages/types/subject_configuration_component_spec.rb
@@ -31,12 +31,12 @@
require "rails_helper"
RSpec.describe WorkPackages::Types::SubjectConfigurationComponent, type: :component do
+ let(:type) { create(:type) }
+
subject(:render_component) do
render_inline(described_class.new(type))
end
- let(:type) { create(:type) }
-
context "when enterprise edition is activated", with_ee: %i[work_package_subject_generation] do
it "shows no enterprise banner" do
render_component
@@ -50,6 +50,60 @@ RSpec.describe WorkPackages::Types::SubjectConfigurationComponent, type: :compon
expect(page.find("input[type=radio][value=generated]")).not_to be_disabled
expect(page.find("input[type=radio][value=manual]")).not_to be_disabled
end
+
+ context "if component is rendered without form values in parameters" do
+ before do
+ render_component
+ end
+
+ context "if work package type has no subject pattern configured" do
+ it "must have manual option checked" do
+ expect(page.find("input[type=radio][value=manual]")).to be_checked
+ end
+ end
+
+ context "if work package type has subject pattern configured" do
+ let(:type) { create(:type, patterns: { subject: { blueprint: "Created by {{assignee}}", enabled: true } }) }
+
+ it "must have generated option checked and pattern input filled" do
+ expect(page.find("input[type=radio][value=generated]")).to be_checked
+ expect(page.find("input[type=hidden][id=types_forms_subject_configuration_form_model_pattern]", visible: false).value)
+ .to eq("Created by {{assignee}}")
+ end
+ end
+ end
+
+ context "if component is rendered with form values in parameters" do
+ before do
+ allow_any_instance_of(described_class).to receive(:params).and_return(params)
+ render_component
+ end
+
+ context "if work package type has subject pattern configured, but form params have option manual selected" do
+ let(:type) { create(:type, patterns: { subject: { blueprint: "Created by {{assignee}}", enabled: true } }) }
+ let(:params) { { types_forms_subject_configuration_form_model: { subject_configuration: :manual } } }
+
+ it "must have manual option checked" do
+ expect(page.find("input[type=radio][value=manual]")).to be_checked
+ end
+ end
+
+ context "if work package type has no subject pattern configured, but form params have a pattern" do
+ let(:params) do
+ {
+ types_forms_subject_configuration_form_model: {
+ subject_configuration: :generated, pattern: "Created by {{assignee}}"
+ }
+ }
+ end
+
+ it "must have generated option checked and pattern input filled" do
+ expect(page.find("input[type=radio][value=generated]")).to be_checked
+ expect(page.find("input[type=hidden][id=types_forms_subject_configuration_form_model_pattern]", visible: false).value)
+ .to eq("Created by {{assignee}}")
+ end
+ end
+ end
end
context "when enterprise edition is not activated", with_ee: %i[] do