Skip to content

Commit

Permalink
test(add mapbox and mapquest static tests):
Browse files Browse the repository at this point in the history
  • Loading branch information
cvalenzuela committed Sep 1, 2017
1 parent fbd26ee commit 51607e9
Show file tree
Hide file tree
Showing 4 changed files with 180 additions and 1 deletion.
4 changes: 3 additions & 1 deletion test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// All tests
// ----------

// import './static/Google.test';
import './static/Google.test';
import './static/Mapbox.test';
import './static/Mapquest.test';
import './tile/Google.test';
// import './tile/Mapbox.test';
7 changes: 7 additions & 0 deletions test/static/Google.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,10 @@ describe('Google staticMap imgUrl', function () {
expect(googleStaticMap.imgUrl).to.include('key=' + googleStaticKey);
});
});

describe('Static Methods', function () {
it('should be a valid latlng', function () {
expect(googleStaticMap.latLngToPixel(0,0)).to.have.property('x').that.is.a('number');
expect(googleStaticMap.latLngToPixel(0,0)).to.have.property('y').that.is.a('number');
});
});
85 changes: 85 additions & 0 deletions test/static/Mapbox.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
// -----------
// Tests for Mapbox Static API v1
// Reference: https://www.mapbox.com/api-documentation/#static
// -----------

import { expect } from 'chai';
import Mappa from '../../src/index';

var mapboxStaticOptions = {
lat: 0,
lng: 0,
zoom: 0,
scale: 1,
width: 650,
height: 650
}
var mapboxStaticKey = 'abcd'
var mapboxStaticMappa = new Mappa('Mapbox', mapboxStaticKey);
var mapboxStaticMap = mapboxStaticMappa.staticMap(mapboxStaticOptions);

describe('Mapbox static instance', function () {
it('should return a new mappa object with provider and key', function () {
expect(mapboxStaticMappa).to.include.all.keys('provider', 'key');
});
});

describe('Mapbox static options initialization', function () {
it('should return a scale of 1 if scale is undefined', function () {
expect(mapboxStaticMap.options).to.have.property('scale', 1);
});
it('should return a pixel option of 256 if scale is undefined', function () {
expect(mapboxStaticMap.options).to.have.property('pixels', 256);
});
it('should return a pixel scale option of 2 if scale is 2', function () {
var mapboxStaticOptions = {
lat: 0,
lng: 0,
zoom: 0,
scale: 2,
width: 650,
height: 650
}
var mapboxStaticMap = mapboxStaticMappa.staticMap(mapboxStaticOptions);
expect(mapboxStaticMap.options).to.have.property('scale', 2);
});
it('should return a pixel option of 512 if scale is 2', function () {
var mapboxStaticOptions = {
lat: 0,
lng: 0,
zoom: 0,
scale: 2,
width: 650,
height: 650
}
var mapboxStaticMap = mapboxStaticMappa.staticMap(mapboxStaticOptions);
expect(mapboxStaticMap.options).to.have.property('pixels', 512);
});
});

describe('Mapbox staticMap options', function () {
it('should contain valid options', function () {
expect(mapboxStaticMap.options).to.not.have.property('lat', undefined);
expect(mapboxStaticMap.options).to.not.have.property('lng', undefined);
expect(mapboxStaticMap.options).to.not.have.property('zoom', undefined);
expect(mapboxStaticMap.options).to.not.have.property('width', undefined);
expect(mapboxStaticMap.options).to.not.have.property('height', undefined);
expect(mapboxStaticMap.options).to.not.have.property('key', undefined);
expect(mapboxStaticMap.options).to.not.have.property('pixels', undefined);
expect(mapboxStaticMap.options).to.not.have.property('scale', undefined);
expect(mapboxStaticMap.options).to.not.have.property('size', undefined);
expect(mapboxStaticMap.options).to.not.have.property('center', undefined);
});
});

