<commit_before>require "test_helper"

class AnnouncementsControllerTest < ActionController::TestCase
  include ActionView::Helpers::DateHelper

  should_be_a_public_facing_controller
  should_show_featured_documents_for :news_article

  test "index highlights three featured news articles" do
    articles = 3.times.map do |n|
      create(:published_news_article, featured: true, published_at: n.days.ago)
    end

    get :index

    assert_equal articles.take(3), assigns[:featured_news_articles]
    assert_select '.featured_items' do
      articles.take(3).each do |article|
        assert_select_object article
      end
    end
  end

  test "index shows news and speeches from the last 24 hours" do
    older_announcements = [create(:published_news_article, published_at: 25.hours.ago), create(:published_speech, published_at: 26.hours.ago)]
    announced_today = [create(:published_news_article, published_at: Time.zone.now), create(:published_speech, published_at: (23.hours.ago + 59.minutes))]

    get :index

    assert_equal announced_today, assigns[:announced_today]

    assert_select '#last_24_hours' do
      announced_today.each do |announcement|
        assert_select_object announcement
      end
    end
  end

  test "featured stories should not appear in the last 24 hours or last 7 days lists of announcements" do
    featured = [<commit_msg>Add tests to check for featured document image on announcements page.<commit_after>require "test_helper"

class AnnouncementsControllerTest < ActionController::TestCase
  include ActionView::Helpers::DateHelper

  should_be_a_public_facing_controller
  should_show_featured_documents_for :news_article

  test "index highlights three featured news articles" do
    articles = 3.times.map do |n|
      create(:published_news_article, featured: true, published_at: n.days.ago)
    end

    get :index

    assert_equal articles.take(3), assigns[:featured_news_articles]
    assert_select '.featured_items' do
      articles.take(3).each do |article|
        assert_select_object article
      end
    end
  end

  test "index should display an image for a featured news article if it has one" do
    image = create(:featured_document_image, image: fixture_file_upload('portas-review.jpg'))
    document = create(:published_news_article, featured: true, featured_document_image: image)
    get :index
    assert_select featured_news_articles_selector do
      assert_select_object document do
        assert_select ".img img[src$='portas-review.jpg']"
      end
    end
  end

  test "index should not display an image for a featured news article if it does not have one" do
    document = create(:published_news_article, featured: true, featured_document_image: nil)
    get :index
    assert_select featured_news_articles_selector do
      assert_select_object document do
        refute_select ".img img"
      end
    end
  end

  test "index shows news and speeches from the last 24 hours" do
    older_announcements = [create(:published_news_article, published_at: 25.hours.ago), create(:published_speech, published_at: 26.hours.ago)]
    announced_today = [create(:published_news_article, published_at: Time.zone.now), create(:published_speech, published_at: (23.hours.ago + 59.minutes))]

    get :index

    assert_equal announced_today, assigns[:announced_today]

    assert_select '#last_24_hours' do
      announced_today.each do |announcement|
        assert_select_object announcement
      end
    end
  end

  test "featured stories should not appear in the last 24 hours or last 7 days lists of announcements" do
    featured = [
{'fraction_non_alphanumeric': 0.07063711911357341, 'fraction_numerical': 0.009972299168975069, 'mean_word_length': 4.188218390804598, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, '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': '4932608', 'n_tokens_mistral': 1089, 'n_tokens_neox': 1006, 'n_words': 303}