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:
@@ -9,6 +9,8 @@
|
||||
"aria-label": target_label %>
|
||||
<% end %>
|
||||
|
||||
<%= render "shared/filter_subnav", i18n_namespace: "sdg_management.relations.index" %>
|
||||
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
class SDGManagement::Relations::IndexComponent < ApplicationComponent
|
||||
include Header
|
||||
include SDG::Goals::OptionsForSelect
|
||||
delegate :valid_filters, :current_filter, to: :helpers
|
||||
|
||||
attr_reader :records
|
||||
|
||||
|
||||
@@ -2,8 +2,12 @@ class SDGManagement::RelationsController < SDGManagement::BaseController
|
||||
before_action :check_feature_flags
|
||||
before_action :load_record, only: [:edit, :update]
|
||||
|
||||
FILTERS = %w[pending_sdg_review all sdg_reviewed].freeze
|
||||
has_filters FILTERS, only: :index
|
||||
|
||||
def index
|
||||
@records = relatable_class
|
||||
.send(@current_filter)
|
||||
.accessible_by(current_ability)
|
||||
.by_goal(params[:goal_code])
|
||||
.by_target(params[:target_code])
|
||||
|
||||
@@ -219,6 +219,7 @@ ignore_unused:
|
||||
- "seeds.settings.*"
|
||||
- "dashboard.polls.*.submit"
|
||||
- "sdg.goals.goal_*"
|
||||
- "sdg_management.relations.index.filter*"
|
||||
####
|
||||
## Exclude these keys from the `i18n-tasks eq-base" report:
|
||||
# ignore_eq_base:
|
||||
|
||||
@@ -32,3 +32,10 @@ en:
|
||||
title: "New local target"
|
||||
update:
|
||||
notice: "Local target updated successfully"
|
||||
relations:
|
||||
index:
|
||||
filter: "Filter"
|
||||
filters:
|
||||
all: "All"
|
||||
pending_sdg_review: "Pending"
|
||||
sdg_reviewed: "Marked as reviewed"
|
||||
|
||||
@@ -32,3 +32,10 @@ es:
|
||||
title: "Nueva meta localizada"
|
||||
update:
|
||||
notice: "Meta localizada asctualizada correctamente"
|
||||
relations:
|
||||
index:
|
||||
filter: "Filtro"
|
||||
filters:
|
||||
all: "Todos"
|
||||
pending_sdg_review: "Pendientes"
|
||||
sdg_reviewed: "Marcados como revisados"
|
||||
|
||||
@@ -1,6 +1,16 @@
|
||||
require "rails_helper"
|
||||
|
||||
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
|
||||
it "orders goals by code in the select" do
|
||||
component = SDGManagement::Relations::IndexComponent.new(Proposal.none.page(1))
|
||||
|
||||
@@ -18,26 +18,31 @@ describe "SDG Relations", :js do
|
||||
|
||||
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 "li.is-active h2", exact_text: "Pending"
|
||||
|
||||
within("#side_menu") { click_link "Debates" }
|
||||
|
||||
expect(page).to have_current_path "/sdg_management/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" }
|
||||
|
||||
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 "li.is-active h2", exact_text: "Pending"
|
||||
|
||||
within("#side_menu") { click_link "Polls" }
|
||||
|
||||
expect(page).to have_current_path "/sdg_management/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" }
|
||||
|
||||
expect(page).to have_current_path "/sdg_management/proposals"
|
||||
expect(page).to have_css "h2", exact_text: "Proposals"
|
||||
expect(page).to have_css "li.is-active h2", exact_text: "Pending"
|
||||
end
|
||||
|
||||
describe "Index" do
|
||||
@@ -88,6 +93,39 @@ describe "SDG Relations", :js do
|
||||
expect(page).to have_css "h2", exact_text: "Build a hospital"
|
||||
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
|
||||
scenario "search by terms" do
|
||||
create(:poll, name: "Internet speech freedom")
|
||||
|
||||
Reference in New Issue
Block a user