Skip to content

Commit

Permalink
fix: impacted tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cmoinier committed Sep 20, 2023
1 parent b3c719c commit 4d1c3c5
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 13 deletions.
37 changes: 26 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 Down Expand Up @@ -69,6 +68,7 @@ class searchServiceMock {
setSearch = jest.fn()
setSortBy = jest.fn()
setSortAndFilters = jest.fn()
setFilters = jest.fn()
}

class AuthServiceMock {
Expand Down Expand Up @@ -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',
})
})
})
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion conf/default.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down

0 comments on commit 4d1c3c5

Please sign in to comment.