Skip to content

Commit

Permalink
feat(ut): add unit tests for the pr
Browse files Browse the repository at this point in the history
  • Loading branch information
cmoinier committed Apr 26, 2024
1 parent b7b6c00 commit 4450fa6
Show file tree
Hide file tree
Showing 4 changed files with 129 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -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()
})
Expand Down Expand Up @@ -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',
Expand Down
40 changes: 40 additions & 0 deletions libs/feature/dataviz/src/lib/service/data.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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 = {
Expand Down Expand Up @@ -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 () => {
Expand Down
37 changes: 37 additions & 0 deletions libs/feature/record/src/lib/map-view/map-view.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
})
Expand All @@ -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', () => {
Expand Down Expand Up @@ -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([])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
])
})
})
})
})

0 comments on commit 4450fa6

Please sign in to comment.