Skip to content

Commit

Permalink
[#55581] use test selectors in spec
Browse files Browse the repository at this point in the history
  • Loading branch information
EinLama committed Nov 26, 2024
1 parent e145b7c commit 14a83be
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 13 deletions.
20 changes: 15 additions & 5 deletions app/components/users/hover_card_component.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,26 @@ 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

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
Expand All @@ -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
Expand Down
12 changes: 6 additions & 6 deletions spec/features/members/membership_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions spec/support/pages/members.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

##
Expand Down

0 comments on commit 14a83be

Please sign in to comment.