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

fix(Lists): Shift the second of two children after deletion of the first (DSP-1353) #1820

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
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
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