@@ -375,26 +375,27 @@ void TestGui::testMergeDatabase()
375
375
QCOMPARE (m_db->rootGroup ()->findChildByName (" General" )->entries ().size (), 1 );
376
376
}
377
377
378
- void TestGui::prepareAndTriggerRemoteSync (const QString& sourceToSync )
378
+ void TestGui::prepareAndTriggerRemoteSync ()
379
379
{
380
- auto * menuRemoteSync = m_mainWindow->findChild <QMenu*>(" menuRemoteSync" );
381
- QSignalSpy remoteAboutToShow (menuRemoteSync, &QMenu::aboutToShow);
382
- QApplication::processEvents ();
383
-
384
380
// create remote settings in settings dialog
385
381
triggerAction (" actionDatabaseSettings" );
386
- auto * dbSettingsDialog = m_dbWidget->findChild <QWidget*>(" databaseSettingsDialog" );
387
- auto * dbSettingsCategoryList = dbSettingsDialog->findChild <CategoryListWidget*>(" categoryList" );
388
- auto * dbSettingsStackedWidget = dbSettingsDialog->findChild <QStackedWidget*>(" stackedWidget" );
389
- dbSettingsCategoryList->setCurrentCategory (2 ); // go into remote category
382
+
383
+ auto dbSettingsDialog = m_dbWidget->findChild <DatabaseSettingsDialog*>(" databaseSettingsDialog" );
384
+ QVERIFY (dbSettingsDialog);
385
+ dbSettingsDialog->showRemoteSettings ();
386
+
390
387
auto name = " testCommand" ;
391
- auto * nameEdit = dbSettingsStackedWidget->findChild <QLineEdit*>(" nameLineEdit" );
392
- auto * downloadCommandEdit = dbSettingsStackedWidget->findChild <QLineEdit*>(" downloadCommand" );
393
- QVERIFY (downloadCommandEdit != nullptr );
394
- downloadCommandEdit->setText (sourceToSync);
388
+ auto nameEdit = dbSettingsDialog->findChild <QLineEdit*>(" nameLineEdit" );
389
+ QVERIFY (nameEdit);
390
+ QVERIFY (nameEdit->isVisible ());
395
391
nameEdit->setText (name);
396
- auto * saveSettingsButton = dbSettingsStackedWidget->findChild <QPushButton*>(" saveSettingsButton" );
397
- QVERIFY (saveSettingsButton != nullptr );
392
+
393
+ auto downloadCommandEdit = dbSettingsDialog->findChild <QLineEdit*>(" downloadCommand" );
394
+ QVERIFY (downloadCommandEdit);
395
+ downloadCommandEdit->setText (" sftp user@server:Database.kdbx" );
396
+
397
+ auto saveSettingsButton = dbSettingsDialog->findChild <QPushButton*>(" saveSettingsButton" );
398
+ QVERIFY (saveSettingsButton);
398
399
QTest::mouseClick (saveSettingsButton, Qt::LeftButton);
399
400
400
401
auto okButton = dbSettingsDialog->findChild <QDialogButtonBox*>(" buttonBox" )->button (QDialogButtonBox::Ok);
@@ -403,32 +404,33 @@ void TestGui::prepareAndTriggerRemoteSync(const QString& sourceToSync)
403
404
404
405
QTRY_COMPARE (m_dbWidget->getRemoteParams ().size (), 1 );
405
406
406
- // trigger aboutToShow to create remote actions
407
- menuRemoteSync->popup (QPoint (0 , 0 ));
407
+ // Show menu to trigger populating with remote sync action
408
+ auto menuRemoteSync = m_mainWindow->findChild <QMenu*>(" menuRemoteSync" );
409
+ QVERIFY (menuRemoteSync);
410
+ menuRemoteSync->popup ({0 , 0 });
408
411
QApplication::processEvents ();
409
- QTRY_COMPARE (remoteAboutToShow.count (), 1 );
410
- // close the opened menu
411
- QTest::keyClick (menuRemoteSync, Qt::Key::Key_Escape);
412
+ menuRemoteSync->close ();
412
413
413
- // trigger remote sync action
414
- for (auto * remoteAction : menuRemoteSync->actions ()) {
414
+ // Trigger the remote sync action
415
+ for (const auto remoteAction : menuRemoteSync->actions ()) {
415
416
if (remoteAction->text () == name) {
416
417
remoteAction->trigger ();
417
- break ;
418
+ return ;
418
419
}
419
420
}
420
- QApplication::processEvents ();
421
+
422
+ // If we get here then something didn't work properly
423
+ QFAIL (" Remote sync action not present in menu." );
421
424
}
422
425
423
426
void TestGui::testRemoteSyncDatabaseSameKey ()
424
427
{
425
- QString sourceToSync = " sftp user@server:Database.kdbx" ;
426
- RemoteHandler::setRemoteProcessFunc ([sourceToSync](QObject* parent) {
428
+ RemoteHandler::setRemoteProcessFunc ([](QObject* parent) {
427
429
return QScopedPointer<RemoteProcess>(
428
430
new MockRemoteProcess (parent, QString (KEEPASSX_TEST_DATA_DIR).append (" /SyncDatabase.kdbx" )));
429
431
});
430
432
QSignalSpy dbSyncSpy (m_dbWidget.data (), &DatabaseWidget::databaseSyncCompleted);
431
- prepareAndTriggerRemoteSync (sourceToSync );
433
+ prepareAndTriggerRemoteSync ();
432
434
QTRY_COMPARE (dbSyncSpy.count (), 1 );
433
435
434
436
m_db = m_tabWidget->currentDatabaseWidget ()->database ();
@@ -443,13 +445,12 @@ void TestGui::testRemoteSyncDatabaseSameKey()
443
445
444
446
void TestGui::testRemoteSyncDatabaseRequiresPassword ()
445
447
{
446
- QString sourceToSync = " sftp user@server:Database.kdbx" ;
447
- RemoteHandler::setRemoteProcessFunc ([sourceToSync](QObject* parent) {
448
+ RemoteHandler::setRemoteProcessFunc ([](QObject* parent) {
448
449
return QScopedPointer<RemoteProcess>(new MockRemoteProcess (
449
450
parent, QString (KEEPASSX_TEST_DATA_DIR).append (" /SyncDatabaseDifferentPassword.kdbx" )));
450
451
});
451
452
QSignalSpy dbSyncSpy (m_dbWidget.data (), &DatabaseWidget::databaseSyncCompleted);
452
- prepareAndTriggerRemoteSync (sourceToSync );
453
+ prepareAndTriggerRemoteSync ();
453
454
454
455
// need to process more events as opening with the same key did not work and more events have been fired
455
456
QApplication::processEvents (QEventLoop::WaitForMoreEvents);
0 commit comments