Files
nairobi/spec/components/users/public_activity_component_spec.rb
Javi Martín 0cec581ec0 Add and apply Capybara/RSpec/HaveSelector rule
This rule was added in rubocop-capybara 2.19.0. We were following it
about 85% of the time.

Now we won't have to check both have_css and have_selector when
searching the code.
2023-11-08 14:18:16 +01:00

111 lines
3.2 KiB
Ruby

require "rails_helper"
describe Users::PublicActivityComponent, controller: UsersController do
include Rails.application.routes.url_helpers
around do |example|
with_request_url(user_path(user)) { example.run }
end
describe "follows tab" do
context "public interests is checked" do
let(:user) { create(:user, public_interests: true) }
let(:component) { Users::PublicActivityComponent.new(user) }
it "is displayed for everyone" do
create(:proposal, author: user, followers: [user])
render_inline component
expect(page).to have_content "1 Following"
end
it "is not displayed when the user isn't following any followables" do
create(:proposal, author: user)
render_inline component
expect(page).not_to have_content "Following"
end
it "is the active tab when the follows filters is selected" do
create(:proposal, author: user, followers: [user])
with_request_url user_path(user, filter: "follows") do
render_inline component
expect(page).to have_css "li.is-active", text: "1 Following"
end
end
end
context "public interests is not checked" do
let(:user) { create(:user, public_interests: false) }
let(:component) { Users::PublicActivityComponent.new(user) }
it "is displayed for its owner" do
create(:proposal, followers: [user])
sign_in(user)
render_inline component
expect(page).to have_content "1 Following"
end
it "is not displayed for anonymous users" do
create(:proposal, author: user, followers: [user])
render_inline component
expect(page).to have_content "1 Proposal"
expect(page).not_to have_content "Following"
end
it "is not displayed for other users" do
create(:proposal, author: user, followers: [user])
sign_in(create(:user))
render_inline component
expect(page).to have_content "1 Proposal"
expect(page).not_to have_content "Following"
end
it "is not displayed for administrators" do
create(:proposal, author: user, followers: [user])
sign_in(create(:administrator).user)
render_inline component
expect(page).to have_content "1 Proposal"
expect(page).not_to have_content "Following"
end
end
end
describe "comments" do
let(:user) { create(:user) }
let(:component) { Users::PublicActivityComponent.new(user) }
it "doesn't show comments for disabled features" do
Setting["process.budgets"] = false
Setting["process.debates"] = false
Setting["process.legislation"] = false
Setting["process.polls"] = false
Setting["process.proposals"] = false
create(:budget_investment_comment, user: user)
create(:debate_comment, user: user)
create(:legislation_annotation_comment, user: user)
create(:legislation_question_comment, user: user)
create(:legislation_proposal_comment, user: user)
create(:poll_comment, user: user)
create(:proposal_comment, user: user)
render_inline component
expect(page).not_to have_content "Comments"
end
end
end