Debian Codegraph @

js_tests/gis/mapwidget.test.js

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