From 7dfcad6f8f6ce4e1370db5ebe79178e242e90e98 Mon Sep 17 00:00:00 2001 From: Nick Spain Date: Sat, 17 Feb 2018 15:30:24 +1100 Subject: [PATCH] Write regression test for #1447 --- tests/gui/TestGui.cpp | 53 +++++++++++++++++++++++++++++++++++++++++++ tests/gui/TestGui.h | 1 + 2 files changed, 54 insertions(+) diff --git a/tests/gui/TestGui.cpp b/tests/gui/TestGui.cpp index cf7b969e1..b56589315 100644 --- a/tests/gui/TestGui.cpp +++ b/tests/gui/TestGui.cpp @@ -61,6 +61,7 @@ #include "gui/entry/EntryView.h" #include "gui/group/GroupModel.h" #include "gui/group/GroupView.h" +#include "gui/group/EditGroupWidget.h" #include "keys/PasswordKey.h" void TestGui::initTestCase() @@ -342,6 +343,58 @@ void TestGui::testEditEntry() QTRY_COMPARE(m_tabWidget->tabText(m_tabWidget->currentIndex()), QString("%1*").arg(m_dbFileName)); } +void TestGui::testSearchEditEntry() +{ + // Regression test for Issue #1447 -- Uses example from issue description + + // Find buttons for group creation + EditGroupWidget* editGroupWidget = m_dbWidget->findChild("editGroupWidget"); + QLineEdit* nameEdit = editGroupWidget->findChild("nameEdit"); + QDialogButtonBox* editGroupWidgetButtonBox = editGroupWidget->findChild("buttonBox"); + + // Add groups "Good" and "Bad" + m_dbWidget->createGroup(); + QTest::keyClicks(nameEdit, "Good"); + QTest::mouseClick(editGroupWidgetButtonBox->button(QDialogButtonBox::Ok), Qt::LeftButton); + m_dbWidget->groupView()->setCurrentGroup(m_db->rootGroup()); // Makes "Good" and "Bad" on the same level + m_dbWidget->createGroup(); + QTest::keyClicks(nameEdit, "Bad"); + QTest::mouseClick(editGroupWidgetButtonBox->button(QDialogButtonBox::Ok), Qt::LeftButton); + m_dbWidget->groupView()->setCurrentGroup(m_db->rootGroup()); + + // Find buttons for entry creation + QToolBar* toolBar = m_mainWindow->findChild("toolBar"); + QWidget* entryNewWidget = toolBar->widgetForAction(m_mainWindow->findChild("actionEntryNew")); + EditEntryWidget* editEntryWidget = m_dbWidget->findChild("editEntryWidget"); + QLineEdit* titleEdit = editEntryWidget->findChild("titleEdit"); + QDialogButtonBox* editEntryWidgetButtonBox = editEntryWidget->findChild("buttonBox"); + + // Create "Doggy" in "Good" + Group* goodGroup = m_dbWidget->currentGroup()->findChildByName(QString("Good")); + m_dbWidget->groupView()->setCurrentGroup(goodGroup); + QTest::mouseClick(entryNewWidget, Qt::LeftButton); + QTest::keyClicks(titleEdit, "Doggy"); + QTest::mouseClick(editEntryWidgetButtonBox->button(QDialogButtonBox::Ok), Qt::LeftButton); + // Select "Bad" group in groupView + Group* badGroup = m_db->rootGroup()->findChildByName(QString("Bad")); + m_dbWidget->groupView()->setCurrentGroup(badGroup); + + // Search for "Doggy" entry + SearchWidget* searchWidget = toolBar->findChild("SearchWidget"); + QLineEdit* searchTextEdit = searchWidget->findChild("searchEdit"); + QTest::mouseClick(searchTextEdit, Qt::LeftButton); + QTest::keyClicks(searchTextEdit, "Doggy"); + QTRY_VERIFY(m_dbWidget->isInSearchMode()); + + // Goto "Doggy"'s edit view + QTest::keyClick(searchTextEdit, Qt::Key_Return); + QCOMPARE(m_dbWidget->currentMode(), DatabaseWidget::EditMode); + + // Check the path in header is "parent-group > entry" + QCOMPARE(m_dbWidget->findChild("editEntryWidget")->findChild("headerLabel")->text(), + QString("Good > Doggy > Edit entry")); +} + void TestGui::testAddEntry() { QToolBar* toolBar = m_mainWindow->findChild("toolBar"); diff --git a/tests/gui/TestGui.h b/tests/gui/TestGui.h index b8d3ce1fc..0b403731d 100644 --- a/tests/gui/TestGui.h +++ b/tests/gui/TestGui.h @@ -46,6 +46,7 @@ private slots: void testAutoreloadDatabase(); void testTabs(); void testEditEntry(); + void testSearchEditEntry(); void testAddEntry(); void testPasswordEntryEntropy(); void testDicewareEntryEntropy();