Skip to content

Commit

Permalink
test: add test for maximum history in database settings
Browse files Browse the repository at this point in the history
This commit adds a test to the TestGui::testDatabaseSettings function for the history maximum items and maximum size settings.
The test opens the database settings dialog, disables the history items and size settings, saves the changes, reopens the dialog, and then cancels without making any changes to load the default values. The test ensures that the default values are loaded correctly.
  • Loading branch information
jNullj committed Apr 27, 2023
1 parent 420c364 commit 476b533
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions tests/gui/TestGui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1466,6 +1466,7 @@ void TestGui::testDatabaseSettings()
auto* dbSettingsStackedWidget = dbSettingsDialog->findChild<QStackedWidget*>("stackedWidget");
auto* transformRoundsSpinBox = dbSettingsDialog->findChild<QSpinBox*>("transformRoundsSpinBox");
auto advancedToggle = dbSettingsDialog->findChild<QCheckBox*>("advancedSettingsToggle");
auto* dbSettingsButtonBox = dbSettingsDialog->findChild<QDialogButtonBox*>("buttonBox");

advancedToggle->setChecked(true);
QApplication::processEvents();
Expand All @@ -1477,6 +1478,27 @@ void TestGui::testDatabaseSettings()
QTest::keyClick(transformRoundsSpinBox, Qt::Key_Enter);
QTRY_COMPARE(m_db->kdf()->rounds(), 123456);

// test disable and default values for maximum history items and size
triggerAction("actionDatabaseSettings");
auto* historyMaxItemsCheckBox = dbSettingsDialog->findChild<QCheckBox*>("historyMaxItemsCheckBox");
auto* historyMaxItemsSpinBox = dbSettingsDialog->findChild<QSpinBox*>("historyMaxItemsSpinBox");
auto* historyMaxSizeCheckBox = dbSettingsDialog->findChild<QCheckBox*>("historyMaxSizeCheckBox");
auto* historyMaxSizeSpinBox = dbSettingsDialog->findChild<QSpinBox*>("historyMaxSizeSpinBox");
// test defaults
QCOMPARE(historyMaxItemsSpinBox->value(), Metadata::DefaultHistoryMaxItems);
QCOMPARE(historyMaxSizeSpinBox->value(), qRound(Metadata::DefaultHistoryMaxSize / qreal(1024 * 1024)));
// disable and test setting as well
historyMaxItemsCheckBox->setChecked(false);
historyMaxSizeCheckBox->setChecked(false);
QTest::mouseClick(dbSettingsButtonBox->button(QDialogButtonBox::Ok), Qt::LeftButton);
QTRY_COMPARE(m_db->metadata()->historyMaxItems(), -1);
QTRY_COMPARE(m_db->metadata()->historyMaxSize(), -1);
// then open to check the saved disabled state in gui
triggerAction("actionDatabaseSettings");
QCOMPARE(historyMaxItemsCheckBox->isChecked(), false);
QCOMPARE(historyMaxSizeCheckBox->isChecked(), false);
QTest::mouseClick(dbSettingsButtonBox->button(QDialogButtonBox::Cancel), Qt::LeftButton);

checkSaveDatabase();
}

Expand Down

0 comments on commit 476b533

Please sign in to comment.