Skip to content

Commit 7197765

Browse files
committed
Add test for deep nested hierarchy preservation in undo/redo
Tests that when a grandparent folder with nested children (grandparent→ parent→5 children) is deleted and undone, the entire hierarchy is correctly restored with all children nested under their parent (not appearing at root). This validates the fix for the issue where children would incorrectly appear at root level after undo because: 1. Items were restored in wrong order (children before parents) 2. Grandchildren's parentID references weren't updated when children got new IDs 3. skipRestore check used modified state instead of original state The test creates a 3-level hierarchy, deletes the root, undos, and verifies all children are properly nested (not at root level). Adds 6 tests (one per item type) to Category 9 (State Consistency)
1 parent a0ee5cc commit 7197765

File tree

1 file changed

+68
-1
lines changed

1 file changed

+68
-1
lines changed

test/dlgTriggerEditorUndoRedoTest.cpp

Lines changed: 68 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1458,7 +1458,7 @@ void runUndoRedoTestSuite(dlgTriggerEditor* editor)
14581458
}
14591459

14601460
// ====================================================================================
1461-
// CATEGORY 9: State Consistency Tests (18 tests)
1461+
// CATEGORY 9: State Consistency Tests (24 tests)
14621462
// ====================================================================================
14631463
qDebug() << "\n=== CATEGORY 9: State Consistency Tests ===";
14641464

@@ -1525,6 +1525,73 @@ void runUndoRedoTestSuite(dlgTriggerEditor* editor)
15251525
}
15261526
}
15271527

1528+
// Test: Deep nested hierarchy preserved after undo (grandparent→parent→children)
1529+
{
1530+
// Create a 3-level nested structure with multiple children at level 3
1531+
itemType.addFolder(); // Grandparent
1532+
QTreeWidgetItem* grandparent = itemType.baseItem->child(0);
1533+
1534+
if (grandparent) {
1535+
itemType.treeWidget->setCurrentItem(grandparent);
1536+
itemType.addFolder(); // Parent
1537+
QTreeWidgetItem* parent = grandparent->child(0);
1538+
1539+
if (parent) {
1540+
// Add 5 children to the parent
1541+
itemType.treeWidget->setCurrentItem(parent);
1542+
for (int i = 0; i < 5; i++) {
1543+
itemType.addItem();
1544+
}
1545+
1546+
int childrenCount = parent->childCount();
1547+
1548+
// Delete the grandparent (should delete entire tree)
1549+
itemType.treeWidget->setCurrentItem(grandparent);
1550+
int baseCountBefore = itemType.baseItem->childCount();
1551+
editor->slot_deleteItemOrGroup();
1552+
1553+
if (itemType.baseItem->childCount() < baseCountBefore) {
1554+
// Undo to restore the entire hierarchy
1555+
editor->mpUndoStack->undo();
1556+
1557+
// Verify hierarchy is fully restored
1558+
QTreeWidgetItem* restoredGP = itemType.baseItem->child(0);
1559+
bool hierarchyPreserved = false;
1560+
1561+
if (restoredGP && restoredGP->childCount() == 1) {
1562+
QTreeWidgetItem* restoredP = restoredGP->child(0);
1563+
if (restoredP && restoredP->childCount() == childrenCount) {
1564+
// Verify all children are under parent (not at root)
1565+
bool allChildrenNested = true;
1566+
for (int i = 0; i < childrenCount; i++) {
1567+
QTreeWidgetItem* child = restoredP->child(i);
1568+
if (!child) {
1569+
allChildrenNested = false;
1570+
break;
1571+
}
1572+
}
1573+
hierarchyPreserved = allChildrenNested;
1574+
}
1575+
}
1576+
1577+
if (hierarchyPreserved) {
1578+
TEST_PASS(itemType.name + ": Deep nested hierarchy preserved after undo");
1579+
} else {
1580+
TEST_FAIL(itemType.name + ": Deep nested hierarchy not preserved - children may be at root level");
1581+
}
1582+
} else {
1583+
TEST_FAIL(itemType.name + ": Grandparent deletion failed");
1584+
}
1585+
} else {
1586+
TEST_FAIL(itemType.name + ": Failed to create parent folder");
1587+
}
1588+
} else {
1589+
TEST_FAIL(itemType.name + ": Failed to create grandparent folder");
1590+
}
1591+
1592+
CLEANUP_ALL(itemType);
1593+
}
1594+
15281595
// Test: Stack command count consistency
15291596
{
15301597
int countBefore = editor->mpUndoStack->count();

0 commit comments

Comments
 (0)