Warn once when suspicious coordinate are used

This commit is contained in:
Andreas Hocevar
2022-02-14 14:55:58 +01:00
parent 75a3adccce
commit 63fc00902f
3 changed files with 72 additions and 2 deletions

View File

@@ -1,5 +1,6 @@
import Projection from '../../../src/ol/proj/Projection.js';
import Units from '../../../src/ol/proj/Units.js';
import View from '../../../src/ol/View.js';
import expect from '../expect.js';
import proj4 from 'proj4';
import {HALF_SIZE} from '../../../src/ol/proj/epsg3857.js';
@@ -8,6 +9,7 @@ import {
addCommon,
clearAllProjections,
clearUserProjection,
disableCoordinateWarning,
equivalent,
fromLonLat,
fromUserCoordinate,
@@ -890,4 +892,43 @@ describe('ol/proj.js', function () {
);
});
});
describe('Console info about `setUserProjection`', function () {
let originalConsole, callCount;
beforeEach(function () {
disableCoordinateWarning(false);
originalConsole = console;
callCount = 0;
global.console = {
...console,
warn: () => ++callCount,
};
});
afterEach(function () {
global.console = originalConsole;
clearUserProjection();
});
it('is shown once when suspicious coordinates are used', function () {
const view = new View({
center: [16, 48],
});
view.setCenter([15, 47]);
expect(callCount).to.be(1);
});
it('is not shown when fromLonLat() is used', function () {
const view = new View({
center: fromLonLat([16, 48]),
});
view.setCenter(fromLonLat([15, 47]));
expect(callCount).to.be(0);
});
it('is not shown when useGeographic() is used', function () {
useGeographic();
const view = new View({
center: [16, 48],
});
view.setCenter([15, 47]);
expect(callCount).to.be(0);
});
});
});