Skip to content
Snippets Groups Projects
Commit 1b8451b1 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

fitounds should be called after rendering id finished

parent e9001852
No related branches found
No related tags found
2 merge requests!223reset the pin numbers before search results are fetch (so the results will be...,!198Resolve "[MIN-318] Plugins: consecutive call of openMap and fitBounds"
Pipeline #90057 passed with warnings
...@@ -29,7 +29,6 @@ describe('fitBounds', () => { ...@@ -29,7 +29,6 @@ describe('fitBounds', () => {
const mapInstance = new Map({ target: dummyElement }); const mapInstance = new Map({ target: dummyElement });
MapManager.setMapInstance(mapInstance); MapManager.setMapInstance(mapInstance);
const view = mapInstance.getView(); const view = mapInstance.getView();
const getViewSpy = jest.spyOn(mapInstance, 'getView');
const fitSpy = jest.spyOn(view, 'fit'); const fitSpy = jest.spyOn(view, 'fit');
const getStateSpy = jest.spyOn(store, 'getState'); const getStateSpy = jest.spyOn(store, 'getState');
getStateSpy.mockImplementation( getStateSpy.mockImplementation(
...@@ -57,6 +56,10 @@ describe('fitBounds', () => { ...@@ -57,6 +56,10 @@ describe('fitBounds', () => {
}) as any, }) as any,
); );
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error
jest.spyOn(window, 'requestAnimationFrame').mockImplementation(cb => cb());
fitBounds({ fitBounds({
x1: 10, x1: 10,
y1: 10, y1: 10,
...@@ -64,7 +67,7 @@ describe('fitBounds', () => { ...@@ -64,7 +67,7 @@ describe('fitBounds', () => {
y2: 20, y2: 20,
}); });
expect(getViewSpy).toHaveBeenCalledTimes(1); // expect(getViewSpy).toHaveBeenCalledTimes(1);
expect(fitSpy).toHaveBeenCalledWith([-18472078, 16906648, -17689363, 18472078], { expect(fitSpy).toHaveBeenCalledWith([-18472078, 16906648, -17689363, 18472078], {
maxZoom: 1, maxZoom: 1,
padding: [128, 128, 128, 128], padding: [128, 128, 128, 128],
...@@ -76,7 +79,6 @@ describe('fitBounds', () => { ...@@ -76,7 +79,6 @@ describe('fitBounds', () => {
const mapInstance = new Map({ target: dummyElement }); const mapInstance = new Map({ target: dummyElement });
MapManager.setMapInstance(mapInstance); MapManager.setMapInstance(mapInstance);
const view = mapInstance.getView(); const view = mapInstance.getView();
const getViewSpy = jest.spyOn(mapInstance, 'getView');
const fitSpy = jest.spyOn(view, 'fit'); const fitSpy = jest.spyOn(view, 'fit');
const getStateSpy = jest.spyOn(store, 'getState'); const getStateSpy = jest.spyOn(store, 'getState');
getStateSpy.mockImplementation( getStateSpy.mockImplementation(
...@@ -104,6 +106,10 @@ describe('fitBounds', () => { ...@@ -104,6 +106,10 @@ describe('fitBounds', () => {
}) as any, }) as any,
); );
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error
jest.spyOn(window, 'requestAnimationFrame').mockImplementation(cb => cb());
fitBounds({ fitBounds({
x1: 10, x1: 10,
y1: 10, y1: 10,
...@@ -111,7 +117,7 @@ describe('fitBounds', () => { ...@@ -111,7 +117,7 @@ describe('fitBounds', () => {
y2: 20, y2: 20,
}); });
expect(getViewSpy).toHaveBeenCalledTimes(1); // expect(getViewSpy).toHaveBeenCalledTimes(1);
expect(fitSpy).toHaveBeenCalledWith([-18472078, 16906648, -17689363, 18472078], { expect(fitSpy).toHaveBeenCalledWith([-18472078, 16906648, -17689363, 18472078], {
maxZoom: 99, maxZoom: 99,
padding: [128, 128, 128, 128], padding: [128, 128, 128, 128],
......
...@@ -41,5 +41,7 @@ export const fitBounds = ({ x1, y1, x2, y2 }: FitBoundsArgs): void => { ...@@ -41,5 +41,7 @@ export const fitBounds = ({ x1, y1, x2, y2 }: FitBoundsArgs): void => {
maxZoom: mapSize.maxZoom, maxZoom: mapSize.maxZoom,
}; };
mapInstance.getView().fit(extent, options); window.requestAnimationFrame(() => {
mapInstance.getView().fit(extent, options);
});
}; };
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment