Files
dspace-angular/src/app/entity-groups/research-entities/submission/name-variant-modal/name-variant-modal.component.spec.ts
2020-02-13 11:09:20 +01:00

54 lines
1.8 KiB
TypeScript

import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { NameVariantModalComponent } from './name-variant-modal.component';
import { NgbActiveModal, NgbModule } from '@ng-bootstrap/ng-bootstrap';
import { TranslateModule } from '@ngx-translate/core';
import { By } from '@angular/platform-browser';
describe('NameVariantModalComponent', () => {
let component: NameVariantModalComponent;
let fixture: ComponentFixture<NameVariantModalComponent>;
let debugElement;
let modal;
function init() {
modal = jasmine.createSpyObj('modal', ['close', 'dismiss']);
}
beforeEach(async(() => {
init();
TestBed.configureTestingModule({
declarations: [NameVariantModalComponent],
imports: [NgbModule, TranslateModule.forRoot()],
providers: [{ provide: NgbActiveModal, useValue: modal }]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(NameVariantModalComponent);
component = fixture.componentInstance;
debugElement = fixture.debugElement;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
it('when close button is clicked, dismiss should be called on the modal', () => {
debugElement.query(By.css('button.close')).triggerEventHandler('click', {});
expect(modal.dismiss).toHaveBeenCalled();
});
it('when confirm button is clicked, close should be called on the modal', () => {
debugElement.query(By.css('button.confirm-button')).triggerEventHandler('click', {});
expect(modal.close).toHaveBeenCalled();
});
it('when decline button is clicked, dismiss should be called on the modal', () => {
debugElement.query(By.css('button.decline-button')).triggerEventHandler('click', {});
expect(modal.dismiss).toHaveBeenCalled();
});
});