diff --git a/apps/metadata-editor/src/app/dashboard/dashboard-menu/dashboard-menu.component.html b/apps/metadata-editor/src/app/dashboard/dashboard-menu/dashboard-menu.component.html index 547afed229..64aba5ac74 100644 --- a/apps/metadata-editor/src/app/dashboard/dashboard-menu/dashboard-menu.component.html +++ b/apps/metadata-editor/src/app/dashboard/dashboard-menu/dashboard-menu.component.html @@ -2,26 +2,28 @@ home dashboard.records.myOrg + work_outline dashboard.records.all + post_add @@ -30,7 +32,7 @@ edit_note @@ -39,7 +41,7 @@ bookmark_border diff --git a/apps/metadata-editor/src/app/records/my-org-records/my-org-records.component.spec.ts b/apps/metadata-editor/src/app/records/my-org-records/my-org-records.component.spec.ts index 4bbfc0c95b..a8a489d901 100644 --- a/apps/metadata-editor/src/app/records/my-org-records/my-org-records.component.spec.ts +++ b/apps/metadata-editor/src/app/records/my-org-records/my-org-records.component.spec.ts @@ -1,10 +1,42 @@ import { ComponentFixture, TestBed } from '@angular/core/testing' import { MyOrgRecordsComponent } from './my-org-records.component' -import { SearchFacade } from '@geonetwork-ui/feature/search' +import { SearchFacade, SearchService } from '@geonetwork-ui/feature/search' import { Component, importProvidersFrom } from '@angular/core' import { TranslateModule } from '@ngx-translate/core' import { RecordsListComponent } from '../records-list.component' +import { + FILTERS_AGGREGATION, + USER_FIXTURE, +} from '@geonetwork-ui/common/fixtures' +import { BehaviorSubject, of } from 'rxjs' +import { AuthService } from '@geonetwork-ui/feature/auth' +import { OrganizationsServiceInterface } from '@geonetwork-ui/common/domain/organizations.service.interface' + +const user = USER_FIXTURE() +const filters = FILTERS_AGGREGATION + +class AuthServiceMock { + user$ = new BehaviorSubject(user) + authReady = jest.fn(() => this._authSubject$) + _authSubject$ = new BehaviorSubject({}) +} +class OrganisationsServiceMock { + getFiltersForOrgs = jest.fn(() => new BehaviorSubject(filters)) + organisationsCount$ = of(456) +} + +class searchServiceMock { + updateSearchFilters = jest.fn() + setSearch = jest.fn() + setSortBy = jest.fn() + setSortAndFilters = jest.fn() +} + +class SearchFacadeMock { + resetSearch = jest.fn() + setFilters = jest.fn() +} @Component({ // eslint-disable-next-line @@ -14,14 +46,11 @@ import { RecordsListComponent } from '../records-list.component' }) export class MockRecordsListComponent {} -class SearchFacadeMock { - resetSearch = jest.fn() -} - describe('MyOrgRecordsComponent', () => { let component: MyOrgRecordsComponent let fixture: ComponentFixture let searchFacade: SearchFacade + let orgService: OrganizationsServiceInterface beforeEach(() => { TestBed.configureTestingModule({ @@ -31,6 +60,19 @@ describe('MyOrgRecordsComponent', () => { provide: SearchFacade, useClass: SearchFacadeMock, }, + { provide: AuthService, useClass: AuthServiceMock }, + { + provide: OrganizationsServiceInterface, + useClass: OrganisationsServiceMock, + }, + { + provide: SearchFacade, + useClass: SearchFacadeMock, + }, + { + provide: SearchService, + useClass: searchServiceMock, + }, ], }).overrideComponent(MyOrgRecordsComponent, { remove: { @@ -41,6 +83,7 @@ describe('MyOrgRecordsComponent', () => { }, }) searchFacade = TestBed.inject(SearchFacade) + orgService = TestBed.inject(OrganizationsServiceInterface) fixture = TestBed.createComponent(MyOrgRecordsComponent) component = fixture.componentInstance fixture.detectChanges() @@ -54,5 +97,13 @@ describe('MyOrgRecordsComponent', () => { it('clears filters on init', () => { expect(searchFacade.resetSearch).toHaveBeenCalled() }) + it('filters by user organisation on init', () => { + expect(orgService.getFiltersForOrgs).toHaveBeenCalledWith([ + { + name: user.organisation, + }, + ]) + expect(searchFacade.setFilters).toHaveBeenCalledWith(filters) + }) }) }) diff --git a/apps/metadata-editor/src/app/records/my-org-records/my-org-records.component.ts b/apps/metadata-editor/src/app/records/my-org-records/my-org-records.component.ts index 3290e0219e..9c9ac5319f 100644 --- a/apps/metadata-editor/src/app/records/my-org-records/my-org-records.component.ts +++ b/apps/metadata-editor/src/app/records/my-org-records/my-org-records.component.ts @@ -3,6 +3,9 @@ import { CommonModule } from '@angular/common' import { TranslateModule } from '@ngx-translate/core' import { RecordsListComponent } from '../records-list.component' import { SearchFacade } from '@geonetwork-ui/feature/search' +import { OrganizationsServiceInterface } from '@geonetwork-ui/common/domain/organizations.service.interface' +import { Organization } from '@geonetwork-ui/common/domain/record' +import { AuthService } from '@geonetwork-ui/feature/auth' @Component({ selector: 'md-editor-my-org-records', @@ -12,7 +15,20 @@ import { SearchFacade } from '@geonetwork-ui/feature/search' imports: [CommonModule, TranslateModule, RecordsListComponent], }) export class MyOrgRecordsComponent { - constructor(public searchFacade: SearchFacade) { + constructor( + public searchFacade: SearchFacade, + private authService: AuthService, + private orgService: OrganizationsServiceInterface + ) { this.searchFacade.resetSearch() + this.authService.user$.subscribe((user) => { + this.searchByOrganisation({ name: user.organisation }) + }) + } + + searchByOrganisation(organisation: Organization) { + this.orgService + .getFiltersForOrgs([organisation]) + .subscribe((filters) => this.searchFacade.setFilters(filters)) } }