From bd1c0ff287fa3ce3f86b5813edb4c529a8c997fc Mon Sep 17 00:00:00 2001 From: Rahat <136263179+rahat2134@users.noreply.github.com> Date: Thu, 17 Apr 2025 13:47:43 +0530 Subject: [PATCH] Add layer tree tests for folder self movement checking (#2579) * Testing folder movement to self * changes * unnecessary code line removed --- .../document/document_message_handler.rs | 29 ++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/editor/src/messages/portfolio/document/document_message_handler.rs b/editor/src/messages/portfolio/document/document_message_handler.rs index b03787f6..f8f9339a 100644 --- a/editor/src/messages/portfolio/document/document_message_handler.rs +++ b/editor/src/messages/portfolio/document/document_message_handler.rs @@ -2813,7 +2813,6 @@ mod document_message_handler_tests { parent.children(document.metadata()).position(|child| child == layer) } - let layer_bottom = get_layer_by_bounds(&mut editor, 0.0, 0.0).await.unwrap(); let layer_middle = get_layer_by_bounds(&mut editor, 50.0, 50.0).await.unwrap(); let layer_top = get_layer_by_bounds(&mut editor, 100.0, 100.0).await.unwrap(); @@ -2832,4 +2831,32 @@ mod document_message_handler_tests { let new_index_middle = get_layer_index(&mut editor, layer_middle).await.unwrap(); assert!(new_index_middle < initial_index_middle, "Middle layer should have moved up"); } + #[tokio::test] + async fn test_move_folder_into_itself_doesnt_crash() { + let mut editor = EditorTestUtils::create(); + editor.new_document().await; + + // Creating a parent folder + editor.handle_message(DocumentMessage::CreateEmptyFolder).await; + let parent_folder = editor.active_document().metadata().all_layers().next().unwrap(); + + // Creating a child folder inside the parent folder + editor.handle_message(NodeGraphMessage::SelectedNodesSet { nodes: vec![parent_folder.to_node()] }).await; + editor.handle_message(DocumentMessage::CreateEmptyFolder).await; + let child_folder = editor.active_document().metadata().all_layers().next().unwrap(); + + // Attempt to move parent folder into child folder + editor.handle_message(NodeGraphMessage::SelectedNodesSet { nodes: vec![parent_folder.to_node()] }).await; + editor + .handle_message(DocumentMessage::MoveSelectedLayersTo { + parent: child_folder, + insert_index: 0, + }) + .await; + + // The operation completed without crashing + // Verifying application still functions by performing another operation + editor.handle_message(DocumentMessage::CreateEmptyFolder).await; + assert!(true, "Application didn't crash after folder move operation"); + } }