From 60b3bc1425bc42963e3d72bf3b31cbf9c8497a92 Mon Sep 17 00:00:00 2001 From: antopalidi Date: Wed, 19 Oct 2022 09:47:25 +0200 Subject: [PATCH 1/2] fixed markers updating on the map --- .../app/views/decidim/proposals/proposals/index.js.erb | 10 ++++++++++ 1 file changed, 10 insertions(+) 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); +} From 58dd58867907fc6bf80de359652f6c6ad664ae3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Verg=C3=A9s?= Date: Fri, 21 Oct 2022 14:51:56 +0200 Subject: [PATCH 2/2] test JS index proposal --- .../proposals/proposals_controller_spec.rb | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) 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