From b08d2d45b750b70730c15c1de142ce4bf9b20af3 Mon Sep 17 00:00:00 2001 From: Florian Geyer Date: Wed, 16 May 2012 09:56:40 +0200 Subject: [PATCH] Add gui test for search. --- tests/gui/TestGui.cpp | 60 +++++++++++++++++++++++++++++++++++++++++++ tests/gui/TestGui.h | 1 + 2 files changed, 61 insertions(+) diff --git a/tests/gui/TestGui.cpp b/tests/gui/TestGui.cpp index b4f1e7bd3..680e51311 100644 --- a/tests/gui/TestGui.cpp +++ b/tests/gui/TestGui.cpp @@ -150,6 +150,66 @@ void TestGui::testAddEntry() QCOMPARE(entry->historyItems().size(), 1); } +void TestGui::testSearch() +{ + DatabaseTabWidget* tabWidget = m_mainWindow->findChild("tabWidget"); + DatabaseWidget* dbWidget = tabWidget->currentDatabaseWidget(); + + EntryView* entryView = dbWidget->findChild("entryView"); + QLineEdit* searchEdit = dbWidget->findChild("searchEdit"); + QPushButton* clearSearch = dbWidget->findChild("clearSearchButton"); + + QTest::keyClicks(searchEdit, "ZZZ"); + QTest::keyClick(searchEdit, Qt::Key_Return); + QTest::qWait(20); + + QCOMPARE(entryView->model()->rowCount(), 0); + + QTest::mouseClick(clearSearch, Qt::LeftButton); + QTest::keyClicks(searchEdit, "some"); + QTest::keyClick(searchEdit, Qt::Key_Return); + QTest::qWait(20); + + QCOMPARE(entryView->model()->rowCount(), 2); + + QToolBar* toolBar = m_mainWindow->findChild("toolBar"); + + QModelIndex item = entryView->model()->index(0, 1); + QRect itemRect = entryView->visualRect(item); + QTest::mouseClick(entryView->viewport(), Qt::LeftButton, Qt::NoModifier, itemRect.center()); + QAction* entryEditAction = m_mainWindow->findChild("actionEntryEdit"); + QVERIFY(entryEditAction->isEnabled()); + QWidget* entryEditWidget = toolBar->widgetForAction(entryEditAction); + QVERIFY(entryEditWidget->isVisible()); + QVERIFY(entryEditWidget->isEnabled()); + QTest::mouseClick(entryEditWidget, Qt::LeftButton); + QTest::qWait(20); + + QCOMPARE(dbWidget->currentMode(), DatabaseWidget::EditMode); + + EditEntryWidget* editEntryWidget = dbWidget->findChild("editEntryWidget"); + QDialogButtonBox* editEntryWidgetButtonBox = editEntryWidget->findChild("buttonBox"); + QTest::mouseClick(editEntryWidgetButtonBox->button(QDialogButtonBox::Ok), Qt::LeftButton); + QTest::qWait(20); + + QCOMPARE(dbWidget->currentMode(), DatabaseWidget::ViewMode); + + QModelIndex item2 = entryView->model()->index(1, 0); + QRect itemRect2 = entryView->visualRect(item2); + QTest::mouseClick(entryView->viewport(), Qt::LeftButton, Qt::NoModifier, itemRect2.center()); + QAction* entryDeleteAction = m_mainWindow->findChild("actionEntryDelete"); + + QWidget* entryDeleteWidget = toolBar->widgetForAction(entryDeleteAction); + QVERIFY(entryDeleteWidget->isVisible()); + QVERIFY(entryDeleteWidget->isEnabled()); + + QTest::mouseClick(entryDeleteWidget, Qt::LeftButton); + QTest::qWait(20); + + QCOMPARE(entryView->model()->rowCount(), 1); + +} + void TestGui::cleanupTestCase() { delete m_mainWindow; diff --git a/tests/gui/TestGui.h b/tests/gui/TestGui.h index aedaebf88..b210b1a5a 100644 --- a/tests/gui/TestGui.h +++ b/tests/gui/TestGui.h @@ -32,6 +32,7 @@ private Q_SLOTS: void testTabs(); void testEditEntry(); void testAddEntry(); + void testSearch(); void cleanupTestCase(); private: