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', () => { ...@@ -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'; ...@@ -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', () => { ...@@ -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', () => { ...@@ -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', () => { ...@@ -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,32 +83,35 @@ describe('EditRelationshipComponent', () => { ...@@ -73,32 +83,35 @@ 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 },
], schemas: [ { provide: NgbModal, useValue: {
open: () => {/*comment*/
}
},
},
], schemas: [
NO_ERRORS_SCHEMA NO_ERRORS_SCHEMA
] ]
}).compileComponents(); }).compileComponents();
...@@ -113,6 +126,7 @@ describe('EditRelationshipComponent', () => { ...@@ -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', () => { ...@@ -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', () => { ...@@ -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);
}); });
......
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