Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix apply button not saving new entries #1141

Merged
merged 1 commit into from
Nov 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/gui/entry/EditEntryWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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")));
Expand Down Expand Up @@ -438,6 +439,7 @@ void EditEntryWidget::saveEntry()
}

updateEntryData(m_entry);
m_saved = true;

if (!m_create) {
m_entry->endUpdate();
Expand Down Expand Up @@ -510,7 +512,7 @@ void EditEntryWidget::cancel()

clear();

emit editFinished(false);
emit editFinished(m_saved);
}

void EditEntryWidget::clear()
Expand Down
1 change: 1 addition & 0 deletions src/gui/entry/EditEntryWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ private slots:

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;
Expand Down
58 changes: 53 additions & 5 deletions tests/gui/TestGui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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");

Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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())
Expand Down
1 change: 1 addition & 0 deletions tests/gui/TestGui.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down