Linting and fixes for unit tests

This commit is contained in:
Olivier Guyot
2019-01-15 17:45:21 +01:00
parent ef6d17d817
commit 433bccd207
14 changed files with 36 additions and 45 deletions

View File

@@ -934,7 +934,7 @@ class View extends BaseObject {
*/ */
getZoom() { getZoom() {
let zoom; let zoom;
const resolution = this.targetResolution_; const resolution = this.getResolution();
if (resolution !== undefined) { if (resolution !== undefined) {
zoom = this.getZoomForResolution(resolution); zoom = this.getZoomForResolution(resolution);
} }
@@ -1339,7 +1339,7 @@ class View extends BaseObject {
const direction = opt_direction || 0; const direction = opt_direction || 0;
const size = this.getSizeFromViewport_(this.getRotation()); const size = this.getSizeFromViewport_(this.getRotation());
return(this.constraints_.resolution(targetResolution, direction, size)); return this.constraints_.resolution(targetResolution, direction, size);
} }
} }

View File

@@ -27,8 +27,8 @@ export function createExtent(extent, onlyCenter, smooth) {
*/ */
function(center, resolution, size, opt_isMoving) { function(center, resolution, size, opt_isMoving) {
if (center) { if (center) {
let viewWidth = onlyCenter ? 0 : size[0] * resolution; const viewWidth = onlyCenter ? 0 : size[0] * resolution;
let viewHeight = onlyCenter ? 0 : size[1] * resolution; const viewHeight = onlyCenter ? 0 : size[1] * resolution;
const minX = extent[0] + viewWidth / 2; const minX = extent[0] + viewWidth / 2;
const maxX = extent[2] - viewWidth / 2; const maxX = extent[2] - viewWidth / 2;
const minY = extent[1] + viewHeight / 2; const minY = extent[1] + viewHeight / 2;

View File

@@ -1,7 +1,6 @@
/** /**
* @module ol/control/ZoomSlider * @module ol/control/ZoomSlider
*/ */
import ViewHint from '../ViewHint.js';
import Control from './Control.js'; import Control from './Control.js';
import {CLASS_CONTROL, CLASS_UNSELECTABLE} from '../css.js'; import {CLASS_CONTROL, CLASS_UNSELECTABLE} from '../css.js';
import {easeOut} from '../easing.js'; import {easeOut} from '../easing.js';

View File

@@ -1,8 +1,7 @@
/** /**
* @module ol/interaction/DragPan * @module ol/interaction/DragPan
*/ */
import ViewHint from '../ViewHint.js'; import {scale as scaleCoordinate, rotate as rotateCoordinate} from '../coordinate.js';
import {scale as scaleCoordinate, rotate as rotateCoordinate, add as addCoordinate} from '../coordinate.js';
import {easeOut} from '../easing.js'; import {easeOut} from '../easing.js';
import {noModifierKeys} from '../events/condition.js'; import {noModifierKeys} from '../events/condition.js';
import {FALSE} from '../functions.js'; import {FALSE} from '../functions.js';

View File

@@ -2,10 +2,8 @@
* @module ol/interaction/DragRotate * @module ol/interaction/DragRotate
*/ */
import {disable} from '../rotationconstraint.js'; import {disable} from '../rotationconstraint.js';
import ViewHint from '../ViewHint.js';
import {altShiftKeysOnly, mouseOnly, mouseActionButton} from '../events/condition.js'; import {altShiftKeysOnly, mouseOnly, mouseActionButton} from '../events/condition.js';
import {FALSE} from '../functions.js'; import {FALSE} from '../functions.js';
import {rotate} from './Interaction.js';
import PointerInteraction from './Pointer.js'; import PointerInteraction from './Pointer.js';

View File

@@ -1,8 +1,6 @@
/** /**
* @module ol/interaction/DragRotateAndZoom * @module ol/interaction/DragRotateAndZoom
*/ */
import {disable} from '../rotationconstraint.js';
import ViewHint from '../ViewHint.js';
import {shiftKeyOnly, mouseOnly} from '../events/condition.js'; import {shiftKeyOnly, mouseOnly} from '../events/condition.js';
import PointerInteraction from './Pointer.js'; import PointerInteraction from './Pointer.js';

View File

@@ -1,9 +1,7 @@
/** /**
* @module ol/interaction/MouseWheelZoom * @module ol/interaction/MouseWheelZoom
*/ */
import ViewHint from '../ViewHint.js';
import {always} from '../events/condition.js'; import {always} from '../events/condition.js';
import {easeOut} from '../easing.js';
import EventType from '../events/EventType.js'; import EventType from '../events/EventType.js';
import {DEVICE_PIXEL_RATIO, FIREFOX, SAFARI} from '../has.js'; import {DEVICE_PIXEL_RATIO, FIREFOX, SAFARI} from '../has.js';
import Interaction, {zoomByDelta} from './Interaction.js'; import Interaction, {zoomByDelta} from './Interaction.js';

View File

@@ -1,9 +1,7 @@
/** /**
* @module ol/interaction/PinchRotate * @module ol/interaction/PinchRotate
*/ */
import ViewHint from '../ViewHint.js';
import {FALSE} from '../functions.js'; import {FALSE} from '../functions.js';
import {rotate} from './Interaction.js';
import PointerInteraction, {centroid as centroidFromPointers} from './Pointer.js'; import PointerInteraction, {centroid as centroidFromPointers} from './Pointer.js';
import {disable} from '../rotationconstraint.js'; import {disable} from '../rotationconstraint.js';

View File

@@ -1,9 +1,7 @@
/** /**
* @module ol/interaction/PinchZoom * @module ol/interaction/PinchZoom
*/ */
import ViewHint from '../ViewHint.js';
import {FALSE} from '../functions.js'; import {FALSE} from '../functions.js';
import {zoom} from './Interaction.js';
import PointerInteraction, {centroid as centroidFromPointers} from './Pointer.js'; import PointerInteraction, {centroid as centroidFromPointers} from './Pointer.js';

View File

@@ -2,8 +2,8 @@
* @module ol/resolutionconstraint * @module ol/resolutionconstraint
*/ */
import {linearFindNearest} from './array.js'; import {linearFindNearest} from './array.js';
import {clamp} from './math.js';
import {getHeight, getWidth} from './extent'; import {getHeight, getWidth} from './extent';
import {clamp} from './math';
/** /**
@@ -123,7 +123,7 @@ export function createSnapToPower(power, maxResolution, opt_minResolution, opt_s
const capped = Math.min(cappedMaxRes, resolution); const capped = Math.min(cappedMaxRes, resolution);
const zoomLevel = Math.floor( const zoomLevel = Math.floor(
Math.log(maxResolution / capped) / Math.log(power) + offset); Math.log(maxResolution / capped) / Math.log(power) + offset);
let newResolution = maxResolution / Math.pow(power, zoomLevel); const newResolution = maxResolution / Math.pow(power, zoomLevel);
return clamp(newResolution, minResolution, cappedMaxRes); return clamp(newResolution, minResolution, cappedMaxRes);
} else { } else {
return undefined; return undefined;

View File

@@ -71,7 +71,7 @@ export function createSnapToZero(opt_tolerance) {
return ( return (
/** /**
* @param {number|undefined} rotation Rotation. * @param {number|undefined} rotation Rotation.
* @param {number} delta Delta. * @param {boolean} opt_isMoving True if an interaction or animation is in progress.
* @return {number|undefined} Rotation. * @return {number|undefined} Rotation.
*/ */
function(rotation, opt_isMoving) { function(rotation, opt_isMoving) {

View File

@@ -1,7 +1,6 @@
import Map from '../../../../src/ol/Map.js'; import Map from '../../../../src/ol/Map.js';
import View from '../../../../src/ol/View.js';
import EventTarget from '../../../../src/ol/events/Target.js'; import EventTarget from '../../../../src/ol/events/Target.js';
import Interaction, {zoomByDelta} from '../../../../src/ol/interaction/Interaction.js'; import Interaction from '../../../../src/ol/interaction/Interaction.js';
import {FALSE} from '../../../../src/ol/functions.js'; import {FALSE} from '../../../../src/ol/functions.js';
describe('ol.interaction.Interaction', function() { describe('ol.interaction.Interaction', function() {

View File

@@ -244,7 +244,7 @@ describe('ol.resolutionconstraint', function() {
describe('snap to power, smooth constraint on', function() { describe('snap to power, smooth constraint on', function() {
it('returns expected resolution value', function() { it('returns expected resolution value', function() {
let resolutionConstraint = createSnapToPower(2, 128, 16, true); const resolutionConstraint = createSnapToPower(2, 128, 16, true);
expect(resolutionConstraint(150, 0, [100, 100], true)).to.be.greaterThan(128); expect(resolutionConstraint(150, 0, [100, 100], true)).to.be.greaterThan(128);
expect(resolutionConstraint(150, 0, [100, 100], true)).to.be.lessThan(150); expect(resolutionConstraint(150, 0, [100, 100], true)).to.be.lessThan(150);
@@ -261,7 +261,7 @@ describe('ol.resolutionconstraint', function() {
describe('snap to power, smooth constraint off', function() { describe('snap to power, smooth constraint off', function() {
it('returns expected resolution value', function() { it('returns expected resolution value', function() {
let resolutionConstraint = createSnapToPower(2, 128, 16, false); const resolutionConstraint = createSnapToPower(2, 128, 16, false);
expect(resolutionConstraint(150, 0, [100, 100], true)).to.eql(128); expect(resolutionConstraint(150, 0, [100, 100], true)).to.eql(128);
expect(resolutionConstraint(130, 0, [100, 100], true)).to.eql(128); expect(resolutionConstraint(130, 0, [100, 100], true)).to.eql(128);
@@ -274,7 +274,7 @@ describe('ol.resolutionconstraint', function() {
describe('snap to resolutions, smooth constraint on', function() { describe('snap to resolutions, smooth constraint on', function() {
it('returns expected resolution value', function() { it('returns expected resolution value', function() {
let resolutionConstraint = createSnapToResolutions([128, 64, 32, 16], true); const resolutionConstraint = createSnapToResolutions([128, 64, 32, 16], true);
expect(resolutionConstraint(150, 0, [100, 100], true)).to.be.greaterThan(128); expect(resolutionConstraint(150, 0, [100, 100], true)).to.be.greaterThan(128);
expect(resolutionConstraint(150, 0, [100, 100], true)).to.be.lessThan(150); expect(resolutionConstraint(150, 0, [100, 100], true)).to.be.lessThan(150);
@@ -291,7 +291,7 @@ describe('ol.resolutionconstraint', function() {
describe('snap to resolutions, smooth constraint off', function() { describe('snap to resolutions, smooth constraint off', function() {
it('returns expected resolution value', function() { it('returns expected resolution value', function() {
let resolutionConstraint = createSnapToResolutions([128, 64, 32, 16], false); const resolutionConstraint = createSnapToResolutions([128, 64, 32, 16], false);
expect(resolutionConstraint(150, 0, [100, 100], true)).to.eql(128); expect(resolutionConstraint(150, 0, [100, 100], true)).to.eql(128);
expect(resolutionConstraint(130, 0, [100, 100], true)).to.eql(128); expect(resolutionConstraint(130, 0, [100, 100], true)).to.eql(128);
@@ -304,7 +304,7 @@ describe('ol.resolutionconstraint', function() {
describe('min/max, smooth constraint on', function() { describe('min/max, smooth constraint on', function() {
it('returns expected resolution value', function() { it('returns expected resolution value', function() {
let resolutionConstraint = createMinMaxResolution(128, 16, true); const resolutionConstraint = createMinMaxResolution(128, 16, true);
expect(resolutionConstraint(150, 0, [100, 100], true)).to.be.greaterThan(128); expect(resolutionConstraint(150, 0, [100, 100], true)).to.be.greaterThan(128);
expect(resolutionConstraint(150, 0, [100, 100], true)).to.be.lessThan(150); expect(resolutionConstraint(150, 0, [100, 100], true)).to.be.lessThan(150);
@@ -321,7 +321,7 @@ describe('ol.resolutionconstraint', function() {
describe('min/max, smooth constraint off', function() { describe('min/max, smooth constraint off', function() {
it('returns expected resolution value', function() { it('returns expected resolution value', function() {
let resolutionConstraint = createMinMaxResolution(128, 16, false); const resolutionConstraint = createMinMaxResolution(128, 16, false);
expect(resolutionConstraint(150, 0, [100, 100], true)).to.eql(128); expect(resolutionConstraint(150, 0, [100, 100], true)).to.eql(128);
expect(resolutionConstraint(130, 0, [100, 100], true)).to.eql(128); expect(resolutionConstraint(130, 0, [100, 100], true)).to.eql(128);

View File

@@ -8,7 +8,6 @@ import {createEmpty} from '../../../src/ol/extent.js';
import Circle from '../../../src/ol/geom/Circle.js'; import Circle from '../../../src/ol/geom/Circle.js';
import LineString from '../../../src/ol/geom/LineString.js'; import LineString from '../../../src/ol/geom/LineString.js';
import Point from '../../../src/ol/geom/Point.js'; import Point from '../../../src/ol/geom/Point.js';
import {zoomByDelta} from '../../../src/ol/interaction/Interaction';
describe('ol.View', function() { describe('ol.View', function() {
@@ -989,7 +988,8 @@ describe('ol.View', function() {
let view; let view;
beforeEach(function() { beforeEach(function() {
view = new View({ view = new View({
resolutions: [512, 256, 128, 64, 32, 16] resolutions: [1024, 512, 256, 128, 64, 32, 16, 8],
smoothResolutionConstraint: false
}); });
}); });
@@ -998,30 +998,31 @@ describe('ol.View', function() {
expect(view.getZoom()).to.be(undefined); expect(view.getZoom()).to.be(undefined);
view.setResolution(513); view.setResolution(513);
expect(view.getZoom()).to.roughlyEqual(Math.log(512 / 513) / Math.LN2, 1e-9); expect(view.getZoom()).to.roughlyEqual(Math.log(1024 / 513) / Math.LN2, 1e-9);
view.setResolution(512); view.setResolution(512);
expect(view.getZoom()).to.be(0); expect(view.getZoom()).to.be(1);
view.setResolution(100); view.setResolution(100);
expect(view.getZoom()).to.roughlyEqual(2.35614, 1e-5); expect(view.getZoom()).to.roughlyEqual(3.35614, 1e-5);
view.setResolution(65); view.setResolution(65);
expect(view.getZoom()).to.roughlyEqual(2.97763, 1e-5); expect(view.getZoom()).to.roughlyEqual(3.97763, 1e-5);
view.setResolution(64); view.setResolution(64);
expect(view.getZoom()).to.be(3); expect(view.getZoom()).to.be(4);
view.setResolution(16); view.setResolution(16);
expect(view.getZoom()).to.be(5); expect(view.getZoom()).to.be(6);
view.setResolution(15); view.setResolution(15);
expect(view.getZoom()).to.roughlyEqual(Math.log(512 / 15) / Math.LN2, 1e-9); expect(view.getZoom()).to.roughlyEqual(Math.log(1024 / 15) / Math.LN2, 1e-9);
}); });
it('works for resolution arrays with variable zoom factors', function() { it('works for resolution arrays with variable zoom factors', function() {
const view = new View({ const view = new View({
resolutions: [10, 5, 2, 1] resolutions: [10, 5, 2, 1],
smoothResolutionConstraint: false
}); });
view.setZoom(1); view.setZoom(1);
@@ -1046,7 +1047,8 @@ describe('ol.View', function() {
it('returns correct zoom levels', function() { it('returns correct zoom levels', function() {
const view = new View({ const view = new View({
minZoom: 10, minZoom: 10,
maxZoom: 20 maxZoom: 20,
smoothResolutionConstraint: false
}); });
view.setZoom(5); view.setZoom(5);
@@ -1122,14 +1124,16 @@ describe('ol.View', function() {
describe('#getResolutionForZoom', function() { describe('#getResolutionForZoom', function() {
it('returns correct zoom resolution', function() { it('returns correct zoom resolution', function() {
const view = new View(); const view = new View({
smoothResolutionConstraint: false
});
const max = view.getMaxZoom(); const max = view.getMaxZoom();
const min = view.getMinZoom(); const min = view.getMinZoom();
expect(view.getResolutionForZoom(max)).to.be(view.getMinResolution()); expect(view.getResolutionForZoom(max)).to.be(view.getMinResolution());
expect(view.getResolutionForZoom(max + 1)).to.be(view.getMinResolution()); expect(view.getResolutionForZoom(max + 1)).to.be(view.getMinResolution() / 2);
expect(view.getResolutionForZoom(min)).to.be(view.getMaxResolution()); expect(view.getResolutionForZoom(min)).to.be(view.getMaxResolution());
expect(view.getResolutionForZoom(min - 1)).to.be(view.getMaxResolution()); expect(view.getResolutionForZoom(min - 1)).to.be(view.getMaxResolution() * 2);
}); });
it('returns correct zoom levels for specifically configured resolutions', function() { it('returns correct zoom levels for specifically configured resolutions', function() {
@@ -1295,10 +1299,10 @@ describe('ol.View', function() {
let size = map.getView().getSizeFromViewport_(); let size = map.getView().getSizeFromViewport_();
expect(size).to.eql([200, 150]); expect(size).to.eql([200, 150]);
size = map.getView().getSizeFromViewport_(Math.PI / 2); size = map.getView().getSizeFromViewport_(Math.PI / 2);
expect(size[0]).to.roughlyEqual(150,1e-9); expect(size[0]).to.roughlyEqual(150, 1e-9);
expect(size[1]).to.roughlyEqual(200, 1e-9); expect(size[1]).to.roughlyEqual(200, 1e-9);
size = map.getView().getSizeFromViewport_(Math.PI); size = map.getView().getSizeFromViewport_(Math.PI);
expect(size[0]).to.roughlyEqual(200,1e-9); expect(size[0]).to.roughlyEqual(200, 1e-9);
expect(size[1]).to.roughlyEqual(150, 1e-9); expect(size[1]).to.roughlyEqual(150, 1e-9);
}); });
}); });
@@ -1481,7 +1485,7 @@ describe('ol.View', function() {
describe('#beginInteraction() and endInteraction()', function() { describe('#beginInteraction() and endInteraction()', function() {
let view; let view;
beforeEach(function() { beforeEach(function() {
view = new View() view = new View();
}); });
it('correctly changes the view hint', function() { it('correctly changes the view hint', function() {