Skip to content

Commit

Permalink
Added basic JS tests for OLMapWidget.js
Browse files Browse the repository at this point in the history
Thanks Trey Hunner for cleaning the initial patch and Tim Graham for
the review.
  • Loading branch information
claudep committed Oct 7, 2015
1 parent 914167a commit 1e8d482
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 1 deletion.
46 changes: 46 additions & 0 deletions js_tests/gis/mapwidget.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/* global module, test, MapWidget */
/* eslint global-strict: 0, strict: 0 */
'use strict';

module('gis.OLMapWidget');

test('MapWidget.featureAdded', function(assert) {
var options = {id: 'id_point', map_id: 'id_point_map', geom_name: 'Point'};
var widget = new MapWidget(options);
assert.equal(widget.layers.vector.features.length, 1);
assert.equal(
widget.layers.vector.features[0].geometry.toString(),
'POINT(7.8177 47.397)',
'Point addded to vector layer'
);
});

test('MapWidget.map_srid', function(assert) {
var options = {id: 'id_point', map_id: 'id_point_map', geom_name: 'Point'};
var widget = new MapWidget(options);
assert.equal(widget.options.map_srid, 4326, 'SRID 4326');
});

test('MapWidget.defaultCenter', function(assert) {
var options = {id: 'id_point', map_id: 'id_point_map', geom_name: 'Point'};
var widget = new MapWidget(options);
assert.equal(widget.defaultCenter().toString(), 'lon=0,lat=0', 'Default center at 0, 0');
options.default_lat = 47.08;
options.default_lon = 6.81;
widget = new MapWidget(options);
assert.equal(
widget.defaultCenter().toString(),
'lon=6.81,lat=47.08',
'Default center at 6.81, 47.08'
);
});

test('MapWidget.getControls', function(assert) {
var options = {id: 'id_point', map_id: 'id_point_map', geom_name: 'Point'};
var widget = new MapWidget(options);
widget.getControls(widget.layers.vector);
assert.equal(widget.controls.length, 3);
assert.equal(widget.controls[0].displayClass, 'olControlNavigation', 'Navigation control');
assert.equal(widget.controls[1].displayClass, 'olControlDrawFeaturePoint', 'Draw control');
assert.equal(widget.controls[2].displayClass, 'olControlModifyFeature', 'Modify control');
});
9 changes: 9 additions & 0 deletions js_tests/tests.html
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,15 @@
<script src='../django/contrib/admin/static/admin/js/prepopulate.js' data-cover></script>
<script src='../django/contrib/admin/static/admin/js/urlify.js' data-cover></script>

<div id="id_point_map">
<textarea id="id_point" name="point"
class="vSerializedField required" style="display:none;"
rows="10" cols="150">POINT (7.8177 47.397)</textarea>
</div>
<script src='http://openlayers.org/api/2.13.1/OpenLayers.js'></script>
<script src='../django/contrib/gis/static/gis/js/OLMapWidget.js' data-cover></script>
<script src='./gis/mapwidget.test.js'></script>

<script>
if (location.href.match(/(\?|&)gruntReport($|&|=)/)) {
blanket.options("reporter", "qunit/grunt-reporter.js");
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "Django",
"private": true,
"scripts": {
"pretest": "eslint django/ js_tests/admin/",
"pretest": "eslint django/ js_tests/admin/ js_tests/gis/",
"test": "grunt test --verbose"
},
"devDependencies": {
Expand Down

0 comments on commit 1e8d482

Please sign in to comment.