Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add promise-based tests to the tutorial tests. #727

Merged
merged 2 commits into from
Aug 4, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions tests/tutorials.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,25 @@ 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);
/* 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);
/* 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();
});
testDefer.resolve();
});
};
/* If we have already run the specific codeblock, don't run it
Expand Down
Binary file added tutorials/basic/thumb.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tutorials/tile_source/thumb.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
61 changes: 32 additions & 29 deletions tutorials/wms/index.pug
Original file line number Diff line number Diff line change
Expand Up @@ -18,43 +18,46 @@ block mainTutorial
});
// place a base tile layer on the map
map.createLayer('osm');

// 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);
// Set the WMS server parameters
var params = {
transparent: true,
format: 'png32',
bbox: bb.left + ',' + bb.bottom + ',' + bb.right + ',' + bb.top,
bboxSR: projection.split(':')[1],
imageSR: projection.split(':')[1],
size: '256,256',
layers: 'show:3',
f: 'image'
}
// construct the url for a tile. We can use jQuery's $.param function.
var url = baseUrl + '?' + $.param(params);
return url;
}

// create a tile layer with the WMS data
map.createLayer('osm', {
attribution: null,
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 can be generated from a function
url: function (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,
bboxSR: projection.split(':')[1],
imageSR: projection.split(':')[1],
size: '256,256',
layers: 'show:3',
f: 'image'
}
// construct the url for a tile. We can use jQuery's $.param function.
var url = baseUrl + '?' + $.param(params);
return url;
}
// 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"; }})'
])
Binary file added tutorials/wms/thumb.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.