Files
discourse/spec/system/user_activity_posts_spec.rb
Alan Guo Xiang Tan f6eb2e083c DEV: Resolve flaky test due to regexp match (#32343)
The test being fixed in this commit was flaking with the following
error:

```
Capybara::Ambiguous:
  Ambiguous match, found 2 elements matching visible css ".stream-topic-title .title a[href*='/2']"
```

The regexp match on the `href` attribute has the potential to match
multiple elements if both urls contain the `/#{topic.id}` substring. For
example, both `/t/-/2/2` and `/t/-/1/2` will satisfy the regexp.
2025-04-17 09:32:22 +08:00

28 lines
943 B
Ruby

# frozen_string_literal: true
describe "User activity posts", type: :system do
before_all { UserActionManager.enable }
fab!(:user)
fab!(:topic1) do
Fabricate(:topic, title: "Title with & characters and emoji :wave:").tap do |t|
Fabricate.times(2, :post, topic: t, user: user).each { |p| UserActionManager.post_created(p) }
end
end
fab!(:topic2) do
Fabricate(:topic).tap do |t|
Fabricate.times(2, :post, topic: t, user: user).each { |p| UserActionManager.post_created(p) }
end
end
it "lists posts with correctly-formatted titles" do
visit "/u/#{user.username_lower}/activity/replies"
expect(page).to have_css(".stream-topic-title .title", count: 2)
title_element = find(".stream-topic-title .title a[href*='/#{topic1.id}/']")
expect(title_element).to have_text("Title with & characters and emoji")
expect(title_element).to have_css("img.emoji[title='wave']")
end
end