Skip to content

Commit

Permalink
feat(editor): Add test to initial filter by org
Browse files Browse the repository at this point in the history
  • Loading branch information
Angi-Kinas committed Sep 14, 2023
1 parent 4169baa commit 24516c8
Showing 1 changed file with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand All @@ -29,6 +35,7 @@ class searchServiceMock {

class SearchFacadeMock {
resetSearch = jest.fn()
setFilters = jest.fn()
}

@Component({
Expand All @@ -43,6 +50,7 @@ describe('MyOrgRecordsComponent', () => {
let component: MyOrgRecordsComponent
let fixture: ComponentFixture<MyOrgRecordsComponent>
let searchFacade: SearchFacade
let orgService: OrganizationsServiceInterface

beforeEach(() => {
TestBed.configureTestingModule({
Expand Down Expand Up @@ -75,6 +83,7 @@ describe('MyOrgRecordsComponent', () => {
},
})
searchFacade = TestBed.inject(SearchFacade)
orgService = TestBed.inject(OrganizationsServiceInterface)
fixture = TestBed.createComponent(MyOrgRecordsComponent)
component = fixture.componentInstance
fixture.detectChanges()
Expand All @@ -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)
})
})
})

0 comments on commit 24516c8

Please sign in to comment.