Add filters to SDG relations controller

We have three filters: "pending", "all" and "reviewed". Where "pending"
is the default one.

Now we are rendering the `shared/_filter_subnav` partial we need to stub
helper methods defined at the controller and the helper methods that
rely on the request parameters to test the component.
This commit is contained in:
Senén Rodero Rodríguez
2020-12-21 18:17:36 +01:00
parent 94a4b67675
commit c6407d82e3
8 changed files with 70 additions and 0 deletions

View File

@@ -9,6 +9,8 @@
"aria-label": target_label %> "aria-label": target_label %>
<% end %> <% end %>
<%= render "shared/filter_subnav", i18n_namespace: "sdg_management.relations.index" %>
<table> <table>
<thead> <thead>
<tr> <tr>

View File

@@ -1,6 +1,7 @@
class SDGManagement::Relations::IndexComponent < ApplicationComponent class SDGManagement::Relations::IndexComponent < ApplicationComponent
include Header include Header
include SDG::Goals::OptionsForSelect include SDG::Goals::OptionsForSelect
delegate :valid_filters, :current_filter, to: :helpers
attr_reader :records attr_reader :records

View File

@@ -2,8 +2,12 @@ class SDGManagement::RelationsController < SDGManagement::BaseController
before_action :check_feature_flags before_action :check_feature_flags
before_action :load_record, only: [:edit, :update] before_action :load_record, only: [:edit, :update]
FILTERS = %w[pending_sdg_review all sdg_reviewed].freeze
has_filters FILTERS, only: :index
def index def index
@records = relatable_class @records = relatable_class
.send(@current_filter)
.accessible_by(current_ability) .accessible_by(current_ability)
.by_goal(params[:goal_code]) .by_goal(params[:goal_code])
.by_target(params[:target_code]) .by_target(params[:target_code])

View File

@@ -219,6 +219,7 @@ ignore_unused:
- "seeds.settings.*" - "seeds.settings.*"
- "dashboard.polls.*.submit" - "dashboard.polls.*.submit"
- "sdg.goals.goal_*" - "sdg.goals.goal_*"
- "sdg_management.relations.index.filter*"
#### ####
## Exclude these keys from the `i18n-tasks eq-base" report: ## Exclude these keys from the `i18n-tasks eq-base" report:
# ignore_eq_base: # ignore_eq_base:

View File

@@ -32,3 +32,10 @@ en:
title: "New local target" title: "New local target"
update: update:
notice: "Local target updated successfully" notice: "Local target updated successfully"
relations:
index:
filter: "Filter"
filters:
all: "All"
pending_sdg_review: "Pending"
sdg_reviewed: "Marked as reviewed"

View File

@@ -32,3 +32,10 @@ es:
title: "Nueva meta localizada" title: "Nueva meta localizada"
update: update:
notice: "Meta localizada asctualizada correctamente" notice: "Meta localizada asctualizada correctamente"
relations:
index:
filter: "Filtro"
filters:
all: "Todos"
pending_sdg_review: "Pendientes"
sdg_reviewed: "Marcados como revisados"

View File

@@ -1,6 +1,16 @@
require "rails_helper" require "rails_helper"
describe SDGManagement::Relations::IndexComponent, type: :component do describe SDGManagement::Relations::IndexComponent, type: :component do
before do
allow(ViewComponent::Base).to receive(:test_controller).and_return("SDGManagement::RelationsController")
allow_any_instance_of(SDGManagement::RelationsController).to receive(:valid_filters)
.and_return(SDGManagement::RelationsController::FILTERS)
allow_any_instance_of(SDGManagement::RelationsController).to receive(:current_filter)
.and_return(SDGManagement::RelationsController::FILTERS.first)
allow_any_instance_of(ApplicationHelper).to receive(:current_path_with_query_params)
.and_return("/anything")
end
describe "#goal_options" do describe "#goal_options" do
it "orders goals by code in the select" do it "orders goals by code in the select" do
component = SDGManagement::Relations::IndexComponent.new(Proposal.none.page(1)) component = SDGManagement::Relations::IndexComponent.new(Proposal.none.page(1))

