Initialise frontend #2

Merged
boris.waaub merged 6 commits from initialise-frontend into main 2026-11-24 15:00:30 +00:00
3 changed files with 50 additions and 5 deletions
Showing only changes of commit 26153caeaf - Show all commits

No files matched your search

+29 -1
View File
@@ -1,4 +1,4 @@
import { describe, expect, it, vi } from 'vitest'
import { beforeEach, describe, expect, it, vi } from 'vitest'
import ResultMap from '@/components/ResultMap.vue'
@@ -29,9 +29,37 @@ vi.mock('maplibre-gl', () => ({
}),
NavigationControl: vi.fn<Fn>(),
ScaleControl: vi.fn<Fn>(),
setWorkerUrl: vi.fn<Fn>(),
}))
describe('ResultMap', () => {
// On ne vide que les mocks de la carte : l'appel à setWorkerUrl a lieu à l'import.
beforeEach(() => {
for (const fn of [...Object.values(mapInstance), ...Object.values(marker)]) fn.mockClear()
})
it('indique à MapLibre où trouver son worker', async () => {
const { setWorkerUrl } = await import('maplibre-gl')
expect(setWorkerUrl).toHaveBeenCalledWith(expect.stringContaining('maplibre-gl-worker'))
})
it('occupe toute la place tant qu’aucune adresse n’est analysée', async () => {
const wrapper = mountWithPlugins(ResultMap, { props: { location: null } })
expect(wrapper.classes()).toContain('expanded')
await wrapper.setProps({ location: { lat: 50.668, lon: 4.617, region: 'WAL' } })
expect(wrapper.classes()).not.toContain('expanded')
})
it('interroge les trois plages d’échelle de l’aléa d’inondation', async () => {
const { Map } = await import('maplibre-gl')
mountWithPlugins(ResultMap, { props: { location: null } })
const style = vi.mocked(Map).mock.lastCall![0].style as {
sources: Record<string, { tiles?: string[] }>
}
expect(style.sources.flood!.tiles![0]).toContain('layers=1%2C2%2C3')
expect(style.sources.flood!.tiles![0]).toContain('bbox={bbox-epsg-3857}')
})
it("centre la carte et place le marqueur sur l'adresse", async () => {
const wrapper = mountWithPlugins(ResultMap, { props: { location: null } })
expect(marker.setLngLat).not.toHaveBeenCalled()
+20 -3
View File
@@ -1,3 +1,12 @@
<script lang="ts">
import { setWorkerUrl } from 'maplibre-gl'
import workerUrl from 'maplibre-gl/dist/maplibre-gl-worker.mjs?url'
// MapLibre cherche son worker à côté de son propre module, ce que le regroupement de Vite
// casse : sans worker, aucune source raster (couches WMS) ne se charge.
setWorkerUrl(workerUrl)
</script>
<script setup lang="ts">
import { Map as MapLibreMap, Marker, NavigationControl, ScaleControl } from 'maplibre-gl'
import { onBeforeUnmount, onMounted, ref, watch } from 'vue'
@@ -29,7 +38,9 @@ function wms(service: string, layers: string): string {
}
const overlays = [
{ id: 'flood', url: wms('EAU/ALEA_INOND', '2'), color: '#00b0f0' },
// Couches 1, 2 et 3 : chacune ne couvre qu'une plage d'échelles (1:25 000 et moins, entre
// 1:25 000 et 1:5 000, au-delà de 1:5 000).
{ id: 'flood', url: wms('EAU/ALEA_INOND', '1,2,3'), color: '#00b0f0' },
{ id: 'noise', url: wms('INDUSTRIES_SERVICES/BRUIT_MROAD_2017', '1'), color: '#e85b25' },
] as const
@@ -108,7 +119,7 @@ watch(() => props.location, showLocation, { flush: 'post' })
</script>
<template>
<div class="result-map prism-card">
<div class="result-map prism-card" :class="{ expanded: !location }">
<div ref="container" class="map" role="region" :aria-label="$t('map.label')"></div>
<fieldset ref="layersPanel" class="map-panel layers">
@@ -153,6 +164,11 @@ watch(() => props.location, showLocation, { flush: 'post' })
height: 720px;
}
/* Avant la première analyse, la carte occupe toute la hauteur disponible. */
.result-map.expanded {
height: max(420px, calc(100vh - 330px));
}
@media (min-width: 992px) {
.result-map {
position: sticky;
@@ -161,7 +177,8 @@ watch(() => props.location, showLocation, { flush: 'post' })
}
@media (max-width: 991.98px) {
.result-map {
.result-map,
.result-map.expanded {
height: 240px;
}
.legend {
+1 -1
View File
@@ -65,7 +65,7 @@ const location = computed(() => result.value?.location ?? null)
</AlertBanner>
<div class="row g-4">
<div class="col-lg-5">
<div :class="result ? 'col-lg-5' : 'col-12'">
<ResultMap :location="location" />
</div>
<div v-if="result" class="col-lg-7 d-flex flex-column gap-4" aria-live="polite">