Skip to content

Commit

Permalink
feat(me): filter by my-org
Browse files Browse the repository at this point in the history
  • Loading branch information
cmoinier committed Oct 3, 2023
1 parent 7c8b49c commit b8b4dcc
Show file tree
Hide file tree
Showing 26 changed files with 440 additions and 82 deletions.
44 changes: 44 additions & 0 deletions apps/metadata-editor-e2e/src/e2e/my-org.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
describe('my-org', () => {
beforeEach(() => {
cy.loginGN('barbie', 'p4ssworD_', false)
cy.visit(`/records/my-org`)
cy.get('md-editor-dashboard-menu').find('a').first().click()
cy.get('main').children('div').first().children('div').eq(1).as('linkGroup')
})
describe('my-org display', () => {
it('should show my-org name and logo', () => {
cy.get('h1').should('not.have.text', '')
cy.get('gn-ui-thumbnail')
})
it('should show the user and record count', () => {
cy.get('@linkGroup')
.find('a')
.children('span')
.first()
.should('not.have.text', '')
cy.get('@linkGroup')
.find('gn-ui-button')
.children('span')
.first()
.should('not.have.text', '')
})
it('should show my-org records', () => {
cy.get('.grid').should('have.length.above', 0)
})
})
describe('routing', () => {
it('should access the datahub with a filter', () => {
cy.get('@linkGroup').find('a').click()
cy.url().should('include', 'search/publisher=')
})
it('should access the user list page and show my-org users', () => {
cy.visit(`/records/my-org`)
cy.get('md-editor-dashboard-menu').find('a').first().click()
cy.get('@linkGroup').find('gn-ui-button').click()
cy.url().should('include', '/users/my-org')
cy.get('.grid').should('have.length.above', 0)
cy.get('h1').should('not.have.text', '')
cy.get('gn-ui-thumbnail')
})
})
})
5 changes: 5 additions & 0 deletions apps/metadata-editor/src/app/app.routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { MyRecordsComponent } from './records/my-records/my-records.component'
import { MyDraftComponent } from './records/my-draft/my-draft.component'
import { MyLibraryComponent } from './records/my-library/my-library.component'
import { SearchRecordsComponent } from './records/search-records/search-records-list.component'
import { MyOrgUsersComponent } from './my-org-users/my-org-users.component'

export const appRoutes: Route[] = [
{ path: '', component: DashboardPageComponent, pathMatch: 'prefix' },
Expand Down Expand Up @@ -61,6 +62,10 @@ export const appRoutes: Route[] = [
},
],
},
{
path: 'users/my-org',
component: MyOrgUsersComponent,
},
{ path: 'sign-in', component: SignInPageComponent },
{ path: 'create', component: CreatePageComponent },
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.record-table-col {
@apply px-5 py-3 items-center truncate;
}

