Skip to content

Commit

Permalink
Merge pull request #404 from geonetwork/link-org-group
Browse files Browse the repository at this point in the history
Rework organisation hydration
  • Loading branch information
fgravin authored Jan 12, 2023
2 parents 22d8aca + ae119a9 commit 885fc96
Show file tree
Hide file tree
Showing 17 changed files with 427 additions and 104 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class RecordsServiceMock {
}

class OrganisationsServiceMock {
countOrganisations = () => of(456)
organisationsCount$ = of(456)
}

describe('KeyFiguresComponent', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
})
export class KeyFiguresComponent {
recordsCount$ = this.catalogRecords.recordsCount$.pipe(startWith('-'))
orgsCount$ = this.catalogOrgs.countOrganisations().pipe(startWith('-'))
orgsCount$ = this.catalogOrgs.organisationsCount$.pipe(startWith('-'))
ROUTE_SEARCH = `/${ROUTER_ROUTE_HOME}/${ROUTER_ROUTE_SEARCH}`
ROUTE_ORGANISATIONS = `/${ROUTER_ROUTE_HOME}/${ROUTER_ROUTE_ORGANISATIONS}`

Expand Down
44 changes: 44 additions & 0 deletions libs/feature/catalog/src/lib/group/group.service.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { TestBed } from '@angular/core/testing'
import { GroupsApiService } from '@geonetwork-ui/data-access/gn4'
import { of } from 'rxjs'

import { GroupService } from './group.service'

const groupsApiMock = [
{
name: 'agence',
label: { eng: 'AGENCE-DE-TEST' },
description: 'une agence',
logo: 'logo-ag.png',
},
{
name: 'association',
label: { eng: 'Association National du testing' },
description: 'une association',
logo: 'logo-asso.png',
},
]

const groupsApiServiceMock = {
getGroups: jest.fn(() => of(groupsApiMock)),
}

describe('GroupsService', () => {
let service: GroupService

beforeEach(() => {
TestBed.configureTestingModule({
providers: [
{
provide: GroupsApiService,
useValue: groupsApiServiceMock,
},
],
})
service = TestBed.inject(GroupService)
})

it('should be created', () => {
expect(service).toBeTruthy()
})
})
15 changes: 15 additions & 0 deletions libs/feature/catalog/src/lib/group/group.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Injectable } from '@angular/core'
import { GroupApiModel, GroupsApiService } from '@geonetwork-ui/data-access/gn4'
import { Observable } from 'rxjs'
import { shareReplay } from 'rxjs/operators'

@Injectable({
providedIn: 'root',
})
export class GroupService {
groups$: Observable<GroupApiModel[]> = this.groupsApiService
.getGroups()
.pipe(shareReplay())

constructor(private groupsApiService: GroupsApiService) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,16 @@
<div
class="grid grid-cols-1 mt-6 gap-x-6 gap-y-8 sm:grid-cols-2 lg:grid-cols-3"
>
<gn-ui-organisation-preview
<gn-ui-content-ghost
ghostClass="h-36 mb-36"
*ngFor="let organisation of organisations$ | async; trackBy: trackByIndex"
[organisation]="organisation"
(clickedOrganisation)="searchByOrganisation($event)"
></gn-ui-organisation-preview>
[showContent]="organisation.description !== null"
>
<gn-ui-organisation-preview
[organisation]="organisation"
(clickedOrganisation)="searchByOrganisation($event)"
></gn-ui-organisation-preview>
</gn-ui-content-ghost>
</div>
<div class="py-20">
<gn-ui-pagination
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ import {
Output,
} from '@angular/core'
import { ComponentFixture, TestBed } from '@angular/core/testing'
import { readFirst } from '@nrwl/angular/testing'
import { By } from '@angular/platform-browser'
import { SearchService } from '@geonetwork-ui/feature/search'
import { ContentGhostComponent } from '@geonetwork-ui/ui/elements'
import { Organisation } from '@geonetwork-ui/util/shared'
import { ORGANISATIONS_FIXTURE } from '@geonetwork-ui/util/shared/fixtures'
import { readFirst } from '@nrwl/angular/testing'
import { of } from 'rxjs'
import { OrganisationsComponent } from './organisations.component'
import { OrganisationsService } from './organisations.service'
import { SearchService } from '@geonetwork-ui/feature/search'

@Component({
selector: 'gn-ui-organisations-sort',
Expand Down Expand Up @@ -43,7 +44,7 @@ class PaginationMockComponent {
}

class OrganisationsServiceMock {
getOrganisationsWithGroups = jest.fn(() => of(ORGANISATIONS_FIXTURE))
hydratedOrganisations$ = of(ORGANISATIONS_FIXTURE)
}

class SearchServiceMock {
Expand Down Expand Up @@ -73,6 +74,7 @@ describe('OrganisationsComponent', () => {
OrganisationsSortMockComponent,
OrganisationPreviewMockComponent,
PaginationMockComponent,
ContentGhostComponent,
],
providers: [
{
Expand Down Expand Up @@ -111,9 +113,6 @@ describe('OrganisationsComponent', () => {
beforeEach(() => {
paginationComponentDE = de.query(By.directive(PaginationMockComponent))
})
it('should call getOrganisationsWithGroups', () => {
expect(organisationsService.getOrganisationsWithGroups).toHaveBeenCalled()
})
describe('pass organisations to ui preview components', () => {
beforeEach(() => {
orgPreviewComponents = de
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ChangeDetectionStrategy, Component, Input } from '@angular/core'
import { SearchService } from '@geonetwork-ui/feature/search'
import { Organisation } from '@geonetwork-ui/util/shared'
import { BehaviorSubject, combineLatest, Observable } from 'rxjs'
import { map, tap } from 'rxjs/operators'
import { map, startWith, tap } from 'rxjs/operators'
import { OrganisationsService } from './organisations.service'

@Component({
Expand All @@ -23,7 +23,9 @@ export class OrganisationsComponent {
sortBy$ = new BehaviorSubject('name-asc')

organisationsSorted$: Observable<Organisation[]> = combineLatest([
this.organisationsService.getOrganisationsWithGroups(),
this.organisationsService.hydratedOrganisations$.pipe(
startWith(Array(this.itemsOnPage).fill({}))
),
this.sortBy$,
]).pipe(
map(([organisations, sortBy]) =>
Expand Down
Loading

0 comments on commit 885fc96

Please sign in to comment.