2016-12-19 18:43:47 +01:00
|
|
|
/* global QUnit, MapWidget */
|
2015-10-03 12:04:32 +02:00
|
|
|
'use strict';
|
|
|
|
|
2016-12-19 18:43:47 +01:00
|
|
|
QUnit.module('gis.OLMapWidget');
|
2015-10-03 12:04:32 +02:00
|
|
|
|
2016-12-19 18:43:47 +01:00
|
|
|
QUnit.test('MapWidget.featureAdded', function(assert) {
|
2020-04-21 02:39:15 +02:00
|
|
|
const options = {id: 'id_point', map_id: 'id_point_map', geom_name: 'Point'};
|
|
|
|
const widget = new MapWidget(options);
|
2015-05-25 17:31:26 +02:00
|
|
|
assert.equal(widget.featureCollection.getLength(), 1);
|
|
|
|
widget.serializeFeatures();
|
2015-10-03 12:04:32 +02:00
|
|
|
assert.equal(
|
2015-05-25 17:31:26 +02:00
|
|
|
document.getElementById('id_point').value,
|
|
|
|
'{"type":"Point","coordinates":[7.8177,47.397]}',
|
|
|
|
'Point added to vector layer'
|
2015-10-03 12:04:32 +02:00
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2016-12-19 18:43:47 +01:00
|
|
|
QUnit.test('MapWidget.map_srid', function(assert) {
|
2020-04-21 02:39:15 +02:00
|
|
|
const options = {id: 'id_point', map_id: 'id_point_map', geom_name: 'Point'};
|
|
|
|
const widget = new MapWidget(options);
|
2015-05-25 17:31:26 +02:00
|
|
|
assert.equal(widget.map.getView().getProjection().getCode(), 'EPSG:3857', 'SRID 3857');
|
2015-10-03 12:04:32 +02:00
|
|
|
});
|
|
|
|
|
2016-12-19 18:43:47 +01:00
|
|
|
QUnit.test('MapWidget.defaultCenter', function(assert) {
|
2020-04-21 02:39:15 +02:00
|
|
|
const options = {id: 'id_point', map_id: 'id_point_map', geom_name: 'Point'};
|
|
|
|
let widget = new MapWidget(options);
|
2015-05-25 17:31:26 +02:00
|
|
|
assert.equal(widget.defaultCenter().toString(), '0,0', 'Default center at 0, 0');
|
2015-10-03 12:04:32 +02:00
|
|
|
options.default_lat = 47.08;
|
|
|
|
options.default_lon = 6.81;
|
|
|
|
widget = new MapWidget(options);
|
|
|
|
assert.equal(
|
|
|
|
widget.defaultCenter().toString(),
|
2015-05-25 17:31:26 +02:00
|
|
|
'6.81,47.08',
|
2015-10-03 12:04:32 +02:00
|
|
|
'Default center at 6.81, 47.08'
|
|
|
|
);
|
2022-12-29 08:30:30 +01:00
|
|
|
assert.equal(Math.round(widget.map.getView().getZoom()), 17);
|
2015-10-03 12:04:32 +02:00
|
|
|
});
|
|
|
|
|
2015-05-25 17:31:26 +02:00
|
|
|
QUnit.test('MapWidget.interactions', function(assert) {
|
2020-04-21 02:39:15 +02:00
|
|
|
const options = {id: 'id_point', map_id: 'id_point_map', geom_name: 'Point'};
|
|
|
|
const widget = new MapWidget(options);
|
2015-05-25 17:31:26 +02:00
|
|
|
assert.equal(Object.keys(widget.interactions).length, 2);
|
|
|
|
assert.equal(widget.interactions.draw.getActive(), false, "Draw is inactive with an existing point");
|
|
|
|
assert.equal(widget.interactions.modify.getActive(), true, "Modify is active with an existing point");
|
|
|
|
});
|
|
|
|
|
|
|
|
QUnit.test('MapWidget.clearFeatures', function(assert) {
|
2020-04-21 02:39:15 +02:00
|
|
|
const options = {id: 'id_point', map_id: 'id_point_map', geom_name: 'Point'};
|
|
|
|
const widget = new MapWidget(options);
|
|
|
|
const initial_value = document.getElementById('id_point').value;
|
2015-05-25 17:31:26 +02:00
|
|
|
widget.clearFeatures();
|
|
|
|
assert.equal(document.getElementById('id_point').value, "");
|
|
|
|
document.getElementById('id_point').value = initial_value;
|
|
|
|
});
|
|
|
|
|
|
|
|
QUnit.test('MapWidget.multipolygon', function(assert) {
|
2020-04-21 02:39:15 +02:00
|
|
|
const options = {id: 'id_multipolygon', map_id: 'id_multipolygon_map', geom_name: 'MultiPolygon'};
|
|
|
|
const widget = new MapWidget(options);
|
2015-05-25 17:31:26 +02:00
|
|
|
assert.ok(widget.options.is_collection);
|
|
|
|
assert.equal(widget.interactions.draw.getActive(), true, "Draw is active with no existing content");
|
2015-10-03 12:04:32 +02:00
|
|
|
});
|
2016-07-30 22:08:50 +02:00
|
|
|
|
2016-12-19 18:43:47 +01:00
|
|
|
QUnit.test('MapWidget.IsCollection', function(assert) {
|
2020-04-21 02:39:15 +02:00
|
|
|
const options = {id: 'id_point', map_id: 'id_point_map', geom_name: 'Point'};
|
|
|
|
let widget = new MapWidget(options);
|
2016-07-30 22:08:50 +02:00
|
|
|
assert.notOk(widget.options.is_collection);
|
|
|
|
// Empty the default initial Point
|
|
|
|
document.getElementById('id_point').value = "";
|
|
|
|
|
|
|
|
options.geom_name = 'Polygon';
|
|
|
|
widget = new MapWidget(options);
|
|
|
|
assert.notOk(widget.options.is_collection);
|
|
|
|
|
|
|
|
options.geom_name = 'LineString';
|
|
|
|
widget = new MapWidget(options);
|
|
|
|
assert.notOk(widget.options.is_collection);
|
|
|
|
|
|
|
|
options.geom_name = 'MultiPoint';
|
|
|
|
widget = new MapWidget(options);
|
|
|
|
assert.ok(widget.options.is_collection);
|
|
|
|
|
|
|
|
options.geom_name = 'MultiPolygon';
|
|
|
|
widget = new MapWidget(options);
|
|
|
|
assert.ok(widget.options.is_collection);
|
|
|
|
|
|
|
|
options.geom_name = 'MultiLineString';
|
|
|
|
widget = new MapWidget(options);
|
|
|
|
assert.ok(widget.options.is_collection);
|
|
|
|
|
|
|
|
options.geom_name = 'GeometryCollection';
|
|
|
|
widget = new MapWidget(options);
|
|
|
|
assert.ok(widget.options.is_collection);
|
|
|
|
});
|