Skip to content

Commit

Permalink
big commit to split
Browse files Browse the repository at this point in the history
fix search effects

refactor: adapt imports for new lib structure

harmonize sortby values

fix last TS errors

adding tests for gn4 repo

test gn4 repo

fixes

fix hits count

fixing more tests

more fixes

more fixes

more test fixes

move gn4 types to repository lib

fix lint errors
  • Loading branch information
jahow committed Aug 22, 2023
1 parent 615b9c8 commit 62d2916
Show file tree
Hide file tree
Showing 264 changed files with 4,339 additions and 4,674 deletions.
2 changes: 1 addition & 1 deletion apps/data-platform/src/app/dataviz/dataviz.model.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { DatavizConfigurationModel } from '@geonetwork-ui/util/types/data/dataviz-configuration.model'
import { DatavizConfigurationModel } from '@geonetwork-ui/common/domain/dataviz-configuration.model'

export type DatavizConfigModel = DatavizConfigurationModel
3 changes: 1 addition & 2 deletions apps/datahub/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import {
} from '@geonetwork-ui/util/app-config'
import { UtilI18nModule } from '@geonetwork-ui/util/i18n'
import {
METADATA_LANGUAGE,
PROXY_PATH,
ThemeService,
UtilSharedModule,
Expand All @@ -48,7 +47,6 @@ import { MetaReducer, StoreModule } from '@ngrx/store'
import { StoreDevtoolsModule } from '@ngrx/store-devtools'
import { TranslateModule } from '@ngx-translate/core'
import { environment } from '../environments/environment'

import { AppComponent } from './app.component'
import { HeaderBadgeButtonComponent } from './home/header-badge-button/header-badge-button.component'
import { HomeHeaderComponent } from './home/home-header/home-header.component'
Expand All @@ -68,6 +66,7 @@ import { FormsModule } from '@angular/forms'
import { UiDatavizModule } from '@geonetwork-ui/ui/dataviz'
import { WEB_COMPONENT_EMBEDDER_URL } from '@geonetwork-ui/feature/record'
import { LANGUAGES_LIST, UiCatalogModule } from '@geonetwork-ui/ui/catalog'
import { METADATA_LANGUAGE } from '@geonetwork-ui/api/repository'

export const metaReducers: MetaReducer[] = !environment.production ? [] : []
// https://github.com/nrwl/nx/issues/191
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,13 @@ import {
SearchFacade,
SearchService,
} from '@geonetwork-ui/feature/search'
import { SortByEnum } from '@geonetwork-ui/util/shared'
import { TranslateModule } from '@ngx-translate/core'
import { readFirst } from '@nx/angular/testing'
import { BehaviorSubject, of } from 'rxjs'
import { BehaviorSubject, firstValueFrom, of } from 'rxjs'
import { ROUTER_ROUTE_NEWS } from '../../router/constants'
import { HeaderBadgeButtonComponent } from '../header-badge-button/header-badge-button.component'
import { HomeHeaderComponent } from './home-header.component'
import resetAllMocks = jest.resetAllMocks
import { SortByEnum } from '@geonetwork-ui/common/domain/search'
import { _setLanguages } from '@geonetwork-ui/util/app-config'

jest.mock('@geonetwork-ui/util/app-config', () => {
Expand All @@ -35,7 +34,7 @@ jest.mock('@geonetwork-ui/util/app-config', () => {
filters: { publisher: ['DREAL'] },
},
{
sort: '-createDate',
sort: 'title',
name: 'filterCarto',
filters: { q: 'Cartographie' },
},
Expand Down Expand Up @@ -146,7 +145,9 @@ describe('HeaderComponent', () => {
})
})
it('displays favoriteBadge when authenticated', async () => {
const isAuthenticated = await readFirst(component.isAuthenticated$)
const isAuthenticated = await firstValueFrom(
component.isAuthenticated$
)
expect(isAuthenticated).toEqual(true)
})
})
Expand All @@ -155,7 +156,9 @@ describe('HeaderComponent', () => {
;(authService as any)._authSubject$.next(null)
})
it('does NOT display favoriteBadge when NOT authenticated', async () => {
const isAuthenticated = await readFirst(component.isAuthenticated$)
const isAuthenticated = await firstValueFrom(
component.isAuthenticated$
)
expect(isAuthenticated).toEqual(false)
})
})
Expand All @@ -177,7 +180,9 @@ describe('HeaderComponent', () => {
})
})
it('displays sort badges on search route', async () => {
const displaySortBadges = await readFirst(component.displaySortBadges$)
const displaySortBadges = await firstValueFrom(
component.displaySortBadges$
)
expect(displaySortBadges).toEqual(true)
})
})
Expand All @@ -188,7 +193,9 @@ describe('HeaderComponent', () => {
})
})
it('displays sort badges on news route', async () => {
const displaySortBadges = await readFirst(component.displaySortBadges$)
const displaySortBadges = await firstValueFrom(
component.displaySortBadges$
)
expect(displaySortBadges).toEqual(true)
})

