Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Datahub : Custom data toggle broken #619

Merged
merged 4 commits into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -20,7 +20,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'
import { CatalogRecord } from '@geonetwork-ui/common/domain/record'
import { sortByFromString } from '@geonetwork-ui/util/shared'

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)
}
cmoinier marked this conversation as resolved.
Show resolved Hide resolved
}
}
3 changes: 2 additions & 1 deletion conf/default.toml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,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 @@ -88,6 +88,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