Add gui tests for deleting entries from the recycle bin.

This commit is contained in:
Felix Geyer 2013-10-08 22:36:27 +02:00
parent a68a86f19b
commit f7dd63a126
2 changed files with 47 additions and 0 deletions

View File

@ -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<QToolBar*>("toolBar");
QAction* entryDeleteAction = m_mainWindow->findChild<QAction*>("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)

View File

@ -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;