Skip to content
Permalink
Browse files
feat(list): add support for deleting child node comments (DEV-965) (#758
)

* feat(list): add support for deleting child node comments

* test(list): uncomment an assertion
  • Loading branch information
mdelez committed Jun 1, 2022
1 parent 4d9b747 commit 50c2d17b5ec4c2546c1063a4488ec50b7dc6d36d
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 9 deletions.

Some generated files are not rendered by default. Learn more.

@@ -34,7 +34,7 @@
"@angular/platform-browser-dynamic": "^13.2.6",
"@angular/router": "^13.2.6",
"@ckeditor/ckeditor5-angular": "^2.0.2",
"@dasch-swiss/dsp-js": "^7.3.0",
"@dasch-swiss/dsp-js": "^7.4.0",
"@datadog/browser-rum": "^3.11.0",
"@ngx-translate/core": "^13.0.0",
"@ngx-translate/http-loader": "6.0.0",
@@ -77,7 +77,7 @@ describe('EditListItemComponent', () => {

const listsEndpointSpyObj = {
admin: {
listsEndpoint: jasmine.createSpyObj('listsEndpoint', ['getListNodeInfo', 'updateChildNode', 'createChildNode'])
listsEndpoint: jasmine.createSpyObj('listsEndpoint', ['getListNodeInfo', 'updateChildNode', 'createChildNode', 'deleteChildComments'])
}
};

@@ -213,6 +213,40 @@ describe('EditListItemComponent', () => {
expect(dspConnSpy.admin.listsEndpoint.updateChildNode).toHaveBeenCalledTimes(1);
expect(dspConnSpy.admin.listsEndpoint.updateChildNode).toHaveBeenCalledWith(updateChildNodeRequest);
});

it('should delete the child node comments', () => {
const dspConnSpy = TestBed.inject(DspApiConnectionToken);

testHostComponent.editListItem.handleData([{ 'value': 'Tree list node 01', 'language': 'en' }, { 'value': 'Baumlistenknoten 01', 'language': 'de' }], 'labels');
testHostComponent.editListItem.handleData([], 'comments');

(dspConnSpy.admin.listsEndpoint as jasmine.SpyObj<ListsEndpointAdmin>).updateChildNode.and.callFake(
() => {
const response = new ListNodeInfoResponse();
response.nodeinfo.id = 'http://rdfh.ch/lists/0001/otherTreeList01';
response.nodeinfo.labels = [{ 'value': 'Tree list node 01', 'language': 'en' }, { 'value': 'Baumlistenknoten 01', 'language': 'de' }];
response.nodeinfo.comments = [];

expect(testHostComponent.editListItem.labels).toEqual(response.nodeinfo.labels);
expect(testHostComponent.editListItem.comments.length).toEqual(0);

return of(ApiResponseData.fromAjaxResponse({ response } as AjaxResponse));
}
);

const updateChildNodeRequest: UpdateChildNodeRequest = new UpdateChildNodeRequest();
updateChildNodeRequest.projectIri = testHostComponent.editListItem.projectIri;
updateChildNodeRequest.listIri = testHostComponent.editListItem.iri;
updateChildNodeRequest.labels = testHostComponent.editListItem.labels;
updateChildNodeRequest.comments = undefined;

testHostComponent.editListItem.updateChildNode();
expect(dspConnSpy.admin.listsEndpoint.updateChildNode).toHaveBeenCalledTimes(1);
expect(dspConnSpy.admin.listsEndpoint.updateChildNode).toHaveBeenCalledWith(updateChildNodeRequest);

expect(dspConnSpy.admin.listsEndpoint.deleteChildComments).toHaveBeenCalledTimes(1);
expect(dspConnSpy.admin.listsEndpoint.deleteChildComments).toHaveBeenCalledWith(updateChildNodeRequest.listIri);
});
});

describe('insert list child node', () => {
@@ -4,6 +4,7 @@ import {
ApiResponseError,
ChildNodeInfoResponse,
CreateChildNodeRequest,
DeleteChildNodeCommentsResponse,
KnoraApiConnection,
List,
ListNodeInfo,
@@ -163,6 +164,12 @@ export class EditListItemComponent implements OnInit {

this._dspApiConnection.admin.listsEndpoint.updateChildNode(childNodeUpdateData).subscribe(
(response: ApiResponseData<ChildNodeInfoResponse>) => {
if (!childNodeUpdateData.comments) {
this._dspApiConnection.admin.listsEndpoint.deleteChildComments(childNodeUpdateData.listIri).subscribe(
(res: ApiResponseData<DeleteChildNodeCommentsResponse>) => {},
(error: ApiResponseError) => this._errorHandler.showMessage(error)
);
}
this.loading = false;
this.closeDialog.emit(response.body.nodeinfo);
},

0 comments on commit 50c2d17

Please sign in to comment.