From 37311fc5e80e26231661af6c9bb11809bdc58b51 Mon Sep 17 00:00:00 2001 From: Angelika Kinas Date: Mon, 11 Sep 2023 13:22:09 +0200 Subject: [PATCH 1/3] feat(editor): Filter by current org --- .../my-org-records.component.spec.ts | 44 ++++++++++++++++--- .../my-org-records.component.ts | 18 +++++++- 2 files changed, 56 insertions(+), 6 deletions(-) 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..c766decb62 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,35 @@ 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 { 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() +class AuthServiceMock { + user$ = new BehaviorSubject(user) + authReady = jest.fn(() => this._authSubject$) + _authSubject$ = new BehaviorSubject({}) +} +class OrganisationsServiceMock { + organisationsCount$ = of(456) +} + +class searchServiceMock { + updateSearchFilters = jest.fn() + setSearch = jest.fn() + setSortBy = jest.fn() + setSortAndFilters = jest.fn() +} + +class SearchFacadeMock { + resetSearch = jest.fn() +} @Component({ // eslint-disable-next-line @@ -14,10 +39,6 @@ import { RecordsListComponent } from '../records-list.component' }) export class MockRecordsListComponent {} -class SearchFacadeMock { - resetSearch = jest.fn() -} - describe('MyOrgRecordsComponent', () => { let component: MyOrgRecordsComponent let fixture: ComponentFixture @@ -31,6 +52,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: { 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)) } } From 4169baa701a52f2eeb6c166530396545866899f7 Mon Sep 17 00:00:00 2001 From: Angelika Kinas Date: Mon, 11 Sep 2023 13:35:02 +0200 Subject: [PATCH 2/3] Make navigation options look selected (active) --- .../dashboard-menu/dashboard-menu.component.html | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) 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 From 24516c85679c44737004763eb2164adf8d370509 Mon Sep 17 00:00:00 2001 From: Angelika Kinas Date: Thu, 14 Sep 2023 13:20:44 +0200 Subject: [PATCH 3/3] feat(editor): Add test to initial filter by org --- .../my-org-records.component.spec.ts | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) 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 c766decb62..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 @@ -5,18 +5,24 @@ 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 { USER_FIXTURE } from '@geonetwork-ui/common/fixtures' +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) } @@ -29,6 +35,7 @@ class searchServiceMock { class SearchFacadeMock { resetSearch = jest.fn() + setFilters = jest.fn() } @Component({ @@ -43,6 +50,7 @@ describe('MyOrgRecordsComponent', () => { let component: MyOrgRecordsComponent let fixture: ComponentFixture let searchFacade: SearchFacade + let orgService: OrganizationsServiceInterface beforeEach(() => { TestBed.configureTestingModule({ @@ -75,6 +83,7 @@ describe('MyOrgRecordsComponent', () => { }, }) searchFacade = TestBed.inject(SearchFacade) + orgService = TestBed.inject(OrganizationsServiceInterface) fixture = TestBed.createComponent(MyOrgRecordsComponent) component = fixture.componentInstance fixture.detectChanges() @@ -88,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) + }) }) })