Merge pull request #1141 from keepassxreboot/hotfix/apply-button-save

Fix apply button not saving new entries
This commit is contained in:
TheZ3ro 2017-11-06 20:27:15 +01:00 committed by GitHub
commit 7ef61b47e3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 58 additions and 6 deletions

View File

@ -278,6 +278,7 @@ void EditEntryWidget::loadEntry(Entry* entry, bool create, bool history, const Q
m_database = database;
m_create = create;
m_history = history;
m_saved = false;
if (history) {
setHeadline(QString("%1 > %2").arg(parentName, tr("Entry history")));
@ -438,6 +439,7 @@ void EditEntryWidget::saveEntry()
}
updateEntryData(m_entry);
m_saved = true;
if (!m_create) {
m_entry->endUpdate();
@ -510,7 +512,7 @@ void EditEntryWidget::cancel()
clear();
emit editFinished(false);
emit editFinished(m_saved);
}
void EditEntryWidget::clear()

View File

@ -121,6 +121,7 @@ private:
bool m_create;
bool m_history;
bool m_saved;
const QScopedPointer<Ui::EditEntryWidgetMain> m_mainUi;
const QScopedPointer<Ui::EditEntryWidgetAdvanced> m_advancedUi;
const QScopedPointer<Ui::EditEntryWidgetAutoType> m_autoTypeUi;

View File

@ -332,15 +332,27 @@ void TestGui::testAddEntry()
QTest::keyClicks(passwordRepeatEdit, "something 2");
QTest::mouseClick(editEntryWidgetButtonBox->button(QDialogButtonBox::Ok), Qt::LeftButton);
// Add entry "something 3"
// Add entry "something 3" using the apply button then click ok
QTest::mouseClick(entryNewWidget, Qt::LeftButton);
QTest::keyClicks(titleEdit, "something 3");
QTest::mouseClick(editEntryWidgetButtonBox->button(QDialogButtonBox::Apply), Qt::LeftButton);
QTest::mouseClick(editEntryWidgetButtonBox->button(QDialogButtonBox::Ok), Qt::LeftButton);
// Add entry "something 4" using the apply button then click cancel
QTest::mouseClick(entryNewWidget, Qt::LeftButton);
QTest::keyClicks(titleEdit, "something 4");
QTest::mouseClick(editEntryWidgetButtonBox->button(QDialogButtonBox::Apply), Qt::LeftButton);
QTest::mouseClick(editEntryWidgetButtonBox->button(QDialogButtonBox::Cancel), Qt::LeftButton);
// Add entry "something 5" but click cancel button (does NOT add entry)
QTest::mouseClick(entryNewWidget, Qt::LeftButton);
QTest::keyClicks(titleEdit, "something 5");
QTest::mouseClick(editEntryWidgetButtonBox->button(QDialogButtonBox::Cancel), Qt::LeftButton);
QApplication::processEvents();
// Confirm that 4 entries now exist
QTRY_COMPARE(entryView->model()->rowCount(), 4);
// Confirm that 5 entries now exist
QTRY_COMPARE(entryView->model()->rowCount(), 5);
}
void TestGui::testPasswordEntryEntropy()
@ -513,7 +525,7 @@ void TestGui::testTotp()
void TestGui::testSearch()
{
// Add canned entries for consistent testing
testAddEntry();
Q_UNUSED(addCannedEntries());
QToolBar* toolBar = m_mainWindow->findChild<QToolBar*>("toolBar");
@ -629,7 +641,7 @@ void TestGui::testSearch()
void TestGui::testDeleteEntry()
{
// Add canned entries for consistent testing
testAddEntry();
Q_UNUSED(addCannedEntries());
GroupView* groupView = m_dbWidget->findChild<GroupView*>("groupView");
EntryView* entryView = m_dbWidget->findChild<EntryView*>("entryView");
@ -905,6 +917,42 @@ void TestGui::cleanupTestCase()
delete m_mainWindow;
}
int TestGui::addCannedEntries()
{
int entries_added = 0;
// Find buttons
QToolBar* toolBar = m_mainWindow->findChild<QToolBar*>("toolBar");
QWidget* entryNewWidget = toolBar->widgetForAction(m_mainWindow->findChild<QAction*>("actionEntryNew"));
EditEntryWidget* editEntryWidget = m_dbWidget->findChild<EditEntryWidget*>("editEntryWidget");
QLineEdit* titleEdit = editEntryWidget->findChild<QLineEdit*>("titleEdit");
QLineEdit* passwordEdit = editEntryWidget->findChild<QLineEdit*>("passwordEdit");
QLineEdit* passwordRepeatEdit = editEntryWidget->findChild<QLineEdit*>("passwordRepeatEdit");
// Add entry "test" and confirm added
QTest::mouseClick(entryNewWidget, Qt::LeftButton);
QTest::keyClicks(titleEdit, "test");
QDialogButtonBox* editEntryWidgetButtonBox = editEntryWidget->findChild<QDialogButtonBox*>("buttonBox");
QTest::mouseClick(editEntryWidgetButtonBox->button(QDialogButtonBox::Ok), Qt::LeftButton);
++entries_added;
// Add entry "something 2"
QTest::mouseClick(entryNewWidget, Qt::LeftButton);
QTest::keyClicks(titleEdit, "something 2");
QTest::keyClicks(passwordEdit, "something 2");
QTest::keyClicks(passwordRepeatEdit, "something 2");
QTest::mouseClick(editEntryWidgetButtonBox->button(QDialogButtonBox::Ok), Qt::LeftButton);
++entries_added;
// Add entry "something 3"
QTest::mouseClick(entryNewWidget, Qt::LeftButton);
QTest::keyClicks(titleEdit, "something 3");
QTest::mouseClick(editEntryWidgetButtonBox->button(QDialogButtonBox::Ok), Qt::LeftButton);
++entries_added;
return entries_added;
}
void TestGui::checkDatabase(QString dbFileName)
{
if (dbFileName.isEmpty())

View File

@ -61,6 +61,7 @@ private slots:
void testDatabaseLocking();
private:
int addCannedEntries();
void checkDatabase(QString dbFileName = "");
void triggerAction(const QString& name);
void dragAndDropGroup(const QModelIndex& sourceIndex, const QModelIndex& targetIndex, int row,