@@ -4,6 +4,7 @@ import $ from 'jquery';
4
4
import PluginSettings from './settings' ;
5
5
import { TemplateSrv } from 'grafana/app/features/templating/template_srv' ;
6
6
import DataFormatter from './data_formatter' ;
7
+ import { ColorModes } from './model' ;
7
8
8
9
describe ( 'Worldmap' , ( ) => {
9
10
let worldMap ;
@@ -150,6 +151,56 @@ describe('Worldmap', () => {
150
151
} ) ;
151
152
} ) ;
152
153
154
+ describe ( 'when the data has three points and color mode is threshold' , ( ) => {
155
+ beforeEach ( ( ) => {
156
+ ctrl . data = new DataBuilder ( )
157
+ . withCountryAndValue ( 'SE' , 1 )
158
+ . withCountryAndValue ( 'IE' , 2 )
159
+ . withCountryAndValue ( 'US' , 3 )
160
+ . withDataRange ( 1 , 3 , 2 )
161
+ . withThresholdValues ( [ 2 ] )
162
+ . build ( ) ;
163
+ ctrl . panel . circleMinSize = '2' ;
164
+ ctrl . panel . circleMaxSize = '10' ;
165
+ ctrl . panel . colorMode = ColorModes . threshold . id ;
166
+ worldMap . drawCircles ( ) ;
167
+ } ) ;
168
+
169
+ it ( 'should set red color on values under threshold' , ( ) => {
170
+ expect ( worldMap . circles [ 0 ] . options . color ) . toBe ( 'red' ) ;
171
+ } ) ;
172
+
173
+ it ( 'should set blue color on values equal to or over threshold' , ( ) => {
174
+ expect ( worldMap . circles [ 1 ] . options . color ) . toBe ( 'blue' ) ;
175
+ expect ( worldMap . circles [ 2 ] . options . color ) . toBe ( 'blue' ) ;
176
+ } ) ;
177
+ } ) ;
178
+
179
+ describe ( 'when the data has three points and color mode is categories' , ( ) => {
180
+ beforeEach ( ( ) => {
181
+ ctrl . data = new DataBuilder ( )
182
+ . withCountryAndValue ( 'SE' , 1 )
183
+ . withCountryAndValue ( 'IE' , 2 )
184
+ . withCountryAndValue ( 'US' , 3 )
185
+ . withDataRange ( 1 , 3 , 2 )
186
+ . withCategories ( [ 'Sweden' ] )
187
+ . build ( ) ;
188
+ ctrl . panel . circleMinSize = '2' ;
189
+ ctrl . panel . circleMaxSize = '10' ;
190
+ ctrl . panel . colorMode = ColorModes . categories . id ;
191
+ worldMap . drawCircles ( ) ;
192
+ } ) ;
193
+
194
+ it ( 'should set red color on locations not defined in categories' , ( ) => {
195
+ expect ( worldMap . circles [ 1 ] . options . color ) . toBe ( 'red' ) ;
196
+ expect ( worldMap . circles [ 2 ] . options . color ) . toBe ( 'red' ) ;
197
+ } ) ;
198
+
199
+ it ( 'should set blue color on defined categories' , ( ) => {
200
+ expect ( worldMap . circles [ 0 ] . options . color ) . toBe ( 'blue' ) ;
201
+ } ) ;
202
+ } ) ;
203
+
153
204
describe ( 'when the data has empty values and hideEmpty is true' , ( ) => {
154
205
beforeEach ( ( ) => {
155
206
ctrl . data = new DataBuilder ( )
@@ -323,6 +374,42 @@ describe('Worldmap', () => {
323
374
} ) ;
324
375
} ) ;
325
376
377
+ describe ( 'when three thresholds are set and color mode is threshold' , ( ) => {
378
+ beforeEach ( ( ) => {
379
+ ctrl . panel . colorMode = ColorModes . threshold . id ;
380
+ ctrl . data = new DataBuilder ( ) . withThresholdValues ( [ 2 , 4 , 6 ] ) . build ( ) ;
381
+ worldMap . createLegend ( ) ;
382
+ } ) ;
383
+
384
+ it ( 'should create a legend with four legend values' , ( ) => {
385
+ expect ( worldMap . legend ) . toBeDefined ( ) ;
386
+ expect ( worldMap . legend . _div . outerHTML ) . toBe (
387
+ '<div class="info legend leaflet-control"><div class="legend-item">' +
388
+ '<i style="background:red"></i> < 2</div><div class="legend-item"><i style="background:blue"></i> 2–4</div>' +
389
+ '<div class="legend-item"><i style="background:green"></i> 4–6</div>' +
390
+ '<div class="legend-item"><i style="background:undefined"></i> 6+</div></div>'
391
+ ) ;
392
+ } ) ;
393
+ } ) ;
394
+
395
+ describe ( 'when three thresholds are set and color mode is categories' , ( ) => {
396
+ beforeEach ( ( ) => {
397
+ ctrl . panel . colorMode = ColorModes . categories . id ;
398
+ ctrl . data = new DataBuilder ( ) . withCategories ( [ 'some cat' , 'other cat' , 'asdf' ] ) . build ( ) ;
399
+ worldMap . createLegend ( ) ;
400
+ } ) ;
401
+
402
+ it ( 'should create a legend with four legend values' , ( ) => {
403
+ expect ( worldMap . legend ) . toBeDefined ( ) ;
404
+ expect ( worldMap . legend . _div . outerHTML ) . toBe (
405
+ '<div class="info legend leaflet-control"><div class="legend-item">' +
406
+ '<i style="background:red"></i> *</div><div class="legend-item"><i style="background:blue"></i> some cat</div>' +
407
+ '<div class="legend-item"><i style="background:green"></i> other cat</div>' +
408
+ '<div class="legend-item"><i style="background:undefined"></i> asdf</div></div>'
409
+ ) ;
410
+ } ) ;
411
+ } ) ;
412
+
326
413
describe ( 'when the legend should be displayed out-of-band' , ( ) => {
327
414
/*
328
415
* Optimizations for small maps
0 commit comments