Skip to content

Commit

Permalink
PR for fix rubyforgood#5924 that should already have merged
Browse files Browse the repository at this point in the history
  • Loading branch information
guswhitten committed Aug 7, 2024
1 parent fddbc40 commit eb7e319
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 42 deletions.
6 changes: 3 additions & 3 deletions spec/factories/notifications.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
casa_case { nil }
end

after(:build) do |notification, eval|
before(:create) do |notification, eval|
notification.params[:created_by] = eval.created_by if eval.created_by.present?
notification.params[:casa_case] = eval.casa_case if eval.casa_case.present?
end
Expand All @@ -20,11 +20,11 @@
end

trait :followup_without_note do
event { association(:followup_notifier, :without_note) }
association :event, factory: [:followup_notifier, :without_note]
end

trait :followup_read do
event { association(:followup_notifier, :read) }
association :event, factory: [:followup_notifier, :read]
read_at { DateTime.current }
seen_at { DateTime.current }
end
Expand Down
111 changes: 72 additions & 39 deletions spec/views/notifications/index.html.erb_spec.rb
Original file line number Diff line number Diff line change
@@ -1,69 +1,78 @@
require "rails_helper"

RSpec.describe "notifications/index", type: :view do
let(:notification_1_hour_ago) { create(:notification, :followup_with_note) }
let(:notification_1_day_ago) { create(:notification, :emancipation_checklist_reminder) }
let(:notification_2_days_ago) { create(:notification, :youth_birthday) }
let(:notification_3_days_ago) { create(:notification, :reimbursement_complete) }

let(:patch_note_group_all_users) { create(:patch_note_group, :all_users) }
let(:patch_note_group_no_volunteers) { create(:patch_note_group, :only_supervisors_and_admins) }
let(:patch_note_type_a) { create(:patch_note_type, name: "patch_note_type_a") }
let(:patch_note_type_b) { create(:patch_note_type, name: "patch_note_type_b") }
let(:patch_note_1) { create(:patch_note, note: "Patch Note 1", patch_note_type: patch_note_type_a) }
let(:patch_note_2) { create(:patch_note, note: "Patch Note B", patch_note_type: patch_note_type_b) }

before do
travel_to Date.new(2021, 1, 1)
assign(:notifications, Noticed::Notification.all)
assign(:patch_notes, PatchNote.all)
assign(:deploy_time, deploy_time)
end

context "when there is a deploy date" do
let(:notification_created_after_deploy_a) { create(:notification) }
let(:notification_created_after_deploy_b) { create(:notification) }
let(:notification_created_at_deploy) { create(:notification) }
let(:notification_created_before_deploy_a) { create(:notification) }
let(:notification_created_before_deploy_b) { create(:notification) }
let(:deploy_time) { 2.days.ago }

before do
Health.instance.update_attribute(:latest_deploy_time, 2.days.ago)
Health.instance.update_attribute(:latest_deploy_time, deploy_time)
end

context "when there are notifications" do
before do
# TODO invalid notifications that break the view
# notification_created_after_deploy_a.update_attribute(:created_at, 1.hour.ago)
# notification_created_after_deploy_b.update_attribute(:created_at, 1.day.ago)
# notification_created_at_deploy.update_attribute(:created_at, 2.days.ago)
# notification_created_before_deploy_a.update_attribute(:created_at, 2.days.ago - 1.hour)
# notification_created_before_deploy_b.update_attribute(:created_at, 3.days.ago)
notification_1_hour_ago.update_attribute(:created_at, 1.hour.ago)
notification_1_day_ago.update_attribute(:created_at, 1.day.ago)
notification_2_days_ago.update_attribute(:created_at, 2.days.ago)
notification_3_days_ago.update_attribute(:created_at, 3.days.ago)

patch_note_1.update_attribute(:patch_note_group, patch_note_group_all_users)
end

xit "has all notifications created after and including the deploy date above the patch note" do
# TODO fill in after notification factory is given ability to create a notification with notes
it "has all notifications created after and including the deploy date above the patch note" do
render template: "notifications/index"

notifications_html = Nokogiri::HTML5(rendered).css(".list-group-item")
patch_note_index = notifications_html.index { |node| node.text.include?("Patch Notes") }

