Skip to content

Commit

Permalink
address feedback, add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Molly Lloyd committed Jan 10, 2017
1 parent 1bb0f0b commit 299fc3b
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 5 deletions.
8 changes: 4 additions & 4 deletions js/ui/control/logo_control.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -26,7 +23,10 @@ class LogoControl {

onRemove() {
this._container.parentNode.removeChild(this._container);
this._map = undefined;
}

getDefaultPosition(){
return 'bottom-left';
}
}

Expand Down
2 changes: 1 addition & 1 deletion js/ui/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
46 changes: 46 additions & 0 deletions test/js/ui/control/logo.test.js
Original file line number Diff line number Diff line change
@@ -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();
})


0 comments on commit 299fc3b

Please sign in to comment.