@@ -7,6 +7,11 @@ import { getPluginForTest } from './pluginsTestUtils';
77import security from '../../reducers/security' ;
88import ReactTestUtils from 'react-dom/test-utils' ;
99
10+ const defaultAvailableProjections = [
11+ { value : "EPSG:4326" , label : "EPSG:4326" } ,
12+ { value : "EPSG:3857" , label : "EPSG:3857" }
13+ ] ;
14+
1015describe ( 'CRSSelector Plugin' , ( ) => {
1116 beforeEach ( ( done ) => {
1217 document . body . innerHTML = '<div id="container"></div>' ;
@@ -42,7 +47,7 @@ describe('CRSSelector Plugin', () => {
4247 }
4348 } ) ;
4449
45- ReactDOM . render ( < Plugin filterAllowedCRS = { [ "EPSG:4326" , "EPSG:3857" ] } additionalCRS = { { } } /> , document . getElementById ( "container" ) ) ;
50+ ReactDOM . render ( < Plugin pluginCfg = { { availableProjections : defaultAvailableProjections } } /> , document . getElementById ( "container" ) ) ;
4651 expect ( document . getElementsByClassName ( 'ms-crs-selector-container' ) . length ) . toBe ( 1 ) ;
4752 } ) ;
4853 it ( 'render the plugin for role ADMIN with allowedRoles ADMIN, USER' , ( ) => {
@@ -61,9 +66,7 @@ describe('CRSSelector Plugin', () => {
6166 } ) ;
6267
6368 ReactDOM . render ( < Plugin
64- filterAllowedCRS = { [ "EPSG:4326" , "EPSG:3857" ] }
65- additionalCRS = { { } }
66- allowedRoles = { [ "ADMIN" , "USER" ] }
69+ pluginCfg = { { availableProjections : defaultAvailableProjections , allowedRoles : [ "ADMIN" , "USER" ] } }
6770 /> , document . getElementById ( "container" ) ) ;
6871 expect ( document . getElementsByClassName ( 'ms-crs-selector-container' ) . length ) . toBe ( 1 ) ;
6972 } ) ;
@@ -83,9 +86,7 @@ describe('CRSSelector Plugin', () => {
8386 } ) ;
8487
8588 ReactDOM . render ( < Plugin
86- filterAllowedCRS = { [ "EPSG:4326" , "EPSG:3857" ] }
87- additionalCRS = { { } }
88- allowedRoles = { [ "ADMIN" , "USER" ] }
89+ pluginCfg = { { availableProjections : defaultAvailableProjections , allowedRoles : [ "ADMIN" , "USER" ] } }
8990 /> , document . getElementById ( "container" ) ) ;
9091 expect ( document . getElementsByClassName ( 'ms-crs-selector-container' ) . length ) . toBe ( 1 ) ;
9192 } ) ;
@@ -105,9 +106,7 @@ describe('CRSSelector Plugin', () => {
105106 } ) ;
106107
107108 ReactDOM . render ( < Plugin
108- filterAllowedCRS = { [ "EPSG:4326" , "EPSG:3857" ] }
109- additionalCRS = { { } }
110- allowedRoles = { [ "ALL" ] }
109+ pluginCfg = { { availableProjections : defaultAvailableProjections , allowedRoles : [ "ALL" ] } }
111110 /> , document . getElementById ( "container" ) ) ;
112111 expect ( document . getElementsByClassName ( 'ms-crs-selector-container' ) . length ) . toBe ( 1 ) ;
113112 } ) ;
@@ -127,16 +126,41 @@ describe('CRSSelector Plugin', () => {
127126 } ) ;
128127
129128 ReactDOM . render ( < Plugin
130- filterAllowedCRS = { [ "EPSG:4326" , "EPSG:3857" ] }
131- additionalCRS = { { } }
132- allowedRoles = { [ "ADMIN" , "USER" ] }
129+ pluginCfg = { { availableProjections : defaultAvailableProjections , allowedRoles : [ "ADMIN" , "USER" ] } }
133130 /> , document . getElementById ( "container" ) ) ;
134131 // plugin is rendered because user is logged in
135132 expect ( document . getElementsByClassName ( 'ms-crs-selector-container' ) . length ) . toBe ( 1 ) ;
136133 // settings (cog) button is hidden because role is not allowed
137134 expect ( document . getElementsByClassName ( 'ms-crs-settings-button' ) . length ) . toBe ( 0 ) ;
138135 } ) ;
139136
137+ it ( 'renders with deprecated filterAllowedCRS and additionalCRS for backward compatibility' , ( ) => {
138+ const { Plugin } = getPluginForTest ( CRSPluginCustomized , {
139+ map : {
140+ projection : "EPSG:900913"
141+ } ,
142+ localConfig : {
143+ projectionDefs : [ ]
144+ } ,
145+ security : {
146+ user : {
147+ role : "USER"
148+ }
149+ }
150+ } ) ;
151+
152+ ReactDOM . render ( < Plugin
153+ pluginCfg = { {
154+ filterAllowedCRS : [ "EPSG:4326" , "EPSG:3857" ] ,
155+ additionalCRS : { "EPSG:3003" : { "label" : "EPSG:3003" } } ,
156+ allowedRoles : [ "ALL" ]
157+ } }
158+ /> , document . getElementById ( "container" ) ) ;
159+ expect ( document . getElementsByClassName ( 'ms-crs-selector-container' ) . length ) . toBe ( 1 ) ;
160+ // Projections from filterAllowedCRS and additionalCRS should be available
161+ const dropdown = document . querySelector ( '.ms-crs-dropdown' ) ;
162+ expect ( dropdown ) . toExist ( ) ;
163+ } ) ;
140164
141165 it ( 'CRSSelector is not rendered when Print Panel is enabled' , ( ) => {
142166 const { Plugin } = getPluginForTest ( CRSPluginCustomized , {
@@ -158,7 +182,7 @@ describe('CRSSelector Plugin', () => {
158182 }
159183 } ) ;
160184
161- ReactDOM . render ( < Plugin filterAllowedCRS = { [ "EPSG:4326" , "EPSG:3857" ] } additionalCRS = { { } } /> , document . getElementById ( "container" ) ) ;
185+ ReactDOM . render ( < Plugin pluginCfg = { { availableProjections : defaultAvailableProjections } } /> , document . getElementById ( "container" ) ) ;
162186 expect ( document . getElementsByClassName ( 'ms-crs-selector-container' ) . length ) . toBe ( 0 ) ;
163187 } ) ;
164188
@@ -182,7 +206,7 @@ describe('CRSSelector Plugin', () => {
182206 }
183207 } ) ;
184208
185- ReactDOM . render ( < Plugin filterAllowedCRS = { [ "EPSG:4326" , "EPSG:3857" ] } additionalCRS = { { } } /> , document . getElementById ( "container" ) ) ;
209+ ReactDOM . render ( < Plugin pluginCfg = { { availableProjections : defaultAvailableProjections } } /> , document . getElementById ( "container" ) ) ;
186210 expect ( document . getElementsByClassName ( 'ms-crs-selector-container' ) . length ) . toBe ( 0 ) ;
187211 } ) ;
188212
@@ -206,7 +230,7 @@ describe('CRSSelector Plugin', () => {
206230 }
207231 } ) ;
208232
209- ReactDOM . render ( < Plugin filterAllowedCRS = { [ "EPSG:4326" , "EPSG:3857" ] } additionalCRS = { { } } /> , document . getElementById ( "container" ) ) ;
233+ ReactDOM . render ( < Plugin pluginCfg = { { availableProjections : defaultAvailableProjections } } /> , document . getElementById ( "container" ) ) ;
210234 expect ( document . getElementsByClassName ( 'ms-crs-selector-container' ) . length ) . toBe ( 0 ) ;
211235 } ) ;
212236
@@ -228,7 +252,7 @@ describe('CRSSelector Plugin', () => {
228252 }
229253 } ) ;
230254
231- ReactDOM . render ( < Plugin filterAllowedCRS = { [ "EPSG:4326" , "EPSG:3857" ] } additionalCRS = { { } } /> , document . getElementById ( "container" ) ) ;
255+ ReactDOM . render ( < Plugin pluginCfg = { { availableProjections : defaultAvailableProjections } } /> , document . getElementById ( "container" ) ) ;
232256 expect ( document . getElementsByClassName ( 'ms-crs-selector-container' ) . length ) . toBe ( 0 ) ;
233257 } ) ;
234258
@@ -264,13 +288,13 @@ describe('CRSSelector Plugin', () => {
264288
265289 ReactDOM . render ( < Plugin
266290 pluginCfg = { {
267- onError : actions . onError
268- } }
269- filterAllowedCRS = { [ "EPSG:4326" , "EPSG:3857" ] }
270- additionalCRS = { {
271- "EPSG:3003" : { "label" : "EPSG:3003" }
291+ onError : actions . onError ,
292+ availableProjections : [
293+ ...defaultAvailableProjections ,
294+ { value : "EPSG:3003" , label : "EPSG:3003" }
295+ ] ,
296+ allowedRoles : [ "ALL" ]
272297 } }
273- allowedRoles = { [ "ALL" ] }
274298 /> , document . getElementById ( "container" ) ) ;
275299 const dropdown = document . querySelector ( '.ms-crs-dropdown' ) ;
276300 expect ( dropdown ) . toExist ( ) ;
@@ -323,13 +347,13 @@ describe('CRSSelector Plugin', () => {
323347 ReactDOM . render ( < Plugin
324348 pluginCfg = { {
325349 onError : actions . onError ,
326- setCrs : actions . setCrs
327- } }
328- filterAllowedCRS = { [ "EPSG:4326" , "EPSG:3857" ] }
329- additionalCRS = { {
330- "EPSG:3003" : { "label" : "EPSG:3003" }
350+ setCrs : actions . setCrs ,
351+ availableProjections : [
352+ ...defaultAvailableProjections ,
353+ { value : "EPSG:3003" , label : "EPSG:3003" }
354+ ] ,
355+ allowedRoles : [ "ALL" ]
331356 } }
332- allowedRoles = { [ "ALL" ] }
333357 /> , document . getElementById ( "container" ) ) ;
334358 const dropdown = document . querySelector ( '.ms-crs-dropdown' ) ;
335359 expect ( dropdown ) . toExist ( ) ;
@@ -350,4 +374,55 @@ describe('CRSSelector Plugin', () => {
350374 }
351375 } , 100 ) ;
352376 } ) ;
377+
378+ it ( 'does not show settings when canEditProjection is false' , ( ) => {
379+ const { Plugin } = getPluginForTest ( CRSPluginCustomized , {
380+ map : {
381+ projection : "EPSG:900913"
382+ } ,
383+ localConfig : {
384+ projectionDefs : [ ]
385+ } ,
386+ security : {
387+ user : {
388+ role : "ADMIN"
389+ }
390+ } ,
391+ crsselector : {
392+ canEdit : false
393+ }
394+ } ) ;
395+
396+ ReactDOM . render ( < Plugin
397+ pluginCfg = { { availableProjections : defaultAvailableProjections , allowedRoles : [ "ADMIN" , "USER" ] } }
398+ /> , document . getElementById ( "container" ) ) ;
399+ expect ( document . getElementsByClassName ( 'ms-crs-selector-container' ) . length ) . toBe ( 1 ) ;
400+ // settings (cog) button is hidden because canEditProjection is false
401+ expect ( document . getElementsByClassName ( 'ms-crs-settings-button' ) . length ) . toBe ( 0 ) ;
402+ } ) ;
403+
404+ it ( 'shows settings when canEditProjection is true and user has allowed role' , ( ) => {
405+ const { Plugin } = getPluginForTest ( CRSPluginCustomized , {
406+ map : {
407+ projection : "EPSG:900913"
408+ } ,
409+ localConfig : {
410+ projectionDefs : [ ]
411+ } ,
412+ security : {
413+ user : {
414+ role : "ADMIN"
415+ }
416+ } ,
417+ crsselector : {
418+ canEdit : true
419+ }
420+ } ) ;
421+
422+ ReactDOM . render ( < Plugin
423+ pluginCfg = { { availableProjections : defaultAvailableProjections , allowedRoles : [ "ADMIN" , "USER" ] } }
424+ /> , document . getElementById ( "container" ) ) ;
425+ expect ( document . getElementsByClassName ( 'ms-crs-selector-container' ) . length ) . toBe ( 1 ) ;
426+ expect ( document . getElementsByClassName ( 'ms-crs-settings-button' ) . length ) . toBe ( 1 ) ;
427+ } ) ;
353428} ) ;
0 commit comments