From e61270546388dfab3f599f4458c8b308a764d64b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Sat, 13 Nov 2021 14:46:16 +0100 Subject: [PATCH] Make investment filters easier to understand So now: * In the first few phases, no filters are shown (just like before) * During the valuation phase, we show "Active" and "Unfeasible" * During the final voting, we show "Active" (which now refers to the selected investments), "Not selected for the final voting" and "Unfeasible" * When the budget is finished, we show "Winners", "Not selected for the final voting" and "Unfeasible" Now each investment is shown in one (and only one) of the filters (except when the budget is finished; in this case we don't show selected investments which didn't win), and we remove the confusing "Not unfeasible" filter by only showing it during the valuation phase (before filters are selected) and renaming it to "Active". We also rearrange the filters so the default one for each phase is shown first. The idea of using the "Active" text for investments which can be selected during the selection phase and voted during the final voting is experimental. Right now, for simplicity, since we assume filters will always use the same text, we're removing the "Active" filter when the budget is finished, since having both "Winners" and "Active" filters would be confusing. --- app/models/budget.rb | 10 +++-- config/locales/en/budgets.yml | 7 ++-- config/locales/es/budgets.yml | 7 ++-- .../investments/filters_component_spec.rb | 37 +++++++++++++++---- spec/models/budget_spec.rb | 8 ++-- spec/system/budgets/investments_spec.rb | 22 +---------- 6 files changed, 46 insertions(+), 45 deletions(-) diff --git a/app/models/budget.rb b/app/models/budget.rb index 6fe8ad07e..1f7c7dc2b 100644 --- a/app/models/budget.rb +++ b/app/models/budget.rb @@ -198,10 +198,12 @@ class Budget < ApplicationRecord def investments_filters [ - (%w[not_unfeasible feasible unfeasible] if valuating_or_later?), - (%w[selected unselected] if publishing_prices_or_later?), - ("winners" if finished?) - ].compact.flatten + ("winners" if finished?), + ("selected" if publishing_prices_or_later? && !finished?), + ("unselected" if publishing_prices_or_later?), + ("not_unfeasible" if valuating?), + ("unfeasible" if valuating_or_later?) + ].compact end def email_selected diff --git a/config/locales/en/budgets.yml b/config/locales/en/budgets.yml index d7f919f5c..6535410f3 100644 --- a/config/locales/en/budgets.yml +++ b/config/locales/en/budgets.yml @@ -117,11 +117,10 @@ en: not_logged_in: "To create a new budget investment you must %{sign_in} or %{sign_up}." filter: "Filtering projects by" filters: - feasible: "Feasible" - not_unfeasible: "Feasible or with undecided feasibility" - selected: "Selected" + not_unfeasible: "Active" + selected: "Active" unfeasible: "Unfeasible" - unselected: "Unselected" + unselected: "Not selected for the final voting" winners: "Winners" orders: random: random diff --git a/config/locales/es/budgets.yml b/config/locales/es/budgets.yml index 322beb317..7c4601039 100644 --- a/config/locales/es/budgets.yml +++ b/config/locales/es/budgets.yml @@ -117,11 +117,10 @@ es: not_logged_in: "Para crear un nuevo proyecto de gasto debes %{sign_in} o %{sign_up}." filter: "Filtrando proyectos" filters: - feasible: "Viables" - not_unfeasible: "Viables o con viabilidad por decidir" - selected: "Seleccionados" + not_unfeasible: "Activos" + selected: "Activos" unfeasible: "Inviables" - unselected: "No seleccionados" + unselected: "No seleccionados para votación" winners: "Ganadores" orders: random: Aleatorios diff --git a/spec/components/budgets/investments/filters_component_spec.rb b/spec/components/budgets/investments/filters_component_spec.rb index 88e9c075d..a711f2c3b 100644 --- a/spec/components/budgets/investments/filters_component_spec.rb +++ b/spec/components/budgets/investments/filters_component_spec.rb @@ -2,6 +2,7 @@ require "rails_helper" describe Budgets::Investments::FiltersComponent do let(:budget) { create(:budget) } + before { allow(controller).to receive(:valid_filters) { budget.investments_filters } } around do |example| with_request_url(Rails.application.routes.url_helpers.budget_investments_path(budget)) do @@ -12,7 +13,6 @@ describe Budgets::Investments::FiltersComponent do it "is not displayed before valuation" do %w[informing accepting reviewing selecting].each do |phase| budget.update!(phase: phase) - allow(controller).to receive(:valid_filters).and_return(budget.investments_filters) render_inline Budgets::Investments::FiltersComponent.new @@ -20,14 +20,35 @@ describe Budgets::Investments::FiltersComponent do end end - it "is displayed during and after valuation" do - Budget::Phase::kind_or_later("valuating").each do |phase| - budget.update!(phase: phase) - allow(controller).to receive(:valid_filters).and_return(budget.investments_filters) + it "shows the active and unfeasible investments during the valuation phase" do + budget.update!(phase: "valuating") - render_inline Budgets::Investments::FiltersComponent.new + render_inline Budgets::Investments::FiltersComponent.new - expect(page).to have_content "Filtering projects by" - end + expect(page).to have_link count: 2 + expect(page).to have_link "Active" + expect(page).to have_link "Unfeasible" + end + + it "shows the active, unselected and unfeasible filters during the final voting" do + budget.update!(phase: "balloting") + + render_inline Budgets::Investments::FiltersComponent.new + + expect(page).to have_link count: 3 + expect(page).to have_link "Active" + expect(page).to have_link "Not selected for the final voting" + expect(page).to have_link "Unfeasible" + end + + it "shows the winners, unselected and unfeasible investments when the budget is finished" do + budget.update!(phase: "finished") + + render_inline Budgets::Investments::FiltersComponent.new + + expect(page).to have_link count: 3 + expect(page).to have_link "Winners" + expect(page).to have_link "Not selected for the final voting" + expect(page).to have_link "Unfeasible" end end diff --git a/spec/models/budget_spec.rb b/spec/models/budget_spec.rb index 91ee27eeb..41e827e31 100644 --- a/spec/models/budget_spec.rb +++ b/spec/models/budget_spec.rb @@ -297,21 +297,21 @@ describe Budget do it "returns feasibility filters during valuation" do budget.phase = "valuating" - expect(budget.investments_filters).to eq(%w[not_unfeasible feasible unfeasible]) + expect(budget.investments_filters).to eq(%w[not_unfeasible unfeasible]) end it "returns feasibility and selection filters during the final voting phases" do %w[publishing_prices balloting reviewing_ballots].each do |phase| budget.phase = phase - expect(budget.investments_filters).to eq(%w[not_unfeasible feasible unfeasible selected unselected]) + expect(budget.investments_filters).to eq(%w[selected unselected unfeasible]) end end - it "returns all filters after the budget has finished" do + it "returns winners, unfeasible and unselected when the budget has finished" do budget.phase = "finished" - expect(budget.investments_filters).to eq(%w[not_unfeasible feasible unfeasible selected unselected winners]) + expect(budget.investments_filters).to eq(%w[winners unselected unfeasible]) end end diff --git a/spec/system/budgets/investments_spec.rb b/spec/system/budgets/investments_spec.rb index 3fee7d277..a48bbb1f2 100644 --- a/spec/system/budgets/investments_spec.rb +++ b/spec/system/budgets/investments_spec.rb @@ -144,42 +144,22 @@ describe "Budget Investments" do expect(page).to have_content "FILTERING PROJECTS BY" - click_link "Feasible" - - expect(page).to have_css ".budget-investment", count: 1 - expect(page).to have_content "Feasible investment" - click_link "Unfeasible" expect(page).to have_content "Unfeasible investment" expect(page).to have_css ".budget-investment", count: 1 - click_link "Unselected" + click_link "Not selected for the final voting" expect(page).to have_css ".budget-investment", count: 3 expect(page).to have_content "Unselected investment" expect(page).to have_content "Unclassified investment" expect(page).to have_content "Feasible investment" - click_link "Selected" - - expect(page).to have_css ".budget-investment", count: 2 - expect(page).to have_content "Selected investment" - expect(page).to have_content "Winner investment" - click_link "Winners" expect(page).to have_css ".budget-investment", count: 1 expect(page).to have_content "Winner investment" - - click_link "Feasible or with undecided feasibility" - - expect(page).to have_css ".budget-investment", count: 5 - expect(page).to have_content "Selected investment" - expect(page).to have_content "Unselected investment" - expect(page).to have_content "Feasible investment" - expect(page).to have_content "Unclassified investment" - expect(page).to have_content "Winner investment" end context("Search") do