Skip to content
Snippets Groups Projects
Commit 038483c8 authored by Samuel's avatar Samuel
Browse files

taskid 66074 Keep virtual metadata on relationship delete - fix tests

parent 891415da
Branches
Tags
No related merge requests found
......@@ -98,6 +98,7 @@ describe('EditRelationshipListComponent', () => {
relationshipService = jasmine.createSpyObj('relationshipService',
{
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 { PageInfo } from '../../../../core/shared/page-info.model';
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';
let item;
let relatedItem;
let author1;
let author2;
let fieldUpdate1;
......@@ -37,6 +41,17 @@ describe('EditRelationshipComponent', () => {
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 = [
Object.assign(new Relationship(), {
self: url + '/2',
......@@ -44,7 +59,9 @@ describe('EditRelationshipComponent', () => {
uuid: '2',
leftId: 'author1',
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(), {
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(), {
id: 'author1',
uuid: 'author1'
......@@ -73,32 +83,35 @@ describe('EditRelationshipComponent', () => {
});
fieldUpdate1 = {
field: author1,
field: relationships[0],
changeType: undefined
};
fieldUpdate2 = {
field: author2,
field: relationships[1],
changeType: FieldChangeType.REMOVE
};
objectUpdatesService = jasmine.createSpyObj('objectUpdatesService',
{
saveChangeFieldUpdate: {},
saveRemoveFieldUpdate: {},
setEditableFieldUpdate: {},
setValidFieldUpdate: {},
removeSingleFieldUpdate: {},
isEditable: observableOf(false), // should always return something --> its in ngOnInit
isValid: observableOf(true) // should always return something --> its in ngOnInit
}
);
const itemSelection = {};
itemSelection[relatedItem.uuid] = false;
itemSelection[item.uuid] = true;
const store = new Store<CoreState>(undefined, undefined, undefined);
objectUpdatesService = new ObjectUpdatesService(store);
spyOn(objectUpdatesService, 'isSelectedVirtualMetadata').and.callFake((a, b, uuid) => observableOf(itemSelection[uuid]));
TestBed.configureTestingModule({
imports: [TranslateModule.forRoot()],
declarations: [EditRelationshipComponent],
providers: [
{ provide: ObjectUpdatesService, useValue: objectUpdatesService }
], schemas: [
{ provide: ObjectUpdatesService, useValue: objectUpdatesService },
{ provide: NgbModal, useValue: {
open: () => {/*comment*/
}
},
},
], schemas: [
NO_ERRORS_SCHEMA
]
}).compileComponents();
......@@ -113,6 +126,7 @@ describe('EditRelationshipComponent', () => {
comp.url = url;
comp.fieldUpdate = fieldUpdate1;
comp.editItem = item;
comp.relatedItem$ = observableOf(relatedItem);
fixture.detectChanges();
});
......@@ -157,21 +171,34 @@ describe('EditRelationshipComponent', () => {
describe('remove', () => {
beforeEach(() => {
spyOn(comp, 'closeVirtualMetadataModal');
spyOn(objectUpdatesService, 'saveRemoveFieldUpdate');
comp.ngOnChanges();
comp.remove();
});
it('should call saveRemoveFieldUpdate with the correct arguments', () => {
expect(objectUpdatesService.saveRemoveFieldUpdate).toHaveBeenCalledWith(url, item);
it('should close the virtual metadata modal and call saveRemoveFieldUpdate with the correct arguments', () => {
expect(comp.closeVirtualMetadataModal).toHaveBeenCalled();
expect(objectUpdatesService.saveRemoveFieldUpdate).toHaveBeenCalledWith(url, Object.assign({}, fieldUpdate1.field, {
keepLeftVirtualMetadata: false,
keepRightVirtualMetadata: true,
}));
});
});
describe('undo', () => {
beforeEach(() => {
spyOn(objectUpdatesService, 'removeSingleFieldUpdate');
comp.undo();
comp.ngOnChanges();
});
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(() => {
spyOn(service, 'findById').and.returnValue(getRemotedataObservable(relationship1));
spyOn(objectCache, 'remove');
service.deleteRelationship(relationships[0].uuid, 'none').subscribe();
service.deleteRelationship(relationships[0].uuid, 'right').subscribe();
});
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);
});
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment