<commit_before>require 'rails_helper'

feature 'Poll budget ballot sheets' do
  let(:budget) { create(:budget) }
  let(:poll) { create(:poll, budget: budget, ends_at: 1.day.ago) }
  let(:booth) { create(:poll_booth) }
  let(:poll_officer) { create(:poll_officer) }

  context "Officing recounts and results view" do

    background do
      create(:poll_booth_assignment, poll: poll, booth: booth)
      create(:poll_shift, :recount_scrutiny_task, officer: poll_officer, booth: booth,
                                                  date: Date.current)
      create(:poll_officer_assignment, officer: poll_officer)

      login_as(poll_officer.user)
      set_officing_booth(booth)
    end

    scenario "Budget polls are visible" do
      visit root_path
      click_link 'Polling officers'

      within("#side_menu") do
        click_link "Total recounts and results"
      end

      within("#poll_#{poll.id}") do
        expect(page).to have_content("#{poll.name}")
        expect(page).to have_content("See ballot sheets list")
        expect(page).to have_content("Add results")
      end
    end

  end

  context "Booth assignment" do

    scenario "Try to access ballot sheets officing without booth assignment" do
      login_as(poll_officer.user)
      visit officing_poll_ballot_sheets_path(poll)

      expect(page).to have_content "You don't have officing shifts today"
    end

    scenario "Access ballot sheets officing with one booth assignment" do
      create(:poll_booth_assignment, poll: poll, booth: booth)
      create(:poll_shift, :recount_scrutiny_task, officer: poll_officer, booth: booth,
                                                  date: Date.current)
      create(:poll_officer_assignment, officer: poll_officer)

      login_as(poll_officer.user)
      set_officing_booth(booth)

      visit officing_poll_ballot_sheets_path(poll)

      expect(page).to have_content "#{poll.name}"
    end

    scenario "Access ballot sheets officing with multiple booth assignments" do
      booth_2 = create(:poll_booth)
      create(:poll_booth_assignment, poll: poll, booth: booth)
      create(:poll_booth_assignment, poll: poll, booth: booth_2)
      create(:poll_shift, :recount_scrutiny_task, officer: poll_officer, booth: booth,
                                                  date: Date.current)
      create(:poll_shift, :recount_scrutiny_task, officer: poll_officer, booth: booth_2,
                                                  date: Date.current)
      create(:poll_officer_assignment, officer: poll_officer)
      create(:poll_officer_assignment, officer: poll_officer)

      login_as(poll_officer.user)

      visit officing_poll_ballot_sheets_path(poll)

      expect(page).to have_content "Choose your booth"
    end

  end

  context "Index" do

    background do<commit_msg>Fix flaky ballot sheets spec<commit_after>require 'rails_helper'

feature 'Poll budget ballot sheets' do
  let(:budget) { create(:budget) }
  let(:poll) { create(:poll, budget: budget, ends_at: 1.day.ago) }
  let(:booth) { create(:poll_booth) }
  let(:poll_officer) { create(:poll_officer) }

  context "Officing recounts and results view" do

    background do
      create(:poll_booth_assignment, poll: poll, booth: booth)
      create(:poll_shift, :recount_scrutiny_task, officer: poll_officer, booth: booth,
                                                  date: Date.current)
      create(:poll_officer_assignment, officer: poll_officer)

      login_as(poll_officer.user)
      set_officing_booth(booth)
    end

    scenario "Budget polls are visible" do
      visit root_path
      click_link 'Polling officers'

      within("#side_menu") do
        click_link "Total recounts and results"
      end

      within("#poll_#{poll.id}") do
        expect(page).to have_content("#{poll.name}")
        expect(page).to have_content("See ballot sheets list")
        expect(page).to have_content("Add results")
      end
    end

  end

  context "Booth assignment" do

    scenario "Try to access ballot sheets officing without booth assignment" do
      login_as(poll_officer.user)
      visit officing_poll_ballot_sheets_path(poll)

      expect(page).to have_content "You don't have officing shifts today"
    end

    scenario "Access ballot sheets officing with one booth assignment" do
      create(:poll_booth_assignment, poll: poll, booth: booth)
      create(:poll_shift, :recount_scrutiny_task, officer: poll_officer, booth: booth,
                                                  date: Date.current)
      create(:poll_officer_assignment, officer: poll_officer)

      login_as(poll_officer.user)
      set_officing_booth(booth)

      visit officing_poll_ballot_sheets_path(poll)

      expect(page).to have_content "#{poll.name}"
    end

    scenario "Access ballot sheets officing with multiple booth assignments", :with_frozen_time do
      booth_2 = create(:poll_booth)
      create(:poll_booth_assignment, poll: poll, booth: booth)
      create(:poll_booth_assignment, poll: poll, booth: booth_2)
      create(:poll_shift, :recount_scrutiny_task, officer: poll_officer, booth: booth,
                                                  date: Date.current)
      create(:poll_shift, :recount_scrutiny_task, officer: poll_officer, booth: booth_2,
                                                  date: Date.current)
      create(:poll_officer_assignment, officer: poll_officer)
      create(:poll_officer_assignment, officer: poll_officer)

      login_as(poll_officer.user)

      visit officing_poll_ballot_sheets_path(poll)

      expect(page).to have_content "Choose your booth"
    end

  end

  context "Index" do

    background do
{'fraction_non_alphanumeric': 0.08620689655172414, 'fraction_numerical': 0.0014074595355383533, 'mean_word_length': 2.872615803814714, 'pattern_counts': {'":': 0, '<': 3, '<?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': 16, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5209990', 'n_tokens_mistral': 1715, 'n_tokens_neox': 1658, 'n_words': 408}