Expand Down
10 changes: 6 additions & 4 deletions apps/datahub/src/app/home/home-header/home-header.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ import {
SearchConfig,
SearchPreset,
} from '@geonetwork-ui/util/app-config'
import { MetadataRecord, SortByEnum } from '@geonetwork-ui/util/shared'
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 { CatalogRecord } from '@geonetwork-ui/common/domain/record'
import { sortByFromString } from '@geonetwork-ui/util/shared'

marker('datahub.header.myfavorites')
marker('datahub.header.lastRecords')
Expand Down Expand Up @@ -64,15 +66,15 @@ export class HomeHeaderComponent {
.authReady()
.pipe(map((user) => !!user?.id))

onFuzzySearchSelection(record: MetadataRecord) {
onFuzzySearchSelection(record: CatalogRecord) {
this.routerFacade.goToMetadata(record)
}

listFavorites(toggled: boolean): void {
this.searchFacade.setFavoritesOnly(toggled)
}

clearSearchAndSort(sort: SortByEnum): void {
clearSearchAndSort(sort: SortByField): void {
this.searchService.setSortAndFilters({}, sort)
}

Expand All @@ -84,7 +86,7 @@ export class HomeHeaderComponent {
)
this.searchService.setSortAndFilters(
searchFilters,
customSearchParameters.sort as SortByEnum
sortByFromString(customSearchParameters.sort)
)
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import { ComponentFixture, TestBed } from '@angular/core/testing'
import { KeyFiguresComponent } from './key-figures.component'
import { of } from 'rxjs'
import {
OrganisationsServiceInterface,
RecordsService,
} from '@geonetwork-ui/feature/catalog'
import { RecordsService } from '@geonetwork-ui/feature/catalog'
import { TranslateModule } from '@ngx-translate/core'
import { NO_ERRORS_SCHEMA } from '@angular/core'
import { RouterTestingModule } from '@angular/router/testing'
import { By } from '@angular/platform-browser'
import { OrganizationsServiceInterface } from '@geonetwork-ui/common/domain/organizations.service.interface'

class RecordsServiceMock {
recordsCount$ = of(1234)
Expand All @@ -32,7 +30,7 @@ describe('KeyFiguresComponent', () => {
useClass: RecordsServiceMock,
},
{
provide: OrganisationsServiceInterface,
provide: OrganizationsServiceInterface,
useClass: OrganisationsServiceMock,
},
],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import { ChangeDetectionStrategy, Component } from '@angular/core'
import { startWith } from 'rxjs/operators'
import {
OrganisationsServiceInterface,
RecordsService,
} from '@geonetwork-ui/feature/catalog'
import { RecordsService } from '@geonetwork-ui/feature/catalog'
import { ROUTER_ROUTE_SEARCH } from '@geonetwork-ui/feature/router'
import { ROUTER_ROUTE_ORGANISATIONS } from '../../../router/constants'
import { OrganizationsServiceInterface } from '@geonetwork-ui/common/domain/organizations.service.interface'

@Component({
selector: 'datahub-key-figures',
Expand All @@ -21,6 +19,6 @@ export class KeyFiguresComponent {

constructor(
private catalogRecords: RecordsService,
private catalogOrgs: OrganisationsServiceInterface
private catalogOrgs: OrganizationsServiceInterface
) {}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { ComponentFixture, TestBed } from '@angular/core/testing'
import { summaryHits } from '@geonetwork-ui/util/shared/fixtures'
import { summaryHits } from '@geonetwork-ui/common/fixtures'
import { of } from 'rxjs'
import { LastCreatedComponent } from './last-created.component'

import { NO_ERRORS_SCHEMA } from '@angular/core'
import { SearchFacade } from '@geonetwork-ui/feature/search'
import { RouterFacade } from '@geonetwork-ui/feature/router'
Expand Down Expand Up @@ -65,16 +64,16 @@ describe('LastCreatedComponent', () => {

it('Should set the correct params in the facade', () => {
expect(facade.setPagination).toHaveBeenCalledWith(0, 10)
expect(facade.setSortBy).toHaveBeenCalledWith('-createDate')
expect(facade.setConfigRequestFields).toHaveBeenCalledWith({
includes: expect.arrayContaining([
expect(facade.setSortBy).toHaveBeenCalledWith(['desc', 'createDate'])
expect(facade.setConfigRequestFields).toHaveBeenCalledWith(
expect.arrayContaining([
'uuid',
'id',
'title',
'createDate',
'changeDate',
]),
})
])
)
})
})
})
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ChangeDetectionStrategy, Component, OnInit } from '@angular/core'
import { ES_SOURCE_BRIEF, MetadataRecord } from '@geonetwork-ui/util/shared'
import { RouterFacade } from '@geonetwork-ui/feature/router'
import { SearchFacade } from '@geonetwork-ui/feature/search'
import { FIELDS_BRIEF, SearchFacade } from '@geonetwork-ui/feature/search'
import { CatalogRecord } from '@geonetwork-ui/common/domain/record'

@Component({
selector: 'datahub-last-created',
Expand All @@ -16,15 +16,17 @@ export class LastCreatedComponent implements OnInit {
) {}

ngOnInit() {
this.searchFacade.setConfigRequestFields({
includes: [...ES_SOURCE_BRIEF, 'createDate', 'changeDate'],
})
this.searchFacade.setConfigRequestFields([
...FIELDS_BRIEF,
'createDate',
'changeDate',
])
this.searchFacade.setPagination(0, 10)
this.searchFacade.setSortBy('-createDate')
this.searchFacade.setSortBy(['desc', 'createDate'])
this.searchFacade.setResultsLayout('FEED')
}

onMetadataSelection(metadata: MetadataRecord): void {
onMetadataSelection(metadata: CatalogRecord): void {
this.routerFacade.goToMetadata(metadata)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ComponentFixture, TestBed } from '@angular/core/testing'

import { OrganisationsPageComponent } from './organisations-page.component'
import { SearchService } from '@geonetwork-ui/feature/search'
import { OrganisationsServiceInterface } from '@geonetwork-ui/feature/catalog'
import { OrganizationsServiceInterface } from '@geonetwork-ui/common/domain/organizations.service.interface'
import { of } from 'rxjs'

class SearchServiceMock {
Expand All @@ -22,7 +22,7 @@ describe('OrganisationsPageComponent', () => {
let component: OrganisationsPageComponent
let fixture: ComponentFixture<OrganisationsPageComponent>
let searchService: SearchService
let orgsService: OrganisationsServiceInterface
let orgsService: OrganizationsServiceInterface

beforeEach(async () => {
await TestBed.configureTestingModule({
Expand All @@ -34,14 +34,14 @@ describe('OrganisationsPageComponent', () => {
useClass: SearchServiceMock,
},
{
provide: OrganisationsServiceInterface,
provide: OrganizationsServiceInterface,
useClass: OrganisationsServiceMock,
},
],
}).compileComponents()

searchService = TestBed.inject(SearchService)
orgsService = TestBed.inject(OrganisationsServiceInterface)
orgsService = TestBed.inject(OrganizationsServiceInterface)

fixture = TestBed.createComponent(OrganisationsPageComponent)
component = fixture.componentInstance
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ChangeDetectionStrategy, Component } from '@angular/core'
import { Organisation } from '@geonetwork-ui/util/shared'
import { SearchService } from '@geonetwork-ui/feature/search'
import { OrganisationsServiceInterface } from '@geonetwork-ui/feature/catalog'
import { OrganizationsServiceInterface } from '@geonetwork-ui/common/domain/organizations.service.interface'
import { Organization } from '@geonetwork-ui/common/domain/record'

@Component({
selector: 'datahub-organisations-page',
Expand All @@ -12,10 +12,10 @@ import { OrganisationsServiceInterface } from '@geonetwork-ui/feature/catalog'
export class OrganisationsPageComponent {
constructor(
private searchService: SearchService,
private orgsService: OrganisationsServiceInterface
private orgsService: OrganizationsServiceInterface
) {}

searchByOrganisation(organisation: Organisation) {
searchByOrganisation(organisation: Organization) {
this.orgsService
.getFiltersForOrgs([organisation])
.subscribe((filters) => this.searchService.setFilters(filters))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,15 @@ import {
SearchFacade,
SearchService,
} from '@geonetwork-ui/feature/search'
import {
AggregationsOrderEnum,
AggregationsTypesEnum,
SearchFilters,
} from '@geonetwork-ui/util/shared'
import { BehaviorSubject, of } from 'rxjs'
import { SearchFiltersComponent } from './search-filters.component'
import { TranslateModule } from '@ngx-translate/core'
import { By } from '@angular/platform-browser'
import { FormsModule } from '@angular/forms'
import {
AggregationsTypes,
FieldFilters,
} from '@geonetwork-ui/common/domain/search'

jest.mock('@geonetwork-ui/util/app-config', () => ({
getOptionalSearchConfig: () => ({
Expand Down Expand Up @@ -66,10 +65,8 @@ export class MockCheckToggleComponent {
export class MockFilterDropdownComponent {
@Input() fieldName: string
@Input() title: string
@Input() order: AggregationsOrderEnum = AggregationsOrderEnum.ASC
@Input() aggregationType: AggregationsTypesEnum = AggregationsTypesEnum.TERMS
}
const state = { OrgForResource: { mel: true } } as SearchFilters
const state = { OrgForResource: { mel: true } } as FieldFilters
class SearchFacadeMock {
searchFilters$ = new BehaviorSubject(state)
hasSpatialFilter$ = new BehaviorSubject(false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { RouterFacade } from '@geonetwork-ui/feature/router'
import { SearchPageComponent } from './search-page.component'
import { SearchFacade } from '@geonetwork-ui/feature/search'
import { UiLayoutModule } from '@geonetwork-ui/ui/layout'
import { RECORDS_SUMMARY_FIXTURE } from '@geonetwork-ui/util/shared/fixtures'
import { DATASET_RECORDS } from '@geonetwork-ui/common/fixtures'

const RouterFacadeMock = {
goToMetadata: jest.fn(),
Expand Down Expand Up @@ -54,9 +54,9 @@ describe('MainSearchComponent', () => {

describe('navigate to metadata record', () => {
it('calls searchRouter goToMetdata with md record', () => {
component.onMetadataSelection(RECORDS_SUMMARY_FIXTURE[0])
component.onMetadataSelection(DATASET_RECORDS[0])
expect(RouterFacadeMock.goToMetadata).toHaveBeenCalledWith(
RECORDS_SUMMARY_FIXTURE[0]
DATASET_RECORDS[0]
)
})
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ChangeDetectionStrategy, Component, OnInit } from '@angular/core'
import { RouterFacade } from '@geonetwork-ui/feature/router'
import { SearchFacade } from '@geonetwork-ui/feature/search'
import { MetadataRecord } from '@geonetwork-ui/util/shared'
import { CatalogRecord } from '@geonetwork-ui/common/domain/record'

@Component({
selector: 'datahub-search-page',
Expand All @@ -19,7 +19,7 @@ export class SearchPageComponent implements OnInit {
this.searchFacade.setResultsLayout('ROW')
}

onMetadataSelection(metadata: MetadataRecord): void {
onMetadataSelection(metadata: CatalogRecord): void {
this.searchRouter.goToMetadata(metadata)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
class="h-full container-lg mx-auto flex flex-col justify-center relative"
>
<gn-ui-favorite-star
*ngIf="metadata?.id"
*ngIf="metadata?.uniqueIdentifier"
[record]="metadata"
class="absolute text-background top-[0.85em] right-[0.85em]"
[style.color]="foregroundColor"
Expand Down
Loading

0 comments on commit 62d2916

Please sign in to comment.