From 4d07b6f893656bde89a3446589432c8093b9863f Mon Sep 17 00:00:00 2001 From: Jonathan White Date: Sat, 19 Oct 2024 00:09:32 -0400 Subject: [PATCH] Fix assert hit when viewing entry history * Fixes #11371 * Adds test for showing entry history --- src/gui/DatabaseWidget.cpp | 3 ++- tests/gui/TestGui.cpp | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/gui/DatabaseWidget.cpp b/src/gui/DatabaseWidget.cpp index fba27d5a8e..cbe27ee4eb 100644 --- a/src/gui/DatabaseWidget.cpp +++ b/src/gui/DatabaseWidget.cpp @@ -183,6 +183,7 @@ DatabaseWidget::DatabaseWidget(QSharedPointer db, QWidget* parent) m_previewSplitter->setSizes({1, 1}); m_editEntryWidget->setObjectName("editEntryWidget"); + m_historyEditEntryWidget->setObjectName("editEntryHistoryWidget"); m_editGroupWidget->setObjectName("editGroupWidget"); m_reportsDialog->setObjectName("reportsDialog"); m_databaseSettingDialog->setObjectName("databaseSettingsDialog"); @@ -277,7 +278,7 @@ DatabaseWidget::Mode DatabaseWidget::currentMode() const mode = Mode::ReportsMode; } else if (widget == m_databaseSettingDialog) { mode = Mode::DatabaseSettingsMode; - } else if (widget == m_editEntryWidget) { + } else if (widget == m_editEntryWidget || widget == m_historyEditEntryWidget) { mode = Mode::EditEntryMode; } else if (widget == m_editGroupWidget) { mode = Mode::EditGroupMode; diff --git a/tests/gui/TestGui.cpp b/tests/gui/TestGui.cpp index 600002545c..4ca7470d07 100644 --- a/tests/gui/TestGui.cpp +++ b/tests/gui/TestGui.cpp @@ -627,6 +627,26 @@ void TestGui::testEditEntry() QCOMPARE(entry->historyItems().size(), ++editCount); QVERIFY(!applyButton->isEnabled()); + // Test viewing entry history + editEntryWidget->setCurrentPage(6); + QApplication::processEvents(); + auto historyView = editEntryWidget->findChild("historyView"); + auto showButton = editEntryWidget->findChild("showButton"); + QVERIFY(historyView); + QVERIFY(historyView->isVisible()); + QVERIFY(!showButton->isEnabled()); + // Select the second row in the history view + historyView->setCurrentIndex(historyView->model()->index(1, 0)); + QVERIFY(showButton->isEnabled()); + QTest::mouseClick(showButton, Qt::LeftButton); + // Verify that the entry history widget is shown + auto* entryHistoryWidget = m_dbWidget->findChild("editEntryHistoryWidget"); + QVERIFY(entryHistoryWidget); + QVERIFY(entryHistoryWidget->isVisible()); + QCOMPARE(m_dbWidget->currentMode(), DatabaseWidget::Mode::EditEntryMode); + QTest::keyClick(entryHistoryWidget, Qt::Key_Escape); + QVERIFY(historyView->isVisible()); + // Test the "known bad" checkbox editEntryWidget->setCurrentPage(1); auto excludeReportsCheckBox = editEntryWidget->findChild("excludeReportsCheckBox");