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 6e0baf9 commit cc0451c
Show file tree
Hide file tree
Showing 2 changed files with 21 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 @@ -182,6 +182,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 @@ -275,7 +276,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
19 changes: 19 additions & 0 deletions tests/gui/TestGui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,25 @@ void TestGui::testEditEntry()
QCOMPARE(entry->historyItems().size(), ++editCount);
QVERIFY(!applyButton->isEnabled());

// Test viewing entry history
editEntryWidget->setCurrentPage(6);
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 cc0451c

Please sign in to comment.