From 3b3bb9a949e7274bb985d30047df58e01e821da7 Mon Sep 17 00:00:00 2001 From: Agoston Szepessy Date: Tue, 23 Dec 2025 22:29:03 -0800 Subject: [PATCH] Add test for healthcheck exclusion Adds 2 groups, excludes one and makes sure it doesn't show up in the health check. --- tests/gui/TestGui.cpp | 110 ++++++++++++++++++++++++++++++++++++++++-- tests/gui/TestGui.h | 7 ++- 2 files changed, 111 insertions(+), 6 deletions(-) diff --git a/tests/gui/TestGui.cpp b/tests/gui/TestGui.cpp index 3dde7edeb..03aba4a2b 100644 --- a/tests/gui/TestGui.cpp +++ b/tests/gui/TestGui.cpp @@ -2473,11 +2473,11 @@ void TestGui::testDatabaseReports() addEntry("Finance", "Chase", "user1", "password"); addEntry("Finance", "Amex", "user1", "password123"); - addEntry("Finance", "Capital One", "user1", "lasdjfi309q23i8u2wjei"); + addEntry("Finance", "Capital One", "user1", "password456"); addEntry("Entertainment", "Netflix", "user1", "password"); - addEntry("Entertainment", "Hulu", "user1", "jwafh783jiwaef"); - addEntry("Entertainment", "Apple TV", "user1", "21983yr2weuajfduiwife;j"); + addEntry("Entertainment", "Hulu", "user1", "password321"); + addEntry("Entertainment", "Apple TV", "user1", "password123"); Group* entertainmentGroup = m_dbWidget->currentGroup()->findChildByName("Entertainment"); QCOMPARE(entertainmentGroup->entries().size(), 3); @@ -2521,7 +2521,109 @@ void TestGui::testDatabaseReports() QVERIFY(healthModel); QTRY_COMPARE(healthCheckWidgetSpy.count(), 1); - QCOMPARE(healthModel->rowCount(), 6); + QCOMPARE(healthModel->rowCount(), 8); // account for 2 existing passwords at the start of each test case + + auto *reportsDialogButtonBox = reportsDialog->findChild("buttonBox"); + QTest::mouseClick(reportsDialogButtonBox->button(QDialogButtonBox::Close), Qt::LeftButton); + QCOMPARE(m_dbWidget->currentMode(), DatabaseWidget::Mode::ViewMode); +} + +void TestGui::testExcludedDatabaseReports() +{ + addGroup("Finance"); + addGroup("Entertainment"); + + // Use bad passwords to make sure they all show up in health report + addEntry("Finance", "Chase", "user1", "password"); + addEntry("Finance", "Amex", "user1", "password123"); + addEntry("Finance", "Capital One", "user1", "password456"); + + addEntry("Entertainment", "Netflix", "user1", "password"); + addEntry("Entertainment", "Hulu", "user1", "password321"); + addEntry("Entertainment", "Apple TV", "user1", "password123"); + + Group* entertainmentGroup = m_dbWidget->currentGroup()->findChildByName("Entertainment"); + m_dbWidget->groupView()->setCurrentGroup(entertainmentGroup); + + auto* toolBar = m_mainWindow->findChild("toolBar"); + QVERIFY(toolBar); + + auto *editGroupAction = m_mainWindow->findChild("actionGroupEdit"); + QVERIFY(editGroupAction->isEnabled()); + triggerAction("actionGroupEdit"); + + auto* editGroupWidget = m_dbWidget->findChild("editGroupWidget"); + QVERIFY(editGroupWidget); + + // Bring up group edit page + QTest::mouseClick(editGroupWidget, Qt::LeftButton); + + QLineEdit* nameEdit = editGroupWidget->findChild("editName"); + QCOMPARE(nameEdit->text(), QString("Entertainment")); + + // Find database report exclusion checkbox and check it + QCheckBox *excludeGroupFromReportsCheckbox = editGroupWidget->findChild("excludeReportsCheckBox"); + QVERIFY(excludeGroupFromReportsCheckbox); + + excludeGroupFromReportsCheckbox->setChecked(true); + + auto* editGroupWidgetButtonBox = editGroupWidget->findChild("buttonBox"); + QVERIFY(editGroupWidgetButtonBox); + + // Apply and go back to main view + QTest::mouseClick(editGroupWidgetButtonBox->button(QDialogButtonBox::Apply), Qt::LeftButton); + QTest::mouseClick(editGroupWidgetButtonBox->button(QDialogButtonBox::Ok), Qt::LeftButton); + QCOMPARE(m_dbWidget->currentMode(), DatabaseWidget::Mode::ViewMode); + + QVERIFY(entertainmentGroup->excludeFromReports()); + + // Verify they don't show up in the report + auto *actionReports = m_mainWindow->findChild("actionReports"); + QVERIFY(actionReports->isEnabled()); + + QWidget* actionReportsWidget = toolBar->widgetForAction(actionReports); + QVERIFY(actionReportsWidget); + QVERIFY(actionReportsWidget->isVisible()); + QVERIFY(actionReportsWidget->isEnabled()); + + QTest::mouseClick(actionReportsWidget, Qt::LeftButton); + + auto *reportsDialog = m_dbWidget->findChild("reportsDialog"); + QVERIFY(reportsDialog); + + CategoryListWidget *categoryList = reportsDialog->findChild("categoryList"); + categoryList->setCurrentCategory(1); + + QStackedWidget *stackedWidget = reportsDialog->findChild("stackedWidget"); + QVERIFY(stackedWidget); + stackedWidget->setCurrentIndex(1); + + ReportsWidgetHealthcheck* healthCheckWidget = reportsDialog->findChild(); + QVERIFY(healthCheckWidget); + + QTest::mouseClick(healthCheckWidget, Qt::LeftButton); + QTableView *healthTable = healthCheckWidget->findChild("healthcheckTableView"); + QVERIFY(healthTable); + + QSignalSpy healthCheckWidgetSpy(healthCheckWidget, &ReportsWidgetHealthcheck::tablePopulated); + + QAbstractItemModel *healthModel = healthTable->model(); + QVERIFY(healthModel); + + // There should be 3 showing + QTRY_COMPARE(healthCheckWidgetSpy.count(), 1); + QCOMPARE(healthModel->rowCount(), 5); // account for 2 existing passwords at the start of each test case + + QCheckBox *showExcludedCheckBox = healthCheckWidget->findChild("showExcluded"); + QVERIFY(showExcludedCheckBox); + QCOMPARE(showExcludedCheckBox->isChecked(), false); + + showExcludedCheckBox->click(); + QVERIFY(showExcludedCheckBox->isChecked()); + QTRY_COMPARE(healthCheckWidgetSpy.count(), 2); + + healthModel = healthTable->model(); + QCOMPARE(healthModel->rowCount(), 8); // account for 2 existing passwords at the start of each test case auto *reportsDialogButtonBox = reportsDialog->findChild("buttonBox"); QTest::mouseClick(reportsDialogButtonBox->button(QDialogButtonBox::Close), Qt::LeftButton); diff --git a/tests/gui/TestGui.h b/tests/gui/TestGui.h index 1ff48d5c6..179ec5ece 100644 --- a/tests/gui/TestGui.h +++ b/tests/gui/TestGui.h @@ -37,6 +37,11 @@ private slots: void cleanup(); void cleanupTestCase(); + + void testDatabaseReports(); + void testExcludedDatabaseReports(); + +private: void testSettingsDefaultTabOrder(); void testCreateDatabase(); void testMergeDatabase(); @@ -71,9 +76,7 @@ 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);