From 88d291208f07a76c666207e10d09e814be5cf32c Mon Sep 17 00:00:00 2001
From: ialokim <ialokim@mailbox.org>
Date: Sun, 9 Jan 2022 21:47:37 +0100
Subject: [PATCH] add test executables for startup screen

---
 .../briar/desktop/RunWithTemporaryAccount.kt  | 20 +++++++++++++------
 .../briar/desktop/TestStartupWithAccount.kt   |  3 +++
 .../desktop/TestStartupWithoutAccount.kt      |  3 +++
 3 files changed, 20 insertions(+), 6 deletions(-)
 create mode 100644 src/test/kotlin/org/briarproject/briar/desktop/TestStartupWithAccount.kt
 create mode 100644 src/test/kotlin/org/briarproject/briar/desktop/TestStartupWithoutAccount.kt

diff --git a/src/test/kotlin/org/briarproject/briar/desktop/RunWithTemporaryAccount.kt b/src/test/kotlin/org/briarproject/briar/desktop/RunWithTemporaryAccount.kt
index fc340f94ce..d14708016a 100644
--- a/src/test/kotlin/org/briarproject/briar/desktop/RunWithTemporaryAccount.kt
+++ b/src/test/kotlin/org/briarproject/briar/desktop/RunWithTemporaryAccount.kt
@@ -9,7 +9,11 @@ import org.briarproject.briar.desktop.TestUtils.getDataDir
 import org.briarproject.briar.desktop.utils.LogUtils
 import java.util.logging.Level.ALL
 
-internal class RunWithTemporaryAccount(val customization: BriarDesktopTestApp.() -> Unit) {
+internal class RunWithTemporaryAccount(
+    val createAccount: Boolean = true,
+    val login: Boolean = true,
+    val customization: BriarDesktopTestApp.() -> Unit = {}
+) {
 
     companion object {
         private val LOG = KotlinLogging.logger {}
@@ -40,12 +44,16 @@ internal class RunWithTemporaryAccount(val customization: BriarDesktopTestApp.()
         val lifecycleManager = app.getLifecycleManager()
         val accountManager = app.getAccountManager()
 
-        val password = "verySecret123!"
-        accountManager.createAccount("alice", password)
+        if (createAccount) {
+            val password = "verySecret123!"
+            accountManager.createAccount("alice", password)
 
-        val dbKey = accountManager.databaseKey ?: throw AssertionError()
-        lifecycleManager.startServices(dbKey)
-        lifecycleManager.waitForStartup()
+            if (login) {
+                val dbKey = accountManager.databaseKey ?: throw AssertionError()
+                lifecycleManager.startServices(dbKey)
+                lifecycleManager.waitForStartup()
+            }
+        }
 
         customization(app)
 
diff --git a/src/test/kotlin/org/briarproject/briar/desktop/TestStartupWithAccount.kt b/src/test/kotlin/org/briarproject/briar/desktop/TestStartupWithAccount.kt
new file mode 100644
index 0000000000..0f7746072e
--- /dev/null
+++ b/src/test/kotlin/org/briarproject/briar/desktop/TestStartupWithAccount.kt
@@ -0,0 +1,3 @@
+package org.briarproject.briar.desktop
+
+fun main() = RunWithTemporaryAccount(login = false).run()
diff --git a/src/test/kotlin/org/briarproject/briar/desktop/TestStartupWithoutAccount.kt b/src/test/kotlin/org/briarproject/briar/desktop/TestStartupWithoutAccount.kt
new file mode 100644
index 0000000000..fd07c97674
--- /dev/null
+++ b/src/test/kotlin/org/briarproject/briar/desktop/TestStartupWithoutAccount.kt
@@ -0,0 +1,3 @@
+package org.briarproject.briar.desktop
+
+fun main() = RunWithTemporaryAccount(createAccount = false).run()
-- 
GitLab