@@ -2,8 +2,11 @@ var Plotly = require('@lib/index');
2
2
var Lib = require ( '@src/lib' ) ;
3
3
4
4
var Geo = require ( '@src/plots/geo' ) ;
5
+ var GeoAssets = require ( '@src/assets/geo_assets' ) ;
5
6
var params = require ( '@src/plots/geo/constants' ) ;
6
7
var supplyLayoutDefaults = require ( '@src/plots/geo/layout/axis_defaults' ) ;
8
+ var geoLocationUtils = require ( '@src/lib/geo_location_utils' ) ;
9
+ var topojsonUtils = require ( '@src/lib/topojson_utils' ) ;
7
10
8
11
var d3 = require ( 'd3' ) ;
9
12
var createGraphDiv = require ( '../assets/create_graph_div' ) ;
@@ -336,6 +339,49 @@ describe('Test Geo layout defaults', function() {
336
339
} ) ;
337
340
} ) ;
338
341
342
+ describe ( 'geojson / topojson utils' , function ( ) {
343
+ 'use strict' ;
344
+
345
+ function _locationToFeature ( topojson , loc , locationmode ) {
346
+ var trace = { locationmode : locationmode } ;
347
+ var features = topojsonUtils . getTopojsonFeatures ( trace , topojson ) ;
348
+
349
+ var feature = geoLocationUtils . locationToFeature ( locationmode , loc , features ) ;
350
+ return feature ;
351
+ }
352
+
353
+ describe ( 'should be able to extract topojson feature from *locations* items' , function ( ) {
354
+ var topojsonName = 'world_110m' ;
355
+ var topojson = GeoAssets . topojson [ topojsonName ] ;
356
+
357
+ it ( 'with *ISO-3* locationmode' , function ( ) {
358
+ var out = _locationToFeature ( topojson , 'CAN' , 'ISO-3' ) ;
359
+
360
+ expect ( Object . keys ( out ) ) . toEqual ( [ 'type' , 'id' , 'properties' , 'geometry' ] ) ;
361
+ expect ( out . id ) . toEqual ( 'CAN' ) ;
362
+ } ) ;
363
+
364
+ it ( 'with *ISO-3* locationmode (not-found case)' , function ( ) {
365
+ var out = _locationToFeature ( topojson , 'XXX' , 'ISO-3' ) ;
366
+
367
+ expect ( out ) . toEqual ( false ) ;
368
+ } ) ;
369
+
370
+ it ( 'with *country names* locationmode' , function ( ) {
371
+ var out = _locationToFeature ( topojson , 'United States' , 'country names' ) ;
372
+
373
+ expect ( Object . keys ( out ) ) . toEqual ( [ 'type' , 'id' , 'properties' , 'geometry' ] ) ;
374
+ expect ( out . id ) . toEqual ( 'USA' ) ;
375
+ } ) ;
376
+
377
+ it ( 'with *country names* locationmode (not-found case)' , function ( ) {
378
+ var out = _locationToFeature ( topojson , 'XXX' , 'country names' ) ;
379
+
380
+ expect ( out ) . toEqual ( false ) ;
381
+ } ) ;
382
+ } ) ;
383
+ } ) ;
384
+
339
385
describe ( 'Test geo interactions' , function ( ) {
340
386
'use strict' ;
341
387
0 commit comments