From 6f6c6480ae0c6961d466b6ea1d9520d6005bf0be Mon Sep 17 00:00:00 2001 From: jNullj <15849761+jNullj@users.noreply.github.com> Date: Tue, 4 Jul 2023 15:43:12 +0300 Subject: [PATCH] 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 --- tests/gui/TestGui.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tests/gui/TestGui.cpp b/tests/gui/TestGui.cpp index 23e59f338e..668a28d38d 100644 --- a/tests/gui/TestGui.cpp +++ b/tests/gui/TestGui.cpp @@ -1470,6 +1470,7 @@ void TestGui::testDatabaseSettings() auto* dbSettingsStackedWidget = dbSettingsDialog->findChild("stackedWidget"); auto* transformRoundsSpinBox = dbSettingsDialog->findChild("transformRoundsSpinBox"); auto advancedToggle = dbSettingsDialog->findChild("advancedSettingsToggle"); + auto* dbSettingsButtonBox = dbSettingsDialog->findChild("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("historyMaxItemsCheckBox"); + auto* historyMaxItemsSpinBox = dbSettingsDialog->findChild("historyMaxItemsSpinBox"); + auto* historyMaxSizeCheckBox = dbSettingsDialog->findChild("historyMaxSizeCheckBox"); + auto* historyMaxSizeSpinBox = dbSettingsDialog->findChild("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(); }