<commit_before>require 'integration_test_helper'

class NotificationsTest < ActionDispatch::IntegrationTest
  context "emergency banner file" do
    should "have an emergency banner file" do
      assert File.exist? "#{Rails.root}/app/views/notifications/_emergency_banner.html.erb"
    end
  end

  context "emergency banner notifications" do
    should "not render a banner if one does not exist" do
      EmergencyBanner::Display.any_instance.stubs(:enabled?).returns(false)
      visit "/templates/wrapper.html.erb"
      refute page.has_selector? ".govuk-emergency-banner"
    end

    should "render a banner if one does exist" do
      EmergencyBanner::Display.any_instance.stubs(:enabled?).returns(true)
      visit "/templates/wrapper.html.erb"
      assert page.has_selector? ".govuk-emergency-banner"
    end

    should "render a banner with a heading and campaign colour" do
      EmergencyBanner::Display.any_instance.stubs(:heading).returns("Alas poor Yorick")
      EmergencyBanner::Display.any_instance.stubs(:campaign_class).returns("notable-death")

      visit "/templates/wrapper.html.erb"

      assert page.has_selector? ".govuk-emergency-banner.notable-death"
      assert_match 'Alas poor Yorick', page.body
    end

    should "render the more information link" do
      EmergencyBanner::Display.any_instance.stubs(:heading).returns("Alas poor Yorick")
      EmergencyBanner::Display.any_instance.stubs(:campaign_class).returns("notable-death")
      EmergencyBanner::Display.any_instance.stubs(:link).returns("https://yoricks.gov")

      visit "/templates/wrapper.html.erb"

      assert_match "More information", page.body
      assert_match(/yoricks\.gov/, page.body)
    end

    should "render the more information link with specified text" do
      EmergencyBanner::Display.any_instance.stubs(:heading).returns("Alas poor Yorick")
      EmergencyBanner::Display.any_instance.stubs(:campaign_class).returns("notable-death")
      EmergencyBanner::Display.any_instance.stubs(:link).returns("https://yoricks.gov")
      EmergencyBanner::Display.any_instance.stubs(:link_text).returns("Some specified text for more information")

      visit "/templates/wrapper.html.erb"

      assert_match "Some specified text for more information", page.body
    end

    should "not render the more information link if it does not exist" do
      EmergencyBanner::Display.any_instance.stubs(:heading).returns("Alas poor Yorick")
      EmergencyBanner::Display.any_instance.stubs(:campaign_class).returns("notable-death")
      EmergencyBanner::Display.any_instance.stubs(:link).returns(nil)

      visit "/templates/wrapper.html.erb"

      refute page.has_selector? ".more-information"
      refute_match(/yoricks\.gov/, page.body)
    end

    should "render the extra information" do
      EmergencyBanner::Display.any_instance.stubs(:heading).returns("Alas poor Yorick")
      EmergencyBanner::Display.any_instance.stubs(:campaign_class).returns("notable-death")
      EmergencyBanner::Display.any_instance.stubs(:short_description).returns("I knew him well")

      visit "/templates/wrapper.html.erb"

      assert_match "I knew him well", page.body
    end

    should "does not render the extra information if it does not exist" do
      EmergencyBanner::Display.any_instance.stubs(:heading).returns("Alas poor Yorick")
      EmergencyBanner::Display.any_instance.stubs(:campaign_class).returns("notable-death")
      EmergencyBanner::Display.any_instance.stubs(:short_description).returns(nil)

      visit "/templates/wrapper.html.erb"

      refute_match "I knew him well", page.body
    end
  end
end<commit_msg>Stub out Redis dependency<commit_after>require 'integration_test_helper'

class NotificationsTest < ActionDispatch::IntegrationTest
  def stub_redis_response(hash)
    Redis.any_instance.stubs(:hgetall).with("emergency_banner").returns(hash)
  end

  context "emergency banner file" do
    should "have an emergency banner file" do
      assert File.exist? "#{Rails.root}/app/views/notifications/_emergency_banner.html.erb"
    end
  end

  context "emergency banner notifications" do
    should "not render a banner if one does not exist" do
      visit "/templates/wrapper.html.erb"
      refute page.has_selector? ".govuk-emergency-banner"
    end

    should "render a banner if one does exist" do
      stub_redis_response(campaign_class: "foo", heading: "bar")

      visit "/templates/wrapper.html.erb"
      assert page.has_selector? ".govuk-emergency-banner"
    end

    should "render a banner with a heading and campaign colour" do
      stub_redis_response(campaign_class: "notable-death", heading: "Alas poor Yorick")

      visit "/templates/wrapper.html.erb"

      assert page.has_selector? ".govuk-emergency-banner.notable-death"
      assert_match 'Alas poor Yorick', page.body
    end

    should "render the more information link" do
      stub_redis_response(campaign_class: "notable-death",
                          heading: "Alas poor Yorick",
                          link: "https://yoricks.gov")

      visit "/templates/wrapper.html.erb"

      assert_match "More information", page.body
      assert_match(/yoricks\.gov/, page.body)
    end

    should "render the more information link with specified text" do
      stub_redis_response(campaign_class: "notable-death",
                          heading: "Alas poor Yorick",
                          link: "https://yoricks.gov",
                          link_text: "Some specified text for more information")

      visit "/templates/wrapper.html.erb"

      assert_match "Some specified text for more information", page.body
    end

    should "not render the more information link if it does not exist" do
      stub_redis_response(campaign_class: "notable-death",
                          heading: "Alas poor Yorick")

      visit "/templates/wrapper.html.erb"

      refute page.has_selector? ".more-information"
      refute_match(/yoricks\.gov/, page.body)
    end

    should "render the extra information" do
      stub_redis_response(campaign_class: "notable-death",
                          heading: "Alas poor Yorick",
                          short_description: "I knew him well")

      visit "/templates/wrapper.html.erb"

      assert_match "I knew him well", page.body
    end

    should "does not render the extra information if it does not exist" do
      stub_redis_response(campaign_class: "notable-death",
                          heading: "Alas poor Yorick")

      visit "/templates/wrapper.html.erb"

      refute_match "I knew him well", page.body
    end
  end
end
{'fraction_non_alphanumeric': 0.10122374981114972, 'fraction_numerical': 0.0, 'mean_word_length': 3.2987012987012987, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4924326', 'n_tokens_mistral': 1998, 'n_tokens_neox': 1893, 'n_words': 458}