Skip to content

Commit

Permalink
test(all-record): add UTs for search
Browse files Browse the repository at this point in the history
  • Loading branch information
tkohr committed Dec 20, 2024
1 parent 183e6a5 commit 737e2bf
Showing 1 changed file with 35 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
} from '@geonetwork-ui/feature/search'
import { ChangeDetectionStrategy } from '@angular/core'
import { TranslateModule } from '@ngx-translate/core'
import { BehaviorSubject, of } from 'rxjs'
import { BehaviorSubject, firstValueFrom, of } from 'rxjs'
import { barbieUserFixture } from '@geonetwork-ui/common/fixtures'
import { ActivatedRoute, Router } from '@angular/router'
import { AllRecordsComponent } from './all-records.component'
Expand All @@ -25,6 +25,7 @@ describe('AllRecordsComponent', () => {

const searchFilters = new BehaviorSubject({
any: 'hello world',
owner: {},
})

let component: AllRecordsComponent
Expand All @@ -34,6 +35,7 @@ describe('AllRecordsComponent', () => {
let searchFacade: SearchFacade
let platformService: PlatformServiceInterface
let fieldsService: FieldsService
let searchService: SearchService

beforeEach(() => {
return MockBuilder(AllRecordsComponent)
Expand Down Expand Up @@ -76,6 +78,7 @@ describe('AllRecordsComponent', () => {

router = TestBed.inject(Router)
searchFacade = TestBed.inject(SearchFacade)
searchService = TestBed.inject(SearchService)
platformService = TestBed.inject(PlatformServiceInterface)
fieldsService = TestBed.inject(FieldsService)

Expand Down Expand Up @@ -103,6 +106,8 @@ describe('AllRecordsComponent', () => {
searchFacade.setPageSize = jest.fn(() => this)
searchFacade.setConfigRequestFields = jest.fn(() => this)

searchService.setFilters = jest.fn(() => this)

component = fixture.componentInstance

fixture.detectChanges()
Expand All @@ -119,6 +124,35 @@ describe('AllRecordsComponent', () => {
})
})

describe('when updating the search filters', () => {
beforeEach(() => {
searchFilters.next({ any: 'new search', owner: { 1: true } })
})

it('updates the search text', async () => {
const searchText = await firstValueFrom(component.searchText$)
expect(searchText).toBe('new search')
})
it('resets the owner filter', () => {
expect(searchService.setFilters).toHaveBeenCalledWith({
any: 'new search',
})
})
})

describe('when destroying the component', () => {
beforeEach(() => {
component.ngOnDestroy()
})

it('resets the search filters', () => {
expect(searchFacade.updateFilters).toHaveBeenCalledWith({ any: '' })
})
it('unsubscribes from component subscription', () => {
expect(component.subscription.closed).toBe(true)
})
})

describe('when clicking createRecord', () => {
beforeEach(() => {
component.createRecord()
Expand Down

0 comments on commit 737e2bf

Please sign in to comment.