From 14a83be131c8320c354007b973d951bc985652a4 Mon Sep 17 00:00:00 2001 From: Tobias Dillmann Date: Tue, 26 Nov 2024 12:05:52 +0100 Subject: [PATCH] [#55581] use test selectors in spec --- .../users/hover_card_component.html.erb | 20 ++++++++++++++----- spec/features/members/membership_spec.rb | 12 +++++------ spec/support/pages/members.rb | 4 ++-- 3 files changed, 23 insertions(+), 13 deletions(-) diff --git a/app/components/users/hover_card_component.html.erb b/app/components/users/hover_card_component.html.erb index 5d0f2442f0b0..1bc4de56a894 100644 --- a/app/components/users/hover_card_component.html.erb +++ b/app/components/users/hover_card_component.html.erb @@ -29,7 +29,7 @@ See COPYRIGHT and LICENSE files for more details. <%= if @user.present? - flex_layout(classes: 'op-user-hover-card') do |flex| + flex_layout(classes: 'op-user-hover-card', data: { test_selector: "user-hover-card-#{@user.id}" }) do |flex| flex.with_row do render(Users::AvatarComponent.new(user: @user, show_name: false, link: false, hover_card: { active: false })) end @@ -37,12 +37,18 @@ See COPYRIGHT and LICENSE files for more details. flex.with_row do flex_layout(classes: 'op-user-hover-card--info') do |f| f.with_column(classes: 'op-user-hover-card--name') do - render(Primer::Beta::Text.new(font_weight: :semibold)) { @user.name } + render(Primer::Beta::Text.new(font_weight: :semibold, data: { test_selector: 'user-hover-card-name' })) do + @user.name + end end if show_email? f.with_column(classes: 'op-user-hover-card--email') do - render(Primer::Beta::Text.new(font_size: :small, color: :muted)) { @user.mail } + render(Primer::Beta::Text.new(font_size: :small, + color: :muted, + data: { test_selector: 'user-hover-card-email' })) do + @user.mail + end end end end @@ -55,13 +61,17 @@ See COPYRIGHT and LICENSE files for more details. end f.with_column do - render(Primer::Beta::Text.new(color: :muted)) { group_membership_summary } + render(Primer::Beta::Text.new(color: :muted, data: { test_selector: 'user-hover-card-groups' })) do + group_membership_summary + end end end end flex.with_row do - render(Primer::Beta::Button.new(tag: :a, href: helpers.allowed_management_user_profile_path(@user))) do + render(Primer::Beta::Button.new(tag: :a, + href: helpers.allowed_management_user_profile_path(@user), + data: { test_selector: 'user-hover-card-profile-btn' })) do I18n.t("users.open_profile") end end diff --git a/spec/features/members/membership_spec.rb b/spec/features/members/membership_spec.rb index ba1789e574ac..850125f8e771 100644 --- a/spec/features/members/membership_spec.rb +++ b/spec/features/members/membership_spec.rb @@ -144,13 +144,13 @@ row.find(".op-principal--avatar").hover end - members_page.in_user_hover_card do |card| - card.find(".op-user-hover-card--name", text: peter.name) - card.find(".op-user-hover-card--email", text: peter.mail) - card.find(".op-user-hover-card--group-list", text: "Member of #{peter.groups.first.name}") + members_page.in_user_hover_card(peter) do + find_test_selector("user-hover-card-name", text: peter.name) + find_test_selector("user-hover-card-email", text: peter.mail) + find_test_selector("user-hover-card-groups", text: "Member of #{peter.groups.first.name}") - button = card.find(".Button", text: "Open profile") - expect(button["href"]).to eq(user_url(peter)) + button = find_test_selector("user-hover-card-profile-btn", text: "Open profile") + expect(button["href"]).to eq(edit_user_url(peter)) end end diff --git a/spec/support/pages/members.rb b/spec/support/pages/members.rb index 3e1771575fdb..d3367ee23fe6 100644 --- a/spec/support/pages/members.rb +++ b/spec/support/pages/members.rb @@ -82,8 +82,8 @@ def in_user_row(user, &) page.within(".principal-#{user.id}", &) end - def in_user_hover_card(&) - page.within("#op-hover-card-body .op-user-hover-card", &) + def in_user_hover_card(user, &) + page.within_test_selector("user-hover-card-#{user.id}", &) end ##