|
| 1 | +import { createMapClassExtending } from '@supermapgis/iclient-common/mapping/MapBase'; |
| 2 | + |
| 3 | +describe('MapBase', () => { |
| 4 | + let MapBase; |
| 5 | + let instance; |
| 6 | + |
| 7 | + beforeEach(() => { |
| 8 | + MapBase = createMapClassExtending(); |
| 9 | + instance = new MapBase(); |
| 10 | + }); |
| 11 | + |
| 12 | + describe('setLegends', () => { |
| 13 | + it('should set _legendList with provided array', () => { |
| 14 | + const legends = [ |
| 15 | + { layerId: 'layer1', items: [{ color: '#fff', label: 'test' }] }, |
| 16 | + { layerId: 'layer2', items: [{ color: '#000' }] } |
| 17 | + ]; |
| 18 | + |
| 19 | + instance.setLegends(legends); |
| 20 | + |
| 21 | + expect(instance._legendList).toEqual(legends); |
| 22 | + }); |
| 23 | + |
| 24 | + it('should set _legendList to empty array when null is passed', () => { |
| 25 | + instance.setLegends(null); |
| 26 | + |
| 27 | + expect(instance._legendList).toEqual([]); |
| 28 | + }); |
| 29 | + |
| 30 | + it('should set _legendList to empty array when undefined is passed', () => { |
| 31 | + instance.setLegends(undefined); |
| 32 | + |
| 33 | + expect(instance._legendList).toEqual([]); |
| 34 | + }); |
| 35 | + |
| 36 | + it('should set _legendList to empty array when no argument is passed', () => { |
| 37 | + instance.setLegends(); |
| 38 | + |
| 39 | + expect(instance._legendList).toEqual([]); |
| 40 | + }); |
| 41 | + |
| 42 | + it('should overwrite existing legends', () => { |
| 43 | + instance._legendList = [{ layerId: 'old' }]; |
| 44 | + |
| 45 | + instance.setLegends([{ layerId: 'new' }]); |
| 46 | + |
| 47 | + expect(instance._legendList).toEqual([{ layerId: 'new' }]); |
| 48 | + }); |
| 49 | + }); |
| 50 | + |
| 51 | + describe('getLegends', () => { |
| 52 | + it('should return _legendList', () => { |
| 53 | + const legends = [{ layerId: 'layer1' }]; |
| 54 | + instance._legendList = legends; |
| 55 | + |
| 56 | + expect(instance.getLegends()).toEqual(legends); |
| 57 | + }); |
| 58 | + |
| 59 | + it('should return empty array when _legendList is not set', () => { |
| 60 | + expect(instance.getLegends()).toEqual([]); |
| 61 | + }); |
| 62 | + }); |
| 63 | + |
| 64 | + describe('getLayerCatalog', () => { |
| 65 | + it('should return _sourceListModel.getLayerCatalog() when _sourceListModel exists', () => { |
| 66 | + const catalogs = [{ id: 'cat1' }]; |
| 67 | + instance._sourceListModel = jasmine.createSpyObj('sourceListModel', ['getLayerCatalog']); |
| 68 | + instance._sourceListModel.getLayerCatalog.and.returnValue(catalogs); |
| 69 | + |
| 70 | + expect(instance.getLayerCatalog()).toEqual(catalogs); |
| 71 | + }); |
| 72 | + |
| 73 | + it('should return empty array when _sourceListModel is null', () => { |
| 74 | + instance._sourceListModel = null; |
| 75 | + |
| 76 | + expect(instance.getLayerCatalog()).toEqual([]); |
| 77 | + }); |
| 78 | + }); |
| 79 | + |
| 80 | + describe('getLayers', () => { |
| 81 | + it('should return _sourceListModel.getLayers() when _sourceListModel exists', () => { |
| 82 | + const layers = [{ id: 'layer1' }]; |
| 83 | + instance._sourceListModel = jasmine.createSpyObj('sourceListModel', ['getLayers']); |
| 84 | + instance._sourceListModel.getLayers.and.returnValue(layers); |
| 85 | + |
| 86 | + expect(instance.getLayers()).toEqual(layers); |
| 87 | + }); |
| 88 | + |
| 89 | + it('should return empty array when _sourceListModel is null', () => { |
| 90 | + instance._sourceListModel = null; |
| 91 | + |
| 92 | + expect(instance.getLayers()).toEqual([]); |
| 93 | + }); |
| 94 | + }); |
| 95 | +}); |
0 commit comments