- MapLibre 6 ne trouvait pas son worker une fois regroupé par Vite : aucune couche raster (aléa d'inondation, bruit routier) ne se chargeait. L'URL du worker est désormais fixée explicitement. - Aléa d'inondation : couches 1, 2 et 3 du service WalOnMap, chacune ne couvrant qu'une plage d'échelles. - Sans résultat, la carte occupe toute la largeur et la hauteur disponible. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
88 lines
3.2 KiB
TypeScript
88 lines
3.2 KiB
TypeScript
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||
|
||
import ResultMap from '@/components/ResultMap.vue'
|
||
|
||
import { mountWithPlugins } from './helpers'
|
||
|
||
// MapLibre a besoin de WebGL, absent de jsdom : on vérifie les appels.
|
||
type Fn = (...args: unknown[]) => unknown
|
||
|
||
const mapInstance = {
|
||
addControl: vi.fn<Fn>(),
|
||
resize: vi.fn<Fn>(),
|
||
jumpTo: vi.fn<Fn>(),
|
||
setLayoutProperty: vi.fn<Fn>(),
|
||
remove: vi.fn<Fn>(),
|
||
}
|
||
const marker = {
|
||
setLngLat: vi.fn<Fn>().mockReturnThis(),
|
||
addTo: vi.fn<Fn>().mockReturnThis(),
|
||
remove: vi.fn<Fn>(),
|
||
}
|
||
|
||
vi.mock('maplibre-gl', () => ({
|
||
Map: vi.fn<() => typeof mapInstance>(function () {
|
||
return mapInstance
|
||
}),
|
||
Marker: vi.fn<() => typeof marker>(function () {
|
||
return marker
|
||
}),
|
||
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()
|
||
|
||
await wrapper.setProps({ location: { lat: 50.668, lon: 4.617, region: 'WAL' } })
|
||
|
||
expect(marker.setLngLat).toHaveBeenCalledWith([4.617, 50.668])
|
||
expect(mapInstance.jumpTo).toHaveBeenCalledWith(
|
||
expect.objectContaining({ center: [4.617, 50.668], zoom: 15 }),
|
||
)
|
||
})
|
||
|
||
it('affiche ou masque une couche WMS', async () => {
|
||
const wrapper = mountWithPlugins(ResultMap, { props: { location: null } })
|
||
await wrapper.find('#layer-noise').setValue(true)
|
||
expect(mapInstance.setLayoutProperty).toHaveBeenCalledWith('noise', 'visibility', 'visible')
|
||
await wrapper.find('#layer-flood').trigger('change')
|
||
expect(mapInstance.setLayoutProperty).toHaveBeenCalledWith('flood', 'visibility', 'none')
|
||
})
|
||
|
||
it('libère la carte au démontage', () => {
|
||
mountWithPlugins(ResultMap, { props: { location: null } }).unmount()
|
||
expect(mapInstance.remove).toHaveBeenCalled()
|
||
})
|
||
})
|