diff --git a/tests/gui/TestGui.cpp b/tests/gui/TestGui.cpp index 05ab9f7b9..9d44ac939 100644 --- a/tests/gui/TestGui.cpp +++ b/tests/gui/TestGui.cpp @@ -244,6 +244,43 @@ void TestGui::testSearch() QCOMPARE(entryView->model()->rowCount(), 1); } +void TestGui::testDeleteEntry() +{ + GroupView* groupView = m_dbWidget->groupView(); + EntryView* entryView = m_dbWidget->entryView(); + QToolBar* toolBar = m_mainWindow->findChild("toolBar"); + QAction* entryDeleteAction = m_mainWindow->findChild("actionEntryDelete"); + QWidget* entryDeleteWidget = toolBar->widgetForAction(entryDeleteAction); + QCOMPARE(groupView->currentGroup(), m_db->rootGroup()); + + QModelIndex rootGroupIndex = groupView->model()->index(0, 0); + clickIndex(groupView->model()->index(groupView->model()->rowCount(rootGroupIndex) - 1, 0, rootGroupIndex), + groupView, Qt::LeftButton); + QCOMPARE(groupView->currentGroup()->name(), m_db->metadata()->recycleBin()->name()); + + clickIndex(entryView->model()->index(0, 0), entryView, Qt::LeftButton); + MessageBox::setNextAnswer(QMessageBox::No); + QTest::mouseClick(entryDeleteWidget, Qt::LeftButton); + QCOMPARE(entryView->model()->rowCount(), 3); + QCOMPARE(m_db->metadata()->recycleBin()->entries().size(), 3); + + MessageBox::setNextAnswer(QMessageBox::Yes); + QTest::mouseClick(entryDeleteWidget, Qt::LeftButton); + QCOMPARE(entryView->model()->rowCount(), 2); + QCOMPARE(m_db->metadata()->recycleBin()->entries().size(), 2); + + clickIndex(entryView->model()->index(0, 0), entryView, Qt::LeftButton); + clickIndex(entryView->model()->index(1, 0), entryView, Qt::LeftButton, Qt::ControlModifier); + MessageBox::setNextAnswer(QMessageBox::Yes); + QTest::mouseClick(entryDeleteWidget, Qt::LeftButton); + QCOMPARE(entryView->model()->rowCount(), 0); + QCOMPARE(m_db->metadata()->recycleBin()->entries().size(), 0); + + clickIndex(groupView->model()->index(0, 0), + groupView, Qt::LeftButton); + QCOMPARE(groupView->currentGroup(), m_db->rootGroup()); +} + void TestGui::testCloneEntry() { EntryView* entryView = m_dbWidget->entryView(); @@ -440,4 +477,10 @@ void TestGui::dragAndDropGroup(const QModelIndex& sourceIndex, const QModelIndex QCOMPARE(group->parentGroup()->children().indexOf(group), expectedPos); } +void TestGui::clickIndex(const QModelIndex& index, QAbstractItemView* view, Qt::MouseButton button, + Qt::KeyboardModifiers stateKey) +{ + QTest::mouseClick(view->viewport(), button, stateKey, view->visualRect(index).center()); +} + QTEST_MAIN(TestGui) diff --git a/tests/gui/TestGui.h b/tests/gui/TestGui.h index 38e4505cc..84167f0da 100644 --- a/tests/gui/TestGui.h +++ b/tests/gui/TestGui.h @@ -24,6 +24,7 @@ class Database; class DatabaseTabWidget; class DatabaseWidget; +class QAbstractItemView; class MainWindow; class TestGui : public QObject @@ -37,6 +38,7 @@ private Q_SLOTS: void testEditEntry(); void testAddEntry(); void testSearch(); + void testDeleteEntry(); void testCloneEntry(); void testDragAndDropEntry(); void testDragAndDropGroup(); @@ -52,6 +54,8 @@ private: void triggerAction(const QString& name); void dragAndDropGroup(const QModelIndex& sourceIndex, const QModelIndex& targetIndex, int row, bool expectedResult, const QString& expectedParentName, int expectedPos); + void clickIndex(const QModelIndex& index, QAbstractItemView* view, Qt::MouseButton button, + Qt::KeyboardModifiers stateKey = 0); MainWindow* m_mainWindow; DatabaseTabWidget* m_tabWidget;