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

* Gui tests: add validation of StatusBarLabel in some tests
This commit is contained in:
Dmytro 2023-02-07 19:11:52 -08:00 committed by GitHub
parent bba0c09b42
commit 5bd871528f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 44 additions and 1 deletions

View File

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

View File

@ -286,6 +286,10 @@ void TestGui::testCreateDatabase()
triggerAction("actionDatabaseNew");
QCOMPARE(m_tabWidget->count(), 2);
statusBarLabelShouldBe("0 Entry(s)");
// there is a new empty db
m_db = m_tabWidget->currentDatabaseWidget()->database();
QCOMPARE(m_db->rootGroup()->children().size(), 0);
@ -306,6 +310,15 @@ void TestGui::testCreateDatabase()
compositeKey->addKey(fileKey);
QCOMPARE(m_db->key()->rawKey(), compositeKey->rawKey());
statusBarLabelShouldBe("0 Entry(s)");
// Test the switching to other DB tab
m_tabWidget->setCurrentIndex(0);
statusBarLabelShouldBe("1 Entry(s)");
m_tabWidget->setCurrentIndex(1);
statusBarLabelShouldBe("0 Entry(s)");
// close the new database
MessageBox::setNextAnswer(MessageBox::No);
triggerAction("actionDatabaseClose");
@ -592,6 +605,9 @@ void TestGui::testAddEntry()
auto* toolBar = m_mainWindow->findChild<QToolBar*>("toolBar");
auto* entryView = m_dbWidget->findChild<EntryView*>("entryView");
// Given the status bar label with initial number of entries.
statusBarLabelShouldBe("1 Entry(s)");
// Find the new entry action
auto* entryNewAction = m_mainWindow->findChild<QAction*>("actionEntryNew");
QVERIFY(entryNewAction->isEnabled());
@ -626,6 +642,9 @@ void TestGui::testAddEntry()
m_db->updateCommonUsernames();
// Then the status bar label should be updated with incremented number of entries.
statusBarLabelShouldBe("2 Entry(s)");
// Add entry "something 2"
QTest::mouseClick(entryNewWidget, Qt::LeftButton);
QTest::keyClicks(titleEdit, "something 2");
@ -645,6 +664,9 @@ void TestGui::testAddEntry()
QCOMPARE(entry->username(), QString("AutocompletionUsername"));
QCOMPARE(entry->historyItems().size(), 0);
// Then the status bar label should be updated with incremented number of entries.
statusBarLabelShouldBe("3 Entry(s)");
// Add entry "something 5" but click cancel button (does NOT add entry)
QTest::mouseClick(entryNewWidget, Qt::LeftButton);
QTest::keyClicks(titleEdit, "something 5");
@ -653,8 +675,9 @@ void TestGui::testAddEntry()
QApplication::processEvents();
// Confirm entry count
// Confirm no changed entry count
QTRY_COMPARE(entryView->model()->rowCount(), 3);
statusBarLabelShouldBe("3 Entry(s)");
}
void TestGui::testPasswordEntryEntropy_data()
@ -1087,6 +1110,7 @@ void TestGui::testDeleteEntry()
{
// Add canned entries for consistent testing
addCannedEntries();
statusBarLabelShouldBe("4 Entry(s)");
auto* groupView = m_dbWidget->findChild<GroupView*>("groupView");
auto* entryView = m_dbWidget->findChild<EntryView*>("entryView");
@ -1116,6 +1140,8 @@ void TestGui::testDeleteEntry()
QCOMPARE(m_db->metadata()->recycleBin()->entries().size(), 1);
}
statusBarLabelShouldBe("3 Entry(s)");
// 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);
@ -1136,6 +1162,7 @@ void TestGui::testDeleteEntry()
QCOMPARE(entryView->model()->rowCount(), 1);
QCOMPARE(m_db->metadata()->recycleBin()->entries().size(), 3);
}
statusBarLabelShouldBe("1 Entry(s)");
// Go to the recycling bin
QCOMPARE(groupView->currentGroup(), m_db->rootGroup());
@ -1144,6 +1171,7 @@ void TestGui::testDeleteEntry()
groupView,
Qt::LeftButton);
QCOMPARE(groupView->currentGroup()->name(), m_db->metadata()->recycleBin()->name());
statusBarLabelShouldBe("3 Entry(s)");
// Delete one entry from the bin
clickIndex(entryView->model()->index(0, 1), entryView, Qt::LeftButton);
@ -1151,6 +1179,7 @@ void TestGui::testDeleteEntry()
QTest::mouseClick(entryDeleteWidget, Qt::LeftButton);
QCOMPARE(entryView->model()->rowCount(), 3);
QCOMPARE(m_db->metadata()->recycleBin()->entries().size(), 3);
statusBarLabelShouldBe("3 Entry(s)");
MessageBox::setNextAnswer(MessageBox::Delete);
QTest::mouseClick(entryDeleteWidget, Qt::LeftButton);
@ -1164,6 +1193,7 @@ void TestGui::testDeleteEntry()
QTest::mouseClick(entryDeleteWidget, Qt::LeftButton);
QCOMPARE(entryView->model()->rowCount(), 0);
QCOMPARE(m_db->metadata()->recycleBin()->entries().size(), 0);
statusBarLabelShouldBe("0 Entry(s)");
// Ensure the entry preview widget shows the recycling group since all entries are deleted
auto* previewWidget = m_dbWidget->findChild<EntryPreviewWidget*>("previewWidget");
@ -1883,6 +1913,16 @@ void TestGui::checkSaveDatabase()
QFAIL("Could not save database.");
}
void TestGui::statusBarLabelShouldBe(const char* expectedText)
{
// Wait a little to have updated status bar text.
// It fails with 150ms on i7 2.5Ghz, let's have double more time: 300ms.
Tools::wait(300);
auto* statusBarLabel = m_mainWindow->findChild<QLabel*>("statusBarLabel");
QVERIFY2(statusBarLabel->isVisible(), "StatusBarLabel is to be visible");
QCOMPARE(statusBarLabel->text(), QString(expectedText));
}
void TestGui::triggerAction(const QString& name)
{
auto* action = m_mainWindow->findChild<QAction*>(name);

View File

@ -84,6 +84,7 @@ private:
Qt::MouseButton button,
Qt::KeyboardModifiers stateKey = 0);
void checkSaveDatabase();
void statusBarLabelShouldBe(const char* expectedText);
QScopedPointer<MainWindow> m_mainWindow;
QPointer<DatabaseTabWidget> m_tabWidget;