Skip to content

Commit

Permalink
test(organisations.component): add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tkohr committed Dec 15, 2023
1 parent e24a047 commit ba6c5d7
Showing 1 changed file with 75 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,15 @@ class OrganisationPreviewMockComponent {
@Output() clickedOrganisation = new EventEmitter<Organization>()
}

@Component({
selector: 'gn-ui-organisations-result',
template: '<div></div>',
})
class OrganisationsResultMockComponent {
@Input() hits: number
@Input() total: number
}

@Component({
selector: 'gn-ui-pagination',
template: '<div></div>',
Expand All @@ -43,6 +52,7 @@ class PaginationMockComponent {

class OrganisationsServiceMock {
organisations$ = of(ORGANISATIONS_FIXTURE)
organisationsCount$ = of(ORGANISATIONS_FIXTURE.length)
}

const organisationMock = {
Expand All @@ -66,6 +76,7 @@ describe('OrganisationsComponent', () => {
OrganisationsFilterMockComponent,
OrganisationPreviewMockComponent,
PaginationMockComponent,
OrganisationsResultMockComponent,
ContentGhostComponent,
],
providers: [
Expand Down Expand Up @@ -93,6 +104,7 @@ describe('OrganisationsComponent', () => {

describe('on component init', () => {
let orgPreviewComponents: OrganisationPreviewMockComponent[]
let orgResultComponent: OrganisationsResultMockComponent
let paginationComponentDE: DebugElement
let setCurrentPageSpy
let setSortBySpy
Expand Down Expand Up @@ -181,6 +193,69 @@ describe('OrganisationsComponent', () => {
)
})
})
describe('filter organisations', () => {
describe('initial state', () => {
beforeEach(() => {
orgResultComponent = de.query(
By.directive(OrganisationsResultMockComponent)
)
})
it('should display number of organisations found to equal all', () => {
expect(orgResultComponent.componentInstance.hits).toEqual(
ORGANISATIONS_FIXTURE.length
)
})
it('should display number of all organisations', () => {
expect(orgResultComponent.componentInstance.total).toEqual(
ORGANISATIONS_FIXTURE.length
)
})
})
describe('entering search terms', () => {
beforeEach(() => {
orgResultComponent = de.query(
By.directive(OrganisationsResultMockComponent)
)
})
it('should ignore case and display 11 matches for "Data", "DATA" or "data"', () => {
component.filterBy$.next('Data')
fixture.detectChanges()
expect(orgResultComponent.componentInstance.hits).toEqual(11)
component.filterBy$.next('DATA')
fixture.detectChanges()
expect(orgResultComponent.componentInstance.hits).toEqual(11)
component.filterBy$.next('data')
fixture.detectChanges()
expect(orgResultComponent.componentInstance.hits).toEqual(11)
})
it('should ignore accents and case and display 2 matches for "é Data Org", "e Data Org" or "E Data Org"', () => {
component.filterBy$.next('é Data Org')
fixture.detectChanges()
expect(orgResultComponent.componentInstance.hits).toEqual(2)
component.filterBy$.next('e Data Org')
fixture.detectChanges()
expect(orgResultComponent.componentInstance.hits).toEqual(2)
component.filterBy$.next('E Data Org')
fixture.detectChanges()
expect(orgResultComponent.componentInstance.hits).toEqual(2)
})
it('should combine multiple termes with "AND" logic and display 1 match for "a data"', () => {
component.filterBy$.next('a data')
fixture.detectChanges()
expect(orgResultComponent.componentInstance.hits).toEqual(1)
})
it('should combine multiple termes with "AND" logic and display 11 matches for "data org"', () => {
component.filterBy$.next('data org')
fixture.detectChanges()
expect(orgResultComponent.componentInstance.hits).toEqual(11)
})
it('should display 12 matches for "ORG"', () => {
component.filterBy$.next('ORG')
fixture.detectChanges()
expect(orgResultComponent.componentInstance.hits).toEqual(12)
})
})
})
describe('click on organisation', () => {
let orgSelected
beforeEach(() => {
Expand Down

0 comments on commit ba6c5d7

Please sign in to comment.