more tests

This commit is contained in:
lotte
2019-12-19 13:57:44 +01:00
parent 20b4da5c33
commit 00039436b6
3 changed files with 104 additions and 0 deletions

View File

@@ -0,0 +1,64 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { ChangeDetectionStrategy, NO_ERRORS_SCHEMA } from '@angular/core';
import { OrgUnitInputSuggestionsComponent } from './org-unit-input-suggestions.component';
import { FormsModule } from '@angular/forms';
let component: OrgUnitInputSuggestionsComponent;
let fixture: ComponentFixture<OrgUnitInputSuggestionsComponent>;
let suggestions: string[];
let testValue;
function init() {
suggestions = ['test', 'suggestion', 'example']
testValue = 'bla';
}
describe('OrgUnitInputSuggestionsComponent', () => {
beforeEach(async(() => {
init();
TestBed.configureTestingModule({
declarations: [OrgUnitInputSuggestionsComponent],
imports: [
FormsModule,
],
providers: [
],
schemas: [NO_ERRORS_SCHEMA]
}).overrideComponent(OrgUnitInputSuggestionsComponent, {
set: { changeDetection: ChangeDetectionStrategy.Default }
}).compileComponents();
}));
beforeEach(async(() => {
fixture = TestBed.createComponent(OrgUnitInputSuggestionsComponent);
component = fixture.componentInstance;
component.suggestions = suggestions;
fixture.detectChanges();
}));
it('should create', () => {
expect(component).toBeTruthy();
});
describe('When the component is initialized', () => {
it('should set the value to the first value of the suggestions', () => {
expect(component.value).toEqual('test');
});
});
describe('When onSubmit is called', () => {
it('should set the value to parameter of the method', () => {
component.onSubmit(testValue);
expect(component.value).toEqual(testValue);
});
});
describe('When onClickSuggestion is called', () => {
it('should set the value to parameter of the method', () => {
component.onClickSuggestion(testValue);
expect(component.value).toEqual(testValue);
});
});
});

View File

@@ -0,0 +1,18 @@
import { getFilterByRelation, getQueryByRelations } from './relation-query.utils';
describe('Relation Query Utils', () => {
const relationtype = 'isAuthorOfPublication';
const itemUUID = 'a7939af0-36ad-430d-af09-7be8b0a4dadd';
describe('getQueryByRelations', () => {
it('Should return the correct query based on relationtype and uuid', () => {
const result = getQueryByRelations(relationtype, itemUUID);
expect(result).toEqual('query=relation.isAuthorOfPublication:a7939af0-36ad-430d-af09-7be8b0a4dadd');
});
});
describe('getFilterByRelation', () => {
it('Should return the correct query based on relationtype and uuid', () => {
const result = getFilterByRelation(relationtype, itemUUID);
expect(result).toEqual('f.isAuthorOfPublication=a7939af0-36ad-430d-af09-7be8b0a4dadd');
});
});
});

View File

@@ -0,0 +1,22 @@
import { currentPath } from './route.utils';
describe('Route Utils', () => {
const urlTree = {
root: {
children: {
primary: {
segments: [
{ path: 'test' },
{ path: 'path' }
]
}
}
}
};
const router = { parseUrl: () => urlTree } as any;
it('Should return the correct current path based on the router', () => {
const result = currentPath(router);
expect(result).toEqual('/test/path');
});
});