mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2026-03-11 08:54:48 +00:00
Add test for database reports
Adds utility functions to create groups and entries for them. Add test to make sure the right amount of entries show up in the database report for password health. Add signal when password health calculation is done so the test harness can wait on it; otherwise the test finishes too soon and doesn't get the right result from the application.
This commit is contained in:
parent
4ffded3169
commit
49e945d1c0
4 changed files with 115 additions and 0 deletions
|
|
@ -304,6 +304,8 @@ void ReportsWidgetHealthcheck::calculateHealth()
|
|||
|
||||
// Only show the "show excluded" checkbox if there are any excluded entries in the database
|
||||
m_ui->showExcluded->setVisible(health->anyExcludedEntries());
|
||||
|
||||
emit tablePopulated();
|
||||
}
|
||||
|
||||
void ReportsWidgetHealthcheck::emitEntryActivated(const QModelIndex& index)
|
||||
|
|
|
|||
|
|
@ -48,6 +48,7 @@ protected:
|
|||
|
||||
signals:
|
||||
void entryActivated(Entry*);
|
||||
void tablePopulated();
|
||||
|
||||
public slots:
|
||||
void calculateHealth();
|
||||
|
|
|
|||
|
|
@ -62,6 +62,8 @@
|
|||
#include "gui/group/GroupModel.h"
|
||||
#include "gui/group/GroupView.h"
|
||||
#include "gui/remote/RemoteHandler.h"
|
||||
#include "gui/reports/ReportsWidgetHealthcheck.h"
|
||||
#include "gui/reports/ReportsDialog.h"
|
||||
#include "gui/tag/TagsEdit.h"
|
||||
#include "gui/wizard/NewDatabaseWizard.h"
|
||||
#include "keys/FileKey.h"
|
||||
|
|
@ -2464,6 +2466,68 @@ void TestGui::testMenuActionStates()
|
|||
QVERIFY(isActionEnabled("actionPasswordGenerator"));
|
||||
}
|
||||
|
||||
void TestGui::testDatabaseReports()
|
||||
{
|
||||
addGroup("Finance");
|
||||
addGroup("Entertainment");
|
||||
|
||||
addEntry("Finance", "Chase", "user1", "password");
|
||||
addEntry("Finance", "Amex", "user1", "password123");
|
||||
addEntry("Finance", "Capital One", "user1", "lasdjfi309q23i8u2wjei");
|
||||
|
||||
addEntry("Entertainment", "Netflix", "user1", "password");
|
||||
addEntry("Entertainment", "Hulu", "user1", "jwafh783jiwaef");
|
||||
addEntry("Entertainment", "Apple TV", "user1", "21983yr2weuajfduiwife;j");
|
||||
|
||||
Group* entertainmentGroup = m_dbWidget->currentGroup()->findChildByName("Entertainment");
|
||||
QCOMPARE(entertainmentGroup->entries().size(), 3);
|
||||
|
||||
Group* financeGroup = m_dbWidget->currentGroup()->findChildByName("Finance");
|
||||
QCOMPARE(financeGroup->entries().size(), 3);
|
||||
|
||||
auto *actionReports = m_mainWindow->findChild<QAction*>("actionReports");
|
||||
QVERIFY(actionReports->isEnabled());
|
||||
|
||||
auto* toolBar = m_mainWindow->findChild<QToolBar*>("toolBar");
|
||||
QVERIFY(toolBar);
|
||||
|
||||
QWidget* actionReportsWidget = toolBar->widgetForAction(actionReports);
|
||||
QVERIFY(actionReportsWidget);
|
||||
QVERIFY(actionReportsWidget->isVisible());
|
||||
QVERIFY(actionReportsWidget->isEnabled());
|
||||
|
||||
QTest::mouseClick(actionReportsWidget, Qt::LeftButton);
|
||||
|
||||
auto *reportsDialog = m_dbWidget->findChild<ReportsDialog*>("reportsDialog");
|
||||
QVERIFY(reportsDialog);
|
||||
|
||||
CategoryListWidget *categoryList = reportsDialog->findChild<CategoryListWidget*>("categoryList");
|
||||
categoryList->setCurrentCategory(1);
|
||||
|
||||
QStackedWidget *stackedWidget = reportsDialog->findChild<QStackedWidget*>("stackedWidget");
|
||||
QVERIFY(stackedWidget);
|
||||
stackedWidget->setCurrentIndex(1);
|
||||
|
||||
ReportsWidgetHealthcheck* healthCheckWidget = reportsDialog->findChild<ReportsWidgetHealthcheck*>();
|
||||
QVERIFY(healthCheckWidget);
|
||||
|
||||
QTest::mouseClick(healthCheckWidget, Qt::LeftButton);
|
||||
QTableView *healthTable = healthCheckWidget->findChild<QTableView*>("healthcheckTableView");
|
||||
QVERIFY(healthTable);
|
||||
|
||||
QSignalSpy healthCheckWidgetSpy(healthCheckWidget, &ReportsWidgetHealthcheck::tablePopulated);
|
||||
|
||||
QAbstractItemModel *healthModel = healthTable->model();
|
||||
QVERIFY(healthModel);
|
||||
|
||||
QTRY_COMPARE(healthCheckWidgetSpy.count(), 1);
|
||||
QCOMPARE(healthModel->rowCount(), 6);
|
||||
|
||||
auto *reportsDialogButtonBox = reportsDialog->findChild<QDialogButtonBox*>("buttonBox");
|
||||
QTest::mouseClick(reportsDialogButtonBox->button(QDialogButtonBox::Close), Qt::LeftButton);
|
||||
QCOMPARE(m_dbWidget->currentMode(), DatabaseWidget::Mode::ViewMode);
|
||||
}
|
||||
|
||||
void TestGui::addCannedEntries()
|
||||
{
|
||||
// Find buttons
|
||||
|
|
@ -2494,6 +2558,51 @@ void TestGui::addCannedEntries()
|
|||
QTest::mouseClick(editEntryWidgetButtonBox->button(QDialogButtonBox::Ok), Qt::LeftButton);
|
||||
}
|
||||
|
||||
void TestGui::addGroup(const QString &name)
|
||||
{
|
||||
// Find buttons for group creation
|
||||
auto* editGroupWidget = m_dbWidget->findChild<EditGroupWidget*>("editGroupWidget");
|
||||
auto* nameEdit = editGroupWidget->findChild<QLineEdit*>("editName");
|
||||
auto* editGroupWidgetButtonBox = editGroupWidget->findChild<QDialogButtonBox*>("buttonBox");
|
||||
|
||||
// Add group with specified name
|
||||
Group *rootGroup = m_db->rootGroup();
|
||||
m_dbWidget->groupView()->setCurrentGroup(rootGroup); // Add group on root level
|
||||
m_dbWidget->createGroup();
|
||||
QTest::keyClicks(nameEdit, name);
|
||||
QTest::mouseClick(editGroupWidgetButtonBox->button(QDialogButtonBox::Ok), Qt::LeftButton);
|
||||
m_dbWidget->groupView()->setCurrentGroup(rootGroup); // Reset to root level
|
||||
}
|
||||
|
||||
void TestGui::addEntry(const QString &groupName, const QString &title, const QString &username, const QString &password)
|
||||
{
|
||||
// Find buttons
|
||||
auto* toolBar = m_mainWindow->findChild<QToolBar*>("toolBar");
|
||||
QWidget* entryNewWidget = toolBar->widgetForAction(m_mainWindow->findChild<QAction*>("actionEntryNew"));
|
||||
auto* editEntryWidget = m_dbWidget->findChild<EditEntryWidget*>("editEntryWidget");
|
||||
auto* titleEdit = editEntryWidget->findChild<QLineEdit*>("titleEdit");
|
||||
auto* usernameComboBox = editEntryWidget->findChild<QComboBox*>("usernameComboBox");
|
||||
auto* passwordEdit =
|
||||
editEntryWidget->findChild<PasswordWidget*>("passwordEdit")->findChild<QLineEdit*>("passwordEdit");
|
||||
auto* editEntryWidgetButtonBox = editEntryWidget->findChild<QDialogButtonBox*>("buttonBox");
|
||||
|
||||
// Add entry to specified group
|
||||
QVERIFY(m_dbWidget->currentGroup());
|
||||
Group* group = m_dbWidget->currentGroup()->findChildByName(groupName);
|
||||
m_dbWidget->groupView()->setCurrentGroup(group);
|
||||
|
||||
QTest::mouseClick(entryNewWidget, Qt::LeftButton);
|
||||
QCOMPARE(m_dbWidget->currentMode(), DatabaseWidget::Mode::EditEntryMode);
|
||||
|
||||
QTest::keyClicks(titleEdit, title);
|
||||
QTest::keyClicks(usernameComboBox, username);
|
||||
QTest::keyClicks(passwordEdit, password);
|
||||
QTest::mouseClick(editEntryWidgetButtonBox->button(QDialogButtonBox::Ok), Qt::LeftButton);
|
||||
|
||||
QCOMPARE(m_dbWidget->currentMode(), DatabaseWidget::Mode::ViewMode);
|
||||
m_dbWidget->groupView()->setCurrentGroup(m_db->rootGroup());
|
||||
}
|
||||
|
||||
void TestGui::checkDatabase(const QString& filePath, const QString& expectedDbName)
|
||||
{
|
||||
auto key = QSharedPointer<CompositeKey>::create();
|
||||
|
|
|
|||
|
|
@ -71,9 +71,12 @@ private slots:
|
|||
void testTrayRestoreHide();
|
||||
void testShortcutConfig();
|
||||
void testMenuActionStates();
|
||||
void testExcludeGroupFromReports();
|
||||
|
||||
private:
|
||||
void addCannedEntries();
|
||||
void addGroup(const QString &name);
|
||||
void addEntry(const QString &groupName, const QString &title, const QString &username, const QString &password);
|
||||
void checkDatabase(const QString& filePath, const QString& expectedDbName);
|
||||
void checkDatabase(const QString& filePath = {});
|
||||
void triggerAction(const QString& name);
|
||||
|
|
|
|||
Loading…
Reference in a new issue