View File

@@ -18,26 +18,31 @@ describe "SDG Relations", :js do
expect(page).to have_current_path "/sdg_management/budget/investments" expect(page).to have_current_path "/sdg_management/budget/investments"
expect(page).to have_css "h2", exact_text: "Participatory budgets" expect(page).to have_css "h2", exact_text: "Participatory budgets"
expect(page).to have_css "li.is-active h2", exact_text: "Pending"
within("#side_menu") { click_link "Debates" } within("#side_menu") { click_link "Debates" }
expect(page).to have_current_path "/sdg_management/debates" expect(page).to have_current_path "/sdg_management/debates"
expect(page).to have_css "h2", exact_text: "Debates" expect(page).to have_css "h2", exact_text: "Debates"
expect(page).to have_css "li.is-active h2", exact_text: "Pending"
within("#side_menu") { click_link "Collaborative legislation" } within("#side_menu") { click_link "Collaborative legislation" }
expect(page).to have_current_path "/sdg_management/legislation/processes" expect(page).to have_current_path "/sdg_management/legislation/processes"
expect(page).to have_css "h2", exact_text: "Collaborative legislation" expect(page).to have_css "h2", exact_text: "Collaborative legislation"
expect(page).to have_css "li.is-active h2", exact_text: "Pending"
within("#side_menu") { click_link "Polls" } within("#side_menu") { click_link "Polls" }
expect(page).to have_current_path "/sdg_management/polls" expect(page).to have_current_path "/sdg_management/polls"
expect(page).to have_css "h2", exact_text: "Polls" expect(page).to have_css "h2", exact_text: "Polls"
expect(page).to have_css "li.is-active h2", exact_text: "Pending"
within("#side_menu") { click_link "Proposals" } within("#side_menu") { click_link "Proposals" }
expect(page).to have_current_path "/sdg_management/proposals" expect(page).to have_current_path "/sdg_management/proposals"
expect(page).to have_css "h2", exact_text: "Proposals" expect(page).to have_css "h2", exact_text: "Proposals"
expect(page).to have_css "li.is-active h2", exact_text: "Pending"
end end
describe "Index" do describe "Index" do
@@ -88,6 +93,39 @@ describe "SDG Relations", :js do
expect(page).to have_css "h2", exact_text: "Build a hospital" expect(page).to have_css "h2", exact_text: "Build a hospital"
end end
scenario "list records pending to review for the current model by default" do
create(:debate, title: "I'm a debate")
create(:sdg_review, relatable: create(:debate, title: "I'm a reviewed debate"))
visit sdg_management_debates_path
expect(page).to have_css "li.is-active h2", exact_text: "Pending"
expect(page).to have_text "I'm a debate"
expect(page).not_to have_text "I'm a reviewed debate"
end
scenario "list all records for the current model when user clicks on 'all' tab" do
create(:debate, title: "I'm a debate")
create(:sdg_review, relatable: create(:debate, title: "I'm a reviewed debate"))
visit sdg_management_debates_path
click_link "All"
expect(page).to have_text "I'm a debate"
expect(page).to have_text "I'm a reviewed debate"
end
scenario "list reviewed records for the current model when user clicks on 'reviewed' tab" do
create(:debate, title: "I'm a debate")
create(:sdg_review, relatable: create(:debate, title: "I'm a reviewed debate"))
visit sdg_management_debates_path
click_link "Marked as reviewed"
expect(page).not_to have_text "I'm a debate"
expect(page).to have_text "I'm a reviewed debate"
end
describe "search" do describe "search" do
scenario "search by terms" do scenario "search by terms" do
create(:poll, name: "Internet speech freedom") create(:poll, name: "Internet speech freedom")