Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix(Lists): fix bug in shifting the second of two children after dele…
…tion of the first one. (#1820)
  • Loading branch information
SepidehAlassi committed Feb 16, 2021
1 parent 01cc8b1 commit d92bb01
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
15 changes: 14 additions & 1 deletion test_data/all_data/anything-data.ttl
Expand Up @@ -1892,7 +1892,20 @@
knora-base:listNodeName "List014";
knora-base:hasRootNode <http://rdfh.ch/lists/0001/notUsedList>;
knora-base:listNodePosition 3;
rdfs:label "List014"@en .
rdfs:label "List014"@en ;
knora-base:hasSubListNode <http://rdfh.ch/lists/0001/notUsedList0141>, <http://rdfh.ch/lists/0001/notUsedList0142>.

<http://rdfh.ch/lists/0001/notUsedList0141> a knora-base:ListNode;
knora-base:listNodeName "first child of node 014";
knora-base:hasRootNode <http://rdfh.ch/lists/0001/notUsedList>;
knora-base:listNodePosition 0;
rdfs:label "first child of node 014"@en .

<http://rdfh.ch/lists/0001/notUsedList0142> a knora-base:ListNode;
knora-base:listNodeName "second child of node 014";
knora-base:hasRootNode <http://rdfh.ch/lists/0001/notUsedList>;
knora-base:listNodePosition 0;
rdfs:label "second child of node 014"@en .

<http://rdfh.ch/lists/0001/notUsedList015> a knora-base:ListNode;
knora-base:listNodeName "List015";
Expand Down
Expand Up @@ -1794,7 +1794,7 @@ class ListsResponderADM(responderData: ResponderData) extends Responder(responde
}

// shift the siblings that were positioned after the deleted node, one place to left.
updatedChildren <- if (remainingChildren.size > 1) {
updatedChildren <- if (remainingChildren.size > 0) {
for {
shiftedChildren <- shiftNodes(
startPos = positionOfDeletedNode + 1,
Expand Down
Expand Up @@ -97,6 +97,21 @@ class DeleteListItemsRouteADME2ESpec
response.status should be(StatusCodes.Forbidden)
}

"delete first of two child node and remaining child" in {
val encodedNodeUrl = java.net.URLEncoder.encode("http://rdfh.ch/lists/0001/notUsedList0141", "utf-8")
val request = Delete(baseApiUrl + s"/admin/lists/" + encodedNodeUrl) ~> addCredentials(
BasicHttpCredentials(anythingAdminUserCreds.user.email, anythingAdminUserCreds.password))
val response: HttpResponse = singleAwaitingRequest(request)
response.status should be(StatusCodes.OK)
val node = AkkaHttpUtils.httpResponseToJson(response).fields("node").convertTo[ListNodeADM]
node.getNodeId should be("http://rdfh.ch/lists/0001/notUsedList014")
val children = node.getChildren
children.size should be(1)
// last child must be shifted one place to left
val leftChild = children.head
leftChild.id should be("http://rdfh.ch/lists/0001/notUsedList0142")
leftChild.position should be(0)
}
"delete a middle node and shift its siblings" in {
val encodedNodeUrl = java.net.URLEncoder.encode("http://rdfh.ch/lists/0001/notUsedList02", "utf-8")
val request = Delete(baseApiUrl + s"/admin/lists/" + encodedNodeUrl) ~> addCredentials(
Expand Down

0 comments on commit d92bb01

Please sign in to comment.