Fix status bar update when switching to other DB (#9073)

* Gui tests: add validation of StatusBarLabel in some tests
This commit is contained in:
Jonathan White 2023-02-19 07:32:29 -08:00
parent f7920c12d5
commit df40742223
No known key found for this signature in database
GPG key ID: 440FC65F2E0C6E01
3 changed files with 36 additions and 1 deletions

View file

@ -689,6 +689,7 @@ MainWindow::MainWindow()
statusBar()->addPermanentWidget(m_progressBar); statusBar()->addPermanentWidget(m_progressBar);
connect(clipboard(), SIGNAL(updateCountdown(int, QString)), this, SLOT(updateProgressBar(int, QString))); connect(clipboard(), SIGNAL(updateCountdown(int, QString)), this, SLOT(updateProgressBar(int, QString)));
m_statusBarLabel = new QLabel(statusBar()); m_statusBarLabel = new QLabel(statusBar());
m_statusBarLabel->setObjectName("statusBarLabel");
statusBar()->addPermanentWidget(m_statusBarLabel); statusBar()->addPermanentWidget(m_statusBarLabel);
restoreConfigState(); restoreConfigState();
@ -1352,6 +1353,7 @@ void MainWindow::databaseTabChanged(int tabIndex)
} }
m_actionMultiplexer.setCurrentObject(m_ui->tabWidget->currentDatabaseWidget()); m_actionMultiplexer.setCurrentObject(m_ui->tabWidget->currentDatabaseWidget());
updateEntryCountLabel();
} }
void MainWindow::closeEvent(QCloseEvent* event) void MainWindow::closeEvent(QCloseEvent* event)

View file

@ -91,6 +91,7 @@ void TestGui::initTestCase()
m_mainWindow.reset(new MainWindow()); m_mainWindow.reset(new MainWindow());
m_tabWidget = m_mainWindow->findChild<DatabaseTabWidget*>("tabWidget"); m_tabWidget = m_mainWindow->findChild<DatabaseTabWidget*>("tabWidget");
m_statusBarLabel = m_mainWindow->findChild<QLabel*>("statusBarLabel");
m_mainWindow->show(); m_mainWindow->show();
m_mainWindow->resize(1024, 768); m_mainWindow->resize(1024, 768);
} }
@ -286,6 +287,10 @@ void TestGui::testCreateDatabase()
triggerAction("actionDatabaseNew"); triggerAction("actionDatabaseNew");
QCOMPARE(m_tabWidget->count(), 2);
checkStatusBarText("0 Ent");
// there is a new empty db // there is a new empty db
m_db = m_tabWidget->currentDatabaseWidget()->database(); m_db = m_tabWidget->currentDatabaseWidget()->database();
QCOMPARE(m_db->rootGroup()->children().size(), 0); QCOMPARE(m_db->rootGroup()->children().size(), 0);
@ -306,6 +311,15 @@ void TestGui::testCreateDatabase()
compositeKey->addKey(fileKey); compositeKey->addKey(fileKey);
QCOMPARE(m_db->key()->rawKey(), compositeKey->rawKey()); 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 // close the new database
MessageBox::setNextAnswer(MessageBox::No); MessageBox::setNextAnswer(MessageBox::No);
triggerAction("actionDatabaseClose"); triggerAction("actionDatabaseClose");
@ -592,6 +606,9 @@ void TestGui::testAddEntry()
auto* toolBar = m_mainWindow->findChild<QToolBar*>("toolBar"); auto* toolBar = m_mainWindow->findChild<QToolBar*>("toolBar");
auto* entryView = m_dbWidget->findChild<EntryView*>("entryView"); auto* entryView = m_dbWidget->findChild<EntryView*>("entryView");
// Given the status bar label with initial number of entries.
checkStatusBarText("1 Ent");
// Find the new entry action // Find the new entry action
auto* entryNewAction = m_mainWindow->findChild<QAction*>("actionEntryNew"); auto* entryNewAction = m_mainWindow->findChild<QAction*>("actionEntryNew");
QVERIFY(entryNewAction->isEnabled()); QVERIFY(entryNewAction->isEnabled());
@ -626,6 +643,9 @@ void TestGui::testAddEntry()
m_db->updateCommonUsernames(); m_db->updateCommonUsernames();
// Then the status bar label should be updated with incremented number of entries.
checkStatusBarText("2 Ent");
// Add entry "something 2" // Add entry "something 2"
QTest::mouseClick(entryNewWidget, Qt::LeftButton); QTest::mouseClick(entryNewWidget, Qt::LeftButton);
QTest::keyClicks(titleEdit, "something 2"); QTest::keyClicks(titleEdit, "something 2");
@ -653,7 +673,7 @@ void TestGui::testAddEntry()
QApplication::processEvents(); QApplication::processEvents();
// Confirm entry count // Confirm no changed entry count
QTRY_COMPARE(entryView->model()->rowCount(), 3); QTRY_COMPARE(entryView->model()->rowCount(), 3);
} }
@ -1087,6 +1107,7 @@ void TestGui::testDeleteEntry()
{ {
// Add canned entries for consistent testing // Add canned entries for consistent testing
addCannedEntries(); addCannedEntries();
checkStatusBarText("4 Ent");
auto* groupView = m_dbWidget->findChild<GroupView*>("groupView"); auto* groupView = m_dbWidget->findChild<GroupView*>("groupView");
auto* entryView = m_dbWidget->findChild<EntryView*>("entryView"); auto* entryView = m_dbWidget->findChild<EntryView*>("entryView");
@ -1116,6 +1137,8 @@ void TestGui::testDeleteEntry()
QCOMPARE(m_db->metadata()->recycleBin()->entries().size(), 1); QCOMPARE(m_db->metadata()->recycleBin()->entries().size(), 1);
} }
checkStatusBarText("3 Ent");
// Select multiple entries and move them to the recycling bin // Select multiple entries and move them to the recycling bin
clickIndex(entryView->model()->index(1, 1), entryView, Qt::LeftButton); clickIndex(entryView->model()->index(1, 1), entryView, Qt::LeftButton);
clickIndex(entryView->model()->index(2, 1), entryView, Qt::LeftButton, Qt::ControlModifier); clickIndex(entryView->model()->index(2, 1), entryView, Qt::LeftButton, Qt::ControlModifier);
@ -1884,6 +1907,14 @@ void TestGui::checkSaveDatabase()
QFAIL("Could not save database."); 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) void TestGui::triggerAction(const QString& name)
{ {
auto* action = m_mainWindow->findChild<QAction*>(name); auto* action = m_mainWindow->findChild<QAction*>(name);

View file

@ -84,8 +84,10 @@ private:
Qt::MouseButton button, Qt::MouseButton button,
Qt::KeyboardModifiers stateKey = 0); Qt::KeyboardModifiers stateKey = 0);
void checkSaveDatabase(); void checkSaveDatabase();
void checkStatusBarText(const QString& textFragment);
QScopedPointer<MainWindow> m_mainWindow; QScopedPointer<MainWindow> m_mainWindow;
QPointer<QLabel> m_statusBarLabel;
QPointer<DatabaseTabWidget> m_tabWidget; QPointer<DatabaseTabWidget> m_tabWidget;
QPointer<DatabaseWidget> m_dbWidget; QPointer<DatabaseWidget> m_dbWidget;
QSharedPointer<Database> m_db; QSharedPointer<Database> m_db;