.record-table-header {
@apply record-table-col capitalize;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<md-editor-records-list [users]="userList" [logo]="logoUrl" [title]="orgName">
</md-editor-records-list>
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import { MyOrgUsersComponent } from './my-org-users.component'
import { BehaviorSubject, of } from 'rxjs'
import {
ORGANISATIONS_FIXTURE,
USER_FIXTURE,
USERS_FIXTURE,
} from '@geonetwork-ui/common/fixtures'
import { OrganizationsServiceInterface } from '@geonetwork-ui/common/domain/organizations.service.interface'
import { AuthService } from '@geonetwork-ui/feature/auth'
import { SearchFacade } from '@geonetwork-ui/feature/search'

describe('MyOrgUsersComponent', () => {
let component: MyOrgUsersComponent
let searchFacade: SearchFacade
let orgService: OrganizationsServiceInterface
let authService: AuthService

beforeEach(() => {
const user = USER_FIXTURE()
const allUsers = USERS_FIXTURE()

const authServiceMock = {
user$: new BehaviorSubject(user),
allUsers$: new BehaviorSubject(allUsers),
}

const organisationsServiceMock = {
organisations$: of(ORGANISATIONS_FIXTURE),
}

const searchFacadeMock = {
resetSearch: jest.fn(),
}

authService = authServiceMock as any
orgService = organisationsServiceMock as any
searchFacade = searchFacadeMock as any

component = new MyOrgUsersComponent(searchFacade, authService, orgService)
})

it('should create', () => {
expect(component).toBeTruthy()
})

describe('Get organization users info', () => {
it('should get the org name', () => {
expect(component.orgName).toEqual('Région Hauts-de-France') // Replace with your test data
})

it('should get the org logo', () => {
expect(component.logoUrl).toEqual('https://my-geonetwork.org/logo11.png') // Replace with your test data
})

it('should get the list of users', () => {
expect(component.userList).toEqual([
{
id: '46798',
profile: 'Administrator',
username: 'Gravin',
name: 'Arnaud',
surname: 'De Maison',
email: '[email protected]',
organisation: 'Région Hauts-de-France',
profileIcon:
'https://www.gravatar.com/avatar/dbdffd183622800bcf8587328daf43a6?d=mp',
},
{
id: '3',
profile: 'Editor',
username: 'voldy63',
name: 'Lord',
surname: 'Voldemort',
email: '[email protected]',
organisation: 'Région Hauts-de-France',
},
{
id: '4',
profile: 'Editor',
username: 'al.dumble98',
name: 'Albus',
surname: 'Dumblerdore',
email: '[email protected]',
organisation: 'Région Hauts-de-France',
},
])
})
})
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { Component } from '@angular/core'
import { RecordsListComponent } from '../records/records-list.component'
import { SearchFacade } from '@geonetwork-ui/feature/search'
import { AuthService } from '@geonetwork-ui/feature/auth'
import { OrganizationsServiceInterface } from '@geonetwork-ui/common/domain/organizations.service.interface'
import { UiInputsModule } from '@geonetwork-ui/ui/inputs'
import { TranslateModule } from '@ngx-translate/core'
import { CommonModule } from '@angular/common'

@Component({
selector: 'md-editor-my-org-users',
templateUrl: './my-org-users.component.html',
styleUrls: ['./my-org-users.component.css'],
standalone: true,
imports: [
RecordsListComponent,
UiInputsModule,
TranslateModule,
CommonModule,
],
})
export class MyOrgUsersComponent {
orgName: string
logoUrl: string
userList: any[]

constructor(
public searchFacade: SearchFacade,
public authService: AuthService,
private orgService: OrganizationsServiceInterface
) {
this.searchFacade.resetSearch()
this.authService.user$.subscribe((user) => {
this.orgName = user.organisation
})
this.orgService.organisations$.subscribe((orgs) => {
const org = orgs.filter((org) => org.name === this.orgName)[0]
if (org) {
this.logoUrl = org.logoUrl?.href.toString()
}
})
this.authService.allUsers$.subscribe((users) => {
this.userList = users.filter((user) => user.organisation === this.orgName)
})
}
}
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
<md-editor-records-list [title]="'dashboard.records.myOrg' | translate">
<md-editor-records-list
[logo]="logoUrl"
[title]="orgName"
[recordCount]="recordCount"
[userCount]="userCount"
>
</md-editor-records-list>
Original file line number Diff line number Diff line change
@@ -1,91 +1,49 @@
import { ComponentFixture, TestBed } from '@angular/core/testing'
import { MyOrgRecordsComponent } from './my-org-records.component'
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 { BehaviorSubject, of } from 'rxjs'
import {
FILTERS_AGGREGATION,
ORGANISATIONS_FIXTURE,
USER_FIXTURE,
USERS_FIXTURE,
} from '@geonetwork-ui/common/fixtures'
import { BehaviorSubject, of } from 'rxjs'
import { OrganizationsServiceInterface } from '@geonetwork-ui/common/domain/organizations.service.interface'
import { AuthService } from '@geonetwork-ui/api/repository/gn4'
import { AuthService } from '@geonetwork-ui/feature/auth'
import { SearchFacade } from '@geonetwork-ui/feature/search'

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
selector: 'md-editor-records-list',
template: '',
standalone: true,
})
export class MockRecordsListComponent {}
const allUsers = USERS_FIXTURE()

describe('MyOrgRecordsComponent', () => {
let component: MyOrgRecordsComponent
let fixture: ComponentFixture<MyOrgRecordsComponent>
let searchFacade: SearchFacade
let orgService: OrganizationsServiceInterface
let authService: AuthService

beforeEach(() => {
TestBed.configureTestingModule({
providers: [
importProvidersFrom(TranslateModule.forRoot()),
{
provide: SearchFacade,
useClass: SearchFacadeMock,
},
{ provide: AuthService, useClass: AuthServiceMock },
{
provide: OrganizationsServiceInterface,
useClass: OrganisationsServiceMock,
},
{
provide: SearchFacade,
useClass: SearchFacadeMock,
},
{
provide: SearchService,
useClass: searchServiceMock,
},
],
}).overrideComponent(MyOrgRecordsComponent, {
remove: {
imports: [RecordsListComponent],
},
add: {
imports: [MockRecordsListComponent],
},
})
searchFacade = TestBed.inject(SearchFacade)
orgService = TestBed.inject(OrganizationsServiceInterface)
fixture = TestBed.createComponent(MyOrgRecordsComponent)
component = fixture.componentInstance
fixture.detectChanges()
const authServiceMock = {
user$: new BehaviorSubject(user),
allUsers$: new BehaviorSubject(allUsers),
}

const organisationsServiceMock = {
organisations$: of(ORGANISATIONS_FIXTURE),
getFiltersForOrgs: jest.fn(() => new BehaviorSubject(filters)),
}

const searchFacadeMock = {
resetSearch: jest.fn(),
setFilters: jest.fn(),
}

authService = authServiceMock as any
orgService = organisationsServiceMock as any
searchFacade = searchFacadeMock as any

component = new MyOrgRecordsComponent(searchFacade, authService, orgService)
})

it('should create', () => {
Expand All @@ -105,4 +63,18 @@ describe('MyOrgRecordsComponent', () => {
expect(searchFacade.setFilters).toHaveBeenCalledWith(filters)
})
})

describe('Get organization users info', () => {
it('should get the org name', () => {
expect(component.orgName).toEqual('Région Hauts-de-France') // Replace with your test data
})

it('should get the org logo', () => {
expect(component.logoUrl).toEqual('https://my-geonetwork.org/logo11.png') // Replace with your test data
})

it('should get the list of users', () => {
expect(component.userCount).toEqual(3)
})
})
})
Loading

0 comments on commit b8b4dcc

Please sign in to comment.