From 5742f0c06839d4c7fecc0da562933521702efbd1 Mon Sep 17 00:00:00 2001 From: Bart van den Eijnden Date: Fri, 1 Apr 2022 14:29:01 +0200 Subject: [PATCH] Add tests --- .../browser/spec/ol/control/scaleline.test.js | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/test/browser/spec/ol/control/scaleline.test.js b/test/browser/spec/ol/control/scaleline.test.js index 076f83ff36..85cdefc536 100644 --- a/test/browser/spec/ol/control/scaleline.test.js +++ b/test/browser/spec/ol/control/scaleline.test.js @@ -79,6 +79,19 @@ describe('ol.control.ScaleLine', function () { }); }); + describe('maxWidth', function () { + it('defaults to undefined', function () { + const ctrl = new ScaleLine(); + expect(ctrl.maxWidth_).to.be(undefined); + }); + it('can be configured', function () { + const ctrl = new ScaleLine({ + maxWidth: 4711, + }); + expect(ctrl.maxWidth_).to.be(4711); + }); + }); + describe('render', function () { it('defaults to `ol.control.ScaleLine.render`', function () { const ctrl = new ScaleLine(); @@ -325,6 +338,21 @@ describe('ol.control.ScaleLine', function () { expect(ctrl.element.innerText).to.be('100 km'); }); + it('maxWidth is applied correctly', function () { + const ctrl = new ScaleLine({maxWidth: 50}); + ctrl.setMap(map); + map.setView( + new View({ + center: fromLonLat([-85.685, 39.891], 'Indiana-East'), + zoom: 7, + projection: 'Indiana-East', + }) + ); + map.renderSync(); + // without maxWidth set this would be 100 km + expect(ctrl.element.innerText).to.be('50 km'); + }); + it('shows the same scale for different projections at higher resolutions', function () { const ctrl = new ScaleLine(); ctrl.setMap(map);