summaryrefslogtreecommitdiff
path: root/www/wiki/extensions/Maps/tests/js/leaflet/GeoJsonTest.js
blob: 768db78855829b3082c2d4075434bdcafaa14536 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
( function () {
	QUnit.module( 'Maps' );

	let GeoJSON = window.maps.leaflet.GeoJson;

	QUnit.test( 'GeoJSON.simpleStyleToLeafletPathOptions', function ( assert ) {
		assert.deepEqual(
			GeoJSON.simpleStyleToLeafletPathOptions( {} ),
			{},
			'Empty properties results in empty path'
		);

		let pathOptions = GeoJSON.simpleStyleToLeafletPathOptions( {
			"stroke": "#a92c2c",
			"stroke-width": 5.1,
			"stroke-opacity": 1,
			"fill": "#ffff00",
			"fill-opacity": 0.5,
			"title": "hi"
		} );

		assert.equal(
			pathOptions.color,
			'#a92c2c',
			'color is set (based on stroke)'
		);

		assert.equal(
			pathOptions.weight,
			5.1,
			'weight is set (based on stroke-width)'
		);

		assert.equal(
			pathOptions.opacity,
			1,
			'opacity is set (based on stroke-opacity)'
		);

		assert.equal(
			pathOptions.fillColor,
			"#ffff00",
			'fillColor is set'
		);

		assert.equal(
			pathOptions.fillOpacity,
			0.5,
			'fillOpacity is set'
		);
	} );

	QUnit.test( 'GeoJSON.popupContentFromProperties', function ( assert ) {
		assert.equal(
			GeoJSON.popupContentFromProperties({
				title: 'Hello World',
				description: 'pew pew'
			}),
			'<strong>Hello World</strong><br>pew pew',
			'Title and description: title is made bold and description is on a new line'
		);

		assert.equal(
			GeoJSON.popupContentFromProperties({
				title: 'Hello World'
			}),
			'Hello World',
			'Only title'
		);

		assert.equal(
			GeoJSON.popupContentFromProperties({
				description: 'pew pew'
			}),
			'pew pew',
			'Only description'
		);

		assert.equal(
			GeoJSON.popupContentFromProperties({
			}),
			'',
			'No content'
		);

		assert.equal(
			GeoJSON.popupContentFromProperties({
				title: 'Hello <a href="#">link</a>'
			}),
			'Hello &lt;a href=\"#\"&gt;link&lt;/a&gt;',
			'Title escaping'
		);

		assert.equal(
			GeoJSON.popupContentFromProperties({
				description: 'Hello <a href="#">link</a>'
			}),
			'Hello &lt;a href=\"#\"&gt;link&lt;/a&gt;',
			'Description escaping'
		);

		assert.equal(
			GeoJSON.popupContentFromProperties({
				title: 'Hello <a href="#">link</a>',
				description: "<script>alert('evil')</script>"
			}),
			'<strong>Hello &lt;a href=\"#\"&gt;link&lt;/a&gt;</strong><br>&lt;script&gt;alert(\'evil\')&lt;/script&gt;',
			'Title and description escaping'
		);
	} );

}() );