mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 10:04:11 +00:00
64574: Tests and small bugfix
This commit is contained in:
@@ -2,23 +2,72 @@ import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { ChangeDetectionStrategy, NO_ERRORS_SCHEMA } from '@angular/core';
|
||||
import { By } from '@angular/platform-browser';
|
||||
import { MetadataRepresentationListComponent } from './metadata-representation-list.component';
|
||||
import { MetadatumRepresentation } from '../../../core/shared/metadata-representation/metadatum/metadatum-representation.model';
|
||||
import { ItemMetadataRepresentation } from '../../../core/shared/metadata-representation/item/item-metadata-representation.model';
|
||||
import { RelationshipService } from '../../../core/data/relationship.service';
|
||||
import { Item } from '../../../core/shared/item.model';
|
||||
import { Relationship } from '../../../core/shared/item-relationships/relationship.model';
|
||||
import { createSuccessfulRemoteDataObject$ } from '../../../shared/testing/utils';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
|
||||
const itemType = 'type';
|
||||
const metadataRepresentation1 = new MetadatumRepresentation(itemType);
|
||||
const metadataRepresentation2 = new ItemMetadataRepresentation();
|
||||
const representations = [metadataRepresentation1, metadataRepresentation2];
|
||||
const itemType = 'Person';
|
||||
const metadataField = 'dc.contributor.author';
|
||||
const parentItem: Item = Object.assign(new Item(), {
|
||||
id: 'parent-item',
|
||||
metadata: {
|
||||
'dc.contributor.author': [
|
||||
{
|
||||
language: null,
|
||||
value: 'Related Author with authority',
|
||||
authority: 'virtual::related-author',
|
||||
place: 2
|
||||
},
|
||||
{
|
||||
language: null,
|
||||
value: 'Author without authority',
|
||||
place: 1
|
||||
}
|
||||
],
|
||||
'dc.title': [
|
||||
{
|
||||
language: null,
|
||||
value: 'Parent Item'
|
||||
}
|
||||
]
|
||||
}
|
||||
});
|
||||
const relatedAuthor: Item = Object.assign(new Item(), {
|
||||
id: 'related-author',
|
||||
metadata: {
|
||||
'dc.title': [
|
||||
{
|
||||
language: null,
|
||||
value: 'Related Author'
|
||||
}
|
||||
]
|
||||
}
|
||||
});
|
||||
const relation: Relationship = Object.assign(new Relationship(), {
|
||||
leftItem: createSuccessfulRemoteDataObject$(parentItem),
|
||||
rightItem: createSuccessfulRemoteDataObject$(relatedAuthor)
|
||||
});
|
||||
let relationshipService: RelationshipService;
|
||||
|
||||
describe('MetadataRepresentationListComponent', () => {
|
||||
let comp: MetadataRepresentationListComponent;
|
||||
let fixture: ComponentFixture<MetadataRepresentationListComponent>;
|
||||
|
||||
relationshipService = jasmine.createSpyObj('relationshipService',
|
||||
{
|
||||
findById: createSuccessfulRemoteDataObject$(relation)
|
||||
}
|
||||
);
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [],
|
||||
imports: [TranslateModule.forRoot()],
|
||||
declarations: [MetadataRepresentationListComponent],
|
||||
providers: [],
|
||||
providers: [
|
||||
{ provide: RelationshipService, useValue: relationshipService }
|
||||
],
|
||||
schemas: [NO_ERRORS_SCHEMA]
|
||||
}).overrideComponent(MetadataRepresentationListComponent, {
|
||||
set: {changeDetection: ChangeDetectionStrategy.Default}
|
||||
@@ -28,13 +77,45 @@ describe('MetadataRepresentationListComponent', () => {
|
||||
beforeEach(async(() => {
|
||||
fixture = TestBed.createComponent(MetadataRepresentationListComponent);
|
||||
comp = fixture.componentInstance;
|
||||
comp.representations = representations;
|
||||
comp.parentItem = parentItem;
|
||||
comp.itemType = itemType;
|
||||
comp.metadataField = metadataField;
|
||||
fixture.detectChanges();
|
||||
}));
|
||||
|
||||
it(`should load ${representations.length} item-type-switcher components`, () => {
|
||||
it('should load 2 item-type-switcher components', () => {
|
||||
const fields = fixture.debugElement.queryAll(By.css('ds-item-type-switcher'));
|
||||
expect(fields.length).toBe(representations.length);
|
||||
expect(fields.length).toBe(2);
|
||||
});
|
||||
|
||||
it('should initialize the original limit', () => {
|
||||
expect(comp.originalLimit).toEqual(comp.limit);
|
||||
});
|
||||
|
||||
describe('when viewMore is called', () => {
|
||||
beforeEach(() => {
|
||||
comp.viewMore();
|
||||
});
|
||||
|
||||
it('should set the limit to a high number in order to retrieve all metadata representations', () => {
|
||||
expect(comp.limit).toBeGreaterThanOrEqual(999);
|
||||
});
|
||||
});
|
||||
|
||||
describe('when viewLess is called', () => {
|
||||
let originalLimit;
|
||||
|
||||
beforeEach(() => {
|
||||
// Store the original value of limit
|
||||
originalLimit = comp.limit;
|
||||
// Set limit to a random number
|
||||
comp.limit = 458;
|
||||
comp.viewLess();
|
||||
});
|
||||
|
||||
it('should reset the limit to the original value', () => {
|
||||
expect(comp.limit).toEqual(originalLimit);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
@@ -29,7 +29,7 @@ const mockItems = [mockItem1, mockItem2];
|
||||
const relationType = 'isItemOfItem';
|
||||
let relationshipService: RelationshipService;
|
||||
|
||||
fdescribe('RelatedItemsComponent', () => {
|
||||
describe('RelatedItemsComponent', () => {
|
||||
let comp: RelatedItemsComponent;
|
||||
let fixture: ComponentFixture<RelatedItemsComponent>;
|
||||
|
||||
@@ -73,6 +73,10 @@ fdescribe('RelatedItemsComponent', () => {
|
||||
it('should call relationship-service\'s getRelatedItemsByLabel with the correct arguments', () => {
|
||||
expect(relationshipService.getRelatedItemsByLabel).toHaveBeenCalledWith(parentItem, relationType, comp.allOptions);
|
||||
});
|
||||
|
||||
it('should set showingAll to true', () => {
|
||||
expect(comp.showingAll).toEqual(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('when viewLess is called', () => {
|
||||
@@ -83,6 +87,10 @@ fdescribe('RelatedItemsComponent', () => {
|
||||
it('should call relationship-service\'s getRelatedItemsByLabel with the correct arguments', () => {
|
||||
expect(relationshipService.getRelatedItemsByLabel).toHaveBeenCalledWith(parentItem, relationType, comp.options);
|
||||
});
|
||||
|
||||
it('should set showingAll to false', () => {
|
||||
expect(comp.showingAll).toEqual(false);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
@@ -244,7 +244,12 @@ export class RelationshipService extends DataService<Relationship> {
|
||||
if (options) {
|
||||
findAllOptions = Object.assign(new FindAllOptions(), options);
|
||||
}
|
||||
findAllOptions.searchParams = [ new SearchParam('label', label), new SearchParam('dso', item.id) ];
|
||||
const searchParams = [ new SearchParam('label', label), new SearchParam('dso', item.id) ];
|
||||
if (findAllOptions.searchParams) {
|
||||
findAllOptions.searchParams = [...findAllOptions.searchParams, ...searchParams];
|
||||
} else {
|
||||
findAllOptions.searchParams = searchParams;
|
||||
}
|
||||
return this.searchBy('byLabel', findAllOptions);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user