mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-10-22 23:16:46 +00:00
fix(tours): preserve viewport when starting a new tour
This commit is contained in:
@@ -463,6 +463,23 @@ describe('MapView', () => {
|
||||
)
|
||||
expect(mapMock.fitBounds).not.toHaveBeenCalled()
|
||||
|
||||
const mapContainer = screen.getByTestId('map-container')
|
||||
const retainedCenter = { lat: 35.2, lng: 135.8 }
|
||||
mapMock.getCenter.mockReturnValue(retainedCenter)
|
||||
mapMock.getZoom.mockReturnValue(12)
|
||||
mapMock.setView([retainedCenter.lat, retainedCenter.lng], 12)
|
||||
mapMock.fitBounds.mockClear()
|
||||
mapMock.setView.mockClear()
|
||||
mapMock.panTo.mockClear()
|
||||
|
||||
rerender(<MapView places={[]} followSelection={false} focusKey={2} focusPoints={[]} />)
|
||||
expect(screen.getByTestId('map-container')).toBe(mapContainer)
|
||||
expect(mapMock.fitBounds).not.toHaveBeenCalled()
|
||||
expect(mapMock.setView).not.toHaveBeenCalled()
|
||||
expect(mapMock.panTo).not.toHaveBeenCalled()
|
||||
expect(mapMock.getCenter()).toEqual(retainedCenter)
|
||||
expect(mapMock.getZoom()).toBe(12)
|
||||
|
||||
rerender(
|
||||
<MapView places={[]} followSelection={false} focusKey={2} focusPoints={[[48, 11], [48.5, 11.8]]} />,
|
||||
)
|
||||
|
||||
@@ -31,6 +31,7 @@ const glMap = vi.hoisted(() => ({
|
||||
flyTo: vi.fn(),
|
||||
jumpTo: vi.fn(),
|
||||
getZoom: vi.fn().mockReturnValue(10),
|
||||
getCenter: vi.fn(() => ({ lng: 0, lat: 0 })),
|
||||
addControl: vi.fn(),
|
||||
removeControl: vi.fn(),
|
||||
remove: vi.fn(),
|
||||
@@ -938,19 +939,6 @@ describe('MapViewGL', () => {
|
||||
route={null}
|
||||
followSelection={false}
|
||||
focusKey={1}
|
||||
focusPoints={[]}
|
||||
glProvider="maplibre-gl"
|
||||
/>,
|
||||
)
|
||||
await act(async () => {})
|
||||
expect(glMap.fitBounds).not.toHaveBeenCalled()
|
||||
|
||||
rerender(
|
||||
<MapViewGL
|
||||
places={[]}
|
||||
route={[[[48, 11], [48.2, 11.3]]]}
|
||||
followSelection={false}
|
||||
focusKey={1}
|
||||
focusPoints={[[48, 11], [48.2, 11.3]]}
|
||||
glProvider="maplibre-gl"
|
||||
/>,
|
||||
@@ -958,26 +946,35 @@ describe('MapViewGL', () => {
|
||||
await act(async () => {})
|
||||
expect(glMap.fitBounds).toHaveBeenCalledOnce()
|
||||
glMap.fitBounds.mockClear()
|
||||
|
||||
rerender(
|
||||
<MapViewGL
|
||||
places={[]}
|
||||
route={[[[48, 11], [48.2, 11.3], [48.4, 11.6]]]}
|
||||
followSelection={false}
|
||||
focusKey={1}
|
||||
focusPoints={[[48, 11], [48.2, 11.3], [48.4, 11.6]]}
|
||||
glProvider="maplibre-gl"
|
||||
/>,
|
||||
)
|
||||
await act(async () => {})
|
||||
expect(glMap.fitBounds).not.toHaveBeenCalled()
|
||||
const mapConstructions = (maplibregl.Map as any).mock.calls.length
|
||||
const retainedCenter = { lng: 135.8, lat: 35.2 }
|
||||
glMap.getCenter.mockReturnValue(retainedCenter)
|
||||
glMap.getZoom.mockReturnValue(12)
|
||||
|
||||
rerender(
|
||||
<MapViewGL
|
||||
places={[]}
|
||||
followSelection={false}
|
||||
focusKey={2}
|
||||
focusPoints={[[48, 11], [48.5, 11.8]]}
|
||||
focusPoints={[]}
|
||||
glProvider="maplibre-gl"
|
||||
/>,
|
||||
)
|
||||
await act(async () => {})
|
||||
expect(glMap.fitBounds).not.toHaveBeenCalled()
|
||||
expect(glMap.flyTo).not.toHaveBeenCalled()
|
||||
expect(glMap.jumpTo).not.toHaveBeenCalled()
|
||||
expect(glMap.easeTo).not.toHaveBeenCalled()
|
||||
expect((maplibregl.Map as any).mock.calls).toHaveLength(mapConstructions)
|
||||
expect(glMap.getCenter()).toEqual(retainedCenter)
|
||||
expect(glMap.getZoom()).toBe(12)
|
||||
|
||||
rerender(
|
||||
<MapViewGL
|
||||
places={[]}
|
||||
followSelection={false}
|
||||
focusKey={2}
|
||||
focusPoints={[[35.01, 135.76]]}
|
||||
glProvider="maplibre-gl"
|
||||
/>,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user