Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix ajax filtering for the map markers #40

Merged
merged 3 commits into from
Oct 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down