mapwidget.test.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /* global QUnit, MapWidget */
  2. 'use strict';
  3. QUnit.module('gis.OLMapWidget');
  4. QUnit.test('MapWidget.featureAdded', function(assert) {
  5. const options = {id: 'id_point', map_id: 'id_point_map', geom_name: 'Point'};
  6. const widget = new MapWidget(options);
  7. assert.equal(widget.featureCollection.getLength(), 1);
  8. widget.serializeFeatures();
  9. assert.equal(
  10. document.getElementById('id_point').value,
  11. '{"type":"Point","coordinates":[7.8177,47.397]}',
  12. 'Point added to vector layer'
  13. );
  14. });
  15. QUnit.test('MapWidget.map_srid', function(assert) {
  16. const options = {id: 'id_point', map_id: 'id_point_map', geom_name: 'Point'};
  17. const widget = new MapWidget(options);
  18. assert.equal(widget.map.getView().getProjection().getCode(), 'EPSG:3857', 'SRID 3857');
  19. });
  20. QUnit.test('MapWidget.defaultCenter', function(assert) {
  21. const options = {id: 'id_point', map_id: 'id_point_map', geom_name: 'Point'};
  22. let widget = new MapWidget(options);
  23. assert.equal(widget.defaultCenter().toString(), '0,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. '6.81,47.08',
  30. 'Default center at 6.81, 47.08'
  31. );
  32. assert.equal(Math.round(widget.map.getView().getZoom()), 17);
  33. });
  34. QUnit.test('MapWidget.interactions', function(assert) {
  35. const options = {id: 'id_point', map_id: 'id_point_map', geom_name: 'Point'};
  36. const widget = new MapWidget(options);
  37. assert.equal(Object.keys(widget.interactions).length, 2);
  38. assert.equal(widget.interactions.draw.getActive(), false, "Draw is inactive with an existing point");
  39. assert.equal(widget.interactions.modify.getActive(), true, "Modify is active with an existing point");
  40. });
  41. QUnit.test('MapWidget.clearFeatures', function(assert) {
  42. const options = {id: 'id_point', map_id: 'id_point_map', geom_name: 'Point'};
  43. const widget = new MapWidget(options);
  44. const initial_value = document.getElementById('id_point').value;
  45. widget.clearFeatures();
  46. assert.equal(document.getElementById('id_point').value, "");
  47. document.getElementById('id_point').value = initial_value;
  48. });
  49. QUnit.test('MapWidget.multipolygon', function(assert) {
  50. const options = {id: 'id_multipolygon', map_id: 'id_multipolygon_map', geom_name: 'MultiPolygon'};
  51. const widget = new MapWidget(options);
  52. assert.ok(widget.options.is_collection);
  53. assert.equal(widget.interactions.draw.getActive(), true, "Draw is active with no existing content");
  54. });
  55. QUnit.test('MapWidget.IsCollection', function(assert) {
  56. const options = {id: 'id_point', map_id: 'id_point_map', geom_name: 'Point'};
  57. let widget = new MapWidget(options);
  58. assert.notOk(widget.options.is_collection);
  59. // Empty the default initial Point
  60. document.getElementById('id_point').value = "";
  61. options.geom_name = 'Polygon';
  62. widget = new MapWidget(options);
  63. assert.notOk(widget.options.is_collection);
  64. options.geom_name = 'LineString';
  65. widget = new MapWidget(options);
  66. assert.notOk(widget.options.is_collection);
  67. options.geom_name = 'MultiPoint';
  68. widget = new MapWidget(options);
  69. assert.ok(widget.options.is_collection);
  70. options.geom_name = 'MultiPolygon';
  71. widget = new MapWidget(options);
  72. assert.ok(widget.options.is_collection);
  73. options.geom_name = 'MultiLineString';
  74. widget = new MapWidget(options);
  75. assert.ok(widget.options.is_collection);
  76. options.geom_name = 'GeometryCollection';
  77. widget = new MapWidget(options);
  78. assert.ok(widget.options.is_collection);
  79. });