@@ -10,17 +10,14 @@ import expect from 'expect';
1010import {
1111 getViewedResourceType ,
1212 isNewResource ,
13- isNewResourcePk ,
1413 getGeoNodeResourceDataFromGeoStory ,
1514 getGeoNodeResourceFromDashboard ,
1615 getResourceThumbnail ,
1716 updatingThumbnailResource ,
1817 isThumbnailChanged ,
1918 canEditPermissions ,
2019 canManageResourcePermissions ,
21- isNewMapDirty ,
22- isNewDashboardDirty ,
23- isNewGeoStoryDirty ,
20+ isNewMapViewerResource ,
2421 defaultViewerPluginsSelector
2522} from '../resource' ;
2623import { ResourceTypes } from '@js/utils/ResourceUtils' ;
@@ -65,16 +62,6 @@ describe('resource selector', () => {
6562 it ( 'is new resource' , ( ) => {
6663 expect ( isNewResource ( testState ) ) . toBeTruthy ( ) ;
6764 } ) ;
68-
69- it ( 'is new resource by pk' , ( ) => {
70- let state = { ...testState , gnresource : { ...testState . gnresource , params : { pk : "new" } } } ;
71- expect ( isNewResourcePk ( state ) ) . toBeTruthy ( ) ;
72- state . gnresource . params . pk = '1' ;
73- expect ( isNewResourcePk ( state ) ) . toBeFalsy ( ) ;
74- state . gnresource . params = undefined ;
75- expect ( isNewResourcePk ( state ) ) . toBeFalsy ( ) ;
76- } ) ;
77-
7865 it ( 'getGeoNodeResourceDataFromGeoStory' , ( ) => {
7966 expect ( getGeoNodeResourceDataFromGeoStory ( testState ) ) . toEqual ( { maps : [ 300 ] , documents : [ 200 , 100 ] } ) ;
8067 } ) ;
@@ -105,266 +92,17 @@ describe('resource selector', () => {
10592 expect ( canManageResourcePermissions ( state ) ) . toBeFalsy ( ) ;
10693 state . gnresource . data . perms = undefined ;
10794 } ) ;
95+ it ( 'test isNewMapViewerResource' , ( ) => {
96+ let state = { ...testState , gnresource : { ...testState . gnresource , type : ResourceTypes . VIEWER , params : { pk : "new" } } } ;
97+ expect ( isNewMapViewerResource ( state ) ) . toBeTruthy ( ) ;
98+ state . gnresource . params . pk = '1' ;
99+ expect ( isNewMapViewerResource ( state ) ) . toBeFalsy ( ) ;
100+ } ) ;
108101 it ( 'test defaultViewerPluginsSelector' , ( ) => {
109102 let state = { ...testState } ;
110103 state . gnresource = { ...state . gnresource , defaultViewerPlugins : [ "TOC" ] } ;
111104 expect ( defaultViewerPluginsSelector ( state ) ) . toEqual ( [ "TOC" ] ) ;
112105 state . gnresource = { ...state . gnresource , defaultViewerPlugins : undefined } ;
113106 expect ( defaultViewerPluginsSelector ( state ) ) . toEqual ( [ ] ) ;
114107 } ) ;
115-
116- it ( 'test isNewMapDirty returns false when no mapConfigRawData exists' , ( ) => {
117- const state = {
118- gnresource : {
119- type : ResourceTypes . MAP
120- } ,
121- map : {
122- present : {
123- zoom : 5 ,
124- center : { x : 0 , y : 0 , crs : 'EPSG:4326' }
125- }
126- }
127- // No mapConfigRawData
128- } ;
129- expect ( isNewMapDirty ( state ) ) . toBeFalsy ( ) ;
130- } ) ;
131-
132- it ( 'test isNewMapDirty returns false when map has not changed from initial config' , ( ) => {
133- const initialConfig = {
134- version : 2 ,
135- map : {
136- zoom : 5 ,
137- center : { x : 0 , y : 0 , crs : 'EPSG:4326' } ,
138- layers : [
139- { id : 'layer1' , type : 'osm' , group : 'background' , visibility : true }
140- ]
141- }
142- } ;
143- const state = {
144- gnresource : {
145- type : ResourceTypes . MAP
146- } ,
147- map : {
148- present : {
149- zoom : 5 ,
150- center : { x : 0 , y : 0 , crs : 'EPSG:4326' } ,
151- layers : [
152- { id : 'layer1' , type : 'osm' , group : 'background' , visibility : true }
153- ]
154- }
155- } ,
156- layers : {
157- flat : [
158- { id : 'layer1' , type : 'osm' , group : 'background' , visibility : true }
159- ]
160- } ,
161- mapConfigRawData : initialConfig
162- } ;
163- expect ( isNewMapDirty ( state ) ) . toBeFalsy ( ) ;
164- } ) ;
165-
166- it ( 'test isNewMapDirty returns true when layers are added' , ( ) => {
167- const initialConfig = {
168- version : 2 ,
169- map : {
170- zoom : 5 ,
171- center : { x : 0 , y : 0 , crs : 'EPSG:4326' } ,
172- layers : [
173- { id : 'layer1' , type : 'osm' , group : 'background' , visibility : true }
174- ]
175- }
176- } ;
177- const state = {
178- gnresource : {
179- type : ResourceTypes . MAP
180- } ,
181- map : {
182- present : {
183- zoom : 5 ,
184- center : { x : 0 , y : 0 , crs : 'EPSG:4326' } ,
185- layers : [
186- { id : 'layer1' , type : 'osm' , group : 'background' , visibility : true } ,
187- { id : 'layer2' , type : 'wms' , name : 'newLayer' , visibility : true }
188- ]
189- }
190- } ,
191- layers : {
192- flat : [
193- { id : 'layer1' , type : 'osm' , group : 'background' , visibility : true } ,
194- { id : 'layer2' , type : 'wms' , name : 'newLayer' , visibility : true }
195- ]
196- } ,
197- mapConfigRawData : initialConfig
198- } ;
199- expect ( isNewMapDirty ( state ) ) . toBeTruthy ( ) ;
200- } ) ;
201-
202- it ( 'test isNewMapDirty ignores ellipsoid terrain layer' , ( ) => {
203- const initialConfig = {
204- version : 2 ,
205- map : {
206- zoom : 5 ,
207- center : { x : 0 , y : 0 , crs : 'EPSG:4326' } ,
208- layers : [
209- { id : 'layer1' , type : 'osm' , group : 'background' , visibility : true }
210- ]
211- }
212- } ;
213- const state = {
214- gnresource : {
215- type : ResourceTypes . MAP
216- } ,
217- map : {
218- present : {
219- zoom : 5 ,
220- center : { x : 0 , y : 0 , crs : 'EPSG:4326' } ,
221- layers : [
222- { id : 'layer1' , type : 'osm' , group : 'background' , visibility : true } ,
223- { id : 'ellipsoid' , type : 'terrain' , provider : 'ellipsoid' , group : 'background' }
224- ]
225- }
226- } ,
227- layers : {
228- flat : [
229- { id : 'layer1' , type : 'osm' , group : 'background' , visibility : true } ,
230- { id : 'ellipsoid' , type : 'terrain' , provider : 'ellipsoid' , group : 'background' }
231- ]
232- } ,
233- mapConfigRawData : initialConfig
234- } ;
235- // Should be false because ellipsoid terrain is filtered out by compareMapChanges
236- expect ( isNewMapDirty ( state ) ) . toBeFalsy ( ) ;
237- } ) ;
238-
239- it ( 'test isNewDashboardDirty returns true when dashboard has widgets' , ( ) => {
240- const state = {
241- gnresource : {
242- type : ResourceTypes . DASHBOARD
243- } ,
244- widgets : {
245- containers : {
246- floating : {
247- widgets : [
248- { id : 'widget1' , widgetType : 'text' }
249- ]
250- }
251- }
252- }
253- } ;
254- expect ( isNewDashboardDirty ( state ) ) . toBeTruthy ( ) ;
255- } ) ;
256-
257- it ( 'test isNewDashboardDirty returns false when dashboard has no widgets' , ( ) => {
258- const state = {
259- gnresource : {
260- type : ResourceTypes . DASHBOARD
261- } ,
262- widgets : {
263- containers : {
264- floating : {
265- widgets : [ ]
266- }
267- }
268- }
269- } ;
270- expect ( isNewDashboardDirty ( state ) ) . toBeFalsy ( ) ;
271- } ) ;
272-
273- it ( 'test isNewGeoStoryDirty returns false for default geostory' , ( ) => {
274- const defaultConfig = {
275- sections : [ { title : 'Default Title' , contents : [ { html : '' } ] } ] ,
276- settings : { }
277- } ;
278- const state = {
279- gnresource : {
280- type : ResourceTypes . GEOSTORY
281- } ,
282- geostory : {
283- currentStory : {
284- ...defaultConfig ,
285- defaultGeoStoryConfig : defaultConfig ,
286- resources : [ ]
287- }
288- }
289- } ;
290- expect ( isNewGeoStoryDirty ( state ) ) . toBeFalsy ( ) ;
291- } ) ;
292-
293- it ( 'test isNewGeoStoryDirty returns true when geostory has multiple sections' , ( ) => {
294- const defaultConfig = {
295- sections : [ { title : 'Default Title' , contents : [ { html : '' } ] } ] ,
296- settings : { }
297- } ;
298- const state = {
299- gnresource : {
300- type : ResourceTypes . GEOSTORY
301- } ,
302- geostory : {
303- currentStory : {
304- sections : [
305- { title : 'Section 1' , contents : [ { html : '' } ] } ,
306- { title : 'Section 2' , contents : [ { html : '' } ] }
307- ] ,
308- defaultGeoStoryConfig : defaultConfig ,
309- resources : [ ] ,
310- settings : { }
311- }
312- }
313- } ;
314- expect ( isNewGeoStoryDirty ( state ) ) . toBeTruthy ( ) ;
315- } ) ;
316-
317- it ( 'test isNewGeoStoryDirty returns true when geostory has resources' , ( ) => {
318- const defaultConfig = {
319- sections : [ { title : 'Default Title' , contents : [ { html : '' } ] } ] ,
320- settings : { }
321- } ;
322- const state = {
323- gnresource : {
324- type : ResourceTypes . GEOSTORY
325- } ,
326- geostory : {
327- currentStory : {
328- sections : [ { title : 'Default Title' , contents : [ { html : '' } ] } ] ,
329- defaultGeoStoryConfig : defaultConfig ,
330- resources : [ { id : 1 , type : 'map' } ] ,
331- settings : { }
332- }
333- }
334- } ;
335- expect ( isNewGeoStoryDirty ( state ) ) . toBeTruthy ( ) ;
336- } ) ;
337-
338- it ( 'test isNewGeoStoryDirty returns true when title section has content' , ( ) => {
339- const defaultConfig = {
340- sections : [ { title : 'Default Title' , contents : [ { html : '' } ] } ] ,
341- settings : { }
342- } ;
343- const state = {
344- gnresource : {
345- type : ResourceTypes . GEOSTORY
346- } ,
347- geostory : {
348- currentStory : {
349- sections : [ { title : 'Default Title' , contents : [ { html : 'Some content here' } ] } ] ,
350- defaultGeoStoryConfig : defaultConfig ,
351- resources : [ ] ,
352- settings : { }
353- }
354- }
355- } ;
356- expect ( isNewGeoStoryDirty ( state ) ) . toBeTruthy ( ) ;
357- } ) ;
358-
359- it ( 'test isNewGeoStoryDirty returns false when currentData is null' , ( ) => {
360- const state = {
361- gnresource : {
362- type : ResourceTypes . GEOSTORY
363- } ,
364- geostory : {
365- currentStory : null
366- }
367- } ;
368- expect ( isNewGeoStoryDirty ( state ) ) . toBeFalsy ( ) ;
369- } ) ;
370108} ) ;
0 commit comments