From 95e36ef89b4fbedab33a8ef04a3c77af37f47ded Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fran=C3=A7ois-Simon=20Fauteux-Chapleau?=
 <francois-simon.fauteux-chapleau@savoirfairelinux.com>
Date: Tue, 9 Jan 2024 09:36:32 -0500
Subject: [PATCH] tests/qml: fix various issues with the MessageOptions test

This commit fixes three issues related to tst_MessageOptions.qml:
1) There was no test to check that the call to createSIPAccount() at the
   beginning of test_createMessageOptionsPopup() actually succeeded
2) The created account was not deleted at the end of the test
3) The test would occasionally crash due to an uncaught
   std::out_of_range exception thrown by the
   AccountModelPimpl::slotAccountDetailsChanged function. I've modified
   the function to issue a warning instead, which makes it consistent
   with AccountModelPimpl::slotVolatileAccountDetailsChanged and avoids
   throwing an exception from a Qt slot (which is considered undefined
   behavior according to the Qt documentation)

Change-Id: I4d939b29f27ee27de673aea7046997ef756fbcee
---
 src/libclient/accountmodel.cpp       | 7 +++----
 tests/qml/src/tst_MessageOptions.qml | 7 ++++++-
 2 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/src/libclient/accountmodel.cpp b/src/libclient/accountmodel.cpp
index 5407b9798..30dc5850e 100644
--- a/src/libclient/accountmodel.cpp
+++ b/src/libclient/accountmodel.cpp
@@ -564,8 +564,8 @@ AccountModelPimpl::slotAccountDetailsChanged(const QString& accountId,
 {
     auto account = accounts.find(accountId);
     if (account == accounts.end()) {
-        throw std::out_of_range("AccountModelPimpl::slotAccountDetailsChanged, can't find "
-                                + accountId.toStdString());
+        qWarning() << Q_FUNC_INFO << ": can't find " << accountId;
+        return;
     }
     auto& accountInfo = account->second.first;
     accountInfo.fromDetails(details);
@@ -585,8 +585,7 @@ AccountModelPimpl::slotVolatileAccountDetailsChanged(const QString& accountId,
 {
     auto account = accounts.find(accountId);
     if (account == accounts.end()) {
-        qWarning() << "AccountModelPimpl::slotVolatileAccountDetailsChanged, can't find "
-                   << accountId;
+        qWarning() << Q_FUNC_INFO << ": can't find " << accountId;
         return;
     }
     auto& accountInfo = account->second.first;
diff --git a/tests/qml/src/tst_MessageOptions.qml b/tests/qml/src/tst_MessageOptions.qml
index c18f37b5a..e32654f06 100644
--- a/tests/qml/src/tst_MessageOptions.qml
+++ b/tests/qml/src/tst_MessageOptions.qml
@@ -82,7 +82,8 @@ Item {
                 "username": "currentAccountUsername"
             });
             // Block on account creation
-            accountAdded.wait(1000);
+            accountAdded.wait(2000);
+            compare(accountAdded.count, 1)
 
             // Add some emoji reactions (one from current account uri, one from another uri)
             emojiReactions.reactions = {
@@ -101,5 +102,9 @@ Item {
             verify(JSON.stringify(optionsPopup.emojiReplied) === JSON.stringify(["🌭"]),
                 "Message options popup should have emoji replied");
         }
+
+        function cleanupTestCase() {
+            AccountAdapter.deleteCurrentAccount()
+        }
     }
 }
-- 
GitLab