-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1140 from ORCID/unit-tests-for-delete-components
add delete affiliation unit tests
- Loading branch information
Showing
4 changed files
with
55 additions
and
13 deletions.
There are no files selected for viewing
55 changes: 50 additions & 5 deletions
55
ui/src/app/affiliation/affiliation-delete.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,68 @@ | ||
import { ComponentFixture, TestBed } from '@angular/core/testing' | ||
|
||
import { AffiliationDeletePopupComponent } from './affiliation-delete.component' | ||
import { AffiliationDeleteDialogComponent, AffiliationDeletePopupComponent } from './affiliation-delete.component' | ||
import { RouterTestingModule } from '@angular/router/testing' | ||
import { AffiliationService } from './service/affiliation.service' | ||
import { EventService } from '../shared/service/event.service' | ||
import { EventType } from '../app.constants' | ||
import { Event } from '../shared/model/event.model' | ||
import { NgbActiveModal, NgbModal } from '@ng-bootstrap/ng-bootstrap' | ||
import { HttpResponse } from '@angular/common/http' | ||
import { of } from 'rxjs' | ||
|
||
describe('AffiliationDeleteComponent', () => { | ||
let component: AffiliationDeletePopupComponent | ||
let fixture: ComponentFixture<AffiliationDeletePopupComponent> | ||
let component: AffiliationDeleteDialogComponent | ||
let fixture: ComponentFixture<AffiliationDeleteDialogComponent> | ||
let affiliationService: jasmine.SpyObj<AffiliationService> | ||
let eventService: jasmine.SpyObj<EventService> | ||
|
||
beforeEach(() => { | ||
const affiliationServiceSpy = jasmine.createSpyObj('AffiliationService', ['delete']) | ||
const eventServiceSpy = jasmine.createSpyObj('EventService', ['broadcast']) | ||
|
||
TestBed.configureTestingModule({ | ||
declarations: [AffiliationDeletePopupComponent], | ||
declarations: [AffiliationDeleteDialogComponent], | ||
imports: [RouterTestingModule], | ||
providers: [ | ||
NgbModal, | ||
NgbActiveModal, | ||
{ provide: AffiliationService, useValue: affiliationServiceSpy }, | ||
{ provide: EventService, useValue: eventServiceSpy }, | ||
], | ||
}) | ||
fixture = TestBed.createComponent(AffiliationDeletePopupComponent) | ||
affiliationService = TestBed.inject(AffiliationService) as jasmine.SpyObj<AffiliationService> | ||
eventService = TestBed.inject(EventService) as jasmine.SpyObj<EventService> | ||
fixture = TestBed.createComponent(AffiliationDeleteDialogComponent) | ||
component = fixture.componentInstance | ||
fixture.detectChanges() | ||
}) | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy() | ||
}) | ||
|
||
it('should confirm the affiliation being deleted', () => { | ||
affiliationService.delete.and.returnValue(of(true)) | ||
component.confirmDelete('id') | ||
|
||
expect(eventService.broadcast).toHaveBeenCalledWith( | ||
new Event(EventType.AFFILIATION_LIST_MODIFICATION, 'Deleted an affiliation') | ||
) | ||
}) | ||
|
||
it('should fail to delete the affiliation', () => { | ||
affiliationService.delete.and.returnValue(of(false)) | ||
component.confirmDelete('id') | ||
|
||
expect(eventService.broadcast).toHaveBeenCalledWith( | ||
new Event(EventType.AFFILIATION_LIST_MODIFICATION, 'Failed to delete an affiliation') | ||
) | ||
}) | ||
|
||
it('should not call the assertion service without an id', () => { | ||
affiliationService.delete.and.returnValue(of(false)) | ||
component.confirmDelete('') | ||
|
||
expect(affiliationService.delete).toHaveBeenCalledTimes(0) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters