Extract matcher to check for avatars

We're going to change the code to render avatars, and having a matcher
will make it easier.
This commit is contained in:
Javi Martín
2024-04-08 03:04:04 +02:00
parent 9beb1608c4
commit d3b1b21d3d
6 changed files with 19 additions and 14 deletions

View File

@@ -18,8 +18,4 @@ module Comments
end
expect(page).to have_content "It will be done next week."
end
def avatar(name)
"img.initialjs-avatar[data-name='#{name}']"
end
end

View File

@@ -0,0 +1,9 @@
RSpec::Matchers.define :have_avatar do |name, **options|
match do
has_css?("img.initialjs-avatar[data-name='#{name}'][src^='data:image/svg']", **options)
end
failure_message do
"expected to find avatar with name #{name} but there were no matches."
end
end

View File

@@ -15,7 +15,7 @@ describe "Account" do
expect(page).to have_current_path(account_path, ignore_query: true)
expect(page).to have_css "input[value='Manuela Colau']"
expect(page).to have_css avatar("Manuela Colau"), count: 1
expect(page).to have_avatar "Manuela Colau", count: 1
end
scenario "Show organization" do
@@ -26,7 +26,7 @@ describe "Account" do
expect(page).to have_css "input[value='Manuela Corp']"
expect(page).not_to have_css "input[value='Manuela Colau']"
expect(page).to have_css avatar("Manuela Corp"), count: 1
expect(page).to have_avatar "Manuela Corp", count: 1
end
scenario "Edit" do

View File

@@ -72,15 +72,15 @@ describe "Debates" do
end
scenario "Show" do
debate = create(:debate)
debate = create(:debate, author: create(:user, username: "Charles Dickens"))
visit debate_path(debate)
expect(page).to have_content debate.title
expect(page).to have_content "Debate description"
expect(page).to have_content debate.author.name
expect(page).to have_content "Charles Dickens"
expect(page).to have_content I18n.l(debate.created_at.to_date)
expect(page).to have_css avatar(debate.author.name)
expect(page).to have_avatar "Charles Dickens"
expect(page.html).to include "<title>#{debate.title}</title>"
end

View File

@@ -114,16 +114,16 @@ describe "Proposals" do
end
scenario "Show" do
proposal = create(:proposal)
proposal = create(:proposal, author: create(:user, username: "Mark Twain"))
visit proposal_path(proposal)
expect(page).to have_content proposal.title
expect(page).to have_content proposal.code
expect(page).to have_content "Proposal description"
expect(page).to have_content proposal.author.name
expect(page).to have_content "Mark Twain"
expect(page).to have_content I18n.l(proposal.created_at.to_date)
expect(page).to have_css avatar(proposal.author.name)
expect(page).to have_avatar "Mark Twain"
expect(page.html).to include "<title>#{proposal.title}</title>"
expect(page).not_to have_css ".js-flag-actions"
expect(page).not_to have_css ".js-follow"

View File

@@ -488,14 +488,14 @@ describe "Users" do
describe "Initials" do
scenario "display SVG avatars when loaded into the DOM" do
login_as(create(:user))
login_as(create(:user, username: "Commentator"))
visit debate_path(create(:debate))
fill_in "Leave your comment", with: "I'm awesome"
click_button "Publish comment"
within ".comment", text: "I'm awesome" do
expect(page).to have_css "img.initialjs-avatar[src^='data:image/svg']"
expect(page).to have_avatar "Commentator"
end
end
end