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

@@ -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))

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_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")