Skip to content

Commit

Permalink
Merge branch 'main' into DH/vue-api-datahub
Browse files Browse the repository at this point in the history
  • Loading branch information
cmoinier authored Dec 21, 2023
2 parents 522c551 + c9e78c3 commit b151b01
Show file tree
Hide file tree
Showing 43 changed files with 831 additions and 141 deletions.
38 changes: 24 additions & 14 deletions apps/datahub-e2e/src/e2e/datasetDetailPage.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ describe('dataset pages', () => {
.find('[id="about"]')
.find('gn-ui-metadata-info')
.find('gn-ui-content-ghost')
.find('gn-ui-max-lines')
.children('div')
.children('div')
.children('p')
.should(($element) => {
const text = $element.text().trim()
Expand Down Expand Up @@ -146,8 +149,11 @@ describe('dataset pages', () => {
cy.get('datahub-record-metadata')
.find('[id="about"]')
.find('gn-ui-metadata-info')
.find('gn-ui-content-ghost')
.find('gn-ui-max-lines')
.children('div')
.children('div')
.children('div')
.eq(1)
.children('gn-ui-badge')
.should('have.length.gt', 0)
})
Expand Down Expand Up @@ -193,22 +199,26 @@ describe('dataset pages', () => {
cy.get('datahub-record-metadata')
.find('[id="about"]')
.find('gn-ui-metadata-info')
.find('gn-ui-content-ghost')
.find('gn-ui-max-lines')
.children('div')
.contains('Read more')
.click()

cy.get('datahub-record-metadata')
.find('gn-ui-badge')
.children('div')
.eq(1)
.children('gn-ui-badge')
.first()
.as('keyword')

cy.get('@keyword')
.children('div')
.then((key) => {
keyword = key.text().toUpperCase()
cy.get('@keyword').click()
cy.url().should('include', '/search?q=')
cy.get('gn-ui-fuzzy-search')
.find('input')
.should('have.value', keyword)
})
cy.get('@keyword').then((key) => {
keyword = key.text().toUpperCase()
cy.get('@keyword').first().click()
cy.url().should('include', '/search?q=')
cy.get('gn-ui-fuzzy-search')
.find('input')
.should('have.value', keyword)
})
})
})
})
Expand Down Expand Up @@ -443,7 +453,7 @@ describe('dataset pages', () => {
.find('gn-ui-copy-text-button')
.find('button')
.first()
.click({ force: true })
.realClick()
// attempt to make the whole page focused
cy.get('body').focus()
cy.get('body').realClick()
Expand Down
43 changes: 41 additions & 2 deletions apps/datahub-e2e/src/e2e/organizations.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ describe('organizations', () => {
cy.visit('/home/organisations')

// aliases
cy.get('gn-ui-organisations-sort')
cy.get('gn-ui-organisations-filter')
.find('gn-ui-dropdown-selector')
.as('sort')
cy.get('gn-ui-pagination').children('div').as('pagination')
Expand All @@ -21,6 +21,12 @@ describe('organizations', () => {
cy.get('@organizations')
.find('[data-cy="organizationRecordsCount"]')
.as('organizationsRecordsCount')
cy.get('gn-ui-organisations-filter')
.find('gn-ui-search-input')
.as('organisationsSearch')
cy.get('gn-ui-organisations')
.find('gn-ui-organisations-result')
.as('organisationsResult')
})

describe('general display', () => {
Expand All @@ -32,7 +38,7 @@ describe('organizations', () => {
.should('eq', 'decoration-primary')
})
it('should display the welcome panel', () => {
cy.get('gn-ui-organisations-sort').should('be.visible')
cy.get('gn-ui-organisations-filter').should('be.visible')
cy.get('@sort').openDropdown().children('button').should('have.length', 4)
})
it('should display organizations with thumbnail, title and description', () => {
Expand Down Expand Up @@ -135,4 +141,37 @@ describe('organizations', () => {
})
})
})

describe('search filter', () => {
it('should display filtered results ignoring accents and case', () => {
cy.get('@organisationsSearch').type('geo2france')
cy.get('@organizationsName').should('have.length', 1)
cy.get('@organisationsResult').should('contain', '1')
cy.get('@organizationsName')
.eq(0)
.invoke('text')
.should('contain', 'Géo2France')
})
it('should display filtered results containing multiple words', () => {
cy.get('@organisationsSearch').type('dreal hdf')
cy.get('@organizationsName').should('have.length', 1)
cy.get('@organisationsResult').should('contain', '1')
cy.get('@organizationsName')
.eq(0)
.invoke('text')
.should('contain', 'DREAL HdF')
})
it('should display multiple results and refine search', () => {
cy.get('@organisationsSearch').type('de')
cy.get('@organizationsName').should('have.length', 10)
cy.get('@organisationsResult').should('contain', '10')
cy.get('@organisationsSearch').type(' Lille')
cy.get('@organizationsName').should('have.length', 1)
cy.get('@organisationsResult').should('contain', '1')
})
it('should display a message for no results found', () => {
cy.get('@organisationsSearch').type('An organisation that does not exist')
cy.get('@organisationsResult').should('contain', 'No organizations found')
})
})
})
7 changes: 7 additions & 0 deletions apps/datahub/src/test-setup.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
import 'jest-preset-angular/setup-jest'
import '../../../jest.setup'

class ResizeObserverMock {
observe = jest.fn()
unobserve = jest.fn()
}

;(window as any).ResizeObserver = ResizeObserverMock
4 changes: 2 additions & 2 deletions conf/default.toml
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ background_color = "#fdfbff"

# Optional; URL template enabling to open map layers in an external viewer; if set, displays a button next to the map's layer drop down
# The template must include the following placeholders, which allow the datahub to inject the correct values when adding a layer to a viewer:
# ${service_url}: URL of the OWS
# ${service_type}: Type of the OWS; currently supported WMS, WFS
# ${service_url}: URL of the OWS or geojson file
# ${service_type}: Type of the OWS or geojson file; currently supported WMS, WFS, GEOJSON
# ${layer_name}: Name of the layer
# Be careful to use englobing single quotes, if your template syntax includes JSON (with double quotes)
# Examples:
Expand Down
12 changes: 12 additions & 0 deletions libs/common/fixtures/src/lib/organisations.fixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,16 @@ export const ORGANISATIONS_FIXTURE: Organization[] = deepFreeze([
logoUrl: new URL('https://my-geonetwork.org/logo11.png'),
recordCount: 2,
},
{
name: "Université de l'Ingénierie",
description: 'another org for testing',
logoUrl: new URL('https://my-geonetwork.org/logo12.png'),
recordCount: 2,
},
{
name: 'ARS / Agence régionale de santé',
description: 'another org for testing',
logoUrl: new URL('https://my-geonetwork.org/logo12.png'),
recordCount: 2,
},
])
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ describe('OrganisationsComponent', () => {
expect(orgPreviewComponents[0].organisation.name).toEqual('A Data Org')
})
it('should pass 6th organisation (sorted by name-asc) on page to 6th ui preview component', () => {
expect(orgPreviewComponents[5].organisation.name).toEqual('é Data Org')
expect(orgPreviewComponents[5].organisation.name).toEqual('E Data Org')
})
})
describe('pass params to ui pagination component', () => {
Expand Down Expand Up @@ -153,14 +153,14 @@ describe('OrganisationsComponent', () => {
})
it('should pass first organisation of second page (sorted by name-asc) to first ui preview component', () => {
expect(orgPreviewComponents[0].organisation.name).toEqual(
'F Data Org'
'é Data Org'
)
})
it('should pass last organisation of second page (sorted by name-asc) to last ui preview component', () => {
expect(
orgPreviewComponents[orgPreviewComponents.length - 1].organisation
.name
).toEqual('wizard-org')
).toEqual('J Data Org')
})
})
})
Expand Down Expand Up @@ -239,6 +239,16 @@ describe('OrganisationsComponent', () => {
fixture.detectChanges()
expect(orgResultComponent.componentInstance.hits).toEqual(2)
})
it('should ignore special character without space and display 1 match for "l\'Ingénierie"', () => {
component.filterBy$.next("l'Ingénierie")
fixture.detectChanges()
expect(orgResultComponent.componentInstance.hits).toEqual(1)
})
it('should ignore special character with space and display 1 match for "ARS / Agence"', () => {
component.filterBy$.next('ARS / Agence')
fixture.detectChanges()
expect(orgResultComponent.componentInstance.hits).toEqual(1)
})
it('should combine multiple termes with "AND" logic and display 1 match for "a data"', () => {
component.filterBy$.next('a data')
fixture.detectChanges()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,7 @@ export class AddLayerRecordPreviewComponent extends RecordPreviewComponent {
name: link.name,
})
} else if (link.accessServiceProtocol === 'wmts') {
return this.mapUtils.getWmtsOptionsFromCapabilities(link).pipe(
map((options) => ({
type: MapContextLayerTypeEnum.WMTS,
options: options,
}))
)
return this.mapUtils.getWmtsLayerFromCapabilities(link)
}
return throwError(() => 'protocol not supported')
}
Expand Down
1 change: 1 addition & 0 deletions libs/feature/map/src/lib/map-context/map-context.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export interface MapContextLayerWmsModel {
export interface MapContextLayerWmtsModel {
type: 'wmts'
options: Options
extent?: Extent
}

interface MapContextLayerWfsModel {
Expand Down
62 changes: 49 additions & 13 deletions libs/feature/map/src/lib/utils/map-utils.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import Map from 'ol/Map'
import ImageWMS from 'ol/source/ImageWMS'
import TileWMS from 'ol/source/TileWMS'
import XYZ from 'ol/source/XYZ'
import { Options } from 'ol/source/WMTS'
import { of } from 'rxjs'
import { MapUtilsWMSService } from './map-utils-wms.service'
import {
Expand All @@ -27,6 +26,7 @@ import {
} from 'ol/interaction'
import { DatasetServiceDistribution } from '@geonetwork-ui/common/domain/model/record'
import MapBrowserEvent from 'ol/MapBrowserEvent'
import type { MapContextLayerWmtsModel } from '../map-context/map-context.model'

jest.mock('ol/proj/proj4', () => {
const fromEPSGCodeMock = jest.fn()
Expand Down Expand Up @@ -444,7 +444,7 @@ describe('MapUtilsService', () => {
window.fetch = originalFetch
})
describe('nominal', () => {
let wmtsOptions: Options
let wmtsLayer: MapContextLayerWmtsModel
beforeEach(async () => {
;(window as any).fetch = jest.fn(() =>
Promise.resolve({
Expand All @@ -453,8 +453,8 @@ describe('MapUtilsService', () => {
text: () => Promise.resolve(SAMPLE_WMTS_CAPABILITIES),
})
)
wmtsOptions = await readFirst(
service.getWmtsOptionsFromCapabilities(SAMPLE_WMTS_LINK)
wmtsLayer = await readFirst(
service.getWmtsLayerFromCapabilities(SAMPLE_WMTS_LINK)
)
})
it('appends query params to the URL', () => {
Expand All @@ -463,13 +463,49 @@ describe('MapUtilsService', () => {
)
})
it('returns appropriate WMTS options', () => {
expect(wmtsOptions).toMatchObject({
format: 'image/jpeg',
layer: 'GEOGRAPHICALGRIDSYSTEMS.ETATMAJOR10',
matrixSet: 'PM',
requestEncoding: 'KVP',
style: 'normal',
urls: ['https://wxs.ign.fr/cartes/geoportail/wmts?'],
expect(wmtsLayer).toMatchObject({
type: 'wmts',
options: {
format: 'image/jpeg',
layer: 'GEOGRAPHICALGRIDSYSTEMS.ETATMAJOR10',
matrixSet: 'PM',
requestEncoding: 'KVP',
style: 'normal',
urls: ['https://wxs.ign.fr/cartes/geoportail/wmts?'],
},
})
})
describe('layer extent', () => {
describe('when the WGS84BoundingBox is defined', () => {
it('set the WGS84BoundingBox', () => {
expect(wmtsLayer.extent).toEqual([
1.82682, 48.3847, 2.79738, 49.5142,
])
})
})
describe('when the WGS84BoundingBox is not defined', () => {
beforeEach(async () => {
;(window as any).fetch = jest.fn(() =>
Promise.resolve({
ok: true,
status: 200,
text: () =>
Promise.resolve(
SAMPLE_WMTS_CAPABILITIES.replace(
/WGS84BoundingBox/g,
'NoWGS84BoundingBox'
)
),
})
)
wmtsLayer = await readFirst(
service.getWmtsLayerFromCapabilities(SAMPLE_WMTS_LINK)
)
})

it('set the WGS84BoundingBox', () => {
expect(wmtsLayer.extent).toBeUndefined()
})
})
})
})
Expand All @@ -489,7 +525,7 @@ describe('MapUtilsService', () => {
)
try {
await readFirst(
service.getWmtsOptionsFromCapabilities(SAMPLE_WMTS_LINK)
service.getWmtsLayerFromCapabilities(SAMPLE_WMTS_LINK)
)
} catch (e) {
error = e
Expand All @@ -515,7 +551,7 @@ describe('MapUtilsService', () => {
)
try {
await readFirst(
service.getWmtsOptionsFromCapabilities(SAMPLE_WMTS_LINK)
service.getWmtsLayerFromCapabilities(SAMPLE_WMTS_LINK)
)
} catch (e) {
error = e
Expand Down
Loading

0 comments on commit b151b01

Please sign in to comment.