mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 01:54:15 +00:00
added tests for new component
This commit is contained in:
@@ -1,20 +1,59 @@
|
||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
|
||||
import { ExistingMetadataListElementComponent } from './existing-metadata-list-element.component';
|
||||
import { ExistingMetadataListElementComponent, Reorderable, ReorderableRelationship } from './existing-metadata-list-element.component';
|
||||
import { NO_ERRORS_SCHEMA } from '@angular/core';
|
||||
import { SelectableListService } from '../../../../object-list/selectable-list/selectable-list.service';
|
||||
import { Store } from '@ngrx/store';
|
||||
import { select, Store } from '@ngrx/store';
|
||||
import { Item } from '../../../../../core/shared/item.model';
|
||||
import { Relationship } from '../../../../../core/shared/item-relationships/relationship.model';
|
||||
import { RelationshipOptions } from '../../models/relationship-options.model';
|
||||
import { createSuccessfulRemoteDataObject$ } from '../../../../testing/utils';
|
||||
import { RemoveRelationshipAction } from '../relation-lookup-modal/relationship.actions';
|
||||
import { ItemSearchResult } from '../../../../object-collection/shared/item-search-result.model';
|
||||
|
||||
describe('ExistingMetadataListElementComponent', () => {
|
||||
let component: ExistingMetadataListElementComponent;
|
||||
let fixture: ComponentFixture<ExistingMetadataListElementComponent>;
|
||||
let selectionService;
|
||||
let store;
|
||||
let listID;
|
||||
let submissionItem;
|
||||
let relationship;
|
||||
let reoRel;
|
||||
let metadataFields;
|
||||
let relationshipOptions;
|
||||
let uuid1;
|
||||
let uuid2;
|
||||
let relatedItem;
|
||||
let leftItemRD$;
|
||||
let rightItemRD$;
|
||||
let relatedSearchResult;
|
||||
|
||||
function init() {
|
||||
uuid1 = '91ce578d-2e63-4093-8c73-3faafd716000';
|
||||
uuid2 = '0e9dba1c-e1c3-4e05-a539-446f08ef57a7';
|
||||
selectionService = jasmine.createSpyObj('selectionService', ['deselectSingle']);
|
||||
store = jasmine.createSpyObj('store', ['dispatch']);
|
||||
listID = '1234-listID';
|
||||
submissionItem = Object.assign(new Item(), { uuid: uuid1 });
|
||||
metadataFields = ['dc.contributor.author'];
|
||||
relationshipOptions = Object.assign(new RelationshipOptions(), { relationshipType: 'isPublicationOfAuthor', filter: 'test.filter', searchConfiguration: 'personConfiguration', nameVariants: true })
|
||||
relatedItem = Object.assign(new Item(), { uuid: uuid2 });
|
||||
leftItemRD$ = createSuccessfulRemoteDataObject$(relatedItem);
|
||||
rightItemRD$ = createSuccessfulRemoteDataObject$(submissionItem);
|
||||
relatedSearchResult = Object.assign(new ItemSearchResult(), { indexableObject: relatedItem });
|
||||
|
||||
relationship = Object.assign(new Relationship(), { leftItem: leftItemRD$, rightItem: rightItemRD$ });
|
||||
reoRel = new ReorderableRelationship(relationship, true);
|
||||
}
|
||||
|
||||
beforeEach(async(() => {
|
||||
init();
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [ExistingMetadataListElementComponent],
|
||||
providers: [
|
||||
{ provide: SelectableListService, useValue: {} },
|
||||
{ provide: Store, useValue: {} },
|
||||
{ provide: SelectableListService, useValue: selectionService },
|
||||
{ provide: Store, useValue: store },
|
||||
],
|
||||
schemas: [NO_ERRORS_SCHEMA]
|
||||
})
|
||||
@@ -24,10 +63,30 @@ describe('ExistingMetadataListElementComponent', () => {
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(ExistingMetadataListElementComponent);
|
||||
component = fixture.componentInstance;
|
||||
component.listId = listID;
|
||||
component.submissionItem = submissionItem;
|
||||
component.reoRel = reoRel;
|
||||
component.metadataFields = metadataFields;
|
||||
component.relationshipOptions = relationshipOptions;
|
||||
fixture.detectChanges();
|
||||
component.ngOnChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
|
||||
describe('removeSelection', () => {
|
||||
it('should deselect the object in the selectable list service', () => {
|
||||
component.removeSelection();
|
||||
expect(selectionService.deselectSingle).toHaveBeenCalledWith(listID, relatedSearchResult);
|
||||
});
|
||||
|
||||
it('should dispatch a RemoveRelationshipAction', () => {
|
||||
component.removeSelection();
|
||||
const action = new RemoveRelationshipAction(submissionItem, relatedItem, relationshipOptions.relationshipType);
|
||||
expect(store.dispatch).toHaveBeenCalledWith(action);
|
||||
|
||||
});
|
||||
})
|
||||
});
|
||||
|
@@ -76,7 +76,6 @@ export class ExistingMetadataListElementComponent implements OnChanges, OnDestro
|
||||
ngOnChanges() {
|
||||
const item$ = this.reoRel.useLeftItem ?
|
||||
this.reoRel.relationship.leftItem : this.reoRel.relationship.rightItem;
|
||||
|
||||
this.subs.push(item$.pipe(
|
||||
getAllSucceededRemoteData(),
|
||||
getRemoteDataPayload(),
|
||||
|
Reference in New Issue
Block a user