Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(list): add support for deleting child node comments (DEV-965) #758

Merged
merged 2 commits into from Jun 1, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -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",
Expand Down
Expand Up @@ -77,7 +77,7 @@ describe('EditListItemComponent', () => {

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

Expand Down Expand Up @@ -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', () => {
Expand Down
Expand Up @@ -4,6 +4,7 @@ import {
ApiResponseError,
ChildNodeInfoResponse,
CreateChildNodeRequest,
DeleteChildNodeCommentsResponse,
KnoraApiConnection,
List,
ListNodeInfo,
Expand Down Expand Up @@ -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);
},
Expand Down