Add request spec for report indicator

This commit is contained in:
Andreas Nedbal 2024-03-01 23:42:55 +01:00 committed by Andreas Nedbal
parent 92c9ed011f
commit 99faf075ff
2 changed files with 53 additions and 0 deletions

View File

@ -70,6 +70,7 @@ RSpec.configure do |config|
config.include Devise::Test::ControllerHelpers, type: :controller config.include Devise::Test::ControllerHelpers, type: :controller
config.include Devise::Test::ControllerHelpers, type: :helper config.include Devise::Test::ControllerHelpers, type: :helper
config.include Devise::Test::ControllerHelpers, type: :view config.include Devise::Test::ControllerHelpers, type: :view
config.include Devise::Test::IntegrationHelpers, type: :request
config.include ViewComponent::TestHelpers, type: :component config.include ViewComponent::TestHelpers, type: :component
config.include ViewComponent::SystemTestHelpers, type: :component config.include ViewComponent::SystemTestHelpers, type: :component
end end

View File

@ -0,0 +1,52 @@
# frozen_string_literal: true
require "rails_helper"
RSpec.describe "New reports indicator", type: :request do
let(:user) { FactoryBot.create(:user, roles: [:moderator]) }
before do
sign_in user
end
subject { get "/" }
describe "setting an assign for new reports" do
context "never visited the reports listing before" do
it "sets a assign" do
subject
expect(assigns["has_new_reports"]).to eq(true)
end
end
context "visited the reports listing, with no new reports" do
before do
user.last_reports_visit = DateTime.now
user.save
end
it "sets a assign" do
subject
expect(assigns["has_new_reports"]).to eq(false)
end
end
context "visited the reports listing, with new reports" do
let(:other_user) { FactoryBot.create :user }
before do
Report.create(user:, target_id: other_user.id, target_user_id: other_user.id, type: "Reports::User", created_at: DateTime.now)
user.last_reports_visit = DateTime.now - 1.day
user.save
end
it "sets a assign" do
subject
expect(assigns["has_new_reports"]).to eq(true)
end
end
end
end