mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-09 19:13:08 +00:00
more tests
This commit is contained in:
@@ -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);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
18
src/app/shared/utils/relation-query.utils.spec.ts
Normal file
18
src/app/shared/utils/relation-query.utils.spec.ts
Normal 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');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
22
src/app/shared/utils/route.utils.spec.ts
Normal file
22
src/app/shared/utils/route.utils.spec.ts
Normal 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');
|
||||||
|
});
|
||||||
|
});
|
Reference in New Issue
Block a user