Skip to content

Commit

Permalink
Fix assert hit when viewing entry history
Browse files Browse the repository at this point in the history
* Fixes #11371
* Adds test for showing entry history
  • Loading branch information
droidmonkey committed Oct 26, 2024
1 parent 34fe413 commit 4d07b6f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/gui/DatabaseWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ DatabaseWidget::DatabaseWidget(QSharedPointer<Database> 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");
Expand Down Expand Up @@ -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;
Expand Down
20 changes: 20 additions & 0 deletions tests/gui/TestGui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<QTreeView*>("historyView");
auto showButton = editEntryWidget->findChild<QPushButton*>("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<QWidget*>("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<QCheckBox*>("excludeReportsCheckBox");
Expand Down

0 comments on commit 4d07b6f

Please sign in to comment.