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

Use Primer Button for "AddButtonComponent"

Henriette Dargeefe54cf8ca75
diff --git a/app/components/add_button_component.html.erb b/app/components/add_button_component.html.erb
index bfe3065020d..179a0cf8998 100644
--- a/app/components/add_button_component.html.erb
+++ b/app/components/add_button_component.html.erb
@@ -1,9 +1,11 @@
-<a href="<%= dynamic_path %>"
- id="<%= id %>"
- title="<%= title %>"
- arial-label="<%= aria_label %>"
- class="<%= link_css_class %>">
- <%= icon %>
- <%= label %>
-</a>
-
+<%= render(Primer::ButtonComponent.new(scheme: :primary,
+ aria: { label: aria_label },
+ title:,
+ test_selector:,
+ tag: :a,
+ id:,
+ href: dynamic_path) ) do |button|
+ button.with_leading_visual_icon(icon: :plus)
+ label_text
+end
+%>
diff --git a/app/components/add_button_component.rb b/app/components/add_button_component.rb
index 3b971f87af9..973e2283ece 100644
--- a/app/components/add_button_component.rb
+++ b/app/components/add_button_component.rb
@@ -48,12 +48,6 @@ class AddButtonComponent < ApplicationComponent
accessibility_label_text
end
- def label
- content_tag(:span,
- label_text,
- class: "button--text")
- end
-
def aria_label
accessibility_label_text
end
@@ -65,12 +59,4 @@ class AddButtonComponent < ApplicationComponent
def label_text
raise "Specify the label text to be used for this component"
end
-
- def link_css_class
- "button -primary"
- end
-
- def icon
- helpers.op_icon("button--icon icon-add")
- end
end
diff --git a/modules/boards/app/components/boards/add_button_component.rb b/modules/boards/app/components/boards/add_button_component.rb
index fb2eac3cf06..495cde364bb 100644
--- a/modules/boards/app/components/boards/add_button_component.rb
+++ b/modules/boards/app/components/boards/add_button_component.rb
@@ -47,6 +47,10 @@ module Boards
"add-board-button"
end
+ def test_selector
+ "add-board-button"
+ end
+
def accessibility_label_text
I18n.t("boards.label_create_new_board")
end
diff --git a/modules/boards/app/views/boards/boards/index.html.erb b/modules/boards/app/views/boards/boards/index.html.erb
index 56996a595d0..256a0c4ae14 100644
--- a/modules/boards/app/views/boards/boards/index.html.erb
+++ b/modules/boards/app/views/boards/boards/index.html.erb
@@ -40,7 +40,7 @@ See COPYRIGHT and LICENSE files for more details.
<%=
render Primer::OpenProject::SubHeader.new do |subheader|
- subheader.with_action_component(data: { "test-selector": "add-board-button"}) do
+ subheader.with_action_component do
render Boards::AddButtonComponent.new(current_project: @project)
end
end
diff --git a/modules/boards/spec/features/support/board_index_page.rb b/modules/boards/spec/features/support/board_index_page.rb
index 96083f2371c..bdcae4a11fd 100644
--- a/modules/boards/spec/features/support/board_index_page.rb
+++ b/modules/boards/spec/features/support/board_index_page.rb
@@ -59,11 +59,9 @@ module Pages
def create_board(action: "Basic", title: "#{action} Board", expect_empty: false, via_toolbar: true)
if via_toolbar
- within '[data-test-selector="add-board-button"]' do
- click_link "Board"
- end
+ page.find_test_selector("add-board-button").click
else
- find('[data-test-selector="boards--create-button"]').click
+ page.find_test_selector("boards--create-button").click
end
new_board_page = NewBoard.new
diff --git a/modules/boards/spec/features/support/board_list_page.rb b/modules/boards/spec/features/support/board_list_page.rb
index 921ae9ad134..e7720229b8b 100644
--- a/modules/boards/spec/features/support/board_list_page.rb
+++ b/modules/boards/spec/features/support/board_list_page.rb
@@ -35,15 +35,11 @@ module Pages
end
def expect_create_button
- within '[data-test-selector="add-board-button"]' do
- expect(page).to have_link "Board"
- end
+ expect(page).to have_test_selector "add-board-button"
end
def expect_no_create_button
- within '[data-test-selector="add-board-button"]' do
- expect(page).to have_no_link "Board"
- end
+ expect(page).not_to have_test_selector "add-board-button"
end
def expect_delete_buttons(*boards)
diff --git a/modules/boards/spec/features/support/board_new_page.rb b/modules/boards/spec/features/support/board_new_page.rb
index 869040a692e..f41ffca0ba2 100644
--- a/modules/boards/spec/features/support/board_new_page.rb
+++ b/modules/boards/spec/features/support/board_new_page.rb
@@ -13,9 +13,7 @@ module Pages
def navigate_by_create_button
visit work_package_boards_path unless page.current_path == work_package_boards_path
- within '[data-test-selector="add-board-button"]' do
- click_link "Board"
- end
+ page.find_test_selector("add-board-button").click
end
def set_title(title)
diff --git a/modules/calendar/app/components/calendar/add_button_component.html.erb b/modules/calendar/app/components/calendar/add_button_component.html.erb
deleted file mode 100644
index b1da75b2a66..00000000000
--- a/modules/calendar/app/components/calendar/add_button_component.html.erb
+++ /dev/null
@@ -1,8 +0,0 @@
-<a href="<%= dynamic_path %>"
- id="<%= id %>"
- title="<%= title %>"
- arial-label="<%= aria_label %>"
- class="<%= link_css_class %>">
- <%= icon %>
- <%= label %>
-</a>
diff --git a/modules/calendar/app/components/calendar/add_button_component.rb b/modules/calendar/app/components/calendar/add_button_component.rb
index 95d23f979aa..c825653bcce 100644
--- a/modules/calendar/app/components/calendar/add_button_component.rb
+++ b/modules/calendar/app/components/calendar/add_button_component.rb
@@ -51,6 +51,10 @@ module Calendar
"add-calendar-button"
end
+ def test_selector
+ "add-calendar-button"
+ end
+
def accessibility_label_text
I18n.t("js.calendar.create_new")
end
diff --git a/modules/calendar/app/views/calendar/calendars/index.html.erb b/modules/calendar/app/views/calendar/calendars/index.html.erb
index f1d7cdbf2b6..f380220465b 100644
--- a/modules/calendar/app/views/calendar/calendars/index.html.erb
+++ b/modules/calendar/app/views/calendar/calendars/index.html.erb
@@ -39,7 +39,7 @@ See COPYRIGHT and LICENSE files for more details.
<%=
render Primer::OpenProject::SubHeader.new do |subheader|
- subheader.with_action_component(data: { "test-selector": "add-calendar-button"}) do
+ subheader.with_action_component do
render Calendar::AddButtonComponent.new(current_project: @project)
end
end
diff --git a/modules/calendar/spec/features/calendar_sharing_spec.rb b/modules/calendar/spec/features/calendar_sharing_spec.rb
index 46dd7c32aec..dc75f286c40 100644
--- a/modules/calendar/spec/features/calendar_sharing_spec.rb
+++ b/modules/calendar/spec/features/calendar_sharing_spec.rb
@@ -140,7 +140,7 @@ RSpec.describe "Calendar sharing via ical", :js do
it "shows disabled sharing menu item" do
visit project_calendars_path(project)
- click_link "Create new calendar"
+ page.find_test_selector("add-calendar-button").click
# wait for settings button to become visible
expect(page).to have_css("#work-packages-settings-button")
diff --git a/modules/calendar/spec/support/pages/calendar.rb b/modules/calendar/spec/support/pages/calendar.rb
index 1f04bb41fc4..be68b344b29 100644
--- a/modules/calendar/spec/support/pages/calendar.rb
+++ b/modules/calendar/spec/support/pages/calendar.rb
@@ -140,9 +140,7 @@ module Pages
end
def click_on_create_button
- within '[data-test-selector="add-calendar-button"]' do
- click_link "Calendar"
- end
+ page.find_test_selector("add-calendar-button").click
end
def click_on_cancel_button
@@ -150,19 +148,19 @@ module Pages
end
def expect_create_button
- expect(page).to have_css ".button", text: "Calendar"
+ expect(page).to have_test_selector "add-calendar-button"
end
def expect_no_create_button
- expect(page).to have_no_css ".button", text: "Calendar"
+ expect(page).not_to have_test_selector "add-calendar-button"
end
def expect_delete_button(query)
- expect(page).to have_css "[data-test-selector='calendar-remove-#{query.id}']"
+ expect(page).to have_test_selector "calendar-remove-#{query.id}"
end
def expect_no_delete_button(query)
- expect(page).to have_no_css "[data-test-selector='calendar-remove-#{query.id}']"
+ expect(page).not_to have_test_selector "calendar-remove-#{query.id}"
end
def expect_no_views_visible
diff --git a/modules/team_planner/app/components/team_planner/add_button_component.rb b/modules/team_planner/app/components/team_planner/add_button_component.rb
index 3724dee5c52..19653b26861 100644
--- a/modules/team_planner/app/components/team_planner/add_button_component.rb
+++ b/modules/team_planner/app/components/team_planner/add_button_component.rb
@@ -47,6 +47,10 @@ module TeamPlanner
"add-team-planner-button"
end
+ def test_selector
+ "add-team-planner-button"
+ end
+
def accessibility_label_text
I18n.t("team_planner.label_create_new_team_planner")
end
diff --git a/modules/team_planner/app/views/team_planner/team_planner/index.html.erb b/modules/team_planner/app/views/team_planner/team_planner/index.html.erb
index 9cfb95ae7a9..73b03fe6f65 100644
--- a/modules/team_planner/app/views/team_planner/team_planner/index.html.erb
+++ b/modules/team_planner/app/views/team_planner/team_planner/index.html.erb
@@ -10,7 +10,7 @@
<%=
render Primer::OpenProject::SubHeader.new do |subheader|
- subheader.with_action_component(data: { "test-selector": "add-team-planner-button"}) do
+ subheader.with_action_component do
render ::TeamPlanner::AddButtonComponent.new(current_project: @project)
end
end
diff --git a/modules/team_planner/app/views/team_planner/team_planner/overview.html.erb b/modules/team_planner/app/views/team_planner/team_planner/overview.html.erb
index 0cfe3fd8cd6..a123874b152 100644
--- a/modules/team_planner/app/views/team_planner/team_planner/overview.html.erb
+++ b/modules/team_planner/app/views/team_planner/team_planner/overview.html.erb
@@ -9,7 +9,7 @@
<%=
render Primer::OpenProject::SubHeader.new do |subheader|
- subheader.with_action_component(data: { "test-selector": "add-team-planner-button"}) do
+ subheader.with_action_component do
render ::TeamPlanner::AddButtonComponent.new
end
end
diff --git a/modules/team_planner/spec/features/team_planner_spec.rb b/modules/team_planner/spec/features/team_planner_spec.rb
index 5fd1465fc86..b29c0e4304a 100644
--- a/modules/team_planner/spec/features/team_planner_spec.rb
+++ b/modules/team_planner/spec/features/team_planner_spec.rb
@@ -43,7 +43,7 @@ RSpec.describe "Team planner",
end
expect(page).to have_content "There is currently nothing to display."
- click_on "Create", match: :first
+ page.find_test_selector("add-team-planner-button").click
team_planner.expect_title
diff --git a/modules/team_planner/spec/support/pages/team_planner.rb b/modules/team_planner/spec/support/pages/team_planner.rb
index 99cbfb08591..63751740896 100644
--- a/modules/team_planner/spec/support/pages/team_planner.rb
+++ b/modules/team_planner/spec/support/pages/team_planner.rb
@@ -172,15 +172,11 @@ module Pages
end
def expect_create_button
- within '[data-test-selector="add-team-planner-button"]' do
- expect(page).to have_link text: "Team planner"
- end
+ expect(page).to have_test_selector "add-team-planner-button"
end
def expect_no_create_button
- within '[data-test-selector="add-team-planner-button"]' do
- expect(page).to have_no_link text: "Team planner"
- end
+ expect(page).not_to have_test_selector "add-team-planner-button"
end
def expect_views_listed_in_order(*queries)
@@ -192,9 +188,7 @@ module Pages
end
def click_on_create_button
- within '[data-test-selector="add-team-planner-button"]' do
- click_link "Team planner"
- end
+ page.find_test_selector("add-team-planner-button").click
end
def click_on_cancel_button