mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-16 22:43:03 +00:00
added tests for popups
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { TextMenuItemComponent } from './text-menu-item.component';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { DebugElement, NO_ERRORS_SCHEMA } from '@angular/core';
|
||||
import { By } from '@angular/platform-browser';
|
||||
import { OnClickMenuItemComponent } from './onclick-menu-item.component';
|
||||
import { OnClickMenuItemModel } from './models/onclick.model';
|
||||
|
||||
describe('OnClickMenuItemComponent', () => {
|
||||
let component: OnClickMenuItemComponent;
|
||||
let fixture: ComponentFixture<OnClickMenuItemComponent>;
|
||||
let debugElement: DebugElement;
|
||||
const text = 'HELLO';
|
||||
const func = () => {
|
||||
};
|
||||
const item = Object.assign(new OnClickMenuItemModel(), { text, function: func });
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [TranslateModule.forRoot()],
|
||||
declarations: [OnClickMenuItemComponent],
|
||||
providers: [
|
||||
{ provide: 'itemModelProvider', useValue: item },
|
||||
],
|
||||
schemas: [NO_ERRORS_SCHEMA]
|
||||
})
|
||||
.compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
spyOn(item, 'function');
|
||||
fixture = TestBed.createComponent(OnClickMenuItemComponent);
|
||||
component = fixture.componentInstance;
|
||||
debugElement = fixture.debugElement;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should contain the correct text', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should contain the text element', () => {
|
||||
const textContent = debugElement.query(By.css('a')).nativeElement.textContent;
|
||||
expect(textContent).toEqual(text);
|
||||
});
|
||||
|
||||
it('should contain call the function on the item when clicked', () => {
|
||||
debugElement.query(By.css('a.nav-link')).triggerEventHandler('click', {});
|
||||
expect(item.function).toHaveBeenCalled();
|
||||
});
|
||||
});
|
Reference in New Issue
Block a user