Skip to content

Commit

Permalink
Use Primer Button for "AddButtonComponent"
Browse files Browse the repository at this point in the history
  • Loading branch information
HDinger committed Oct 11, 2024
1 parent d200c26 commit efe54cf
Show file tree
Hide file tree
Showing 17 changed files with 42 additions and 66 deletions.
20 changes: 11 additions & 9 deletions app/components/add_button_component.html.erb
Original file line number Diff line number Diff line change
@@ -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
%>
14 changes: 0 additions & 14 deletions app/components/add_button_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,6 @@ def title
accessibility_label_text
end

def label
content_tag(:span,
label_text,
class: "button--text")
end

def aria_label
accessibility_label_text
end
Expand All @@ -65,12 +59,4 @@ def accessibility_label_text
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
4 changes: 4 additions & 0 deletions modules/boards/app/components/boards/add_button_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ def id
"add-board-button"
end

def test_selector
"add-board-button"
end

def accessibility_label_text
I18n.t("boards.label_create_new_board")
end
Expand Down
2 changes: 1 addition & 1 deletion modules/boards/app/views/boards/boards/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 2 additions & 4 deletions modules/boards/spec/features/support/board_index_page.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,9 @@ def expect_board(name, present: true)

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
Expand Down
8 changes: 2 additions & 6 deletions modules/boards/spec/features/support/board_list_page.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,11 @@ def visit!
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)
Expand Down
4 changes: 1 addition & 3 deletions modules/boards/spec/features/support/board_new_page.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ def visit!
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)
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ def id
"add-calendar-button"
end

def test_selector
"add-calendar-button"
end

def accessibility_label_text
I18n.t("js.calendar.create_new")
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion modules/calendar/spec/features/calendar_sharing_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@
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")
Expand Down
12 changes: 5 additions & 7 deletions modules/calendar/spec/support/pages/calendar.rb
Original file line number Diff line number Diff line change
Expand Up @@ -140,29 +140,27 @@ def click_on_submit
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
click_on "Cancel"
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ def id
"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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion modules/team_planner/spec/features/team_planner_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
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

Expand Down
12 changes: 3 additions & 9 deletions modules/team_planner/spec/support/pages/team_planner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -172,15 +172,11 @@ def expect_view_not_rendered(query)
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)
Expand All @@ -192,9 +188,7 @@ def expect_views_listed_in_order(*queries)
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
Expand Down

0 comments on commit efe54cf

Please sign in to comment.