Add promise-based tests to the tutorials.
This allows tutorial tests to include promises.  This ensure that, for instance, the external WMS server in that example returns a PNG.
MODIFY
tests/tutorials.js
tests/tutorials.js
@@ -58,15 +58,26 @@ describe('tutorials', function () {
tut$.when.apply(tut$, deferreds).fail(function () {
throw new Error('Idle functions were rejected');
}).then(function () {
+ var subtestDeferreds = [];
test.data('tests').forEach(function (testExp) {
- var result = targetWindow.eval(testExp);
+ /* The test expression can return a value or a promise. We
+ * use jQuery's when to generically get the results in a
+ * resolution function. A rejection is a failure. */
+ var testResult = targetWindow.eval(testExp);
+ var subtestDefer = tut$.when(testResult).done(function (result) {
/* If the result isn't truthy, make sure our expect has a
* description telling which test block and specific test
* failed. */
expect(result).toBeTruthy(test.data('description') + ' -> ' + testExp);
+ }).fail(function () {
+ expect(false).toBeTruthy(test.data('description') + ' promise failed -> ' + testExp);
});
+ subtestDeferreds.push(subtestDefer);
+ });
+ tut$.when.apply(tut$, subtestDeferreds).then(function () {
testDefer.resolve();
});
+ });
};
/* If we have already run the specific codeblock, don't run it
* again. If not, click run and wait for the results. On the

MODIFY
tutorials/wms/index.pug
tutorials/wms/index.pug
@@ -18,29 +18,21 @@ block mainTutorial
});
// place a base tile layer on the map
map.createLayer('osm');
- // create a tile layer with the WMS data
- map.createLayer('osm', {
- attribution: null,
- // the tiles are transparent, so don't keep the lower level ones; they
- // would build up
- keepLower: false,
- // the map tile URL can be generated from a function
- url: function (x, y, zoom) {
+
+ // define a function that, given a tile location, returns a URL with
+ // appropriate parameters for a WMS server
+ function getWMSURL(x, y, zoom) {
var service = 'NWS_Observations';
var observation = 'radar_base_reflectivity';
// get data from NOAA
var baseUrl = 'https://idpgis.ncep.noaa.gov/arcgis/rest/services/' + service + '/' + observation + '/MapServer/export';
-
// Get the bounding box of the tile in the desired projection
var bb = this.gcsTileBounds({x: x, y: y, level: zoom}, projection);
- // make a string which the WMS server requires for the bounding box
- var bbSpec = bb.left + ',' + bb.bottom + ',' + bb.right + ',' + bb.top;
-
// Set the WMS server parameters
var params = {
transparent: true,
format: 'png32',
- bbox: bbSpec,
+ bbox: bb.left + ',' + bb.bottom + ',' + bb.right + ',' + bb.top,
bboxSR: projection.split(':')[1],
imageSR: projection.split(':')[1],
size: '256,256',
@@ -51,10 +43,21 @@ block mainTutorial
var url = baseUrl + '?' + $.param(params);
return url;
}
+
+ // create a tile layer with the WMS data
+ map.createLayer('osm', {
+ attribution: 'Data from <a href="https://idpgis.ncep.noaa.gov/arcgis/rest/services/NWS_Observations/">NOAA</a>',
+ // the tiles are transparent, so don't keep the lower level ones; they
+ // would build up
+ keepLower: false,
+ // the map tile URL is generated from a function
+ url: getWMSURL
});
+codeblock_test('map has two osm layers, one from a WMS server', [
'map.layers().length === 2',
'map.layers()[0] instanceof geo.osmLayer',
'map.layers()[1] instanceof geo.osmLayer',
- 'geo.util.isFunction(map.layers()[1].url())'
+ 'geo.util.isFunction(map.layers()[1].url())',
+ /* Test that the WMS server responds with a PNG */
+ '$.ajax({url: getWMSURL.call(map.layers()[1], 3, 6, 4), dataFilter: function (resp) { return resp.substr(1, 3) == "PNG"; }})'
])

Add promise-based tests to the tutorials.

This allows tutorial tests to include promises.  This ensure that, for instance, the external WMS server in that example returns a PNG.