diff --git a/decidim-proposals/app/views/decidim/proposals/proposals/index.js.erb b/decidim-proposals/app/views/decidim/proposals/proposals/index.js.erb index bdabe6434a66e..ce270e815b015 100644 --- a/decidim-proposals/app/views/decidim/proposals/proposals/index.js.erb +++ b/decidim-proposals/app/views/decidim/proposals/proposals/index.js.erb @@ -8,3 +8,13 @@ $orderFilterInput.val('<%= order %>'); var $dropdownMenu = $('.dropdown.menu', $proposals); $dropdownMenu.foundation(); + +var markerData = JSON.parse('<%= escape_javascript proposals_data_for_map(search.results.select(&:geocoded_and_valid?)) +.to_json.html_safe %>'); + +var $map = $("#map"); +var controller = $map.data("map-controller"); +if (controller) { + controller.clearMarkers(); + controller.addMarkers(markerData); +} diff --git a/decidim-proposals/spec/controllers/decidim/proposals/proposals_controller_spec.rb b/decidim-proposals/spec/controllers/decidim/proposals/proposals_controller_spec.rb index 2f82443ec03f8..b3d0e8fcc96d6 100644 --- a/decidim-proposals/spec/controllers/decidim/proposals/proposals_controller_spec.rb +++ b/decidim-proposals/spec/controllers/decidim/proposals/proposals_controller_spec.rb @@ -78,6 +78,49 @@ module Proposals end end end + + context "when XHR request" do + include_context "with controller rendering the view" do + before do + controller.view_context_class.class_eval do + def proposals_path(_options) + "/" + end + + def proposal_path(_options) + "/" + end + end + end + + let(:component) { create(:proposal_component, :with_geocoding_enabled) } + let!(:proposal) { create(:proposal, :accepted, component: component, address: "Peny Lane 1") } + let(:params) do + { + participatory_process_slug: component.participatory_space.slug, + component_id: component.id, + filter: { + state: [state] + } + } + end + let(:state) { "accepted" } + + it "has all accepted proposals" do + get :index, xhr: true, params: params + expect(response.body).to have_content('address\\":\\"Peny Lane 1\\"') + end + + context "when filtering" do + let(:state) { "rejected" } + + it "does not have accepted proposals" do + get :index, xhr: true, params: params + expect(response.body).not_to have_content('address\\":\\"Peny Lane 1\\"') + end + end + end + end end describe "GET new" do