<commit_before>require 'rails_helper'

feature 'Budget Investments' do

  let(:author)  { create(:user, :level_two, username: 'Isabel') }
  let(:budget)  { create(:budget, name: "Big Budget") }
  let(:group)   { create(:budget_group, name: "Health", budget: budget) }
  let!(:heading) { create(:budget_heading, name: "More hospitals", group: group) }

  scenario 'Index' do
    investments = [create(:budget_investment, heading: heading), create(:budget_investment, heading: heading), create(:budget_investment, :feasible, heading: heading)]
    unfeasible_investment = create(:budget_investment, :unfeasible, heading: heading)

    visit budget_investments_path(budget, heading_id: heading.id)

    expect(page).to have_selector('#budget-investments .budget-investment', count: 3)
    investments.each do |investment|
      within('#budget-investments') do
        expect(page).to have_content investment.title
        expect(page).to have_css("a[href='#{budget_investment_path(budget_id: budget.id, id: investment.id)}']", text: investment.title)
        expect(page).to_not have_content(unfeasible_investment.title)
      end
    end
  end

  context("Search") do

    scenario 'Search by text' do
      investment1 = create(:budget_investment, heading: heading, title: "Get Schwifty")
      investment2 = create(:budget_investment, heading: heading, title: "Schwifty Hello")
      investment3 = create(:budget_investment, heading: heading, title: "Do not show me")

      visit budget_investments_path(budget, heading_id: heading.id)

      within(".expanded #search_form") do
        fill_in "search", with: "Schwifty"
        click_button "Search"
      end

      within("#budget-investments") do
        expect(page).to have_css('.budget-investment', count: 2)

        expect(page).to have_content(investment1.title)
        expect(page).to have_content(investment2.title)
        expect(page).to_not have_content(investment3.title)
      end
    end

  end

  context("Filters") do

    scenario 'by unfeasibility' do
      investment1 = create(:budget_investment, :unfeasible, heading: heading, valuation_finished: true)
      investment2 = create(:budget_investment, :feasible, heading: heading)
      investment3 = create(:budget_investment, heading: heading)
      investment4 = create(:budget_investment, :feasible, heading: heading)

      visit budget_investments_path(budget_id: budget.id, heading_id: heading.id, unfeasible: 1)

      within("#budget-investments") do
        expect(page).to have_css('.budget-investment', count: 1)

        expect(page).to have_content(investment1.title)
        expect(page).to_not have_content(investment2.title)
        expect(page).to_not have_content(investment3.title)
        expect(page).to_not have_content(investment4.title)
      end
    end

    scenario "by unfeasibilty link for group with one heading", :focus do
      group   = create(:budget_group,   name: 'All City', budget: budget)
      heading = create(:budget_heading, name: "Madrid",   group: group)

      visit budget_path(budget)
      click_link 'See unfeasible investments'

      click_link "All City"

      expected_path = budget_investments_path(budget, heading_id: heading.id, unfeasible: 1)
      expect(page).to have_current_path(expected_path)
    end

    scenario "by unfeasibilty link for group with many headings", :focus do
      group = create(:budget_group, name: 'Districts', budget: budget)
      heading1 = create(:budget_heading, name: 'Carabanchel', group: group)
      heading2 = create(:budget_heading, name: 'Barajas',     group: group)

      visit budget_path(budget)

      click_link 'See unfeasible investments'

      click_link 'Districts'
      click_link 'Carabanchel'<commit_msg>removes focus<commit_after>require 'rails_helper'

feature 'Budget Investments' do

  let(:author)  { create(:user, :level_two, username: 'Isabel') }
  let(:budget)  { create(:budget, name: "Big Budget") }
  let(:group)   { create(:budget_group, name: "Health", budget: budget) }
  let!(:heading) { create(:budget_heading, name: "More hospitals", group: group) }

  scenario 'Index' do
    investments = [create(:budget_investment, heading: heading), create(:budget_investment, heading: heading), create(:budget_investment, :feasible, heading: heading)]
    unfeasible_investment = create(:budget_investment, :unfeasible, heading: heading)

    visit budget_investments_path(budget, heading_id: heading.id)

    expect(page).to have_selector('#budget-investments .budget-investment', count: 3)
    investments.each do |investment|
      within('#budget-investments') do
        expect(page).to have_content investment.title
        expect(page).to have_css("a[href='#{budget_investment_path(budget_id: budget.id, id: investment.id)}']", text: investment.title)
        expect(page).to_not have_content(unfeasible_investment.title)
      end
    end
  end

  context("Search") do

    scenario 'Search by text' do
      investment1 = create(:budget_investment, heading: heading, title: "Get Schwifty")
      investment2 = create(:budget_investment, heading: heading, title: "Schwifty Hello")
      investment3 = create(:budget_investment, heading: heading, title: "Do not show me")

      visit budget_investments_path(budget, heading_id: heading.id)

      within(".expanded #search_form") do
        fill_in "search", with: "Schwifty"
        click_button "Search"
      end

      within("#budget-investments") do
        expect(page).to have_css('.budget-investment', count: 2)

        expect(page).to have_content(investment1.title)
        expect(page).to have_content(investment2.title)
        expect(page).to_not have_content(investment3.title)
      end
    end

  end

  context("Filters") do

    scenario 'by unfeasibility' do
      investment1 = create(:budget_investment, :unfeasible, heading: heading, valuation_finished: true)
      investment2 = create(:budget_investment, :feasible, heading: heading)
      investment3 = create(:budget_investment, heading: heading)
      investment4 = create(:budget_investment, :feasible, heading: heading)

      visit budget_investments_path(budget_id: budget.id, heading_id: heading.id, unfeasible: 1)

      within("#budget-investments") do
        expect(page).to have_css('.budget-investment', count: 1)

        expect(page).to have_content(investment1.title)
        expect(page).to_not have_content(investment2.title)
        expect(page).to_not have_content(investment3.title)
        expect(page).to_not have_content(investment4.title)
      end
    end

    scenario "by unfeasibilty link for group with one heading" do
      group   = create(:budget_group,   name: 'All City', budget: budget)
      heading = create(:budget_heading, name: "Madrid",   group: group)

      visit budget_path(budget)
      click_link 'See unfeasible investments'

      click_link "All City"

      expected_path = budget_investments_path(budget, heading_id: heading.id, unfeasible: 1)
      expect(page).to have_current_path(expected_path)
    end

    scenario "by unfeasibilty link for group with many headings" do
      group = create(:budget_group, name: 'Districts', budget: budget)
      heading1 = create(:budget_heading, name: 'Carabanchel', group: group)
      heading2 = create(:budget_heading, name: 'Barajas',     group: group)

      visit budget_path(budget)

      click_link 'See unfeasible investments'

      click_link 'Districts'
      click_link 'Carabanchel'
{'fraction_non_alphanumeric': 0.11158683435911158, 'fraction_numerical': 0.00561948086700562, 'mean_word_length': 4.057510148849797, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1776311', 'n_tokens_mistral': 2417, 'n_tokens_neox': 2286, 'n_words': 532}