Skip to content

Commit bf62121

Browse files
committed
Add tests for leaflet.markercluster
1 parent 24e1923 commit bf62121

File tree

4 files changed

+100
-0
lines changed

4 files changed

+100
-0
lines changed
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<template>
2+
<div style="height:100vh; width:100vw">
3+
<h1>Marker Cluster</h1>
4+
<LMap
5+
ref="map"
6+
:zoom="6"
7+
:max-zoom="18"
8+
:center="[47.21322, -1.559482]"
9+
:use-global-leaflet="true"
10+
@ready="onMapReady"
11+
>
12+
<LTileLayer
13+
url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
14+
attribution="&amp;copy; <a href=&quot;https://www.openstreetmap.org/&quot;>OpenStreetMap</a> contributors"
15+
layer-type="base"
16+
name="OpenStreetMap"
17+
/>
18+
</LMap>
19+
</div>
20+
</template>
21+
22+
<script setup lang="ts">
23+
import L from 'leaflet';
24+
import { ref } from 'vue';
25+
26+
const map = ref(null) as any;
27+
28+
// Create locations data (20 locations around Nantes)
29+
const locations = [
30+
{ name: 'Nantes', lat: 47.218371, lng: -1.553621, options: {
31+
// Standard Leaflet Marker options
32+
draggable: true,
33+
icon: L.icon({
34+
iconUrl: '/nuxt-leaflet-logo.png',
35+
iconSize: [30, 30],
36+
})
37+
} },
38+
{
39+
// name is optional (no tooltip will be displayed if not provided)
40+
/* name: 'Saint-Nazaire', */
41+
lat: 47.273018, lng: -2.213733
42+
},
43+
{ name: 'La Baule', lat: 47.286835, lng: -2.393108 },
44+
{ name: 'Pornic', lat: 47.112, lng: -2.102 },
45+
{ name: 'Guérande', lat: 47.328, lng: -2.429 },
46+
{ name: 'Clisson', lat: 47.087, lng: -1.276 },
47+
{ name: 'Ancenis', lat: 47.366, lng: -1.176 },
48+
{ name: 'Châteaubriant', lat: 47.716, lng: -1.376 },
49+
{ name: 'Redon', lat: 47.652, lng: -2.084 },
50+
{ name: 'Pontchâteau', lat: 47.433, lng: -2.117 },
51+
{ name: 'Savenay', lat: 47.327, lng: -1.952 },
52+
{ name: 'Rezé', lat: 47.183, lng: -1.55 },
53+
{ name: 'Vertou', lat: 47.166, lng: -1.466 },
54+
{ name: 'Carquefou', lat: 47.283, lng: -1.5 },
55+
{ name: 'Orvault', lat: 47.283, lng: -1.633 },
56+
{ name: 'Saint-Herblain', lat: 47.216, lng: -1.65 },
57+
{ name: 'Sainte-Luce-sur-Loire', lat: 47.233, lng: -1.483 },
58+
{ name: 'Bouguenais', lat: 47.183, lng: -1.583 },
59+
{ name: 'Saint-Sébastien-sur-Loire', lat: 47.183, lng: -1.483 },
60+
{ name: 'Basse-Goulaine', lat: 47.2, lng: -1.483 }
61+
];
62+
63+
// When the map is ready
64+
const onMapReady = () => {
65+
useLMarkerCluster({
66+
leafletObject: map.value.leafletObject,
67+
markers: locations
68+
});
69+
}
70+
</script>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import NuxtLeaflet from '../../../src/module'
2+
3+
export default defineNuxtConfig({
4+
modules: [
5+
NuxtLeaflet
6+
],
7+
compatibilityDate: '2024-04-03',
8+
ssr: false
9+
})
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"private": true,
3+
"name": "basic",
4+
"type": "module"
5+
}

test/markercluster.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { describe, it, expect } from 'vitest'
2+
import { fileURLToPath } from 'node:url'
3+
import { setup, $fetch } from '@nuxt/test-utils'
4+
5+
describe('nuxt leaflet', async () => {
6+
await setup({
7+
rootDir: fileURLToPath(new URL('./fixtures/markercluster', import.meta.url)),
8+
})
9+
10+
it('renders a basic map with the leaflet.markercluster plugin', async () => {
11+
// Get response to a server-rendered page with `$fetch`.
12+
const html = await $fetch('/')
13+
// Verify there is no error
14+
expect(html).toContain('<html')
15+
})
16+
})

0 commit comments

Comments
 (0)