| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 6315883 commit 14a28f5
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,4 +1,5 @@ | |||
| 1 | 1 | import { createWebMapV3Extending } from '../../../src/common/mapping/WebMapV3'; | |
| 2 | + import { createWebMapBaseExtending } from '../../../src/common/mapping/WebMapBase'; | ||
| 2 | 3 | import { Events } from '../../../src/common/commontypes'; | |
| 3 | 4 | ||
| 4 | 5 | const mockCrsManager = { | |
@@ -132,34 +133,7 @@ describe('WebMapV3 - _getLegendInfos', () => { | |||
| 132 | 133 | let instance; | |
| 133 | 134 | ||
| 134 | 135 | beforeEach(() => { | |
| 135 | - // Create a minimal mock instance with the method | ||
| 136 | - instance = { | ||
| 137 | - _mapResourceInfo: {}, | ||
| 138 | - _getLegendInfoByCatalog: function(catalog, res = []) { | ||
| 139 | - const { catalogType, children, showLegend, title, layersContent, id } = catalog; | ||
| 140 | - if (catalogType === 'group' && children) { | ||
| 141 | - children.forEach(child => { | ||
| 142 | - this._getLegendInfoByCatalog(child, res); | ||
| 143 | - }); | ||
| 144 | - } | ||
| 145 | - if (catalogType === 'layer') { | ||
| 146 | - res.push({ | ||
| 147 | - showLegend: showLegend !== false, | ||
| 148 | - id: layersContent || id, | ||
| 149 | - title: title | ||
| 150 | - }); | ||
| 151 | - } | ||
| 152 | - }, | ||
| 153 | - _getLegendInfos: function(_mapResourceInfo) { | ||
| 154 | - const mapResourceInfo = _mapResourceInfo || this._mapResourceInfo; | ||
| 155 | - const { catalogs = [] } = mapResourceInfo; | ||
| 156 | - const res = []; | ||
| 157 | - catalogs.forEach((item) => { | ||
| 158 | - this._getLegendInfoByCatalog(item, res); | ||
| 159 | - }); | ||
| 160 | - return res; | ||
| 161 | - } | ||
| 162 | - }; | ||
| 136 | + instance = createWebMapV3Instance(); | ||
| 163 | 137 | }); | |
| 164 | 138 | ||
| 165 | 139 | describe('_getLegendInfos', () => { | |
@@ -170,13 +144,13 @@ describe('WebMapV3 - _getLegendInfos', () => { | |||
| 170 | 144 | catalogType: 'layer', | |
| 171 | 145 | title: 'Layer1', | |
| 172 | 146 | showLegend: true, | |
| 173 | - layersContent: 'layer1' | ||
| 147 | + id: 'layer1' | ||
| 174 | 148 | }, | |
| 175 | 149 | { | |
| 176 | 150 | catalogType: 'layer', | |
| 177 | 151 | title: 'Layer2', | |
| 178 | 152 | showLegend: false, | |
| 179 | - layersContent: 'layer2' | ||
| 153 | + id: 'layer2' | ||
| 180 | 154 | } | |
| 181 | 155 | ] | |
| 182 | 156 | }; | |
@@ -199,7 +173,7 @@ describe('WebMapV3 - _getLegendInfos', () => { | |||
| 199 | 173 | catalogType: 'layer', | |
| 200 | 174 | title: 'ChildLayer', | |
| 201 | 175 | showLegend: true, | |
| 202 | - layersContent: 'childLayer' | ||
| 176 | + id: 'childLayer' | ||
| 203 | 177 | } | |
| 204 | 178 | ] | |
| 205 | 179 | } | |
@@ -219,7 +193,7 @@ describe('WebMapV3 - _getLegendInfos', () => { | |||
| 219 | 193 | { | |
| 220 | 194 | catalogType: 'layer', | |
| 221 | 195 | title: 'Layer1', | |
| 222 | - layersContent: 'layer1' | ||
| 196 | + id: 'layer1' | ||
| 223 | 197 | } | |
| 224 | 198 | ] | |
| 225 | 199 | }; | |
@@ -231,21 +205,22 @@ describe('WebMapV3 - _getLegendInfos', () => { | |||
| 231 | 205 | ]); | |
| 232 | 206 | }); | |
| 233 | 207 | ||
| 234 | - it('should use id when layersContent is not available', () => { | ||
| 235 | - instance._mapResourceInfo = { | ||
| 208 | + it('should use the provided map resource info', () => { | ||
| 209 | + const mapResourceInfo = { | ||
| 236 | 210 | catalogs: [ | |
| 237 | 211 | { | |
| 238 | 212 | catalogType: 'layer', | |
| 239 | 213 | title: 'Layer1', | |
| 214 | + showLegend: true, | ||
| 240 | 215 | id: 'layer1' | |
| 241 | 216 | } | |
| 242 | 217 | ] | |
| 243 | 218 | }; | |
| 244 | 219 | ||
| 245 | - const result = instance._getLegendInfos(); | ||
| 220 | + const result = instance._getLegendInfos(mapResourceInfo); | ||
| 246 | 221 | ||
| 247 | 222 | expect(result).toEqual([ | |
| 248 | - { showLegend: false, id: 'layer1', title: 'Layer1' } | ||
| 223 | + { showLegend: true, id: 'layer1', title: 'Layer1' } | ||
| 249 | 224 | ]); | |
| 250 | 225 | }); | |
| 251 | 226 | ||
@@ -270,7 +245,7 @@ describe('WebMapV3 - _getLegendInfos', () => { | |||
| 270 | 245 | catalogType: 'layer', | |
| 271 | 246 | title: 'NestedLayer', | |
| 272 | 247 | showLegend: true, | |
| 273 | - layersContent: 'nestedLayer' | ||
| 248 | + id: 'nestedLayer' | ||
| 274 | 249 | } | |
| 275 | 250 | ] | |
| 276 | 251 | } | |
@@ -301,7 +276,7 @@ describe('WebMapV3 - _getLegendInfos', () => { | |||
| 301 | 276 | catalogType: 'layer', | |
| 302 | 277 | title: 'DeepLayer', | |
| 303 | 278 | showLegend: false, | |
| 304 | - layersContent: 'deepLayer' | ||
| 279 | + id: 'deepLayer' | ||
| 305 | 280 | } | |
| 306 | 281 | ] | |
| 307 | 282 | } | |
@@ -325,7 +300,7 @@ describe('WebMapV3 - _getLegendInfos', () => { | |||
| 325 | 300 | catalogType: 'other', | |
| 326 | 301 | title: 'Other', | |
| 327 | 302 | showLegend: true, | |
| 328 | - layersContent: 'other' | ||
| 303 | + id: 'other' | ||
| 329 | 304 | }; | |
| 330 | 305 | ||
| 331 | 306 | instance._getLegendInfoByCatalog(catalog, res); | |
@@ -339,7 +314,7 @@ describe('WebMapV3 - _getLegendInfos', () => { | |||
| 339 | 314 | catalogType: 'layer', | |
| 340 | 315 | title: 'TestLayer', | |
| 341 | 316 | showLegend: true, | |
| 342 | - layersContent: 'testLayer' | ||
| 317 | + id: 'testLayer' | ||
| 343 | 318 | }; | |
| 344 | 319 | ||
| 345 | 320 | instance._getLegendInfoByCatalog(catalog, res); | |
@@ -354,7 +329,7 @@ describe('WebMapV3 - _getLegendInfos', () => { | |||
| 354 | 329 | const catalog = { | |
| 355 | 330 | catalogType: 'layer', | |
| 356 | 331 | title: 'TestLayer', | |
| 357 | - layersContent: 'testLayer' | ||
| 332 | + id: 'testLayer' | ||
| 358 | 333 | }; | |
| 359 | 334 | ||
| 360 | 335 | instance._getLegendInfoByCatalog(catalog, res); | |
@@ -379,38 +354,41 @@ describe('WebMapV3 - _getLegendInfos', () => { | |||
| 379 | 354 | }); | |
| 380 | 355 | ||
| 381 | 356 | describe('getLegendInfos (WebMapV3)', () => { | |
| 382 | - it('should call _handler._getLegendInfos through WebMapBase', () => { | ||
| 383 | - const webMapBase = { | ||
| 384 | - _handler: null, | ||
| 385 | - getLegendInfos: function() { | ||
| 386 | - return (this._handler && this._handler._getLegendInfos()) || []; | ||
| 387 | - } | ||
| 388 | - }; | ||
| 357 | + let webMapBase; | ||
| 389 | 358 | ||
| 390 | - const mockLegendInfos = [ | ||
| 391 | - { showLegend: true, id: 'layer1', title: 'Layer1' } | ||
| 392 | - ]; | ||
| 393 | - webMapBase._handler = { | ||
| 394 | - _getLegendInfos: jasmine.createSpy('_getLegendInfos').and.returnValue(mockLegendInfos) | ||
| 395 | - }; | ||
| 396 | - | ||
| 397 | - const result = webMapBase.getLegendInfos(); | ||
| 398 | - | ||
| 399 | - expect(webMapBase._handler._getLegendInfos).toHaveBeenCalled(); | ||
| 400 | - expect(result).toEqual(mockLegendInfos); | ||
| 359 | + beforeEach(() => { | ||
| 360 | + const WebMapBase = createWebMapBaseExtending(Events, { mapRepo: {} }); | ||
| 361 | + webMapBase = new WebMapBase({}, { target: 'map' }); | ||
| 401 | 362 | }); | |
| 402 | 363 | ||
| 403 | - it('should return empty array when _handler is null', () => { | ||
| 404 | - const webMapBase = { | ||
| 405 | - _handler: null, | ||
| 406 | - getLegendInfos: function() { | ||
| 407 | - return (this._handler && this._handler._getLegendInfos()) || []; | ||
| 408 | - } | ||
| 364 | + it('should return legend info from the WebMapV3 handler', () => { | ||
| 365 | + instance._mapResourceInfo = { | ||
| 366 | + catalogs: [ | ||
| 367 | + { | ||
| 368 | + catalogType: 'layer', | ||
| 369 | + id: 'layer1', | ||
| 370 | + title: 'Layer1', | ||
| 371 | + showLegend: true | ||
| 372 | + }, | ||
| 373 | + { | ||
| 374 | + catalogType: 'layer', | ||
| 375 | + id: 'layer2', | ||
| 376 | + title: 'Layer2' | ||
| 377 | + } | ||
| 378 | + ] | ||
| 409 | 379 | }; | |
| 380 | + webMapBase._handler = instance; | ||
| 410 | 381 | ||
| 411 | - const result = webMapBase.getLegendInfos(); | ||
| 382 | + expect(webMapBase.getLegendInfos()).toEqual([ | ||
| 383 | + { showLegend: true, id: 'layer1', title: 'Layer1' }, | ||
| 384 | + { showLegend: false, id: 'layer2', title: 'Layer2' } | ||
| 385 | + ]); | ||
| 386 | + }); | ||
| 412 | 387 | ||
| 413 | - expect(result).toEqual([]); | ||
| 388 | + it('should return an empty array when the handler is null', () => { | ||
| 389 | + webMapBase._handler = null; | ||
| 390 | + | ||
| 391 | + expect(webMapBase.getLegendInfos()).toEqual([]); | ||
| 414 | 392 | }); | |
| 415 | 393 | }); | |
| 416 | 394 | }); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments