Skip to content

Commit

Permalink
Add test for TileJSON schemes, refactor VectorTileSource tests (#2594)
Browse files Browse the repository at this point in the history
ref #2565
  • Loading branch information
lucaswoj authored and mourner committed May 19, 2016
1 parent 43409c6 commit fad72fa
Showing 1 changed file with 50 additions and 16 deletions.
66 changes: 50 additions & 16 deletions test/js/source/vector_tile_source.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,39 @@ var st = require('st');
var http = require('http');
var path = require('path');
var VectorTileSource = require('../../../js/source/vector_tile_source');
var TileCoord = require('../../../js/source/tile_coord');

var server = http.createServer(st({path: path.join(__dirname, '/../../fixtures')}));

function createSource(options) {
var source = new VectorTileSource(options);

source.on('error', function(e) {
throw e.error;
});

source.dispatcher = { send: function() {} };

source.map = {
transform: { angle: 0, pitch: 0, showCollisionBoxes: false }
};

return source;
}

test('VectorTileSource', function(t) {
t.test('before', function(t) {
server.listen(2900, t.end);
});

t.test('can be constructed from TileJSON', function(t) {
var source = new VectorTileSource({
var source = createSource({
minzoom: 1,
maxzoom: 10,
attribution: "Mapbox",
tiles: ["http://example.com/{z}/{x}/{y}.png"]
});

source.on('error', function(e) {
t.error(e.error);
});

source.on('load', function() {
t.ok(source.loaded());
t.deepEqual(source.tiles, ["http://example.com/{z}/{x}/{y}.png"]);
Expand All @@ -36,14 +49,10 @@ test('VectorTileSource', function(t) {
});

t.test('can be constructed from a TileJSON URL', function(t) {
var source = new VectorTileSource({
var source = createSource({
url: "http://localhost:2900/source.json"
});

source.on('error', function(e) {
t.error(e.error);
});

source.on('load', function() {
t.ok(source.loaded());
t.deepEqual(source.tiles, ["http://example.com/{z}/{x}/{y}.png"]);
Expand All @@ -55,7 +64,7 @@ test('VectorTileSource', function(t) {
});

t.test('ignores reload before loaded', function(t) {
var source = new VectorTileSource({
var source = createSource({
url: "http://localhost:2900/source.json"
});

Expand All @@ -68,19 +77,19 @@ test('VectorTileSource', function(t) {
});
});

t.test('serialize', function(t) {
var source = new VectorTileSource({
url: "http://example.com"
t.test('serialize URL', function(t) {
var source = createSource({
url: "http://localhost:2900/source.json"
});
t.deepEqual(source.serialize(), {
type: 'vector',
url: "http://example.com"
url: "http://localhost:2900/source.json"
});
t.end();
});

t.test('serialize TileJSON', function(t) {
var source = new VectorTileSource({
var source = createSource({
minzoom: 1,
maxzoom: 10,
attribution: "Mapbox",
Expand All @@ -96,6 +105,31 @@ test('VectorTileSource', function(t) {
t.end();
});

function testScheme(scheme, expectedURL) {
t.test('scheme "' + scheme + '"', function(t) {
var source = createSource({
minzoom: 1,
maxzoom: 10,
attribution: "Mapbox",
tiles: ["http://example.com/{z}/{x}/{y}.png"],
scheme: scheme
});

source.dispatcher.send = function(type, params) {
t.equal(type, 'load tile');
t.equal(expectedURL, params.url);
t.end();
};

source.on('load', function() {
source._loadTile({coord: new TileCoord(10, 5, 5, 0)});
});
});
}

testScheme('xyz', 'http://example.com/10/5/5.png');
testScheme('tms', 'http://example.com/10/5/1018.png');

t.test('after', function(t) {
server.close(t.end);
});
Expand Down

0 comments on commit fad72fa

Please sign in to comment.