diff --git a/apps/datahub/src/app/home/home-header/home-header.component.spec.ts b/apps/datahub/src/app/home/home-header/home-header.component.spec.ts index 6d32a51734..5c8ba2afb4 100644 --- a/apps/datahub/src/app/home/home-header/home-header.component.spec.ts +++ b/apps/datahub/src/app/home/home-header/home-header.component.spec.ts @@ -34,7 +34,6 @@ jest.mock('@geonetwork-ui/util/app-config', () => { filters: { publisher: ['DREAL'] }, }, { - sort: 'title', name: 'filterCarto', filters: { q: 'Cartographie' }, }, @@ -69,6 +68,7 @@ class searchServiceMock { setSearch = jest.fn() setSortBy = jest.fn() setSortAndFilters = jest.fn() + setFilters = jest.fn() } class AuthServiceMock { @@ -234,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', + }) + }) }) }) diff --git a/apps/datahub/src/app/home/home-header/home-header.component.ts b/apps/datahub/src/app/home/home-header/home-header.component.ts index 5ef3aeb0f5..ce3093a834 100644 --- a/apps/datahub/src/app/home/home-header/home-header.component.ts +++ b/apps/datahub/src/app/home/home-header/home-header.component.ts @@ -85,7 +85,7 @@ export class HomeHeaderComponent { ) ) if (customSearchParameters.sort) { - const sortBy = sortByFromString(customSearchParameters.sort[0]) + const sortBy = sortByFromString(customSearchParameters.sort) this.searchService.setSortAndFilters(searchFilters, sortBy) } else { this.searchService.setFilters(searchFilters) diff --git a/conf/default.toml b/conf/default.toml index 8788371b6f..830ec315c1 100644 --- a/conf/default.toml +++ b/conf/default.toml @@ -88,7 +88,7 @@ background_color = "#fdfbff" # filters.publicationYear = ['2023', '2022'] # filters.isSpatial = ['yes'] # filters.license = ['unknown'] -# sort = ['createDate'] +# sort = 'createDate' # [[search_preset]] # name = 'otherFilterName' # filters.q = 'Other Full text search'