Skip to content

Commit

Permalink
fix unit tests 🔧
Browse files Browse the repository at this point in the history
  • Loading branch information
Molly Lloyd committed Mar 2, 2017
1 parent e770240 commit a1f38ae
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 29 deletions.
2 changes: 1 addition & 1 deletion src/source/geojson_source.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,13 @@ class GeoJSONSource extends Evented {
*/
setData(data) {
this._data = data;

this.fire('dataloading', {dataType: 'source'});
this._updateWorkerData((err) => {
if (err) {
return this.fire('error', { error: err });
}
this.fire('source.update');
this.fire('data', {dataType: 'source'});
});

return this;
Expand Down
6 changes: 3 additions & 3 deletions src/source/source_cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -417,17 +417,17 @@ class SourceCache extends Evented {
}
}
}

if (!tile) {
const cached = Boolean(tile);
if (!cached) {
const zoom = coord.z;
const overscaling = zoom > this._source.maxzoom ? Math.pow(2, zoom - this._source.maxzoom) : 1;
tile = new Tile(wrapped, this._source.tileSize * overscaling, this._source.maxzoom);
this._source.fire('dataloading', {tile: tile, coord: tile.coord, dataType: 'tile'});
this.loadTile(tile, this._tileLoaded.bind(this, tile, coord.id));
}

tile.uses++;
this._tiles[coord.id] = tile;
if (!cached) this._source.fire('dataloading', {tile: tile, coord: tile.coord, dataType: 'tile'});

return tile;
}
Expand Down
1 change: 0 additions & 1 deletion src/source/vector_tile_source.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ class VectorTileSource extends Evented {
return;
}
util.extend(this, tileJSON);

this.fire('source.load');
this.fire('source.update');
});
Expand Down
10 changes: 4 additions & 6 deletions src/ui/control/attribution_control.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class AttributionControl {
this._updateAttributions();
this._updateEditLink();

this._map.on('data', this._updateData);
this._map.on('source.load', this._updateData);
this._map.on('moveend', this._updateEditLink);

if (compact === undefined) {
Expand All @@ -58,7 +58,7 @@ class AttributionControl {
onRemove() {
this._container.parentNode.removeChild(this._container);

this._map.off('data', this._updateData);
this._map.off('source.load', this._updateData);
this._map.off('moveend', this._updateEditLink);
this._map.off('resize', this._updateCompact);

Expand All @@ -75,10 +75,8 @@ class AttributionControl {
}

_updateData(event) {
if (event.dataType === 'source') {
this._updateAttributions();
this._updateEditLink();
}
this._updateAttributions();
this._updateEditLink();
}

_updateAttributions() {
Expand Down
4 changes: 2 additions & 2 deletions src/ui/control/logo_control.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ class LogoControl {
this._map = map;
this._container = DOM.create('div', 'mapboxgl-ctrl');

this._map.on('data', this._updateLogo);
this._map.on('source.load', this._updateLogo);
this._updateLogo();
return this._container;
}

onRemove() {
this._container.parentNode.removeChild(this._container);
this._map.off('data', this._updateLogo);
this._map.off('source.load', this._updateLogo);
}

getDefaultPosition() {
Expand Down
8 changes: 4 additions & 4 deletions test/unit/source/source_cache.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ test('SourceCache#addTile', (t) => {
sourceCache.addTile(coord);

t.equal(load, 1);
t.equal(add, 2);
t.equal(add, 1);

t.end();
});
Expand Down Expand Up @@ -181,7 +181,7 @@ test('SourceCache#addTile', (t) => {
const t2 = sourceCache.addTile(new TileCoord(0, 0, 0, 1));

t.equal(load, 1);
t.equal(add, 2);
t.equal(add, 1);
t.equal(t1, t2);

t.end();
Expand Down Expand Up @@ -291,7 +291,7 @@ test('SourceCache / Source lifecycle', (t) => {
sourceCache.onAdd();
});

t.test('reloads tiles after a "source" data event', (t) => {
t.test('reloads tiles after a "source.update" event', (t) => {
const transform = new Transform();
transform.resize(511, 511);
transform.zoom = 0;
Expand All @@ -309,7 +309,7 @@ test('SourceCache / Source lifecycle', (t) => {

sourceCache.on('source.load', () => {
sourceCache.update(transform);
sourceCache.getSource().fire('data', {dataType: 'source'});
sourceCache.getSource().fire('source.update');
});

sourceCache.onAdd();
Expand Down
6 changes: 3 additions & 3 deletions test/unit/source/vector_tile_source.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ test('VectorTileSource', (t) => {
window.server.respond();
});

t.test('fires "data" event', (t) => {
t.test('fires "source.update" event', (t) => {
window.server.respondWith('/source.json', JSON.stringify(require('../../fixtures/source')));
const source = createSource({ url: "/source.json" });
source.on('data', t.end);
source.on('source.update', t.end);
window.server.respond();
});

Expand All @@ -78,7 +78,7 @@ test('VectorTileSource', (t) => {
dataloadingFired = true;
});
const source = createSource({ url: "/source.json", eventedParent: evented });
source.on('data', () => {
source.on('source.load', () => {
if (!dataloadingFired) t.fail();
t.end();
});
Expand Down
16 changes: 7 additions & 9 deletions test/unit/ui/control/attribution.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ test('AttributionControl dedupes attributions that are substrings of others', (t
});

let times = 0;
map.on('data', (event) => {
if (event.dataType === 'source' && ++times === 5) {
map.on('source.load', () => {
if (++times === 5) {
t.equal(attribution._container.innerHTML, 'Hello World | Another Source');
t.end();
}
Expand All @@ -104,13 +104,11 @@ test('AttributionControl has the correct edit map link', (t) => {

map.on('load', () => {
map.addSource('1', {type: 'vector', attribution: '<a class="mapbox-improve-map" href="https://www.mapbox.com/map-feedback/" target="_blank">Improve this map</a>'});
map.on('data', (event) => {
if (event.dataType === 'source') {
t.equal(attribution._editLink.href, 'https://www.mapbox.com/map-feedback/#/0/0/1', 'edit link contains map location data');
map.setZoom(2);
t.equal(attribution._editLink.href, 'https://www.mapbox.com/map-feedback/#/0/0/3', 'edit link updates on mapmove');
t.end();
}
map.on('source.load', () => {
t.equal(attribution._editLink.href, 'https://www.mapbox.com/map-feedback/#/0/0/1', 'edit link contains map location data');
map.setZoom(2);
t.equal(attribution._editLink.href, 'https://www.mapbox.com/map-feedback/#/0/0/3', 'edit link updates on mapmove');
t.end();
});
});
});

0 comments on commit a1f38ae

Please sign in to comment.