describe('Mapbox staticMap imgUrl', function () {
it('should be a string', function () {
expect(mapboxStaticMap.imgUrl).to.be.a('string');
});
it('should be a valid Mapbox Maps url', function () {
expect(mapboxStaticMap.imgUrl).to.not.include('undefined');
expect(mapboxStaticMap.imgUrl).to.not.include('null');
expect(mapboxStaticMap.imgUrl).to.include('https://api.mapbox.com/styles/v1/');
expect(mapboxStaticMap.imgUrl).to.include('access_token=' + mapboxStaticKey);
});
});
85 changes: 85 additions & 0 deletions test/static/Mapquest.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
// -----------
// Tests for Mapquest v5
// Reference: https://developer.mapquest.com/documentation/static-map-api/v5/
// -----------

import { expect } from 'chai';
import Mappa from '../../src/index';

var mapquestStaticOptions = {
lat: 0,
lng: 0,
zoom: 0,
scale: 1,
width: 650,
height: 650
}
var mapquestStaticKey = 'abcd'
var mapquestStaticMappa = new Mappa('Mapquest', mapquestStaticKey);
var mapquestStaticMap = mapquestStaticMappa.staticMap(mapquestStaticOptions);

describe('Mapquest static instance', function () {
it('should return a new mappa object with provider and key', function () {
expect(mapquestStaticMappa).to.include.all.keys('provider', 'key');
});
});

describe('Mapquest static options initialization', function () {
it('should return a scale of 1 if scale is undefined', function () {
expect(mapquestStaticMap.options).to.have.property('scale', 1);
});
it('should return a pixel option of 128 if scale is undefined', function () {
expect(mapquestStaticMap.options).to.have.property('pixels', 128);
});
it('should return a pixel scale option of 2 if scale is 2', function () {
var mapquestStaticOptions = {
lat: 0,
lng: 0,
zoom: 0,
scale: 2,
width: 650,
height: 650
}
var mapquestStaticMap = mapquestStaticMappa.staticMap(mapquestStaticOptions);
expect(mapquestStaticMap.options).to.have.property('scale', 2);
});
it('should return a pixel option of 256 if scale is 2', function () {
var mapquestStaticOptions = {
lat: 0,
lng: 0,
zoom: 0,
scale: 2,
width: 650,
height: 650
}
var mapquestStaticMap = mapquestStaticMappa.staticMap(mapquestStaticOptions);
expect(mapquestStaticMap.options).to.have.property('pixels', 256);
});
});

describe('Mapquest staticMap options', function () {
it('should contain valid options', function () {
expect(mapquestStaticMap.options).to.not.have.property('lat', undefined);
expect(mapquestStaticMap.options).to.not.have.property('lng', undefined);
expect(mapquestStaticMap.options).to.not.have.property('zoom', undefined);
expect(mapquestStaticMap.options).to.not.have.property('width', undefined);
expect(mapquestStaticMap.options).to.not.have.property('height', undefined);
expect(mapquestStaticMap.options).to.not.have.property('key', undefined);
expect(mapquestStaticMap.options).to.not.have.property('pixels', undefined);
expect(mapquestStaticMap.options).to.not.have.property('scale', undefined);
expect(mapquestStaticMap.options).to.not.have.property('size', undefined);
expect(mapquestStaticMap.options).to.not.have.property('center', undefined);
});
});

describe('Mapquest staticMap imgUrl', function () {
it('should be a string', function () {
expect(mapquestStaticMap.imgUrl).to.be.a('string');
});
it('should be a valid Mapquest Maps url', function () {
expect(mapquestStaticMap.imgUrl).to.not.include('undefined');
expect(mapquestStaticMap.imgUrl).to.not.include('null');
expect(mapquestStaticMap.imgUrl).to.include('https://www.mapquestapi.com/staticmap/v5/');
expect(mapquestStaticMap.imgUrl).to.include('key=' + mapquestStaticKey);
});
});

0 comments on commit 51607e9

Please sign in to comment.