From 09d2dd91f9135a9ab8c37f491e1cb015af1862c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20K=C3=BCrten?= <sebastian@mobanisto.de> Date: Thu, 30 Sep 2021 14:28:27 +0200 Subject: [PATCH] Create test data on startup for testing app --- .../briar/desktop/BriarService.kt | 6 ++++++ .../briar/desktop/TestWithTemporaryAccount.kt | 19 ++++++++++++++++--- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/main/kotlin/org/briarproject/briar/desktop/BriarService.kt b/src/main/kotlin/org/briarproject/briar/desktop/BriarService.kt index 4dc34b77df..b78aba7ca3 100644 --- a/src/main/kotlin/org/briarproject/briar/desktop/BriarService.kt +++ b/src/main/kotlin/org/briarproject/briar/desktop/BriarService.kt @@ -81,6 +81,7 @@ constructor( var screenState by remember { mutableStateOf( if (accountManager.hasDatabaseKey()) { + loadContacts() Screen.MAIN } else if (accountManager.accountExists()) { Screen.LOGIN @@ -101,6 +102,7 @@ constructor( onSubmit = { username, password -> accountManager.createAccount(username, password) signedIn() + loadContacts() screenState = Screen.MAIN } ) @@ -110,6 +112,7 @@ constructor( try { accountManager.signIn(it) signedIn() + loadContacts() screenState = Screen.MAIN } catch (e: DecryptionException) { // failure, try again @@ -135,6 +138,9 @@ constructor( val dbKey = accountManager.databaseKey ?: throw AssertionError() lifecycleManager.startServices(dbKey) lifecycleManager.waitForStartup() + } + + private fun loadContacts() { val contacts = contactManager.contacts for (contact in contacts) { println("${contact.author.name} (${contact.alias})") diff --git a/src/test/kotlin/org/briarproject/briar/desktop/TestWithTemporaryAccount.kt b/src/test/kotlin/org/briarproject/briar/desktop/TestWithTemporaryAccount.kt index 15d9af08a1..20c9561e43 100644 --- a/src/test/kotlin/org/briarproject/briar/desktop/TestWithTemporaryAccount.kt +++ b/src/test/kotlin/org/briarproject/briar/desktop/TestWithTemporaryAccount.kt @@ -29,16 +29,29 @@ private class TestWithTemporaryAccount { println("Using data directory '$dataDir'") val app = - DaggerBriarDesktopApp.builder().desktopModule( - DesktopModule(dataDir.toFile()) + DaggerBriarDesktopTestApp.builder().desktopTestModule( + DesktopTestModule(dataDir.toFile()) ).build() // We need to load the eager singletons directly after making the // dependency graphs BrambleCoreEagerSingletons.Helper.injectEagerSingletons(app) BriarCoreEagerSingletons.Helper.injectEagerSingletons(app) + val lifecycleManager = app.getLifecycleManager() + val accountManager = app.getAccountManager() + val password = "verySecret123!" - app.getAccountManager().createAccount("alice", password) + accountManager.createAccount("alice", password) + + val dbKey = accountManager.databaseKey ?: throw AssertionError() + lifecycleManager.startServices(dbKey) + lifecycleManager.waitForStartup() + + app.getTestDataCreator().createTestData(10, 20, 50, 4, 4, 10) + + // Creating test data happens on a background thread. As we do not get notified about updates to the conact + // list yet, we need to wait a moment in order for that to finish (hopefully). + Thread.sleep(1000) app.getUI().startBriar() } -- GitLab