diff --git a/libs/feature/map/src/lib/add-layer-from-ogc-api/add-layer-from-ogc-api.component.spec.ts b/libs/feature/map/src/lib/add-layer-from-ogc-api/add-layer-from-ogc-api.component.spec.ts index ab58f79785..8979e6e2b7 100644 --- a/libs/feature/map/src/lib/add-layer-from-ogc-api/add-layer-from-ogc-api.component.spec.ts +++ b/libs/feature/map/src/lib/add-layer-from-ogc-api/add-layer-from-ogc-api.component.spec.ts @@ -1,6 +1,5 @@ import { ComponentFixture, TestBed } from '@angular/core/testing' import { AddLayerFromOgcApiComponent } from './add-layer-from-ogc-api.component' -import { MapFacade } from '../+state/map.facade' import { TranslateModule } from '@ngx-translate/core' import { NO_ERRORS_SCHEMA } from '@angular/core' import { MapContextLayerTypeEnum } from '../map-context/map-context.model' @@ -9,6 +8,9 @@ jest.mock('@camptocamp/ogc-client', () => ({ OgcApiEndpoint: class { constructor(private url) {} isReady() { + if (this.url === 'http://example.com/ogc') { + return Promise.resolve(this) + } if (this.url.indexOf('error') > -1) { return Promise.reject(new Error('Something went wrong')) } @@ -19,17 +21,57 @@ jest.mock('@camptocamp/ogc-client', () => ({ } return Promise.resolve(this) } - get featureCollections() { + get allCollections() { + if (this.url === 'http://example.com/ogc') { + return Promise.resolve([ + { + name: 'NaturalEarth:physical:ne_10m_lakes_pluvial', + hasVectorTiles: true, + hasMapTiles: true, + }, + { + name: 'NaturalEarth:physical:ne_10m_land_ocean_seams', + hasVectorTiles: true, + hasMapTiles: true, + }, + ]) + } if (this.url.includes('error')) { return Promise.reject(new Error('Simulated loading error')) } - return Promise.resolve(['layer1', 'layer2', 'layer3']) + return Promise.resolve([ + { + name: 'NaturalEarth:physical:ne_10m_lakes_pluvial', + hasVectorTiles: true, + hasMapTiles: true, + }, + { + name: 'NaturalEarth:physical:ne_10m_land_ocean_seams', + hasVectorTiles: true, + hasMapTiles: true, + }, + ]) } getCollectionItemsUrl(collectionId) { + if (this.url === 'http://example.com/ogc') { + return Promise.resolve( + `http://example.com/collections/${collectionId}/items` + ) + } return Promise.resolve( `http://example.com/collections/${collectionId}/items` ) } + getVectorTilesetUrl(collectionId) { + return Promise.resolve( + `http://example.com/collections/${collectionId}/tiles/vector` + ) + } + getMapTilesetUrl(collectionId) { + return Promise.resolve( + `http://example.com/collections/${collectionId}/tiles/map` + ) + } }, })) @@ -68,7 +110,18 @@ describe('AddLayerFromOgcApiComponent', () => { await component.loadLayers() expect(component.errorMessage).toBeFalsy() expect(component.loading).toBe(false) - expect(component.layers).toEqual(['layer1', 'layer2', 'layer3']) + expect(component.layers).toEqual([ + { + name: 'NaturalEarth:physical:ne_10m_lakes_pluvial', + hasVectorTiles: true, + hasMapTiles: true, + }, + { + name: 'NaturalEarth:physical:ne_10m_land_ocean_seams', + hasVectorTiles: true, + hasMapTiles: true, + }, + ]) }) it('should handle errors while loading layers', async () => { @@ -79,4 +132,40 @@ describe('AddLayerFromOgcApiComponent', () => { expect(component.layers.length).toBe(0) }) }) + + describe('Add Collection', () => { + it('should add feature type collection to map', async () => { + const layerAddedSpy = jest.spyOn(component.layerAdded, 'emit') + await component.addLayer('layer1', 'features') + expect(layerAddedSpy).toHaveBeenCalledWith({ + name: 'layer1', + url: 'http://example.com/collections/layer1/items', + type: MapContextLayerTypeEnum.OGCAPI, + layerType: 'features', + title: 'layer1', + }) + }) + it('should add vector tile collection to map', async () => { + const layerAddedSpy = jest.spyOn(component.layerAdded, 'emit') + await component.addLayer('layer1', 'vectorTiles') + expect(layerAddedSpy).toHaveBeenCalledWith({ + name: 'layer1', + url: 'http://example.com/collections/layer1/tiles/vector', + type: MapContextLayerTypeEnum.OGCAPI, + layerType: 'vectorTiles', + title: 'layer1', + }) + }) + it('should add map tile collection to map', async () => { + const layerAddedSpy = jest.spyOn(component.layerAdded, 'emit') + await component.addLayer('layer1', 'mapTiles') + expect(layerAddedSpy).toHaveBeenCalledWith({ + name: 'layer1', + url: 'http://example.com/collections/layer1/tiles/map', + type: MapContextLayerTypeEnum.OGCAPI, + layerType: 'mapTiles', + title: 'layer1', + }) + }) + }) }) diff --git a/libs/feature/map/src/lib/add-layer-from-ogc-api/add-layer-from-ogc-api.component.ts b/libs/feature/map/src/lib/add-layer-from-ogc-api/add-layer-from-ogc-api.component.ts index bcf46431d6..2ea471ce28 100644 --- a/libs/feature/map/src/lib/add-layer-from-ogc-api/add-layer-from-ogc-api.component.ts +++ b/libs/feature/map/src/lib/add-layer-from-ogc-api/add-layer-from-ogc-api.component.ts @@ -107,9 +107,8 @@ export class AddLayerFromOgcApiComponent implements OnInit { async addLayer(layer: string, layerType: any) { try { - console.log(layerType) const ogcEndpoint = await new OgcApiEndpoint(this.ogcUrl) - let layerUrl + let layerUrl: string if (layerType === 'vectorTiles') { layerUrl = await ogcEndpoint.getVectorTilesetUrl(layer) @@ -121,7 +120,6 @@ export class AddLayerFromOgcApiComponent implements OnInit { }) } - // const layerUrl = await ogcEndpoint.getCollectionItemsUrl(layer, {outputFormat: 'json'}) const layerToAdd: MapContextLayerModel = { name: layer, url: layerUrl,