Skip to content

Commit

Permalink
Merge pull request #619 from geonetwork/datahub-custom-data-toggle-br…
Browse files Browse the repository at this point in the history
…oken

Datahub : Custom data toggle broken
  • Loading branch information
cmoinier committed Sep 21, 2023
2 parents 175dbb0 + 4d1c3c5 commit a9fd646
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 17 deletions.
38 changes: 27 additions & 11 deletions apps/datahub/src/app/home/home-header/home-header.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ jest.mock('@geonetwork-ui/util/app-config', () => {
filters: { publisher: ['DREAL'] },
},
{
sort: 'title',
name: 'filterCarto',
filters: { q: 'Cartographie' },
},
Expand All @@ -61,13 +60,15 @@ class routerFacadeMock {
class searchFacadeMock {
setFavoritesOnly = jest.fn()
setSortBy = jest.fn()
sortBy$ = new BehaviorSubject(['desc', 'createDate'])
}

class searchServiceMock {
updateSearchFilters = jest.fn()
setSearch = jest.fn()
setSortBy = jest.fn()
setSortAndFilters = jest.fn()
setFilters = jest.fn()
}

class AuthServiceMock {
Expand Down Expand Up @@ -233,17 +234,32 @@ describe('HeaderComponent', () => {
const allBadges = fixture.debugElement.queryAll(By.css('.badge-btn'))
expect(allBadges.length).toBe(4)
})
beforeEach(() => {
const firstCustomBadge = fixture.debugElement.queryAll(
By.css('.badge-btn')
)[2]
firstCustomBadge.nativeElement.click()
describe('when sort is defined', () => {
beforeEach(() => {
const firstCustomBadge = fixture.debugElement.queryAll(
By.css('.badge-btn')
)[2]
firstCustomBadge.nativeElement.click()
})
it('should redirect correctly', () => {
expect(searchService.setSortAndFilters).toHaveBeenCalledWith(
{ thisIs: 'a fake filter' },
SortByEnum.CREATE_DATE
)
})
})
it('should redirect correctly', () => {
expect(searchService.setSortAndFilters).toHaveBeenCalledWith(
{ thisIs: 'a fake filter' },
SortByEnum.CREATE_DATE
)
describe('when sort is not defined', () => {
beforeEach(() => {
const secondCustomBadge = fixture.debugElement.queryAll(
By.css('.badge-btn')
)[3]
secondCustomBadge.nativeElement.click()
})
it('should redirect correctly', () => {
expect(searchService.setFilters).toHaveBeenCalledWith({
thisIs: 'a fake filter',
})
})
})
})

Expand Down
12 changes: 7 additions & 5 deletions apps/datahub/src/app/home/home-header/home-header.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
import { SortByEnum, SortByField } from '@geonetwork-ui/common/domain/search'
import { map } from 'rxjs/operators'
import { ROUTER_ROUTE_NEWS } from '../../router/constants'
import { lastValueFrom } from 'rxjs'
import { firstValueFrom, lastValueFrom } from 'rxjs'

Check warning on line 22 in apps/datahub/src/app/home/home-header/home-header.component.ts

View workflow job for this annotation

GitHub Actions / Format check, lint, unit tests

'firstValueFrom' is defined but never used
import { CatalogRecord } from '@geonetwork-ui/common/domain/record'
import { sortByFromString } from '@geonetwork-ui/util/shared'
import { AuthService } from '@geonetwork-ui/api/repository/gn4'
Expand Down Expand Up @@ -84,9 +84,11 @@ export class HomeHeaderComponent {
customSearchParameters.filters
)
)
this.searchService.setSortAndFilters(
searchFilters,
sortByFromString(customSearchParameters.sort)
)
if (customSearchParameters.sort) {
const sortBy = sortByFromString(customSearchParameters.sort)
this.searchService.setSortAndFilters(searchFilters, sortBy)
} else {
this.searchService.setFilters(searchFilters)
}
}
}
3 changes: 2 additions & 1 deletion conf/default.toml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ background_color = "#fdfbff"

# One or several search presets can be defined here; every search preset is composed of:
# - a name (which can be a translation key)
# - a sort criteria: either `createDate`, `userSavedCount` or `_score` (prepend with `-` for descending sort)
# - a sort criteria: either `createDate`, `userSavedCount` or `_score` (prepend with `-` for descending sort) (optionnal)
# - filters which can be expressed like so:
# [[search_preset]]
# name = 'filterByName'
Expand All @@ -90,6 +90,7 @@ background_color = "#fdfbff"
# filters.publicationYear = ['2023', '2022']
# filters.isSpatial = ['yes']
# filters.license = ['unknown']
# sort = 'createDate'
# [[search_preset]]
# name = 'otherFilterName'
# filters.q = 'Other Full text search'
Expand Down

0 comments on commit a9fd646

Please sign in to comment.