From 99faf075ff343fe883b54e0d8bdee2623b59a1e1 Mon Sep 17 00:00:00 2001 From: Andreas Nedbal Date: Fri, 1 Mar 2024 23:42:55 +0100 Subject: [PATCH] Add request spec for report indicator --- spec/rails_helper.rb | 1 + spec/requests/new_reports_spec.rb | 52 +++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 spec/requests/new_reports_spec.rb diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 74cb6c76..fd019daf 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -70,6 +70,7 @@ RSpec.configure do |config| config.include Devise::Test::ControllerHelpers, type: :controller config.include Devise::Test::ControllerHelpers, type: :helper config.include Devise::Test::ControllerHelpers, type: :view + config.include Devise::Test::IntegrationHelpers, type: :request config.include ViewComponent::TestHelpers, type: :component config.include ViewComponent::SystemTestHelpers, type: :component end diff --git a/spec/requests/new_reports_spec.rb b/spec/requests/new_reports_spec.rb new file mode 100644 index 00000000..cd7e63ba --- /dev/null +++ b/spec/requests/new_reports_spec.rb @@ -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