diff --git a/src/gui/MainWindow.cpp b/src/gui/MainWindow.cpp index 9ef9179a8..3f4547195 100644 --- a/src/gui/MainWindow.cpp +++ b/src/gui/MainWindow.cpp @@ -689,6 +689,7 @@ MainWindow::MainWindow() statusBar()->addPermanentWidget(m_progressBar); connect(clipboard(), SIGNAL(updateCountdown(int, QString)), this, SLOT(updateProgressBar(int, QString))); m_statusBarLabel = new QLabel(statusBar()); + m_statusBarLabel->setObjectName("statusBarLabel"); statusBar()->addPermanentWidget(m_statusBarLabel); restoreConfigState(); @@ -1352,6 +1353,7 @@ void MainWindow::databaseTabChanged(int tabIndex) } m_actionMultiplexer.setCurrentObject(m_ui->tabWidget->currentDatabaseWidget()); + updateEntryCountLabel(); } void MainWindow::closeEvent(QCloseEvent* event) diff --git a/tests/gui/TestGui.cpp b/tests/gui/TestGui.cpp index 330ec473c..1440cc8b5 100644 --- a/tests/gui/TestGui.cpp +++ b/tests/gui/TestGui.cpp @@ -91,6 +91,7 @@ void TestGui::initTestCase() m_mainWindow.reset(new MainWindow()); m_tabWidget = m_mainWindow->findChild("tabWidget"); + m_statusBarLabel = m_mainWindow->findChild("statusBarLabel"); m_mainWindow->show(); m_mainWindow->resize(1024, 768); } @@ -286,6 +287,10 @@ void TestGui::testCreateDatabase() triggerAction("actionDatabaseNew"); + QCOMPARE(m_tabWidget->count(), 2); + + checkStatusBarText("0 Ent"); + // there is a new empty db m_db = m_tabWidget->currentDatabaseWidget()->database(); QCOMPARE(m_db->rootGroup()->children().size(), 0); @@ -306,6 +311,15 @@ void TestGui::testCreateDatabase() compositeKey->addKey(fileKey); QCOMPARE(m_db->key()->rawKey(), compositeKey->rawKey()); + checkStatusBarText("0 Ent"); + + // Test the switching to other DB tab + m_tabWidget->setCurrentIndex(0); + checkStatusBarText("1 Ent"); + + m_tabWidget->setCurrentIndex(1); + checkStatusBarText("0 Ent"); + // close the new database MessageBox::setNextAnswer(MessageBox::No); triggerAction("actionDatabaseClose"); @@ -592,6 +606,9 @@ void TestGui::testAddEntry() auto* toolBar = m_mainWindow->findChild("toolBar"); auto* entryView = m_dbWidget->findChild("entryView"); + // Given the status bar label with initial number of entries. + checkStatusBarText("1 Ent"); + // Find the new entry action auto* entryNewAction = m_mainWindow->findChild("actionEntryNew"); QVERIFY(entryNewAction->isEnabled()); @@ -626,6 +643,9 @@ void TestGui::testAddEntry() m_db->updateCommonUsernames(); + // Then the status bar label should be updated with incremented number of entries. + checkStatusBarText("2 Ent"); + // Add entry "something 2" QTest::mouseClick(entryNewWidget, Qt::LeftButton); QTest::keyClicks(titleEdit, "something 2"); @@ -653,7 +673,7 @@ void TestGui::testAddEntry() QApplication::processEvents(); - // Confirm entry count + // Confirm no changed entry count QTRY_COMPARE(entryView->model()->rowCount(), 3); } @@ -1087,6 +1107,7 @@ void TestGui::testDeleteEntry() { // Add canned entries for consistent testing addCannedEntries(); + checkStatusBarText("4 Ent"); auto* groupView = m_dbWidget->findChild("groupView"); auto* entryView = m_dbWidget->findChild("entryView"); @@ -1116,6 +1137,8 @@ void TestGui::testDeleteEntry() QCOMPARE(m_db->metadata()->recycleBin()->entries().size(), 1); } + checkStatusBarText("3 Ent"); + // Select multiple entries and move them to the recycling bin clickIndex(entryView->model()->index(1, 1), entryView, Qt::LeftButton); clickIndex(entryView->model()->index(2, 1), entryView, Qt::LeftButton, Qt::ControlModifier); @@ -1884,6 +1907,14 @@ void TestGui::checkSaveDatabase() QFAIL("Could not save database."); } +void TestGui::checkStatusBarText(const QString& textFragment) +{ + QApplication::processEvents(); + QVERIFY(m_statusBarLabel->isVisible()); + QTRY_VERIFY2(m_statusBarLabel->text().startsWith(textFragment), + qPrintable(QString("'%1' doesn't start with '%2'").arg(m_statusBarLabel->text(), textFragment))); +} + void TestGui::triggerAction(const QString& name) { auto* action = m_mainWindow->findChild(name); diff --git a/tests/gui/TestGui.h b/tests/gui/TestGui.h index 2e18ce4cd..c631e5bdc 100644 --- a/tests/gui/TestGui.h +++ b/tests/gui/TestGui.h @@ -84,8 +84,10 @@ private: Qt::MouseButton button, Qt::KeyboardModifiers stateKey = 0); void checkSaveDatabase(); + void checkStatusBarText(const QString& textFragment); QScopedPointer m_mainWindow; + QPointer m_statusBarLabel; QPointer m_tabWidget; QPointer m_dbWidget; QSharedPointer m_db;