Skip to content

Commit

Permalink
feat: tests and startwith falsy
Browse files Browse the repository at this point in the history
  • Loading branch information
cmoinier committed Jun 5, 2024
1 parent 2130c4a commit d89a1b0
Show file tree
Hide file tree
Showing 6 changed files with 163 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { SourcesService } from '@geonetwork-ui/feature/catalog'
import { SearchService } from '@geonetwork-ui/feature/search'
import { ErrorType } from '@geonetwork-ui/ui/elements'
import { BehaviorSubject, combineLatest } from 'rxjs'
import { filter, map, mergeMap } from 'rxjs/operators'
import { filter, map, mergeMap, startWith } from 'rxjs/operators'
import { OrganizationsServiceInterface } from '@geonetwork-ui/common/domain/organizations.service.interface'
import {
Keyword,
Expand All @@ -26,7 +26,8 @@ export class RecordMetadataComponent {
]).pipe(
map(([mapApiLinks, geoDataLinksWithGeometry]) => {
return mapApiLinks?.length > 0 || geoDataLinksWithGeometry?.length > 0
})
}),
startWith(false)
)

displayData$ = combineLatest([
Expand Down
8 changes: 8 additions & 0 deletions libs/common/fixtures/src/lib/records.fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,14 @@ Cette section contient des *caractères internationaux* (ainsi que des "caractè
description: 'This WFS service offers direct download capability',
identifierInService: 'my:featuretype',
},
{
type: 'service',
url: new URL('https://my-org.net/ogc'),
accessServiceProtocol: 'ogcFeatures',
name: 'my:featuretype',
description: 'This OGC service offers direct download capability',
identifierInService: 'my:featuretype',
},
],
lineage: `This record was edited manually to test the conversion processes
Expand Down
27 changes: 27 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 @@ -93,6 +93,13 @@ jest.mock('@camptocamp/ogc-client', () => ({
})
}
allCollections = Promise.resolve([{ name: 'collection1' }])
featureCollections =
this.url.indexOf('error.http') > -1
? Promise.reject(new Error())
: Promise.resolve(['collection1', 'collection2'])
getCollectionItem(collection, id) {
return Promise.resolve('item1')
}
},
}))

Expand Down Expand Up @@ -700,5 +707,25 @@ describe('DataService', () => {
)
})
})
describe('#getItemsFromOgcApi', () => {
describe('calling getItemsFromOgcApi() with a valid URL', () => {
it('returns the first collection item when collections array is not empty', async () => {
const item = await service.getItemsFromOgcApi(
'https://my.ogc.api/features'
)
expect(item).toBe('item1')
})
})

describe('calling getItemsFromOgcApi() with an erroneous URL', () => {
it('throws an error', async () => {
try {
await service.getItemsFromOgcApi('http://error.http/ogcapi')
} catch (e) {
expect(e.message).toBe('ogc.unreachable.unknown')
}
})
})
})
})
})
10 changes: 10 additions & 0 deletions libs/feature/map/src/lib/utils/map-utils.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,16 @@ describe('MapUtilsService', () => {
})
})

describe('getRecordExtent', () => {
it('should return null if spatialExtents is not present or is an empty array', () => {
const record1: Partial<CatalogRecord> = {}
const record2: Partial<CatalogRecord> = { spatialExtents: [] }

expect(service.getRecordExtent(record1)).toBeNull()
expect(service.getRecordExtent(record2)).toBeNull()
})
})

describe('#prioritizePageScroll', () => {
const interactions = defaults()
let dragRotate
Expand Down
114 changes: 113 additions & 1 deletion libs/feature/record/src/lib/state/mdview.facade.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TestBed } from '@angular/core/testing'
import { TestBed, fakeAsync, tick } from '@angular/core/testing'
import { MockStore, provideMockStore } from '@ngrx/store/testing'
import {
initialMetadataViewState,
Expand All @@ -13,6 +13,26 @@ import {
} from '@geonetwork-ui/common/fixtures'
import { DatavizConfigurationModel } from '@geonetwork-ui/common/domain/model/dataviz/dataviz-configuration.model'
import { AvatarServiceInterface } from '@geonetwork-ui/api/repository'
import { TestScheduler } from 'rxjs/testing'

const newEndpointCall = jest.fn()
let testScheduler: TestScheduler

jest.mock('@camptocamp/ogc-client', () => ({
_newEndpointCall: jest.fn(),
OgcApiEndpoint: class {
constructor(private url) {
newEndpointCall(url) // to track endpoint creation
}
featureCollections =
this.url.indexOf('error.http') > -1
? Promise.reject(new Error())
: Promise.resolve(['collection1', 'collection2'])
getCollectionItem(collection, id) {
return Promise.resolve('item1')
}
},
}))

describe('MdViewFacade', () => {
let store: MockStore
Expand Down Expand Up @@ -217,4 +237,96 @@ describe('MdViewFacade', () => {
expect(store.scannedActions$).toBeObservable(expected)
})
})

describe('geoDataLinksWithGeometry$', () => {
beforeEach(() => {
testScheduler = new TestScheduler((actual, expected) => {
expect(actual).toEqual(expected)
})
store.setState({
[METADATA_VIEW_FEATURE_STATE_KEY]: {
...initialMetadataViewState,
metadata: DATASET_RECORDS[0],
},
})
})
it('should return OGC links that have geometry', fakeAsync(() => {
const values = {
a: [
{
type: 'download',
url: new URL('http://my-org.net/download/2.geojson'),
mimeType: 'application/geo+json',
name: 'Direct download',
},
{
type: 'service',
url: new URL('https://my-org.net/wfs'),
accessServiceProtocol: 'wfs',
name: 'my:featuretype', // FIXME: same as identifier otherwise it will be lost in iso...
description: 'This WFS service offers direct download capability',
identifierInService: 'my:featuretype',
},
{
type: 'service',
url: new URL('https://my-org.net/ogc'),
accessServiceProtocol: 'ogcFeatures',
name: 'my:featuretype',
description: 'This OGC service offers direct download capability',
identifierInService: 'my:featuretype',
},
],
}
jest.spyOn(facade.dataService, 'getItemsFromOgcApi').mockResolvedValue({
id: '123',
type: 'Feature',
time: null,
properties: {
type: '',
title: '',
},
links: [],
geometry: { type: 'MultiPolygon', coordinates: [] },
})
let result
facade.geoDataLinksWithGeometry$.subscribe((v) => (result = v))
tick()
expect(result).toEqual(values.a)
}))
it('should not return OGC links that do not have geometry', fakeAsync(() => {
const values = {
a: [
{
type: 'download',
url: new URL('http://my-org.net/download/2.geojson'),
mimeType: 'application/geo+json',
name: 'Direct download',
},
{
type: 'service',
url: new URL('https://my-org.net/wfs'),
accessServiceProtocol: 'wfs',
name: 'my:featuretype', // FIXME: same as identifier otherwise it will be lost in iso...
description: 'This WFS service offers direct download capability',
identifierInService: 'my:featuretype',
},
],
}
jest.spyOn(facade.dataService, 'getItemsFromOgcApi').mockResolvedValue({
id: '123',
type: 'Feature',
time: null,
properties: {
type: '',
title: '',
},
links: [],
geometry: null,
})
let result
facade.geoDataLinksWithGeometry$.subscribe((v) => (result = v))
tick()
expect(result).toEqual(values.a)
}))
})
})
4 changes: 2 additions & 2 deletions libs/feature/record/src/lib/state/mdview.facade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ import { DataService } from '@geonetwork-ui/feature/dataviz'
export class MdViewFacade {
constructor(
private store: Store,
private linkClassifier: LinkClassifierService,
public linkClassifier: LinkClassifierService,
private avatarService: AvatarServiceInterface,
private dataService: DataService
public dataService: DataService
) {}

isPresent$ = this.store.pipe(
Expand Down

0 comments on commit d89a1b0

Please sign in to comment.