Skip to content

Commit

Permalink
Add banner view tests
Browse files Browse the repository at this point in the history
  • Loading branch information
carrollsa committed Aug 10, 2023
1 parent 60602e9 commit 6f3f826
Showing 1 changed file with 66 additions and 0 deletions.
66 changes: 66 additions & 0 deletions spec/views/banners/new.html.erb_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
require "rails_helper"

RSpec.describe "banners/new", type: :view do
context "when new banner is marked as inactive" do
it "does not warn that current active banner will be deactivated" do
user = build_stubbed(:casa_admin)
current_organization = user.casa_org
current_organization_banner = build(:banner, active: true, casa_org: current_organization)

allow(view).to receive(:current_user).and_return(user)
allow(view).to receive(:current_organization).and_return(current_organization)

assign :banners, [current_organization_banner]
assign :banner, Banner.new(active: false)
assign :has_alternate_active_banner, true

render template: "banners/new"

expect(rendered).not_to have_checked_field("banner_active")
expect(rendered).to have_css("span.d-none", text: "Warning: This will replace your current active banner")
end
end

context "when organization has an active banner" do
context "when new banner is marked as active" do
it "warns that current active banner will be deactivated" do
user = build_stubbed(:casa_admin)
current_organization = user.casa_org
current_organization_banner = build(:banner, active: true, casa_org: current_organization)

allow(view).to receive(:current_user).and_return(user)
allow(view).to receive(:current_organization).and_return(current_organization)

assign :banners, [current_organization_banner]
assign :banner, Banner.new(active: true)
assign :has_alternate_active_banner, true

render template: "banners/new"

expect(rendered).to have_checked_field("banner_active")
expect(rendered).not_to have_css("span.d-none", text: "Warning: This will replace your current active banner")
end
end
end

context "when organization has no active banner" do
context "when new banner is marked as active" do
it "does not warn that current active banner will be deactivated" do
user = build_stubbed(:casa_admin)
current_organization = user.casa_org

allow(view).to receive(:current_user).and_return(user)
allow(view).to receive(:current_organization).and_return(current_organization)

assign :banners, []
assign :banner, Banner.new(active: true)
assign :has_alternate_active_banner, false

render template: "banners/new"

expect(rendered).to have_checked_field("banner_active")
expect(rendered).to have_css("span.d-none", text: "Warning: This will replace your current active banner")
end
end
end
end

0 comments on commit 6f3f826

Please sign in to comment.