Skip to content
This repository has been archived by the owner on Dec 1, 2020. It is now read-only.

Commit

Permalink
Merge pull request #150 from Esri/more-unit-tests
Browse files Browse the repository at this point in the history
Unit tests for esri.core services
  • Loading branch information
tomwayson committed Nov 16, 2015
2 parents c00b744 + b48db78 commit d97ce33
Show file tree
Hide file tree
Showing 12 changed files with 502 additions and 80 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,6 @@ node_modules

# WebStorm IDE settings
.idea

# istanbull test coverage reports
test/unit/coverage
13 changes: 12 additions & 1 deletion gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,13 +154,24 @@ gulp.task('karma-once', function(done) {
}, done).start();
});

gulp.task('karma-coverage', function(done) {
new KarmaServer({
configFile: __dirname + '/test/unit/karma.conf.js',
singleRun: true,
reporters: ['progress', 'coverage'],
preprocessors: {
'../../src/**/*.js': ['coverage']
}
}, done).start();
});

gulp.task('karma', function(done) {
new KarmaServer({
configFile: __dirname + '/test/unit/karma.conf.js'
}, done).start();
});

gulp.task('test', ['karma-once', 'serve-test'], function() {
gulp.task('test', ['karma-coverage', 'serve-test'], function() {
return gulp.src(['./test/e2e/specs/*.js'])
.pipe(angularProtractor({
'configFile': 'test/e2e/conf.js',
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"jasmine-core": "^2.3.4",
"karma": "^0.13.15",
"karma-chrome-launcher": "^0.2.1",
"karma-coverage": "^0.5.3",
"karma-jasmine": "^0.3.6",
"karma-phantomjs-launcher": "^0.2.1",
"phantomjs": "^1.9.18",
Expand Down
2 changes: 1 addition & 1 deletion site/app/examples/custom-basemap.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ angular.module('esri-map-docs')
esriMapUtils.addCustomBasemap('delorme', {
urls: ['http://services.arcgisonline.com/ArcGIS/rest/services/Specialty/DeLorme_World_Base_Map/MapServer'],
title: 'DeLorme',
thumbnailurl: 'http://servername.fqdn.suffix/images/thumbnail_2014-11-25_61051.png'
thumbnailUrl: 'http://servername.fqdn.suffix/images/thumbnail_2014-11-25_61051.png'
}).then(function(esriBasemaps) {
console.log(esriBasemaps);
// because we are adding the basemap in the controller,
Expand Down
9 changes: 6 additions & 3 deletions src/core/esriLayerUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,11 @@
/**
* @ngdoc function
* @name createFeatureLayer
* @description Create an instance of a {@link https://developers.arcgis.com/javascript/jsapi/featurelayer-amd.html FeatureLayer}
* @methodOf esri.core.factory:esriLayerUtils
* @param {String} url The url of the map or feature service layer
* @param {Object=} options FeatureLayer options
* @returns {Promise} Returns a $q style promise resolved with an instance of {@link https://developers.arcgis.com/javascript/jsapi/featurelayer-amd.html#featurelayer1 FeatureLayer}
* @returns {Promise} Returns a $q style promise resolved with an instance of a FeatureLayer
*/
service.createFeatureLayer = function(url, layerOptions) {
return esriLoader.require(['esri/layers/FeatureLayer', 'esri/InfoTemplate']).then(function(esriModules) {
Expand Down Expand Up @@ -84,10 +85,11 @@
/**
* @ngdoc function
* @name createDynamicMapServiceLayer
* @description Create an instance of an {@link https://developers.arcgis.com/javascript/jsapi/arcgisdynamicmapservicelayer-amd.html#arcgisdynamicmapservicelayer1 ArcGISDynamicMapServiceLayer}
* @methodOf esri.core.factory:esriLayerUtils
* @param {String} url The url of the map service
* @param {Object=} options ArcGISDynamicMapServiceLayer options
* @returns {Promise} Returns a $q style promise resolved with an instance of {@link https://developers.arcgis.com/javascript/jsapi/arcgisdynamicmapservicelayer-amd.html#arcgisdynamicmapservicelayer1 ArcGISDynamicMapServiceLayer}
* @returns {Promise} Returns a $q style promise resolved with an instance of ArcGISDynamicMapServiceLayer
*/
service.createDynamicMapServiceLayer = function(url, layerOptions, visibleLayers) {
return esriLoader.require(['esri/layers/ArcGISDynamicMapServiceLayer', 'esri/InfoTemplate', 'esri/layers/ImageParameters']).then(function(esriModules) {
Expand Down Expand Up @@ -141,9 +143,10 @@
/**
* @ngdoc function
* @name createInfoTemplate
* @description Create an instance of an {@link https://developers.arcgis.com/javascript/jsapi/infotemplate-amd.html InfoTemplate}
* @methodOf esri.core.factory:esriLayerUtils
* @param {Object|Array} infoTemplate Either an array with `['title', 'content']` or an object with `{title: 'title', content: 'content'}`
* @returns {Promise} Returns a $q style promise resolved with an instance of {@link https://developers.arcgis.com/javascript/jsapi/infotemplate-amd.html InfoTemplate}
* @returns {Promise} Returns a $q style promise resolved with an instance of InfoTemplate
*/
service.createInfoTemplate = function(infoTemplate) {
return esriLoader.require('esri/InfoTemplate').then(function(InfoTemplate) {
Expand Down
46 changes: 42 additions & 4 deletions src/core/esriMapUtils.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
(function(angular) {
'use strict';

/**
* @ngdoc service
* @name esri.core.factory:esriMapUtils
*
* @description
* Functions to help create map instances.
*
* @requires esri.core.factory:esriLoader
*/
angular.module('esri.core').factory('esriMapUtils', function($q, esriLoader) {

// construct Extent if object is not already an instance
Expand All @@ -16,7 +25,19 @@
// stateless utility service
var service = {};

// add a custom basemap definition to be used by maps
/**
* @ngdoc function
* @name addCustomBasemap
* @description Add a custom basemap definition to {@link https://developers.arcgis.com/javascript/jsapi/esri.basemaps-amd.html esriBasemaps}
* @methodOf esri.core.factory:esriMapUtils
* @param {String} name Name to be used when setting the basemap
* @param {Object} basemapDefinition Basemap layer urls and other options (either basemapDefinition.baseMapLayers or basemapDefinition.urls is required)
* @param {Array=} basemapDefinition.baseMapLayers Array of basemap layer objects
* @param {Array=} basemapDefinition.urls Array of basemap layer urls
* @param {String=} basemapDefinition.thumbnailUrl Basemap thumbnail URL
* @param {String=} basemapDefinition.title Basemap Title
* @returns {Promise} Returns a $q style promise resolved with esriBasemaps
*/
service.addCustomBasemap = function(name, basemapDefinition) {
return esriLoader.require('esri/basemaps').then(function(esriBasemaps) {
var baseMapLayers = basemapDefinition.baseMapLayers;
Expand All @@ -38,14 +59,22 @@
});
};

// create a new map at an element w/ the given id
/**
* @ngdoc function
* @name createMap
* @description Create a new {@link https://developers.arcgis.com/javascript/jsapi/map-amd.html Map} instance at an element w/ the given id
* @methodOf esri.core.factory:esriMapUtils
* @param {String} elementId Id of the element for the map
* @param {Object} options {@link https://developers.arcgis.com/javascript/jsapi/map-amd.html#map1 Optional parameters}
* @returns {Promise} Returns a $q style promise resolved with the Map instance
*/
service.createMap = function(elementId, mapOptions) {
return esriLoader.require(['esri/map', 'esri/geometry/Extent']).then(function(esriModules) {
var Map = esriModules[0];
var Extent = esriModules[1];

// construct optional Extent for mapOptions
if (mapOptions.hasOwnProperty('extent')) {
if (mapOptions && mapOptions.hasOwnProperty('extent')) {
mapOptions.extent = objectToExtent(mapOptions.extent, Extent);
}

Expand All @@ -55,8 +84,17 @@
});
};

/**
* @ngdoc function
* @name createWebMap
* @description Create a new {@link https://developers.arcgis.com/javascript/jsapi/map-amd.html Map} instance from a web map at an element w/ the given id
* @methodOf esri.core.factory:esriMapUtils
* @param {String} webmapId Item id of the web map
* @param {String} elementId Id of the element for the map
* @param {Object} options {@link https://developers.arcgis.com/javascript/jsapi/esri.arcgis.utils-amd.html#createmap Optional parameters}
* @returns {Promise} Returns a $q style promise resolved with the Map instance
*/
// TODO: would be better if we didn't have to pass mapController
// create a new map from a web map at an element w/ the given id
service.createWebMap = function(webmapId, elementId, mapOptions, mapController) {
// this deferred will be resolved with the map
// NOTE: wrapping in $q deferred to avoid injecting
Expand Down
2 changes: 1 addition & 1 deletion test/custom-basemap.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ <h2>Custom Basemap</h2>
esriMapUtils.addCustomBasemap('delorme', {
urls: ['http://services.arcgisonline.com/ArcGIS/rest/services/Specialty/DeLorme_World_Base_Map/MapServer'],
title: 'DeLorme',
thumbnailurl: 'http://servername.fqdn.suffix/images/thumbnail_2014-11-25_61051.png'
thumbnailUrl: 'http://servername.fqdn.suffix/images/thumbnail_2014-11-25_61051.png'
}).then(function(esriBasemaps) {
console.log(esriBasemaps);
// esri registry is only needed b/c basemap was not added before
Expand Down
Loading

0 comments on commit d97ce33

Please sign in to comment.