From 4a12fccd28af756a5bc9500f76c22cc21d021320 Mon Sep 17 00:00:00 2001 From: Behrokh Satarnejad Date: Tue, 3 Dec 2024 09:50:55 +0100 Subject: [PATCH] create a separate method for selecting relation type --- .../relations/primerized_relations_spec.rb | 16 ++------------- .../components/work_packages/relations.rb | 20 ++++++++++--------- 2 files changed, 13 insertions(+), 23 deletions(-) diff --git a/spec/features/work_packages/details/relations/primerized_relations_spec.rb b/spec/features/work_packages/details/relations/primerized_relations_spec.rb index 03bf35b2e105..bd7cb8c42a4c 100644 --- a/spec/features/work_packages/details/relations/primerized_relations_spec.rb +++ b/spec/features/work_packages/details/relations/primerized_relations_spec.rb @@ -216,13 +216,7 @@ def label_for_relation_type(relation_type) # wp_predecessor is already related to work_package as relation_follows # in a predecessor relation, so it should not be autocompleteable anymore # under the "Predecessor (before)" type - scroll_to_element relations_panel - - relations_panel.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 "Predecessor (before)" - end + relations_tab.select_relation_type "Predecessor (before)" wait_for_reload @@ -254,13 +248,7 @@ def label_for_relation_type(relation_type) end it "doesn't autocomplete parent, children, and WP itself" do - scroll_to_element relations_panel - - relations_panel.find("[data-test-selector='new-relation-action-menu']").click - - within page.find_by_id("new-relation-action-menu-list") do - click_link_or_button "Child" - end + relations_tab.select_relation_type "Child" wait_for_reload diff --git a/spec/support/components/work_packages/relations.rb b/spec/support/components/work_packages/relations.rb index 2c992d574349..246412fb1520 100644 --- a/spec/support/components/work_packages/relations.rb +++ b/spec/support/components/work_packages/relations.rb @@ -80,6 +80,14 @@ def expect_no_row(relatable) expect(page).not_to have_test_selector("op-relation-row-#{actual_relatable.id}") end + def select_relation_type(relation_type) + page.find_test_selector("new-relation-action-menu").click + + within page.find_by_id("new-relation-action-menu-list") do + click_link_or_button relation_type + end + end + def remove_relation(relatable) actual_relatable = find_relatable(relatable) relatable_row = find_row(actual_relatable) @@ -131,12 +139,10 @@ def add_relation(type:, relatable:, description: nil) # Open create form SeleniumHubWaiter.wait - page.find_test_selector("new-relation-action-menu").click label_text_for_relation_type = I18n.t("#{i18n_namespace}.label_#{type}_singular") - within page.find_by_id("new-relation-action-menu-list") do # Primer appends "list" to the menu id automatically - click_link_or_button label_text_for_relation_type.capitalize - end + + select_relation_type label_text_for_relation_type.capitalize wait_for_reload if using_cuprite? @@ -272,11 +278,7 @@ def add_existing_child(work_package) SeleniumHubWaiter.wait retry_block do - page.find_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" - end + select_relation_type "Child" end within "##{WorkPackageRelationsTab::AddWorkPackageChildFormComponent::DIALOG_ID}" do