Use blocked scoped variables
In addition to using const and let, this also upgrades our linter config and removes lint (mostly whitespace).
This commit is contained in:
@@ -5,9 +5,9 @@ import {fromLonLat} from '../../../../src/ol/proj.js';
|
||||
import Projection from '../../../../src/ol/proj/Projection.js';
|
||||
|
||||
describe('ol.control.ScaleLine', function() {
|
||||
var map;
|
||||
let map;
|
||||
beforeEach(function() {
|
||||
var target = document.createElement('div');
|
||||
const target = document.createElement('div');
|
||||
document.body.appendChild(target);
|
||||
map = new Map({
|
||||
target: target
|
||||
@@ -20,7 +20,7 @@ describe('ol.control.ScaleLine', function() {
|
||||
|
||||
describe('constructor', function() {
|
||||
it('can be constructed without arguments', function() {
|
||||
var ctrl = new ScaleLine();
|
||||
const ctrl = new ScaleLine();
|
||||
expect(ctrl).to.be.an(ScaleLine);
|
||||
});
|
||||
});
|
||||
@@ -29,23 +29,23 @@ describe('ol.control.ScaleLine', function() {
|
||||
|
||||
describe('className', function() {
|
||||
it('defaults to "ol-scale-line"', function() {
|
||||
var ctrl = new ScaleLine();
|
||||
const ctrl = new ScaleLine();
|
||||
ctrl.setMap(map);
|
||||
var element = document.querySelector('.ol-scale-line', map.getTarget());
|
||||
const element = document.querySelector('.ol-scale-line', map.getTarget());
|
||||
expect(element).to.not.be(null);
|
||||
expect(element).to.be.a(HTMLDivElement);
|
||||
});
|
||||
it('can be configured', function() {
|
||||
var ctrl = new ScaleLine({
|
||||
const ctrl = new ScaleLine({
|
||||
className: 'humpty-dumpty'
|
||||
});
|
||||
ctrl.setMap(map);
|
||||
|
||||
// check that the default was not chosen
|
||||
var element1 = document.querySelector('.ol-scale-line', map.getTarget());
|
||||
const element1 = document.querySelector('.ol-scale-line', map.getTarget());
|
||||
expect(element1).to.be(null);
|
||||
// check if the configured classname was chosen
|
||||
var element2 = document.querySelector('.humpty-dumpty', map.getTarget());
|
||||
const element2 = document.querySelector('.humpty-dumpty', map.getTarget());
|
||||
expect(element2).to.not.be(null);
|
||||
expect(element2).to.be.a(HTMLDivElement);
|
||||
});
|
||||
@@ -53,11 +53,11 @@ describe('ol.control.ScaleLine', function() {
|
||||
|
||||
describe('minWidth', function() {
|
||||
it('defaults to 64', function() {
|
||||
var ctrl = new ScaleLine();
|
||||
const ctrl = new ScaleLine();
|
||||
expect(ctrl.minWidth_).to.be(64);
|
||||
});
|
||||
it('can be configured', function() {
|
||||
var ctrl = new ScaleLine({
|
||||
const ctrl = new ScaleLine({
|
||||
minWidth: 4711
|
||||
});
|
||||
expect(ctrl.minWidth_).to.be(4711);
|
||||
@@ -66,14 +66,14 @@ describe('ol.control.ScaleLine', function() {
|
||||
|
||||
describe('render', function() {
|
||||
it('defaults to `ol.control.ScaleLine.render`', function() {
|
||||
var ctrl = new ScaleLine();
|
||||
const ctrl = new ScaleLine();
|
||||
expect(ctrl.render).to.be(ScaleLine.render);
|
||||
});
|
||||
it('can be configured', function() {
|
||||
var myRender = function() {
|
||||
const myRender = function() {
|
||||
|
||||
};
|
||||
var ctrl = new ScaleLine({
|
||||
const ctrl = new ScaleLine({
|
||||
render: myRender
|
||||
});
|
||||
expect(ctrl.render).to.be(myRender);
|
||||
@@ -84,8 +84,8 @@ describe('ol.control.ScaleLine', function() {
|
||||
|
||||
describe('synchronisation with map view', function() {
|
||||
it('calls `render` as soon as the map is rendered', function(done) {
|
||||
var renderSpy = sinon.spy();
|
||||
var ctrl = new ScaleLine({
|
||||
const renderSpy = sinon.spy();
|
||||
const ctrl = new ScaleLine({
|
||||
render: renderSpy
|
||||
});
|
||||
expect(renderSpy.called).to.be(false);
|
||||
@@ -103,8 +103,8 @@ describe('ol.control.ScaleLine', function() {
|
||||
});
|
||||
});
|
||||
it('calls `render` as often as the map is rendered', function() {
|
||||
var renderSpy = sinon.spy();
|
||||
var ctrl = new ScaleLine({
|
||||
const renderSpy = sinon.spy();
|
||||
const ctrl = new ScaleLine({
|
||||
render: renderSpy
|
||||
});
|
||||
ctrl.setMap(map);
|
||||
@@ -120,8 +120,8 @@ describe('ol.control.ScaleLine', function() {
|
||||
expect(renderSpy.callCount).to.be(3);
|
||||
});
|
||||
it('calls `render` as when the view changes', function(done) {
|
||||
var renderSpy = sinon.spy();
|
||||
var ctrl = new ScaleLine({
|
||||
const renderSpy = sinon.spy();
|
||||
const ctrl = new ScaleLine({
|
||||
render: renderSpy
|
||||
});
|
||||
ctrl.setMap(map);
|
||||
@@ -140,7 +140,7 @@ describe('ol.control.ScaleLine', function() {
|
||||
|
||||
describe('static method `render`', function() {
|
||||
it('updates the rendered text', function() {
|
||||
var ctrl = new ScaleLine();
|
||||
const ctrl = new ScaleLine();
|
||||
expect(ctrl.element.innerText).to.be('');
|
||||
ctrl.setMap(map);
|
||||
map.setView(new View({
|
||||
@@ -154,17 +154,17 @@ describe('ol.control.ScaleLine', function() {
|
||||
|
||||
describe('#getUnits', function() {
|
||||
it('returns "metric" by default', function() {
|
||||
var ctrl = new ScaleLine();
|
||||
const ctrl = new ScaleLine();
|
||||
expect(ctrl.getUnits()).to.be('metric');
|
||||
});
|
||||
it('returns what is configured via `units` property', function() {
|
||||
var ctrl = new ScaleLine({
|
||||
const ctrl = new ScaleLine({
|
||||
units: 'nautical'
|
||||
});
|
||||
expect(ctrl.getUnits()).to.be('nautical');
|
||||
});
|
||||
it('returns what is configured `setUnits` method', function() {
|
||||
var ctrl = new ScaleLine();
|
||||
const ctrl = new ScaleLine();
|
||||
ctrl.setUnits('nautical');
|
||||
expect(ctrl.getUnits()).to.be('nautical');
|
||||
});
|
||||
@@ -172,7 +172,7 @@ describe('ol.control.ScaleLine', function() {
|
||||
|
||||
describe('#setUnits', function() {
|
||||
it('triggers rerendering', function() {
|
||||
var ctrl = new ScaleLine();
|
||||
const ctrl = new ScaleLine();
|
||||
map.setView(new View({
|
||||
center: [0, 0],
|
||||
zoom: 0
|
||||
@@ -189,12 +189,12 @@ describe('ol.control.ScaleLine', function() {
|
||||
});
|
||||
|
||||
describe('different units result in different contents', function() {
|
||||
var ctrl;
|
||||
var metricHtml;
|
||||
var nauticalHtml;
|
||||
var degreesHtml;
|
||||
var imperialHtml;
|
||||
var usHtml;
|
||||
let ctrl;
|
||||
let metricHtml;
|
||||
let nauticalHtml;
|
||||
let degreesHtml;
|
||||
let imperialHtml;
|
||||
let usHtml;
|
||||
beforeEach(function(done) {
|
||||
ctrl = new ScaleLine();
|
||||
ctrl.setMap(map);
|
||||
@@ -246,7 +246,7 @@ describe('ol.control.ScaleLine', function() {
|
||||
|
||||
describe('projections affect the scaleline', function() {
|
||||
it('is rendered differently for different projections', function() {
|
||||
var ctrl = new ScaleLine();
|
||||
const ctrl = new ScaleLine();
|
||||
ctrl.setMap(map);
|
||||
map.setView(new View({
|
||||
center: fromLonLat([7, 52]),
|
||||
@@ -254,19 +254,19 @@ describe('ol.control.ScaleLine', function() {
|
||||
projection: 'EPSG:3857'
|
||||
}));
|
||||
map.renderSync();
|
||||
var innerHtml3857 = ctrl.element_.innerHTML;
|
||||
const innerHtml3857 = ctrl.element_.innerHTML;
|
||||
map.setView(new View({
|
||||
center: [7, 52],
|
||||
zoom: 2,
|
||||
projection: 'EPSG:4326'
|
||||
}));
|
||||
map.renderSync();
|
||||
var innerHtml4326 = ctrl.element_.innerHTML;
|
||||
const innerHtml4326 = ctrl.element_.innerHTML;
|
||||
expect(innerHtml4326).to.not.be(innerHtml3857);
|
||||
});
|
||||
|
||||
it('Projection\'s metersPerUnit affect scale for non-degree units', function() {
|
||||
var ctrl = new ScaleLine();
|
||||
const ctrl = new ScaleLine();
|
||||
ctrl.setMap(map);
|
||||
map.setView(new View({
|
||||
center: [0, 0],
|
||||
@@ -303,7 +303,7 @@ describe('ol.control.ScaleLine', function() {
|
||||
describe('latitude may affect scale line in EPSG:4326', function() {
|
||||
|
||||
it('is rendered differently at different latitudes for metric', function() {
|
||||
var ctrl = new ScaleLine();
|
||||
const ctrl = new ScaleLine();
|
||||
ctrl.setMap(map);
|
||||
map.setView(new View({
|
||||
center: fromLonLat([7, 0]),
|
||||
@@ -311,15 +311,15 @@ describe('ol.control.ScaleLine', function() {
|
||||
projection: 'EPSG:4326'
|
||||
}));
|
||||
map.renderSync();
|
||||
var innerHtml0 = ctrl.element_.innerHTML;
|
||||
const innerHtml0 = ctrl.element_.innerHTML;
|
||||
map.getView().setCenter([7, 52]);
|
||||
map.renderSync();
|
||||
var innerHtml52 = ctrl.element_.innerHTML;
|
||||
const innerHtml52 = ctrl.element_.innerHTML;
|
||||
expect(innerHtml0).to.not.be(innerHtml52);
|
||||
});
|
||||
|
||||
it('is rendered the same at different latitudes for degrees', function() {
|
||||
var ctrl = new ScaleLine({
|
||||
const ctrl = new ScaleLine({
|
||||
units: 'degrees'
|
||||
});
|
||||
ctrl.setMap(map);
|
||||
@@ -329,22 +329,22 @@ describe('ol.control.ScaleLine', function() {
|
||||
projection: 'EPSG:4326'
|
||||
}));
|
||||
map.renderSync();
|
||||
var innerHtml0 = ctrl.element_.innerHTML;
|
||||
const innerHtml0 = ctrl.element_.innerHTML;
|
||||
map.getView().setCenter([7, 52]);
|
||||
map.renderSync();
|
||||
var innerHtml52 = ctrl.element_.innerHTML;
|
||||
const innerHtml52 = ctrl.element_.innerHTML;
|
||||
expect(innerHtml0).to.be(innerHtml52);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('zoom affects the scaleline', function() {
|
||||
var currentZoom;
|
||||
var ctrl;
|
||||
var renderedHtmls;
|
||||
var mapView;
|
||||
let currentZoom;
|
||||
let ctrl;
|
||||
let renderedHtmls;
|
||||
let mapView;
|
||||
|
||||
var getMetricUnit = function(zoom) {
|
||||
const getMetricUnit = function(zoom) {
|
||||
if (zoom > 30) {
|
||||
return 'μm';
|
||||
} else if (zoom > 20) {
|
||||
@@ -384,11 +384,11 @@ describe('ol.control.ScaleLine', function() {
|
||||
while (--currentZoom >= 0) {
|
||||
mapView.setZoom(currentZoom);
|
||||
map.renderSync();
|
||||
var currentHtml = ctrl.element_.innerHTML;
|
||||
const currentHtml = ctrl.element_.innerHTML;
|
||||
expect(currentHtml in renderedHtmls).to.be(false);
|
||||
renderedHtmls[currentHtml] = true;
|
||||
|
||||
var unit = ctrl.innerElement_.textContent.match(/\d+ (.+)/)[1];
|
||||
const unit = ctrl.innerElement_.textContent.match(/\d+ (.+)/)[1];
|
||||
expect(unit).to.eql(getMetricUnit(currentZoom));
|
||||
}
|
||||
});
|
||||
@@ -399,7 +399,7 @@ describe('ol.control.ScaleLine', function() {
|
||||
while (--currentZoom >= 0) {
|
||||
mapView.setZoom(currentZoom);
|
||||
map.renderSync();
|
||||
var currentHtml = ctrl.element_.innerHTML;
|
||||
const currentHtml = ctrl.element_.innerHTML;
|
||||
expect(currentHtml in renderedHtmls).to.be(false);
|
||||
renderedHtmls[currentHtml] = true;
|
||||
}
|
||||
@@ -411,7 +411,7 @@ describe('ol.control.ScaleLine', function() {
|
||||
while (--currentZoom >= 0) {
|
||||
mapView.setZoom(currentZoom);
|
||||
map.renderSync();
|
||||
var currentHtml = ctrl.element_.innerHTML;
|
||||
const currentHtml = ctrl.element_.innerHTML;
|
||||
expect(currentHtml in renderedHtmls).to.be(false);
|
||||
renderedHtmls[currentHtml] = true;
|
||||
}
|
||||
@@ -423,7 +423,7 @@ describe('ol.control.ScaleLine', function() {
|
||||
while (--currentZoom >= 0) {
|
||||
mapView.setZoom(currentZoom);
|
||||
map.renderSync();
|
||||
var currentHtml = ctrl.element_.innerHTML;
|
||||
const currentHtml = ctrl.element_.innerHTML;
|
||||
expect(currentHtml in renderedHtmls).to.be(false);
|
||||
renderedHtmls[currentHtml] = true;
|
||||
}
|
||||
@@ -435,7 +435,7 @@ describe('ol.control.ScaleLine', function() {
|
||||
while (--currentZoom >= 0) {
|
||||
mapView.setZoom(currentZoom);
|
||||
map.renderSync();
|
||||
var currentHtml = ctrl.element_.innerHTML;
|
||||
const currentHtml = ctrl.element_.innerHTML;
|
||||
expect(currentHtml in renderedHtmls).to.be(false);
|
||||
renderedHtmls[currentHtml] = true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user