mapwidget.test.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /* global QUnit, MapWidget */
  2. /* eslint global-strict: 0, strict: 0 */
  3. 'use strict';
  4. QUnit.module('gis.OLMapWidget');
  5. QUnit.test('MapWidget.featureAdded', function(assert) {
  6. var options = {id: 'id_point', map_id: 'id_point_map', geom_name: 'Point'};
  7. var widget = new MapWidget(options);
  8. assert.equal(widget.layers.vector.features.length, 1);
  9. assert.equal(
  10. widget.layers.vector.features[0].geometry.toString(),
  11. 'POINT(7.8177 47.397)',
  12. 'Point addded to vector layer'
  13. );
  14. });
  15. QUnit.test('MapWidget.map_srid', function(assert) {
  16. var options = {id: 'id_point', map_id: 'id_point_map', geom_name: 'Point'};
  17. var widget = new MapWidget(options);
  18. assert.equal(widget.options.map_srid, 4326, 'SRID 4326');
  19. });
  20. QUnit.test('MapWidget.defaultCenter', function(assert) {
  21. var options = {id: 'id_point', map_id: 'id_point_map', geom_name: 'Point'};
  22. var widget = new MapWidget(options);
  23. assert.equal(widget.defaultCenter().toString(), 'lon=0,lat=0', 'Default center at 0, 0');
  24. options.default_lat = 47.08;
  25. options.default_lon = 6.81;
  26. widget = new MapWidget(options);
  27. assert.equal(
  28. widget.defaultCenter().toString(),
  29. 'lon=6.81,lat=47.08',
  30. 'Default center at 6.81, 47.08'
  31. );
  32. });
  33. QUnit.test('MapWidget.getControls', function(assert) {
  34. var options = {id: 'id_point', map_id: 'id_point_map', geom_name: 'Point'};
  35. var widget = new MapWidget(options);
  36. widget.getControls(widget.layers.vector);
  37. assert.equal(widget.controls.length, 3);
  38. assert.equal(widget.controls[0].displayClass, 'olControlNavigation', 'Navigation control');
  39. assert.equal(widget.controls[1].displayClass, 'olControlDrawFeaturePoint', 'Draw control');
  40. assert.equal(widget.controls[2].displayClass, 'olControlModifyFeature', 'Modify control');
  41. });
  42. QUnit.test('MapWidget.IsCollection', function(assert) {
  43. var options = {id: 'id_point', map_id: 'id_point_map', geom_name: 'Point'};
  44. var widget = new MapWidget(options);
  45. assert.notOk(widget.options.is_collection);
  46. // Empty the default initial Point
  47. document.getElementById('id_point').value = "";
  48. options.geom_name = 'Polygon';
  49. widget = new MapWidget(options);
  50. assert.notOk(widget.options.is_collection);
  51. options.geom_name = 'LineString';
  52. widget = new MapWidget(options);
  53. assert.notOk(widget.options.is_collection);
  54. options.geom_name = 'MultiPoint';
  55. widget = new MapWidget(options);
  56. assert.ok(widget.options.is_collection);
  57. options.geom_name = 'MultiPolygon';
  58. widget = new MapWidget(options);
  59. assert.ok(widget.options.is_collection);
  60. options.geom_name = 'MultiLineString';
  61. widget = new MapWidget(options);
  62. assert.ok(widget.options.is_collection);
  63. options.geom_name = 'GeometryCollection';
  64. widget = new MapWidget(options);
  65. assert.ok(widget.options.is_collection);
  66. });