diff --git a/__tests__/MapComponent.test.js b/__tests__/MapComponent.test.js index 210fb57a1..d7f0a61ee 100644 --- a/__tests__/MapComponent.test.js +++ b/__tests__/MapComponent.test.js @@ -1,9 +1,89 @@ // __tests__/MapComponent.test.js // Ein einfacher Testfall, der sicherstellt, dass die Addition korrekt ist -test("simple addition", () => { +/* test("simple addition", () => { const a = 1; const b = 2; const c = a + b; expect(c).toBe(3); // Überprüft, ob c gleich 3 ist +}); */ + +import L from "leaflet"; +import { checkOverlappingMarkers } from "../utils/mapUtils"; // Passe den Pfad entsprechend an + +describe("checkOverlappingMarkers", () => { + let map; + + beforeEach(() => { + // Erstelle eine neue Leaflet-Karte für jeden Test + map = L.map(document.createElement("div")); + }); + + it("should group markers by coordinates and add plus icons for overlapping markers", () => { + // Erstelle einige Beispielmarker + const markers = [ + L.marker([51.505, -0.09]), + L.marker([51.505, -0.09]), + L.marker([51.51, -0.1]), + ]; + + const plusIcon = L.divIcon({ className: "plus-icon" }); + + // Rufe die Funktion auf + checkOverlappingMarkers(map, markers, plusIcon); + + // Überprüfe, dass die Marker zu Gruppen hinzugefügt wurden + const overlappingGroups = map._layers; + expect(Object.keys(overlappingGroups).length).toBeGreaterThan(0); + + // Überprüfe, dass die Plus-Marker hinzugefügt wurden + const plusMarkers = Object.values(overlappingGroups).filter( + (layer) => + layer.options.icon && + layer.options.icon.options.className === "plus-icon" + ); + expect(plusMarkers.length).toBeGreaterThan(0); + }); + + it("should handle non-array markers argument gracefully", () => { + const plusIcon = L.divIcon({ className: "plus-icon" }); + + // Rufe die Funktion mit einem ungültigen Argument auf + checkOverlappingMarkers(map, null, plusIcon); + + // Stelle sicher, dass keine Marker hinzugefügt wurden + const layers = map._layers; + expect(Object.keys(layers).length).toBe(0); + }); + + it("should not add plus markers if there are no overlaps", () => { + // Erstelle einige Beispielmarker + const markers = [ + L.marker([51.505, -0.09]), + L.marker([51.51, -0.1]), + L.marker([51.52, -0.12]), + ]; + + const plusIcon = L.divIcon({ className: "plus-icon" }); + + // Rufe die Funktion auf + checkOverlappingMarkers(map, markers, plusIcon); + + // Überprüfe, dass keine Plus-Marker hinzugefügt wurden + const plusMarkers = Object.values(map._layers).filter( + (layer) => + layer.options.icon && + layer.options.icon.options.className === "plus-icon" + ); + expect(plusMarkers.length).toBe(0); + }); }); +/* +In diesem Test: + +Wird eine neue Leaflet-Karte vor jedem Test erstellt. +checkOverlappingMarkers wird aufgerufen, um zu überprüfen, ob die Funktion die Marker richtig gruppiert und Plus-Icons für überlappende Marker hinzufügt. +Der Test überprüft auch, ob die Funktion ungültige Argumente (wie null für Marker) korrekt behandelt. +Es wird sichergestellt, dass keine Plus-Marker hinzugefügt werden, wenn keine Überlappungen vorliegen. +Stelle sicher, dass du die Pfade und Importe entsprechend deiner Projektstruktur anpasst. +*/