Skip to content

Commit

Permalink
Fix specs
Browse files Browse the repository at this point in the history
  • Loading branch information
JoonasAapro committed Nov 16, 2023
1 parent 07a4bd7 commit 66ad5ba
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 17 deletions.
2 changes: 1 addition & 1 deletion app/packs/src/decidim/locations/map/controller/location.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ export default class ModelLocMapController extends MapController {
})
}
this.markers[markerId] = marker;
this.triggerEvent("markeradd", [marker, ev]);
marker.addTo(this.map);
this.triggerEvent("markeradd", [marker, ev]);

return markerId;
}
Expand Down
19 changes: 12 additions & 7 deletions app/packs/src/decidim/locations/map/integration/forms.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ export default () => {
}, 300);
});

typeLocButton.addEventListener("click", () => {
typeLocButton.addEventListener("click", (event) => {
event.preventDefault()
const markerId = ctrl.addMarker(typeLocCoords, "typeEv");
const addressData = { address: typeLocInput.value, position: {lat: typeLocCoords[0], lng: typeLocCoords[1]}, markerId };
typeLocInput.value = "";
Expand Down Expand Up @@ -174,16 +175,20 @@ export default () => {
});
ctrl.setEventHandler("markeradd", (marker, ev) => {
const markerId = marker.options.id;
const oldMarker = markerFieldContainer.querySelector(".marker-field");
if (mapConfig && mapConfig === "single" && oldMarker && ev === "clickEv") {
ctrl.deleteMarker(oldMarker.dataset.markerId);
markerFieldContainer.querySelector(`[data-marker-id="${oldMarker.dataset.markerId}"]`).remove();
}

if (mapConfig && mapConfig === "single" && (ev === "typeEv" || ev === "clickEv")) {
const oldMarker = markerFieldContainer.querySelector(".marker-field");
if (oldMarker) {
ctrl.deleteMarker(oldMarker.dataset.markerId);
markerFieldContainer.querySelector(`[data-marker-id="${oldMarker.dataset.markerId}"]`).remove();
};
};
addMarkerField(markerFieldContainer, markerId);
if (ev === "clickEv") {
ctrl.bindPopUp(markerId);
$(mapEl).trigger("geocoder-reverse.decidim", [marker.getLatLng(), { markerId }]);
}
};

marker.on("click", () => {
editModalEl.dataset.markerId = markerId;

Expand Down
11 changes: 2 additions & 9 deletions spec/system/map_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ def drag_marker
end

context "when adding multiple locations and configuration limits it" do
let!(:map_configuration) { "single" }
let(:map_configuration) { "single" }

it "adds a single location" do
click_link "Type locations"
Expand All @@ -357,7 +357,7 @@ def drag_marker
)
find("#autoComplete_result_0").click
click_button "Add"
expect(page).to have_css(".leaflet-marker-draggable")
expect(page).to have_css(".marker-field")
expect(page).to have_css(".leaflet-marker-draggable", count: 1)
expect(page).to have_field("dummy_locations__index__address", type: :hidden, with: "Veneentekijäntie 4, Finland")
find("#dummy_address").set("veneen")
Expand All @@ -367,13 +367,6 @@ def drag_marker
find("#autoComplete_result_1").click
click_button "Add"
expect(page).to have_field("dummy_locations__index__address", type: :hidden, with: "Veneentekijäntie 6, Finland")
find("#dummy_address").set("veneen")
expect(page).to have_content(
"Veneentekijäntie 4, Finland\nVeneentekijäntie 6, Finland\nVeneentekijäntie 7, Finland"
)
find("#autoComplete_result_2").click
click_button "Add"
expect(page).to have_field("dummy_locations__index__address", type: :hidden, with: "Veneentekijäntie 7, Finland")
expect(page).to have_css(".leaflet-marker-draggable", count: 1)
end
end
Expand Down

0 comments on commit 66ad5ba

Please sign in to comment.