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

Provide correct aria attributes for quick add menu and fix some more tests

Henriette Dargea877bf802d54
diff --git a/lib/redmine/menu_manager/top_menu/quick_add_menu.rb b/lib/redmine/menu_manager/top_menu/quick_add_menu.rb
index 0c40aca43cc..47278afae6e 100644
--- a/lib/redmine/menu_manager/top_menu/quick_add_menu.rb
+++ b/lib/redmine/menu_manager/top_menu/quick_add_menu.rb
@@ -62,13 +62,17 @@ module Redmine::MenuManager::TopMenu::QuickAddMenu
def add_first_level_items(menu)
first_level_menu_items_for(:quick_add_menu, @project).each do |item|
+ html_options = item.html_options
+ html_options[:aria] = { labelledby: id_for_name(item.caption) } if html_options[:aria].blank?
+
menu.with_item(
href: item.url.present? ? allowed_node_url(item, @project) : "#",
content_arguments: {
target: "_top",
- **item.html_options,
+ **html_options,
test_selector: "quick-add-menu-item"
},
+ label_arguments: { id: id_for_name(item.caption) },
label: item.caption,
test_selector: "op-menu--item-action"
) do |menu_item|
@@ -86,8 +90,12 @@ module Redmine::MenuManager::TopMenu::QuickAddMenu
menu_group.with_item(
href: item[:href],
label: item[:caption],
- content_arguments: { target: "_top" },
- label_arguments: { classes: item[:classes] },
+ content_arguments: {
+ target: "_top",
+ aria: { labelledby: id_for_name(item[:caption]) }
+ },
+ label_arguments: { id: id_for_name(item[:caption]),
+ classes: item[:classes] },
test_selector: "op-menu--item-action"
)
end
@@ -162,4 +170,8 @@ module Redmine::MenuManager::TopMenu::QuickAddMenu
def any_types?
visible_types.any?
end
+
+ def id_for_name(name)
+ "quick-add-menu-item--item-#{name.parameterize(separator: '_')}"
+ end
end
diff --git a/modules/auth_plugins/spec/features/auth_provider_spec.rb b/modules/auth_plugins/spec/features/auth_provider_spec.rb
index 8a982e7a344..d29b60e89f4 100644
--- a/modules/auth_plugins/spec/features/auth_provider_spec.rb
+++ b/modules/auth_plugins/spec/features/auth_provider_spec.rb
@@ -45,7 +45,7 @@ RSpec.describe "rendering the login buttons", :js do
it "renders correctly" do
visit project_path(public_project)
- page.find("a", text: "Sign in").click
+ click_link_or_button "Sign in"
item = page.find("a.auth-provider", text: "mock_auth")
expect(item[:href]).to end_with "/auth/mock_auth"
end
diff --git a/modules/bim/spec/features/revit_add_in/bim_revit_add_in_navigation_spec.rb b/modules/bim/spec/features/revit_add_in/bim_revit_add_in_navigation_spec.rb
index 7ff827a7e5c..2c2fa356fe4 100644
--- a/modules/bim/spec/features/revit_add_in/bim_revit_add_in_navigation_spec.rb
+++ b/modules/bim/spec/features/revit_add_in/bim_revit_add_in_navigation_spec.rb
@@ -42,6 +42,7 @@ RSpec.describe "BIM Revit Add-in navigation spec", :js,
create(:user,
member_with_roles: { project => role })
end
+ let(:user_menu) { Components::UserMenu.new }
context "when logged in on model page" do
before do
@@ -69,7 +70,7 @@ RSpec.describe "BIM Revit Add-in navigation spec", :js,
it "the user menu has an option to go to the add-in settings" do
within ".op-app-header" do
- page.find("a[title='#{user.name}']").click
+ user_menu.open
expect(page).to have_css("li", text: I18n.t("js.revit.revit_add_in_settings"))
end
diff --git a/modules/costs/spec/features/timer_spec.rb b/modules/costs/spec/features/timer_spec.rb
index b45b9acd60e..5235eda5c55 100644
--- a/modules/costs/spec/features/timer_spec.rb
+++ b/modules/costs/spec/features/timer_spec.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
#-- copyright
# OpenProject is an open source project management software.
# Copyright (C) the OpenProject GmbH
@@ -38,6 +40,7 @@ RSpec.describe "Work Package timer", :js, :selenium do
let(:wp_view_b) { Pages::FullWorkPackage.new(work_package_b) }
let(:time_logging_modal) { Components::TimeLoggingModal.new }
let(:timer_button) { Components::WorkPackages::TimerButton.new }
+ let(:user_menu) { Components::UserMenu.new }
let(:user) { create(:user, member_with_permissions: { project => permissions }) }
@@ -58,7 +61,7 @@ RSpec.describe "Work Package timer", :js, :selenium do
expect(timer_entry.entity).to eq work_package_a
expect(timer_entry.hours).to be_nil
- page.find(".op-top-menu-user").click
+ user_menu.open
expect(page).to have_css(".op-timer-account-menu", wait: 10)
expect(page).to have_css(".op-timer-account-menu--wp-details", text: "##{work_package_a.id}: WP A")
page.find_test_selector("op-timer-account-menu-stop").click
@@ -80,6 +83,7 @@ RSpec.describe "Work Package timer", :js, :selenium do
expect(timer_entry.ongoing).to be false
expect(timer_entry.hours).not_to be_nil
+ user_menu.close
timer_button.start
timer_button.expect_active
@@ -153,6 +157,7 @@ RSpec.describe "Work Package timer", :js, :selenium do
second_window = open_new_window
within_window(second_window) do
wp_view_a.visit!
+ wait_for_network_idle
timer_button.expect_visible
timer_button.start
timer_button.expect_active
diff --git a/modules/openid_connect/spec/features/oidc_end_session_redirect_spec.rb b/modules/openid_connect/spec/features/oidc_end_session_redirect_spec.rb
index 82595fd6f14..d17f30f7407 100644
--- a/modules/openid_connect/spec/features/oidc_end_session_redirect_spec.rb
+++ b/modules/openid_connect/spec/features/oidc_end_session_redirect_spec.rb
@@ -38,6 +38,7 @@ RSpec.describe "OpenID Connect end_session_redirect",
slug: "keycloak",
end_session_endpoint: "https://example.com")
end
+ let(:user_menu) { Components::UserMenu.new }
let(:password) { "password!123" }
let(:user) { create(:user, authentication_provider: provider, password:, password_confirmation: password) }
@@ -47,7 +48,7 @@ RSpec.describe "OpenID Connect end_session_redirect",
visit home_path
- page.find(".op-top-menu-user").click
+ user_menu.open
click_link_or_button "Sign out"
expect(page).to have_current_path("https://example.com")
diff --git a/spec/features/auth/logout_spec.rb b/spec/features/auth/logout_spec.rb
index 45aa1beb3fc..700a1cefce7 100644
--- a/spec/features/auth/logout_spec.rb
+++ b/spec/features/auth/logout_spec.rb
@@ -38,6 +38,7 @@ RSpec.describe "Logout",
password: user_password,
password_confirmation: user_password)
end
+ let(:user_menu) { Components::UserMenu.new }
before do
login_with(user.login, user_password)
@@ -48,7 +49,7 @@ RSpec.describe "Logout",
visit my_page_path
within ".op-app-header" do
- page.find("a[title='#{user.name}']").click
+ user_menu.open
click_link I18n.t(:label_logout)
end
diff --git a/spec/features/users/create_spec.rb b/spec/features/users/create_spec.rb
index 560b4fb0a31..9f9ccc6ce68 100644
--- a/spec/features/users/create_spec.rb
+++ b/spec/features/users/create_spec.rb
@@ -93,7 +93,9 @@ RSpec.describe "create users" do
# landed on the 'my page'
expect(page).to have_text "Welcome, your account has been activated. You are logged in now."
- expect(page).to have_link "bobfirst boblast"
+ within_test_selector "op-app-header--user-menu-button" do
+ expect(page).to have_element title: "bobfirst boblast"
+ end
end
end
end
@@ -151,11 +153,13 @@ RSpec.describe "create users" do
fill_in "password", with: "dummy" # accepted by DummyAuthSource
- click_button "Sign in"
+ click_button "Sign in", type: "submit"
expect(page).to have_text "OpenProject"
expect(page).to have_current_path "/", ignore_query: true
- expect(page).to have_link "bobfirst boblast"
+ within_test_selector "op-app-header--user-menu-button" do
+ expect(page).to have_element title: "bobfirst boblast"
+ end
end
end
end
@@ -198,7 +202,9 @@ RSpec.describe "create users" do
# landed on the 'my page'
expect(page).to have_text "Welcome, your account has been activated. You are logged in now."
- expect(page).to have_link "bobfirst boblast"
+ within_test_selector "op-app-header--user-menu-button" do
+ expect(page).to have_element title: "bobfirst boblast"
+ end
end
end
end
diff --git a/spec/support/components/menu/quick_add_menu.rb b/spec/support/components/menu/quick_add_menu.rb
index 0fa4c2e3a2b..f3ec57ef04f 100644
--- a/spec/support/components/menu/quick_add_menu.rb
+++ b/spec/support/components/menu/quick_add_menu.rb
@@ -44,7 +44,7 @@ module Components
end
def expect_add_project(present: true)
- expect_link "New project", present:
+ expect_link "Project", present:
end
def expect_user_invite(present: true)
@@ -76,9 +76,9 @@ module Components
def expect_link(matcher, present: true)
within_dropdown do
if present
- expect(page).to have_link aria: { label: matcher }
+ expect(page).to have_link matcher
else
- expect(page).to have_no_link aria: { label: matcher }
+ expect(page).to have_no_link matcher
end
end
end
diff --git a/spec/support/components/menu/user_menu.rb b/spec/support/components/menu/user_menu.rb
new file mode 100644
index 00000000000..2e5adb4a57d
--- /dev/null
+++ b/spec/support/components/menu/user_menu.rb
@@ -0,0 +1,45 @@
+# frozen_string_literal: true
+
+#-- 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.
+#++
+
+module Components
+ class UserMenu
+ include Capybara::DSL
+ include Capybara::RSpecMatchers
+ include RSpec::Matchers
+
+ def open
+ page.find_test_selector("op-app-header--user-menu-button").click
+ end
+
+ def close
+ page.find(".op-app-header--modules-menu-header .close-button").click
+ end
+ end
+end