1
- import WorldMap from './worldmap' ;
2
1
import DataBuilder from '../test/data_builder' ;
2
+ import { createBasicMap } from '../test/map_builder' ;
3
3
import $ from 'jquery' ;
4
4
5
+
5
6
describe ( 'Worldmap' , ( ) => {
7
+
6
8
let worldMap ;
7
9
let ctrl ;
8
10
9
11
beforeEach ( ( ) => {
10
- setupWorldmapFixture ( ) ;
12
+ worldMap = createBasicMap ( ) ;
13
+ ctrl = worldMap . ctrl ;
14
+ worldMap . createMap ( ) ;
15
+ } ) ;
16
+
17
+ afterEach ( ( ) => {
18
+ const fixture : HTMLElement = document . getElementById ( 'fixture' ) ! ;
19
+ document . body . removeChild ( fixture ) ;
11
20
} ) ;
12
21
13
22
describe ( 'when a Worldmap is created' , ( ) => {
@@ -388,49 +397,18 @@ describe('Worldmap', () => {
388
397
} ) ;
389
398
} ) ;
390
399
391
- afterEach ( ( ) => {
392
- const fixture : HTMLElement = document . getElementById ( 'fixture' ) ! ;
393
- document . body . removeChild ( fixture ) ;
394
- } ) ;
395
-
396
- function setupWorldmapFixture ( ) {
397
- const fixture = '<div id="fixture" class="mapcontainer"></div>' ;
398
- document . body . insertAdjacentHTML ( 'afterbegin' , fixture ) ;
399
-
400
- ctrl = {
401
- panel : {
402
- center : {
403
- mapCenterLatitude : 0 ,
404
- mapCenterLongitude : 0 ,
405
- initialZoom : 1 ,
406
- } ,
407
- colors : [ 'red' , 'blue' , 'green' ] ,
408
- circleOptions : { } ,
409
- } ,
410
- tileServer : 'CartoDB Positron' ,
411
- } ;
412
-
413
- // This mimics the `ctrl.panel` proxying established
414
- // by `PluginSettings` to make the tests happy.
415
- // Todo: Don't worry, this will go away.
416
- ctrl . settings = ctrl . panel ;
417
-
418
- worldMap = new WorldMap ( ctrl , document . getElementsByClassName ( 'mapcontainer' ) [ 0 ] ) ;
419
- worldMap . createMap ( ) ;
420
- }
421
400
} ) ;
422
401
423
402
describe ( 'WorldmapFoundation' , ( ) => {
424
403
/*
425
- * Optimizations for small maps
426
- *
427
- * In order to test the `createMap()` method,
428
- * we need to pass a half-configured `WorldMap`
404
+ * In order to individually configure the map before the `createMap()`
405
+ * method will be invoked, we need to pass a half-configured `WorldMap`
429
406
* instance into the test cases.
430
407
*
431
408
* We are testing the "showZoomControl" and "showAttribution"
432
409
* options here to proof they actually toggle the visibility
433
- * of the respective control elements.
410
+ * of the respective control elements. These have been introduced
411
+ * to optimize Worldmap for small maps.
434
412
*
435
413
* See also https://community.hiveeyes.org/t/grafana-worldmap-panel-ng/1824/3
436
414
*/
@@ -439,7 +417,13 @@ describe('WorldmapFoundation', () => {
439
417
let ctrl ;
440
418
441
419
beforeEach ( ( ) => {
442
- setupWorldmapHalfFixture ( ) ;
420
+ worldMap = createBasicMap ( ) ;
421
+ ctrl = worldMap . ctrl ;
422
+ } ) ;
423
+
424
+ afterEach ( ( ) => {
425
+ const fixture : HTMLElement = document . getElementById ( 'fixture' ) ! ;
426
+ document . body . removeChild ( fixture ) ;
443
427
} ) ;
444
428
445
429
describe ( 'when a Worldmap is created with default parameters' , ( ) => {
@@ -476,35 +460,4 @@ describe('WorldmapFoundation', () => {
476
460
} ) ;
477
461
} ) ;
478
462
479
- afterEach ( ( ) => {
480
- const fixture : HTMLElement = document . getElementById ( 'fixture' ) ! ;
481
- document . body . removeChild ( fixture ) ;
482
- } ) ;
483
-
484
- function setupWorldmapHalfFixture ( ) {
485
- const fixture = '<div id="fixture" class="mapcontainer"></div>' ;
486
- document . body . insertAdjacentHTML ( 'afterbegin' , fixture ) ;
487
-
488
- ctrl = {
489
- panel : {
490
- center : {
491
- mapCenterLatitude : 0 ,
492
- mapCenterLongitude : 0 ,
493
- initialZoom : 1 ,
494
- } ,
495
- colors : [ 'red' , 'blue' , 'green' ] ,
496
- circleOptions : { } ,
497
- showZoomControl : true ,
498
- showAttribution : true ,
499
- } ,
500
- tileServer : 'CartoDB Positron' ,
501
- } ;
502
-
503
- // This mimics the `ctrl.panel` proxying established
504
- // by `PluginSettings` to make the tests happy.
505
- // Todo: Don't worry, this will go away.
506
- ctrl . settings = ctrl . panel ;
507
-
508
- worldMap = new WorldMap ( ctrl , document . getElementsByClassName ( 'mapcontainer' ) [ 0 ] ) ;
509
- }
510
463
} ) ;
0 commit comments