mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2024-12-18 04:04:29 -05:00
Fix creation of history item when a new entry is added.
Add corresponding gui test.
This commit is contained in:
parent
887e4067ec
commit
44489bf6f8
@ -134,6 +134,7 @@ void EditEntryWidget::loadEntry(Entry* entry, bool create, const QString& groupN
|
|||||||
{
|
{
|
||||||
m_entry = entry;
|
m_entry = entry;
|
||||||
m_metadata = metadata;
|
m_metadata = metadata;
|
||||||
|
m_create = create;
|
||||||
|
|
||||||
if (create) {
|
if (create) {
|
||||||
m_ui->headerLabel->setText(groupName+" > "+tr("Add entry"));
|
m_ui->headerLabel->setText(groupName+" > "+tr("Add entry"));
|
||||||
@ -212,7 +213,9 @@ void EditEntryWidget::saveEntry()
|
|||||||
|
|
||||||
m_currentAttribute = QPersistentModelIndex();
|
m_currentAttribute = QPersistentModelIndex();
|
||||||
|
|
||||||
m_entry->beginUpdate();
|
if (!m_create) {
|
||||||
|
m_entry->beginUpdate();
|
||||||
|
}
|
||||||
|
|
||||||
m_entry->setTitle(m_mainUi->titleEdit->text());
|
m_entry->setTitle(m_mainUi->titleEdit->text());
|
||||||
m_entry->setUsername(m_mainUi->usernameEdit->text());
|
m_entry->setUsername(m_mainUi->usernameEdit->text());
|
||||||
@ -245,7 +248,9 @@ void EditEntryWidget::saveEntry()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
m_entry->endUpdate();
|
if (!m_create) {
|
||||||
|
m_entry->endUpdate();
|
||||||
|
}
|
||||||
|
|
||||||
m_entry = 0;
|
m_entry = 0;
|
||||||
m_entryAttributes->clear();
|
m_entryAttributes->clear();
|
||||||
|
@ -83,6 +83,7 @@ private:
|
|||||||
Entry* m_entry;
|
Entry* m_entry;
|
||||||
Metadata* m_metadata;
|
Metadata* m_metadata;
|
||||||
|
|
||||||
|
bool m_create;
|
||||||
const QScopedPointer<Ui::EditEntryWidget> m_ui;
|
const QScopedPointer<Ui::EditEntryWidget> m_ui;
|
||||||
const QScopedPointer<Ui::EditEntryWidgetMain> m_mainUi;
|
const QScopedPointer<Ui::EditEntryWidgetMain> m_mainUi;
|
||||||
const QScopedPointer<Ui::EditEntryWidgetNotes> m_notesUi;
|
const QScopedPointer<Ui::EditEntryWidgetNotes> m_notesUi;
|
||||||
|
@ -28,10 +28,12 @@
|
|||||||
#include "config-keepassx-tests.h"
|
#include "config-keepassx-tests.h"
|
||||||
#include "tests.h"
|
#include "tests.h"
|
||||||
#include "crypto/Crypto.h"
|
#include "crypto/Crypto.h"
|
||||||
|
#include "core/Entry.h"
|
||||||
#include "gui/DatabaseTabWidget.h"
|
#include "gui/DatabaseTabWidget.h"
|
||||||
#include "gui/DatabaseWidget.h"
|
#include "gui/DatabaseWidget.h"
|
||||||
#include "gui/EditEntryWidget.h"
|
#include "gui/EditEntryWidget.h"
|
||||||
#include "gui/EntryView.h"
|
#include "gui/EntryView.h"
|
||||||
|
#include "gui/EntryModel.h"
|
||||||
#include "gui/FileDialog.h"
|
#include "gui/FileDialog.h"
|
||||||
#include "gui/MainWindow.h"
|
#include "gui/MainWindow.h"
|
||||||
|
|
||||||
@ -97,6 +99,58 @@ void TestGui::testEditEntry()
|
|||||||
QCOMPARE(tabWidget->tabText(tabWidget->currentIndex()), QString("NewDatabase.kdbx"));
|
QCOMPARE(tabWidget->tabText(tabWidget->currentIndex()), QString("NewDatabase.kdbx"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TestGui::testAddEntry()
|
||||||
|
{
|
||||||
|
DatabaseTabWidget* tabWidget = m_mainWindow->findChild<DatabaseTabWidget*>("tabWidget");
|
||||||
|
DatabaseWidget* dbWidget = tabWidget->currentDatabaseWidget();
|
||||||
|
|
||||||
|
EntryView* entryView = dbWidget->findChild<EntryView*>("entryView");
|
||||||
|
QAction* entryNewAction = m_mainWindow->findChild<QAction*>("actionEntryNew");
|
||||||
|
QVERIFY(entryNewAction->isEnabled());
|
||||||
|
QToolBar* toolBar = m_mainWindow->findChild<QToolBar*>("toolBar");
|
||||||
|
QWidget* entryNewWidget = toolBar->widgetForAction(entryNewAction);
|
||||||
|
QVERIFY(entryNewWidget->isVisible());
|
||||||
|
QVERIFY(entryNewWidget->isEnabled());
|
||||||
|
|
||||||
|
QTest::mouseClick(entryNewWidget, Qt::LeftButton);
|
||||||
|
QTest::qWait(20);
|
||||||
|
|
||||||
|
QCOMPARE(dbWidget->currentMode(), DatabaseWidget::EditMode);
|
||||||
|
|
||||||
|
EditEntryWidget* editEntryWidget = dbWidget->findChild<EditEntryWidget*>("editEntryWidget");
|
||||||
|
QLineEdit* titleEdit = editEntryWidget->findChild<QLineEdit*>("titleEdit");
|
||||||
|
QTest::keyClicks(titleEdit, "test");
|
||||||
|
QTest::qWait(20);
|
||||||
|
|
||||||
|
QDialogButtonBox* editEntryWidgetButtonBox = editEntryWidget->findChild<QDialogButtonBox*>("buttonBox");
|
||||||
|
QTest::mouseClick(editEntryWidgetButtonBox->button(QDialogButtonBox::Ok), Qt::LeftButton);
|
||||||
|
QTest::qWait(20);
|
||||||
|
|
||||||
|
QCOMPARE(dbWidget->currentMode(), DatabaseWidget::ViewMode);
|
||||||
|
QModelIndex item = entryView->model()->index(1, 0);
|
||||||
|
Entry* entry = static_cast<EntryModel*>(entryView->model())->entryFromIndex(item);
|
||||||
|
|
||||||
|
QCOMPARE(entry->title(), QString("test"));
|
||||||
|
QCOMPARE(entry->historyItems().size(), 0);
|
||||||
|
QCOMPARE(tabWidget->tabText(tabWidget->currentIndex()), QString("NewDatabase.kdbx*"));
|
||||||
|
|
||||||
|
QAction* entryEditAction = m_mainWindow->findChild<QAction*>("actionEntryEdit");
|
||||||
|
QVERIFY(entryEditAction->isEnabled());
|
||||||
|
QWidget* entryEditWidget = toolBar->widgetForAction(entryEditAction);
|
||||||
|
QVERIFY(entryEditWidget->isVisible());
|
||||||
|
QVERIFY(entryEditWidget->isEnabled());
|
||||||
|
QTest::mouseClick(entryEditWidget, Qt::LeftButton);
|
||||||
|
QTest::qWait(20);
|
||||||
|
|
||||||
|
QCOMPARE(dbWidget->currentMode(), DatabaseWidget::EditMode);
|
||||||
|
QTest::keyClicks(titleEdit, "something");
|
||||||
|
QTest::mouseClick(editEntryWidgetButtonBox->button(QDialogButtonBox::Ok), Qt::LeftButton);
|
||||||
|
QTest::qWait(20);
|
||||||
|
|
||||||
|
QCOMPARE(entry->title(), QString("testsomething"));
|
||||||
|
QCOMPARE(entry->historyItems().size(), 1);
|
||||||
|
}
|
||||||
|
|
||||||
void TestGui::cleanupTestCase()
|
void TestGui::cleanupTestCase()
|
||||||
{
|
{
|
||||||
delete m_mainWindow;
|
delete m_mainWindow;
|
||||||
|
@ -31,6 +31,7 @@ private Q_SLOTS:
|
|||||||
void testOpenDatabase();
|
void testOpenDatabase();
|
||||||
void testTabs();
|
void testTabs();
|
||||||
void testEditEntry();
|
void testEditEntry();
|
||||||
|
void testAddEntry();
|
||||||
void cleanupTestCase();
|
void cleanupTestCase();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
Loading…
Reference in New Issue
Block a user