Make "see all" links filter per goal
This commit is contained in:
@@ -7,7 +7,7 @@ class Widgets::Feeds::FeedComponent < ApplicationComponent
|
||||
end
|
||||
|
||||
def see_all_path
|
||||
polymorphic_path(feed.items.model)
|
||||
polymorphic_path(feed.items.model, filters)
|
||||
end
|
||||
|
||||
private
|
||||
@@ -22,4 +22,12 @@ class Widgets::Feeds::FeedComponent < ApplicationComponent
|
||||
Widgets::Feeds::ProcessComponent
|
||||
end
|
||||
end
|
||||
|
||||
def filters
|
||||
if feed.respond_to?(:goal)
|
||||
{ advanced_search: { goal: feed.goal.code }}
|
||||
else
|
||||
{}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -20,7 +20,7 @@ module Filterable
|
||||
def allowed_filter?(filter, value)
|
||||
return if value.blank?
|
||||
|
||||
["official_level", "date_range"].include?(filter)
|
||||
["official_level", "date_range", "goal"].include?(filter)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
57
spec/components/widgets/feeds/feed_component_spec.rb
Normal file
57
spec/components/widgets/feeds/feed_component_spec.rb
Normal file
@@ -0,0 +1,57 @@
|
||||
require "rails_helper"
|
||||
|
||||
describe Widgets::Feeds::FeedComponent, type: :component do
|
||||
describe "#see_all_path" do
|
||||
context "debates" do
|
||||
let(:feed) { Widget::Feed.new(kind: "debates") }
|
||||
|
||||
it "points to the debates path for homepage debates feeds" do
|
||||
component = Widgets::Feeds::FeedComponent.new(feed)
|
||||
|
||||
render_inline component
|
||||
|
||||
expect(component.see_all_path).to eq "/debates"
|
||||
end
|
||||
|
||||
it "points to the debates filtered by goal for goal feeds" do
|
||||
component = Widgets::Feeds::FeedComponent.new(SDG::Widget::Feed.new(feed, SDG::Goal[6]))
|
||||
|
||||
render_inline component
|
||||
|
||||
expect(component.see_all_path).to eq "/debates?advanced_search#{CGI.escape("[goal]")}=6"
|
||||
end
|
||||
end
|
||||
|
||||
context "proposals" do
|
||||
let(:feed) { Widget::Feed.new(kind: "proposals") }
|
||||
|
||||
it "points to the proposals path for homepage proposals feeds" do
|
||||
component = Widgets::Feeds::FeedComponent.new(feed)
|
||||
|
||||
render_inline component
|
||||
|
||||
expect(component.see_all_path).to eq "/proposals"
|
||||
end
|
||||
|
||||
it "points to the proposals filtered by goal for goal feeds" do
|
||||
component = Widgets::Feeds::FeedComponent.new(SDG::Widget::Feed.new(feed, SDG::Goal[6]))
|
||||
|
||||
render_inline component
|
||||
|
||||
expect(component.see_all_path).to eq "/proposals?advanced_search#{CGI.escape("[goal]")}=6"
|
||||
end
|
||||
end
|
||||
|
||||
context "processes" do
|
||||
let(:feed) { Widget::Feed.new(kind: "processes") }
|
||||
|
||||
it "points to the legislation processes path for homepage processes feeds" do
|
||||
component = Widgets::Feeds::FeedComponent.new(feed)
|
||||
|
||||
render_inline component
|
||||
|
||||
expect(component.see_all_path).to eq "/legislation/processes"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -33,14 +33,16 @@ describe "SDG Goals", :js do
|
||||
end
|
||||
|
||||
describe "Show" do
|
||||
scenario "shows the SDG and its related content" do
|
||||
before do
|
||||
goal = SDG::Goal[15]
|
||||
|
||||
create(:debate, title: "Solar panels", sdg_goals: [SDG::Goal[7]])
|
||||
create(:debate, title: "Hunting ground", sdg_goals: [goal])
|
||||
create(:proposal, title: "Animal farm", sdg_goals: [goal])
|
||||
create(:proposal, title: "Sea farm", sdg_goals: [SDG::Goal[14]])
|
||||
end
|
||||
|
||||
scenario "shows the SDG and its related content" do
|
||||
visit sdg_goal_path(15)
|
||||
|
||||
within(".sdg-goal header") { expect(page).to have_content "Life on Land" }
|
||||
@@ -55,5 +57,25 @@ describe "SDG Goals", :js do
|
||||
expect(page).not_to have_content "Solar panels"
|
||||
end
|
||||
end
|
||||
|
||||
scenario "has links to debates and proposals filtered by goal" do
|
||||
visit sdg_goal_path(15)
|
||||
|
||||
click_link "See all debates"
|
||||
|
||||
within "#debates" do
|
||||
expect(page).to have_content "Hunting ground"
|
||||
expect(page).not_to have_content "Solar panels"
|
||||
end
|
||||
|
||||
go_back
|
||||
|
||||
click_link "See all proposals"
|
||||
|
||||
within "#proposals" do
|
||||
expect(page).to have_content "Animal farm"
|
||||
expect(page).not_to have_content "Sea farm"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user