expect(notifications_html[0].text).to match(/User \d+ has flagged a Case Contact that needs follow up/)
expect(notifications_html[1].text).to match(/Your case CINA-\d+ is a transition aged youth/)
expect(notifications_html[2].text).to match(/Your youth, case number: CINA-\d+ has a birthday next month/)
expect(patch_note_index).to eq(3)
end

xit "has all notifications created after and including the deploy date above the patch note" do
# TODO fill in after notification factory is filled out
it "has all notifications created before the deploy date below the patch note" do
render template: "notifications/index"

notifications_html = Nokogiri::HTML5(rendered).css(".list-group-item")
patch_note_index = notifications_html.index { |node| node.text.include?("Patch Notes") }

expect(patch_note_index).to eq(3)
expect(notifications_html[patch_note_index + 1].text).to match(/Volunteer User \d+'s request for reimbursement for 0mi on .* has been processed and is en route./)
end
end

context "when there are patch notes" do
let(:patch_note_group_all_users) { create(:patch_note_group, :all_users) }
let(:patch_note_group_no_volunteers) { create(:patch_note_group, :only_supervisors_and_admins) }
let(:patch_note_type_a) { create(:patch_note_type, name: "patch_note_type_a") }
let(:patch_note_type_b) { create(:patch_note_type, name: "patch_note_type_b") }
let(:patch_note_1) { create(:patch_note, note: "Patch Note 1", patch_note_type: patch_note_type_a) }
let(:patch_note_2) { create(:patch_note, note: "Patch Note B", patch_note_type: patch_note_type_b) }

before do
Health.instance.update_attribute(:latest_deploy_time, Date.today)
assign(:notifications, Noticed::Notification.all)
patch_note_1.update_attribute(:patch_note_group, patch_note_group_all_users)
patch_note_2.update_attribute(:patch_note_group, patch_note_group_no_volunteers)
end

it "shows all the patch notes available" do
assign(:patch_notes, PatchNote.all)
assign(:deploy_time, Time.now)

render template: "notifications/index"

expect(rendered).to have_text(patch_note_1.note)
expect(rendered).to have_text(patch_note_2.note)
expect(rendered).to have_text("Patch Note 1")
expect(rendered).to have_text("Patch Note B")
end

it "shows the patch notes under the correct type" do
assign(:patch_notes, PatchNote.all)
assign(:deploy_time, Time.now)

render template: "notifications/index"

queryable_html = Nokogiri.HTML5(rendered)
Expand All @@ -72,17 +81,41 @@
patch_note_type_b_header = queryable_html.xpath("//*[text()[contains(.,'#{patch_note_type_b.name}')]]").first

patch_note_a_data = patch_note_type_a_header.parent.css("ul").first
expect(patch_note_a_data.text).to include(patch_note_1.note)
expect(patch_note_a_data.text).to include("Patch Note 1")

patch_note_b_data = patch_note_type_b_header.parent.css("ul").first
expect(patch_note_b_data.text).to include(patch_note_2.note)
expect(patch_note_b_data.text).to include("Patch Note B")
end
end
end

context "without a deploy date" do
xit "shows the correct number of notifications" do
# TODO fill in after notification factory is given ability to create displayable notifications
let(:deploy_time) { nil }

before do
notification_1_hour_ago.update_attribute(:created_at, 1.hour.ago)
notification_1_day_ago.update_attribute(:created_at, 1.day.ago)
notification_2_days_ago.update_attribute(:created_at, 2.days.ago)
notification_3_days_ago.update_attribute(:created_at, 3.days.ago)

patch_note_1.update_attribute(:patch_note_group, patch_note_group_all_users)
patch_note_2.update_attribute(:patch_note_group, patch_note_group_no_volunteers)
end

it "shows the correct number of notifications" do
render template: "notifications/index"

expect(rendered).to have_css(".list-group-item", count: 4)
end

it "does not display patch notes" do
render template: "notifications/index"

notifications_html = Nokogiri::HTML5(rendered).css(".list-group-item")
view_patch_notes = notifications_html.select { |node| node.text.include?("Patch Notes") }

expect(PatchNote.all.size).to eql(2)
expect(view_patch_notes).to be_empty
end
end
end
end

0 comments on commit eb7e319

Please sign in to comment.