diff --git a/apps/datahub/src/app/record/record-downloads/record-downloads.component.spec.ts b/apps/datahub/src/app/record/record-downloads/record-downloads.component.spec.ts index 866b597369..176a3c1ea9 100644 --- a/apps/datahub/src/app/record/record-downloads/record-downloads.component.spec.ts +++ b/apps/datahub/src/app/record/record-downloads/record-downloads.component.spec.ts @@ -55,6 +55,20 @@ class DataServiceMock { url: newUrl(`${link.url}/query?f=geojson&where=1=1&outFields=*`), }, ]) + getDownloadLinksFromOgcApiFeatures = jest.fn((link) => + link.url.toString().indexOf('error') > -1 + ? throwError(() => new Error('would not fetch links')) + : of([ + { + ...link, + mimeType: 'application/geo+json', + }, + { + ...link, + mimeType: 'application/json', + }, + ]) + ) } @Component({ @@ -210,6 +224,15 @@ describe('DataDownloadsComponent', () => { type: 'service', accessServiceProtocol: 'esriRest', }, + { + name: 'Surveillance littorale OGC', + description: 'OGC API service', + url: newUrl( + 'https://demo.ldproxy.net/zoomstack/collections/airports/items' + ), + type: 'service', + accessServiceProtocol: 'ogcFeatures', + }, ]) fixture.detectChanges() }) @@ -274,6 +297,26 @@ describe('DataDownloadsComponent', () => { type: 'service', accessServiceProtocol: 'wfs', }, + { + description: 'OGC API service', + mimeType: 'application/geo+json', + name: 'Surveillance littorale OGC', + url: newUrl( + 'https://demo.ldproxy.net/zoomstack/collections/airports/items' + ), + type: 'service', + accessServiceProtocol: 'ogcFeatures', + }, + { + description: 'OGC API service', + mimeType: 'application/json', + name: 'Surveillance littorale OGC', + url: newUrl( + 'https://demo.ldproxy.net/zoomstack/collections/airports/items' + ), + type: 'service', + accessServiceProtocol: 'ogcFeatures', + }, { description: 'ArcGIS GeoService', mimeType: 'application/json', diff --git a/libs/feature/dataviz/src/lib/service/data.service.spec.ts b/libs/feature/dataviz/src/lib/service/data.service.spec.ts index f36e8ee5c7..f1da1f3eb3 100644 --- a/libs/feature/dataviz/src/lib/service/data.service.spec.ts +++ b/libs/feature/dataviz/src/lib/service/data.service.spec.ts @@ -3,6 +3,7 @@ import { DataService } from './data.service' import { openDataset } from '@geonetwork-ui/data-fetcher' import { PROXY_PATH } from '@geonetwork-ui/util/shared' import { lastValueFrom } from 'rxjs' +import { url } from 'inspector' const newEndpointCall = jest.fn() @@ -76,6 +77,17 @@ jest.mock('@camptocamp/ogc-client', () => ({ return '2.0.0' } }, + OgcApiEndpoint: class { + constructor(private url) { + newEndpointCall(url) // to track endpoint creation + } + getCollectionInfo() { + return Promise.resolve({ + bulkDownloadLinks: { json: 'http://json', csv: 'http://csv' }, + }) + } + featureCollections = () => Promise.resolve(['collection1']) + }, })) const SAMPLE_GEOJSON = { @@ -445,6 +457,34 @@ describe('DataService', () => { }) }) + describe('#getDownloadLinksFromOgcApiFeatures', () => { + it('returns links with formats for link', async () => { + const url = new URL('https://my.ogc.api/features') + const links = await service.getDownloadLinksFromOgcApiFeatures({ + name: 'mycollection', + url, + type: 'service', + accessServiceProtocol: 'ogcFeatures', + }) + expect(links).toEqual([ + { + name: 'mycollection', + mimeType: 'application/json', + url: new URL('http://json'), + type: 'download', + accessServiceProtocol: 'ogcFeatures', + }, + { + name: 'mycollection', + mimeType: 'text/csv', + url: new URL('http://csv'), + type: 'download', + accessServiceProtocol: 'ogcFeatures', + }, + ]) + }) + }) + describe('#getDataset', () => { describe('parse failure', () => { it('returns an observable that errors with a relevant error', async () => { diff --git a/libs/feature/record/src/lib/map-view/map-view.component.spec.ts b/libs/feature/record/src/lib/map-view/map-view.component.spec.ts index 90167937f7..6753dff0bf 100644 --- a/libs/feature/record/src/lib/map-view/map-view.component.spec.ts +++ b/libs/feature/record/src/lib/map-view/map-view.component.spec.ts @@ -377,6 +377,12 @@ describe('MapViewComponent', () => { name: 'data.geojson', type: 'download', }, + { + url: new URL('http://abcd.com/data/ogcapi'), + name: 'ogc api', + type: 'service', + accessServiceProtocol: 'ogcFeatures', + }, ]) fixture.detectChanges() }) @@ -394,6 +400,10 @@ describe('MapViewComponent', () => { value: 2, label: 'data.geojson (geojson)', }, + { + value: 3, + label: 'ogc api', + }, ]) }) it('provides first (selected) link to the external viewer component', () => { @@ -490,6 +500,33 @@ describe('MapViewComponent', () => { }) }) + describe('with a link using OGC API protocol', () => { + beforeEach(fakeAsync(() => { + mdViewFacade.mapApiLinks$.next([]) + mdViewFacade.geoDataLinks$.next([ + { + name: 'ogc layer', + url: new URL('http://abcd.com/data/ogcapi'), + type: 'service', + accessServiceProtocol: 'ogcFeatures', + }, + ]) + tick(200) + fixture.detectChanges() + })) + it('emits a map context with the the downloaded data from the ESRI REST API', () => { + expect(mapComponent.context).toEqual({ + layers: [ + { + type: 'geojson', + data: SAMPLE_GEOJSON, + }, + ], + view: expect.any(Object), + }) + }) + }) + describe('with a link using WFS which returns an error', () => { beforeEach(() => { mdViewFacade.mapApiLinks$.next([]) diff --git a/libs/util/shared/src/lib/links/link-classifier.service.spec.ts b/libs/util/shared/src/lib/links/link-classifier.service.spec.ts index 3b864f429b..fbdfa45514 100644 --- a/libs/util/shared/src/lib/links/link-classifier.service.spec.ts +++ b/libs/util/shared/src/lib/links/link-classifier.service.spec.ts @@ -111,5 +111,14 @@ describe('LinkClassifierService', () => { ]) }) }) + describe('for an OGC API Features link', () => { + it('returns download, data and API usage', () => { + expect(service.getUsagesForLink(LINK_FIXTURES.ogcApiFormat)).toEqual([ + LinkUsage.API, + LinkUsage.DOWNLOAD, + LinkUsage.GEODATA, + ]) + }) + }) }) })