test: add test for maximum history in database settings (#9176)

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.

Co-authored-by: jNullj <jNullj@users.noreply.github.com>
This commit is contained in:
jNullj 2023-07-04 15:43:12 +03:00 committed by GitHub
parent 338fe553ba
commit e755ee8e04
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1470,6 +1470,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();
@ -1481,6 +1482,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();
}