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
Fix more specs
Aaron Contrerasdbb42ea6b776
diff --git a/app/components/work_package_relations_tab/work_package_relation_form_component.html.erb b/app/components/work_package_relations_tab/work_package_relation_form_component.html.erbindex 6fdc8cea68d..e4ecf807f32 100644--- a/app/components/work_package_relations_tab/work_package_relation_form_component.html.erb+++ b/app/components/work_package_relations_tab/work_package_relation_form_component.html.erb@@ -48,6 +48,7 @@autocomplete_options: {resource: 'work_packages',url:,+ relations: true, # Activates relations fetch mode in the autocompleteopenDirectly: false,focusDirectly: false,dropdownPosition: 'bottom',diff --git a/app/controllers/work_package_children_controller.rb b/app/controllers/work_package_children_controller.rbindex 27c17135d7c..2c95e3cc8a3 100644--- a/app/controllers/work_package_children_controller.rb+++ b/app/controllers/work_package_children_controller.rb@@ -61,6 +61,9 @@ class WorkPackageChildrenController < ApplicationControllerchildren: @children)replace_via_turbo_stream(component:)+ update_flash_message_via_turbo_stream(+ message: I18n.t(:notice_successful_update), scheme: :success+ )respond_with_turbo_streamsendend@@ -77,6 +80,9 @@ class WorkPackageChildrenController < ApplicationControllerchildren: @children)replace_via_turbo_stream(component:)+ update_flash_message_via_turbo_stream(+ message: I18n.t(:notice_successful_update), scheme: :success+ )respond_with_turbo_streamsenddiff --git a/spec/features/work_packages/details/relations/hierarchy_spec.rb b/spec/features/work_packages/details/relations/hierarchy_spec.rbindex a66690e17fa..ca29971fc18 100644--- a/spec/features/work_packages/details/relations/hierarchy_spec.rb+++ b/spec/features/work_packages/details/relations/hierarchy_spec.rb@@ -62,99 +62,31 @@ RSpec.shared_examples "work package relations tab", :js, :selenium doit "allows to manage hierarchy" do# Add parentrelations.add_parent(parent.id, parent)+ wp_page.expect_and_dismiss_toaster(message: "Successful update.")relations.expect_parent(parent)### Add child #1- relations.open_children_autocompleter-relations.add_existing_child(child)+ expect_and_dismiss_flash(message: "Successful update.")relations.expect_child(child)### Add child #2- relations.open_children_autocompleter-relations.add_existing_child(child2)+ expect_and_dismiss_flash(message: "Successful update.")relations.expect_child(child2)# Count child relations in split view- tabs.expect_counter(relations_tab, 2)- end-- context "when switching to custom field with required CF" do- let(:custom_field) do- create(- :work_package_custom_field,- field_format: "string",- default_value: nil,- is_required: true,- is_for_all: true- )- end- let(:type2) { create(:type, custom_fields: [custom_field]) }- let(:relations) { Components::WorkPackages::Relations.new(parent) }- let!(:status) { create(:status, is_default: true) }- let!(:priority) { create(:priority, is_default: true) }-- before do- project.types << type2- project.save!- custom_field- end-- it "shows the required field when switching" do- relations.inline_create_child "my new child"- table = relations.children_table-- table.expect_work_package_subject "my new child"- wp = WorkPackage.find_by!(subject: "my new child")- type_field = table.edit_field(wp, :type)-- type_field.activate!- type_field.set_value type2.name-- wp_page.expect_toast message: "#{custom_field.name} can't be blank.",- type: "error"-- cf_field = wp_page.edit_field(custom_field.attribute_name(:camel_case))- cf_field.expect_active!- cf_field.expect_value("")-- cf_field.set_value "my value"- cf_field.save!-- wp_page.expect_toast message: "Successful update.",- type: "success"+ # Marking as "visible: :all" because the counter+ # is hidden by some weird white element only in TEST mode+ # in the header.- wp.reload- expect(wp.custom_value_for(custom_field).value).to eq "my value"- end- end-- describe "inline create" do- let!(:status) { create(:status, is_default: true) }- let!(:priority) { create(:priority, is_default: true) }- let(:type_bug) { create(:type_bug) }- let!(:project) do- create(:project, types: [type_bug])- end-- it "can inline-create children" do- relations.inline_create_child "my new child"- table = relations.children_table-- table.expect_work_package_subject "my new child"- work_package.reload- expect(work_package.children.count).to eq(1)-- # If new child is inline created, counter should increase- tabs.expect_counter(relations_tab, 1)- end+ tabs.expect_counter(relations_tab, 2)endend- describe "relation group-by toggler" do+ describe "as non-admin" dolet(:project) { create(:project, types: [type1, type2]) }let(:type1) { create(:type) }let(:type2) { create(:type) }@@ -175,7 +107,6 @@ RSpec.shared_examples "work package relations tab", :js, :selenium dorelation_type: Relation::TYPE_RELATES)end- let(:toggle_btn_selector) { "#wp-relation-group-by-toggle" }let(:visit) { false }before do@@ -202,19 +133,12 @@ RSpec.shared_examples "work package relations tab", :js, :selenium dolet!(:work_package) { create(:work_package, parent:, project:, subject: "Child WP") }it "shows no links to create relations" do- # No create buttons should exist- expect(page).to have_no_css(".wp-relations-create-button")-- # Test for add relation- expect(page).to have_no_css("#relation--add-relation")+ # No create buttons should exist (relation or children)+ relations.expect_no_add_relation_button# Test for add parentexpect(page).to have_no_css(".wp-relation--parent-change")- # Test for add children- expect(page).to have_no_css("#hierarchy--add-existing-child")- expect(page).to have_no_css("#hierarchy--add-new-child")-# But it should show the linked parentexpect(page).to have_test_selector("op-wp-breadcrumb-parent", text: parent.subject)@@ -236,10 +160,8 @@ RSpec.shared_examples "work package relations tab", :js, :selenium do### Add child- relations.open_children_autocompleter-relations.add_existing_child(child)- wp_page.expect_and_dismiss_toaster(message: "Successful update.")+ expect_and_dismiss_flash(message: "Successful update.")relations.expect_child(child)# Expect counter to add up child to the existing relations@@ -253,6 +175,7 @@ RSpec.shared_examples "work package relations tab", :js, :selenium do# Remove childrelations.remove_child(child)# Should also check for successful update but no message is shown, yet.+ expect_and_dismiss_flash(message: "Successful update.")relations.expect_not_child(child)# Expect counter to count the two relationsdiff --git a/spec/support/components/work_packages/relations.rb b/spec/support/components/work_packages/relations.rbindex 87e860fbe50..5e7a3e99e9e 100644--- a/spec/support/components/work_packages/relations.rb+++ b/spec/support/components/work_packages/relations.rb@@ -43,32 +43,63 @@ module Components@work_package = work_packageend+ def find_relatable(relatable)+ case relatable+ when WorkPackage+ relatable+ when Relation+ relatable.other_work_package(work_package)+ else+ raise "Unknown relatable type: #{relatable.class}"+ end+ end++ def expect_no_add_relation_button+ expect(page).to have_no_css("[data-test-selector='new-relation-action-menu']")+ end+def find_row(relatable)- page.find("[data-test-selector='op-relation-row-#{relatable.id}']")+ actual_relatable = find_relatable(relatable)+ page.find("[data-test-selector='op-relation-row-#{actual_relatable.id}']")enddef find_some_row(text:)page.find("[data-test-selector^='op-relation-row']", text:)end+ def expect_row(work_package)+ find_row(work_package)+ end+def expect_no_row(relatable)- if relatable.is_a?(Relation)- expect(page).to have_no_css("[data-test-selector='op-relation-row-#{relatable.to.id}']")- else- expect(page).to have_no_css("[data-test-selector='op-relation-row-#{relatable.id}']")- end+ actual_relatable = find_relatable(relatable)+ expect(page).to have_no_css("[data-test-selector='op-relation-row-#{actual_relatable.id}']")enddef remove_relation(relatable)- relatable_row = find_row(relatable)+ actual_relatable = find_relatable(relatable)+ relatable_row = find_row(actual_relatable)- within(relatable_row) do- page.find("[data-test-selector='op-relation-row-#{relatable.id}-action-menu']").click- page.find("[data-test-selector='op-relation-row-#{relatable.id}-delete-button']").click+ retry_block do+ SeleniumHubWaiter.wait+ within(relatable_row) do+ relatable_action_menu(actual_relatable).click+ relatable_delete_button(actual_relatable).click+ end++ # Expect relation to be gone+ expect_no_row(relatable)end+ end- # Expect relation to be gone- expect_no_row(relatable)+ def relatable_action_menu(relatable)+ actual_relatable = find_relatable(relatable)+ page.find("[data-test-selector='op-relation-row-#{actual_relatable.id}-action-menu']")+ end++ def relatable_delete_button(relatable)+ actual_relatable = find_relatable(relatable)+ page.find("[data-test-selector='op-relation-row-#{actual_relatable.id}-delete-button']")enddef add_relation(type:, to:)@@ -164,10 +195,14 @@ module Componentsenddef add_existing_child(work_package)- page.find("[data-test-selector='new-relation-action-menu']").click+ SeleniumHubWaiter.wait- within page.find_by_id("new-relation-action-menu-list") do # Primer appends "list" to the menu id automatically- click_link_or_button "Child"+ retry_block do+ page.find("[data-test-selector='new-relation-action-menu']").click++ within page.find_by_id("new-relation-action-menu-list") do # Primer appends "list" to the menu id automatically+ click_link_or_button "Child"+ endendwithin "##{WorkPackageRelationsTab::AddWorkPackageChildFormComponent::DIALOG_ID}" do@@ -180,6 +215,10 @@ module Componentsendend+ def relations_group+ page.find_by_id("work-package-relations-tab-content")+ end+def expect_child(work_package)expect_row(work_package)end@@ -188,16 +227,12 @@ module Componentsexpect_no_row(work_package)end- def relations_group- page.find_by_id("work-package-relations-tab-content")- end-def remove_child(work_package)child_wp_row = find_row(work_package)within(child_wp_row) do- page.find("[data-test-selector='op-relation-row-#{work_package.id}-action-menu']").click- page.find("[data-test-selector='op-relation-row-#{work_package.id}-delete-button']").click+ relatable_action_menu(work_package).click+ relatable_delete_button(work_package).clickendexpect_no_row(work_package)