| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent a8458a3 commit 9171bd0
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,4 +1,11 @@ | |||
| 1 | 1 | import { createMapClassExtending } from '../../../src/common/mapping/MapBase'; | |
| 2 | + import { createWebMapBaseExtending } from '../../../src/common/mapping/WebMapBase'; | ||
| 3 | + import { Events } from '../../../src/common/commontypes'; | ||
| 4 | + | ||
| 5 | + function createWebMapBaseInstance() { | ||
| 6 | + const WebMapBase = createWebMapBaseExtending(Events, { mapRepo: {} }); | ||
| 7 | + return new WebMapBase('', { target: 'map' }); | ||
| 8 | + } | ||
| 2 | 9 | ||
| 3 | 10 | describe('WebMapBase - MapBase Methods', () => { | |
| 4 | 11 | let MapBase; | |
@@ -80,150 +87,141 @@ describe('WebMapBase - MapBase Methods', () => { | |||
| 80 | 87 | }); | |
| 81 | 88 | }); | |
| 82 | 89 | ||
| 83 | - describe('WebMapBase - Handler Methods', () => { | ||
| 90 | + describe('WebMapBase - getLegendInfos', () => { | ||
| 84 | 91 | let instance; | |
| 85 | 92 | let mockHandler; | |
| 86 | 93 | ||
| 87 | 94 | beforeEach(() => { | |
| 88 | - const MapBase = createMapClassExtending(); | ||
| 89 | - instance = new MapBase(); | ||
| 90 | - instance.getLegendInfos = function() { | ||
| 91 | - return (this._handler && this._handler._getLegendInfos()) || []; | ||
| 92 | - }; | ||
| 93 | - // Mock WebMapV2 handler | ||
| 95 | + instance = createWebMapBaseInstance(); | ||
| 94 | 96 | mockHandler = { | |
| 95 | - _getLegendInfos: jasmine.createSpy('_getLegendInfos').and.callFake(() => { | ||
| 96 | - return [ | ||
| 97 | - { showLegend: true, id: 'layer1', title: 'Layer 1' }, | ||
| 98 | - { showLegend: false, id: 'layer2', title: 'Layer 2' } | ||
| 99 | - ]; | ||
| 100 | - }) | ||
| 97 | + _getLegendInfos: jasmine.createSpy('_getLegendInfos').and.returnValue([ | ||
| 98 | + { showLegend: true, id: 'layer1', title: 'Layer 1' }, | ||
| 99 | + { showLegend: false, id: 'layer2', title: 'Layer 2' } | ||
| 100 | + ]) | ||
| 101 | 101 | }; | |
| 102 | 102 | instance._handler = mockHandler; | |
| 103 | 103 | }); | |
| 104 | 104 | ||
| 105 | - describe('getLegendInfos', () => { | ||
| 106 | - it('should call handler._getLegendInfos and return result', () => { | ||
| 107 | - const result = instance.getLegendInfos(); | ||
| 108 | - | ||
| 109 | - expect(mockHandler._getLegendInfos).toHaveBeenCalled(); | ||
| 110 | - expect(result).toEqual([ | ||
| 111 | - { showLegend: true, id: 'layer1', title: 'Layer 1' }, | ||
| 112 | - { showLegend: false, id: 'layer2', title: 'Layer 2' } | ||
| 113 | - ]); | ||
| 114 | - }); | ||
| 105 | + it('should call handler._getLegendInfos and return result', () => { | ||
| 106 | + const result = instance.getLegendInfos(); | ||
| 115 | 107 | ||
| 116 | - it('should return empty array when handler._getLegendInfos returns null', () => { | ||
| 117 | - mockHandler._getLegendInfos.and.returnValue(null); | ||
| 108 | + expect(mockHandler._getLegendInfos).toHaveBeenCalled(); | ||
| 109 | + expect(result).toEqual([ | ||
| 110 | + { showLegend: true, id: 'layer1', title: 'Layer 1' }, | ||
| 111 | + { showLegend: false, id: 'layer2', title: 'Layer 2' } | ||
| 112 | + ]); | ||
| 113 | + }); | ||
| 118 | 114 | ||
| 119 | - const result = instance.getLegendInfos(); | ||
| 115 | + it('should return empty array when handler._getLegendInfos returns empty array', () => { | ||
| 116 | + mockHandler._getLegendInfos.and.returnValue([]); | ||
| 120 | 117 | ||
| 121 | - expect(result).toEqual([]); | ||
| 122 | - }); | ||
| 118 | + expect(instance.getLegendInfos()).toEqual([]); | ||
| 119 | + }); | ||
| 123 | 120 | ||
| 124 | - it('should return empty array when handler._getLegendInfos returns undefined', () => { | ||
| 125 | - mockHandler._getLegendInfos.and.returnValue(undefined); | ||
| 121 | + it('should return empty array when handler._getLegendInfos returns null', () => { | ||
| 122 | + mockHandler._getLegendInfos.and.returnValue(null); | ||
| 126 | 123 | ||
| 127 | - const result = instance.getLegendInfos(); | ||
| 124 | + expect(instance.getLegendInfos()).toEqual([]); | ||
| 125 | + }); | ||
| 128 | 126 | ||
| 129 | - expect(result).toEqual([]); | ||
| 130 | - }); | ||
| 127 | + it('should return empty array when handler._getLegendInfos returns undefined', () => { | ||
| 128 | + mockHandler._getLegendInfos.and.returnValue(undefined); | ||
| 131 | 129 | ||
| 132 | - it('should return empty array when handler is null', () => { | ||
| 133 | - instance._handler = null; | ||
| 130 | + expect(instance.getLegendInfos()).toEqual([]); | ||
| 131 | + }); | ||
| 134 | 132 | ||
| 135 | - const result = instance.getLegendInfos(); | ||
| 133 | + it('should return empty array when handler is null', () => { | ||
| 134 | + instance._handler = null; | ||
| 136 | 135 | ||
| 137 | - expect(result).toEqual([]); | ||
| 138 | - }); | ||
| 136 | + expect(instance.getLegendInfos()).toEqual([]); | ||
| 139 | 137 | }); | |
| 140 | 138 | ||
| 141 | - describe('getLegendInfos with WebMapV2-like handler', () => { | ||
| 142 | - it('should return legend info from _mapInfo.layers (WebMapV2)', () => { | ||
| 143 | - const webMapV2Handler = { | ||
| 144 | - _getLegendInfos: jasmine.createSpy('_getLegendInfos').and.callFake(function() { | ||
| 145 | - const { layers = [] } = this._mapInfo || {}; | ||
| 146 | - return layers.map((layer) => { | ||
| 147 | - const { legendSetting, name, layerID: layerId } = layer; | ||
| 148 | - return { | ||
| 149 | - showLegend: legendSetting ? legendSetting.isShow : false, | ||
| 150 | - id: layerId, | ||
| 151 | - title: name | ||
| 152 | - }; | ||
| 153 | - }); | ||
| 154 | - }), | ||
| 155 | - _mapInfo: { | ||
| 156 | - layers: [ | ||
| 157 | - { name: 'Layer1', layerID: 'layer1', legendSetting: { isShow: true } }, | ||
| 158 | - { name: 'Layer2', layerID: 'layer2', legendSetting: { isShow: false } } | ||
| 159 | - ] | ||
| 160 | - } | ||
| 161 | - }; | ||
| 162 | - instance._handler = webMapV2Handler; | ||
| 163 | - | ||
| 164 | - const result = instance.getLegendInfos(); | ||
| 165 | - | ||
| 166 | - expect(webMapV2Handler._getLegendInfos).toHaveBeenCalled(); | ||
| 167 | - expect(result).toEqual([ | ||
| 168 | - { showLegend: true, id: 'layer1', title: 'Layer1' }, | ||
| 169 | - { showLegend: false, id: 'layer2', title: 'Layer2' } | ||
| 170 | - ]); | ||
| 171 | - }); | ||
| 139 | + it('should return empty array when handler is undefined', () => { | ||
| 140 | + instance._handler = undefined; | ||
| 141 | + | ||
| 142 | + expect(instance.getLegendInfos()).toEqual([]); | ||
| 172 | 143 | }); | |
| 173 | 144 | ||
| 174 | - describe('getLegendInfos with WebMapV3-like handler', () => { | ||
| 175 | - it('should return legend info from catalogs (WebMapV3)', () => { | ||
| 176 | - const webMapV3Handler = { | ||
| 177 | - _getLegendInfos: jasmine.createSpy('_getLegendInfos').and.callFake(function() { | ||
| 178 | - const { catalogs = [] } = this._mapResourceInfo || {}; | ||
| 179 | - const res = []; | ||
| 180 | - const processCatalog = (catalog) => { | ||
| 181 | - const { catalogType, children, showLegend, title, layersContent, id } = catalog; | ||
| 182 | - if (catalogType === 'group' && children) { | ||
| 183 | - children.forEach(child => processCatalog(child)); | ||
| 184 | - } | ||
| 185 | - if (catalogType === 'layer') { | ||
| 186 | - res.push({ | ||
| 187 | - showLegend: showLegend !== false, | ||
| 188 | - id: layersContent || id, | ||
| 189 | - title: title | ||
| 190 | - }); | ||
| 191 | - } | ||
| 145 | + it('should return legend info from WebMapV2-like handler', () => { | ||
| 146 | + const webMapV2Handler = { | ||
| 147 | + _getLegendInfos: jasmine.createSpy('_getLegendInfos').and.callFake(function() { | ||
| 148 | + const { layers = [] } = this._mapInfo || {}; | ||
| 149 | + return layers.map((layer) => { | ||
| 150 | + const { legendSetting, name, layerID: layerId } = layer; | ||
| 151 | + return { | ||
| 152 | + showLegend: legendSetting ? legendSetting.isShow : false, | ||
| 153 | + id: layerId, | ||
| 154 | + title: name | ||
| 192 | 155 | }; | |
| 193 | - catalogs.forEach(item => processCatalog(item)); | ||
| 194 | - return res; | ||
| 195 | - }), | ||
| 196 | - _mapResourceInfo: { | ||
| 197 | - catalogs: [ | ||
| 198 | - { | ||
| 199 | - catalogType: 'layer', | ||
| 200 | - title: 'Layer1', | ||
| 201 | - showLegend: true, | ||
| 202 | - layersContent: 'layer1' | ||
| 203 | - }, | ||
| 204 | - { | ||
| 205 | - catalogType: 'group', | ||
| 206 | - children: [ | ||
| 207 | - { | ||
| 208 | - catalogType: 'layer', | ||
| 209 | - title: 'Layer2', | ||
| 210 | - showLegend: false, | ||
| 211 | - layersContent: 'layer2' | ||
| 212 | - } | ||
| 213 | - ] | ||
| 214 | - } | ||
| 215 | - ] | ||
| 216 | - } | ||
| 217 | - }; | ||
| 218 | - instance._handler = webMapV3Handler; | ||
| 219 | - | ||
| 220 | - const result = instance.getLegendInfos(); | ||
| 221 | - | ||
| 222 | - expect(webMapV3Handler._getLegendInfos).toHaveBeenCalled(); | ||
| 223 | - expect(result).toEqual([ | ||
| 224 | - { showLegend: true, id: 'layer1', title: 'Layer1' }, | ||
| 225 | - { showLegend: false, id: 'layer2', title: 'Layer2' } | ||
| 226 | - ]); | ||
| 227 | - }); | ||
| 156 | + }); | ||
| 157 | + }), | ||
| 158 | + _mapInfo: { | ||
| 159 | + layers: [ | ||
| 160 | + { name: 'Layer1', layerID: 'layer1', legendSetting: { isShow: true } }, | ||
| 161 | + { name: 'Layer2', layerID: 'layer2', legendSetting: { isShow: false } }, | ||
| 162 | + { name: 'Layer3', layerID: 'layer3', legendSetting: {} } | ||
| 163 | + ] | ||
| 164 | + } | ||
| 165 | + }; | ||
| 166 | + instance._handler = webMapV2Handler; | ||
| 167 | + | ||
| 168 | + expect(instance.getLegendInfos()).toEqual([ | ||
| 169 | + { showLegend: true, id: 'layer1', title: 'Layer1' }, | ||
| 170 | + { showLegend: false, id: 'layer2', title: 'Layer2' }, | ||
| 171 | + { showLegend: undefined, id: 'layer3', title: 'Layer3' } | ||
| 172 | + ]); | ||
| 173 | + expect(webMapV2Handler._getLegendInfos).toHaveBeenCalled(); | ||
| 174 | + }); | ||
| 175 | + | ||
| 176 | + it('should return legend info from WebMapV3-like handler', () => { | ||
| 177 | + const webMapV3Handler = { | ||
| 178 | + _getLegendInfos: jasmine.createSpy('_getLegendInfos').and.callFake(function() { | ||
| 179 | + const { catalogs = [] } = this._mapResourceInfo || {}; | ||
| 180 | + const res = []; | ||
| 181 | + const processCatalog = (catalog) => { | ||
| 182 | + const { catalogType, children, showLegend, title, id } = catalog; | ||
| 183 | + if (catalogType === 'group' && children) { | ||
| 184 | + children.forEach(child => processCatalog(child)); | ||
| 185 | + } | ||
| 186 | + if (catalogType === 'layer') { | ||
| 187 | + res.push({ | ||
| 188 | + showLegend: showLegend !== false, | ||
| 189 | + id: id, | ||
| 190 | + title: title | ||
| 191 | + }); | ||
| 192 | + } | ||
| 193 | + }; | ||
| 194 | + catalogs.forEach(item => processCatalog(item)); | ||
| 195 | + return res; | ||
| 196 | + }), | ||
| 197 | + _mapResourceInfo: { | ||
| 198 | + catalogs: [ | ||
| 199 | + { | ||
| 200 | + catalogType: 'layer', | ||
| 201 | + title: 'Layer1', | ||
| 202 | + showLegend: true, | ||
| 203 | + id: 'layer1' | ||
| 204 | + }, | ||
| 205 | + { | ||
| 206 | + catalogType: 'group', | ||
| 207 | + children: [ | ||
| 208 | + { | ||
| 209 | + catalogType: 'layer', | ||
| 210 | + title: 'Layer2', | ||
| 211 | + showLegend: false, | ||
| 212 | + id: 'layer2' | ||
| 213 | + } | ||
| 214 | + ] | ||
| 215 | + } | ||
| 216 | + ] | ||
| 217 | + } | ||
| 218 | + }; | ||
| 219 | + instance._handler = webMapV3Handler; | ||
| 220 | + | ||
| 221 | + expect(instance.getLegendInfos()).toEqual([ | ||
| 222 | + { showLegend: true, id: 'layer1', title: 'Layer1' }, | ||
| 223 | + { showLegend: false, id: 'layer2', title: 'Layer2' } | ||
| 224 | + ]); | ||
| 225 | + expect(webMapV3Handler._getLegendInfos).toHaveBeenCalled(); | ||
| 228 | 226 | }); | |
| 229 | 227 | }); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -171,7 +171,7 @@ describe('WebMapV2 - _getLegendInfos', () => { | |||
| 171 | 171 | ]); | |
| 172 | 172 | }); | |
| 173 | 173 | ||
| 174 | - it('should return showLegend false when legendSetting exists without isShow', () => { | ||
| 174 | + it('should return showLegend undefined when legendSetting exists without isShow', () => { | ||
| 175 | 175 | instance._mapInfo = { | |
| 176 | 176 | layers: [{ name: 'Layer3', layerID: 'layer3', legendSetting: {} }] | |
| 177 | 177 | }; | |
@@ -193,4 +193,19 @@ describe('WebMapV2 - _getLegendInfos', () => { | |||
| 193 | 193 | instance._mapInfo = {}; | |
| 194 | 194 | expect(instance._getLegendInfos()).toEqual([]); | |
| 195 | 195 | }); | |
| 196 | + | ||
| 197 | + it('should return legend info for multiple layers', () => { | ||
| 198 | + instance._mapInfo = { | ||
| 199 | + layers: [ | ||
| 200 | + { name: 'Layer1', layerID: 'layer1', legendSetting: { isShow: true } }, | ||
| 201 | + { name: 'Layer2', layerID: 'layer2' }, | ||
| 202 | + { name: 'Layer3', layerID: 'layer3', legendSetting: { isShow: false } } | ||
| 203 | + ] | ||
| 204 | + }; | ||
| 205 | + expect(instance._getLegendInfos()).toEqual([ | ||
| 206 | + { showLegend: true, id: 'layer1', title: 'Layer1' }, | ||
| 207 | + { showLegend: false, id: 'layer2', title: 'Layer2' }, | ||
| 208 | + { showLegend: false, id: 'layer3', title: 'Layer3' } | ||
| 209 | + ]); | ||
| 210 | + }); | ||
| 196 | 211 | }); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments