mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 10:04:11 +00:00
taskid 66074 Keep virtual metadata on relationship delete - fix tests
This commit is contained in:
@@ -98,6 +98,7 @@ describe('EditRelationshipListComponent', () => {
|
|||||||
relationshipService = jasmine.createSpyObj('relationshipService',
|
relationshipService = jasmine.createSpyObj('relationshipService',
|
||||||
{
|
{
|
||||||
getRelatedItemsByLabel: observableOf(new RemoteData(false, false, true, null, new PaginatedList(new PageInfo(), [author1, author2]))),
|
getRelatedItemsByLabel: observableOf(new RemoteData(false, false, true, null, new PaginatedList(new PageInfo(), [author1, author2]))),
|
||||||
|
getItemRelationshipsByLabel: observableOf(new RemoteData(false, false, true, null, new PaginatedList(new PageInfo(), relationships))),
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@@ -11,11 +11,15 @@ import { Item } from '../../../../core/shared/item.model';
|
|||||||
import { PaginatedList } from '../../../../core/data/paginated-list';
|
import { PaginatedList } from '../../../../core/data/paginated-list';
|
||||||
import { PageInfo } from '../../../../core/shared/page-info.model';
|
import { PageInfo } from '../../../../core/shared/page-info.model';
|
||||||
import { FieldChangeType } from '../../../../core/data/object-updates/object-updates.actions';
|
import { FieldChangeType } from '../../../../core/data/object-updates/object-updates.actions';
|
||||||
|
import {NgbModal} from "@ng-bootstrap/ng-bootstrap";
|
||||||
|
import {Store} from "@ngrx/store";
|
||||||
|
import {CoreState} from "../../../../core/core.reducers";
|
||||||
|
|
||||||
let objectUpdatesService: ObjectUpdatesService;
|
let objectUpdatesService;
|
||||||
const url = 'http://test-url.com/test-url';
|
const url = 'http://test-url.com/test-url';
|
||||||
|
|
||||||
let item;
|
let item;
|
||||||
|
let relatedItem;
|
||||||
let author1;
|
let author1;
|
||||||
let author2;
|
let author2;
|
||||||
let fieldUpdate1;
|
let fieldUpdate1;
|
||||||
@@ -37,6 +41,17 @@ describe('EditRelationshipComponent', () => {
|
|||||||
rightwardType: 'isPublicationOfAuthor'
|
rightwardType: 'isPublicationOfAuthor'
|
||||||
});
|
});
|
||||||
|
|
||||||
|
item = Object.assign(new Item(), {
|
||||||
|
self: 'fake-item-url/publication',
|
||||||
|
id: 'publication',
|
||||||
|
uuid: 'publication',
|
||||||
|
relationships: observableOf(new RemoteData(false, false, true, undefined, new PaginatedList(new PageInfo(), relationships)))
|
||||||
|
});
|
||||||
|
|
||||||
|
relatedItem = Object.assign(new Item(), {
|
||||||
|
uuid: 'related item id',
|
||||||
|
});
|
||||||
|
|
||||||
relationships = [
|
relationships = [
|
||||||
Object.assign(new Relationship(), {
|
Object.assign(new Relationship(), {
|
||||||
self: url + '/2',
|
self: url + '/2',
|
||||||
@@ -44,7 +59,9 @@ describe('EditRelationshipComponent', () => {
|
|||||||
uuid: '2',
|
uuid: '2',
|
||||||
leftId: 'author1',
|
leftId: 'author1',
|
||||||
rightId: 'publication',
|
rightId: 'publication',
|
||||||
relationshipType: observableOf(new RemoteData(false, false, true, undefined, relationshipType))
|
relationshipType: observableOf(new RemoteData(false, false, true, undefined, relationshipType)),
|
||||||
|
leftItem: observableOf(new RemoteData(false, false, true, undefined, relatedItem)),
|
||||||
|
rightItem: observableOf(new RemoteData(false, false, true, undefined, item)),
|
||||||
}),
|
}),
|
||||||
Object.assign(new Relationship(), {
|
Object.assign(new Relationship(), {
|
||||||
self: url + '/3',
|
self: url + '/3',
|
||||||
@@ -56,13 +73,6 @@ describe('EditRelationshipComponent', () => {
|
|||||||
})
|
})
|
||||||
];
|
];
|
||||||
|
|
||||||
item = Object.assign(new Item(), {
|
|
||||||
self: 'fake-item-url/publication',
|
|
||||||
id: 'publication',
|
|
||||||
uuid: 'publication',
|
|
||||||
relationships: observableOf(new RemoteData(false, false, true, undefined, new PaginatedList(new PageInfo(), relationships)))
|
|
||||||
});
|
|
||||||
|
|
||||||
author1 = Object.assign(new Item(), {
|
author1 = Object.assign(new Item(), {
|
||||||
id: 'author1',
|
id: 'author1',
|
||||||
uuid: 'author1'
|
uuid: 'author1'
|
||||||
@@ -73,31 +83,34 @@ describe('EditRelationshipComponent', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
fieldUpdate1 = {
|
fieldUpdate1 = {
|
||||||
field: author1,
|
field: relationships[0],
|
||||||
changeType: undefined
|
changeType: undefined
|
||||||
};
|
};
|
||||||
fieldUpdate2 = {
|
fieldUpdate2 = {
|
||||||
field: author2,
|
field: relationships[1],
|
||||||
changeType: FieldChangeType.REMOVE
|
changeType: FieldChangeType.REMOVE
|
||||||
};
|
};
|
||||||
|
|
||||||
objectUpdatesService = jasmine.createSpyObj('objectUpdatesService',
|
const itemSelection = {};
|
||||||
{
|
itemSelection[relatedItem.uuid] = false;
|
||||||
saveChangeFieldUpdate: {},
|
itemSelection[item.uuid] = true;
|
||||||
saveRemoveFieldUpdate: {},
|
|
||||||
setEditableFieldUpdate: {},
|
const store = new Store<CoreState>(undefined, undefined, undefined);
|
||||||
setValidFieldUpdate: {},
|
|
||||||
removeSingleFieldUpdate: {},
|
objectUpdatesService = new ObjectUpdatesService(store);
|
||||||
isEditable: observableOf(false), // should always return something --> its in ngOnInit
|
|
||||||
isValid: observableOf(true) // should always return something --> its in ngOnInit
|
spyOn(objectUpdatesService, 'isSelectedVirtualMetadata').and.callFake((a, b, uuid) => observableOf(itemSelection[uuid]));
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
TestBed.configureTestingModule({
|
TestBed.configureTestingModule({
|
||||||
imports: [TranslateModule.forRoot()],
|
imports: [TranslateModule.forRoot()],
|
||||||
declarations: [EditRelationshipComponent],
|
declarations: [EditRelationshipComponent],
|
||||||
providers: [
|
providers: [
|
||||||
{ provide: ObjectUpdatesService, useValue: objectUpdatesService }
|
{ provide: ObjectUpdatesService, useValue: objectUpdatesService },
|
||||||
|
{ provide: NgbModal, useValue: {
|
||||||
|
open: () => {/*comment*/
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
], schemas: [
|
], schemas: [
|
||||||
NO_ERRORS_SCHEMA
|
NO_ERRORS_SCHEMA
|
||||||
]
|
]
|
||||||
@@ -113,6 +126,7 @@ describe('EditRelationshipComponent', () => {
|
|||||||
comp.url = url;
|
comp.url = url;
|
||||||
comp.fieldUpdate = fieldUpdate1;
|
comp.fieldUpdate = fieldUpdate1;
|
||||||
comp.editItem = item;
|
comp.editItem = item;
|
||||||
|
comp.relatedItem$ = observableOf(relatedItem);
|
||||||
|
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
});
|
});
|
||||||
@@ -157,21 +171,34 @@ describe('EditRelationshipComponent', () => {
|
|||||||
|
|
||||||
describe('remove', () => {
|
describe('remove', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
|
spyOn(comp, 'closeVirtualMetadataModal');
|
||||||
|
spyOn(objectUpdatesService, 'saveRemoveFieldUpdate');
|
||||||
|
comp.ngOnChanges();
|
||||||
comp.remove();
|
comp.remove();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should call saveRemoveFieldUpdate with the correct arguments', () => {
|
it('should close the virtual metadata modal and call saveRemoveFieldUpdate with the correct arguments', () => {
|
||||||
expect(objectUpdatesService.saveRemoveFieldUpdate).toHaveBeenCalledWith(url, item);
|
expect(comp.closeVirtualMetadataModal).toHaveBeenCalled();
|
||||||
|
expect(objectUpdatesService.saveRemoveFieldUpdate).toHaveBeenCalledWith(url, Object.assign({}, fieldUpdate1.field, {
|
||||||
|
keepLeftVirtualMetadata: false,
|
||||||
|
keepRightVirtualMetadata: true,
|
||||||
|
}));
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('undo', () => {
|
describe('undo', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
|
spyOn(objectUpdatesService, 'removeSingleFieldUpdate');
|
||||||
comp.undo();
|
comp.undo();
|
||||||
|
comp.ngOnChanges();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should call removeSingleFieldUpdate with the correct arguments', () => {
|
it('should call removeSingleFieldUpdate with the correct arguments', () => {
|
||||||
expect(objectUpdatesService.removeSingleFieldUpdate).toHaveBeenCalledWith(url, item.uuid);
|
|
||||||
|
fixture.whenStable().then(() => {
|
||||||
|
expect(objectUpdatesService.removeSingleFieldUpdate).toHaveBeenCalledWith(url, fieldUpdate1[0]);
|
||||||
|
})
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@@ -109,11 +109,11 @@ describe('RelationshipService', () => {
|
|||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
spyOn(service, 'findById').and.returnValue(getRemotedataObservable(relationship1));
|
spyOn(service, 'findById').and.returnValue(getRemotedataObservable(relationship1));
|
||||||
spyOn(objectCache, 'remove');
|
spyOn(objectCache, 'remove');
|
||||||
service.deleteRelationship(relationships[0].uuid, 'none').subscribe();
|
service.deleteRelationship(relationships[0].uuid, 'right').subscribe();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should send a DeleteRequest', () => {
|
it('should send a DeleteRequest', () => {
|
||||||
const expected = new DeleteRequest(requestService.generateRequestId(), relationshipsEndpointURL + '/' + relationship1.uuid);
|
const expected = new DeleteRequest(requestService.generateRequestId(), relationshipsEndpointURL + '/' + relationship1.uuid + '?copyVirtualMetadata=right');
|
||||||
expect(requestService.configure).toHaveBeenCalledWith(expected);
|
expect(requestService.configure).toHaveBeenCalledWith(expected);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user