From 299fc3b82819b302b86db77dc75ccdca39785409 Mon Sep 17 00:00:00 2001 From: Molly Lloyd Date: Tue, 10 Jan 2017 10:45:19 -0800 Subject: [PATCH] address feedback, add tests --- js/ui/control/logo_control.js | 8 +++--- js/ui/map.js | 2 +- test/js/ui/control/logo.test.js | 46 +++++++++++++++++++++++++++++++++ 3 files changed, 51 insertions(+), 5 deletions(-) create mode 100644 test/js/ui/control/logo.test.js diff --git a/js/ui/control/logo_control.js b/js/ui/control/logo_control.js index 32debf62964..52c62e4d687 100644 --- a/js/ui/control/logo_control.js +++ b/js/ui/control/logo_control.js @@ -11,11 +11,8 @@ const DOM = require('../../util/dom'); **/ class LogoControl { - constructor() { - } onAdd(map) { - this._map = map; this._container = DOM.create('div', 'mapboxgl-ctrl'); const anchor = DOM.create('a', 'mapboxgl-ctrl-logo'); anchor.target = "_blank"; @@ -26,7 +23,10 @@ class LogoControl { onRemove() { this._container.parentNode.removeChild(this._container); - this._map = undefined; + } + + getDefaultPosition(){ + return 'bottom-left'; } } diff --git a/js/ui/map.js b/js/ui/map.js index aa5c2dfd570..9bb081e7b51 100755 --- a/js/ui/map.js +++ b/js/ui/map.js @@ -203,7 +203,7 @@ class Map extends Camera { if (options.style) this.setStyle(options.style); if (options.attributionControl) this.addControl(new AttributionControl()); - if (options.logoControl) this.addControl(new LogoControl(), 'bottom-left'); + if (options.logoControl) this.addControl(new LogoControl()); this.on('style.load', function() { if (this.transform.unmodified) { diff --git a/test/js/ui/control/logo.test.js b/test/js/ui/control/logo.test.js new file mode 100644 index 00000000000..48c5ddd575e --- /dev/null +++ b/test/js/ui/control/logo.test.js @@ -0,0 +1,46 @@ +'use strict'; + +const test = require('mapbox-gl-js-test').test; +const window = require('../../../../js/util/window'); +const Map = require('../../../../js/ui/map'); +const LogoControl = require('../../../../js/ui/control/logo_control'); + +function createMap() { + const container = window.document.createElement('div'); + return new Map({ + container: container, + attributionControl: false, + style: { + version: 8, + sources: {}, + layers: [] + } + }); +} + +test('LogoControl appears in bottom-left by default', (t) => { + const map = createMap(); + + t.equal(map.getContainer().querySelectorAll('.mapboxgl-ctrl-bottom-left .mapboxgl-ctrl-logo').length, 1); + t.end(); +}); + +test('LogoControl appears in the position specified by the position option', (t) => { + const map = createMap(); + map.addControl(new LogoControl(), 'top-left'); + + t.equal(map.getContainer().querySelectorAll('.mapboxgl-ctrl-top-left .mapboxgl-ctrl-logo').length, 1); + t.end(); +}); + +test('LogoControl is removed from map when map.removeControl is called', (t) => { + const map = createMap(); + const logoControl = new LogoControl(); + map.addControl(logoControl, 'top-left'); + t.equal(map.getContainer().querySelectorAll('.mapboxgl-ctrl-top-left .mapboxgl-ctrl-logo').length, 1); + map.removeControl(logoControl); + t.equal(map.getContainer().querySelectorAll('.mapboxgl-ctrl-top-left .mapboxgl-ctrl-logo').length, 0); + t.end(); +}) + +