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

feat(editor): Filter by current org #615

Merged
merged 3 commits into from
Sep 14, 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
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,28 @@
<a
class="menu-item"
routerLink="/records/my-org"
routerLinkActive
routerLinkActive="btn-active"
#rlaMyOrg="routerLinkActive"
>
<mat-icon class="material-icons-outlined">home</mat-icon>
<span translate="">dashboard.records.myOrg</span>
</a>

<a
class="menu-item"
routerLink="/records/all"
routerLinkActive
routerLinkActive="btn-active"
#rlaAll="routerLinkActive"
>
<mat-icon class="material-icons-outlined">work_outline</mat-icon>
<span translate="">dashboard.records.all</span>
</a>

<div class="menu-title" translate="">dashboard.labels.mySpace</div>
<a
class="menu-item"
routerLink="/records/my-records"
routerLinkActive
routerLinkActive="btn-active"
#rlaMyRecords="routerLinkActive"
>
<mat-icon class="material-icons-outlined">post_add</mat-icon>
Expand All @@ -30,7 +32,7 @@
<a
class="menu-item"
routerLink="/records/my-draft"
routerLinkActive
routerLinkActive="btn-active"
#rlaMyDraft="routerLinkActive"
>
<mat-icon class="material-icons-outlined">edit_note</mat-icon>
Expand All @@ -39,7 +41,7 @@
<a
class="menu-item"
routerLink="/records/my-library"
routerLinkActive
routerLinkActive="btn-active"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very good idea, navigation looks clearer now 👍

#rlaMyLibrary="routerLinkActive"
>
<mat-icon class="material-icons-outlined">bookmark_border</mat-icon>
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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<MyOrgRecordsComponent>
let searchFacade: SearchFacade
let orgService: OrganizationsServiceInterface

beforeEach(() => {
TestBed.configureTestingModule({
Expand All @@ -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,
},
Copy link
Collaborator

@cmoinier cmoinier Sep 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need a test for the new functionnality!

],
}).overrideComponent(MyOrgRecordsComponent, {
remove: {
Expand All @@ -41,6 +83,7 @@ describe('MyOrgRecordsComponent', () => {
},
})
searchFacade = TestBed.inject(SearchFacade)
orgService = TestBed.inject(OrganizationsServiceInterface)
fixture = TestBed.createComponent(MyOrgRecordsComponent)
component = fixture.componentInstance
fixture.detectChanges()
Expand All @@ -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)
})
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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))
}
}
Loading