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 @@
filters: { publisher: ['DREAL'] },
},
{
sort: 'title',
name: 'filterCarto',
filters: { q: 'Cartographie' },
},
Expand All @@ -61,13 +60,15 @@
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 @@ -139,7 +140,7 @@
describe('isAuthenticated$', () => {
describe('user is authenticated', () => {
beforeEach(() => {
;(authService as any)._authSubject$.next({

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

View workflow job for this annotation

GitHub Actions / Format check, lint, unit tests

Unexpected any. Specify a different type
id: 'user-id',
name: 'testuser',
})
Expand All @@ -153,7 +154,7 @@
})
describe('user is NOT authenticated', () => {
beforeEach(() => {
;(authService as any)._authSubject$.next(null)

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

View workflow job for this annotation

GitHub Actions / Format check, lint, unit tests

Unexpected any. Specify a different type
})
it('does NOT display favoriteBadge when NOT authenticated', async () => {
const isAuthenticated = await firstValueFrom(
Expand All @@ -175,7 +176,7 @@
describe('sort badges', () => {
describe('navigate to search route', () => {
beforeEach(() => {
;(routerFacade.currentRoute$ as any).next({

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

View workflow job for this annotation

GitHub Actions / Format check, lint, unit tests

Unexpected any. Specify a different type
url: [{ path: ROUTER_ROUTE_SEARCH }],
})
})
Expand All @@ -188,7 +189,7 @@
})
describe('navigate to news route', () => {
beforeEach(() => {
;(routerFacade.currentRoute$ as any).next({

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

View workflow job for this annotation

GitHub Actions / Format check, lint, unit tests

Unexpected any. Specify a different type
url: [{ path: ROUTER_ROUTE_NEWS }],
})
})
Expand Down Expand Up @@ -233,17 +234,32 @@
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,8 +19,8 @@
} from '@geonetwork-ui/util/app-config'
import { SortByEnum, SortByField } from '@geonetwork-ui/common/domain/search'
import { map } from 'rxjs/operators'
import { ROUTER_ROUTE_NEWS } from '../../router/constants'

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 { 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 @@
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
Loading