Skip to content
Snippets Groups Projects
Commit 09d2dd91 authored by Sebastian's avatar Sebastian Committed by Mikolai Gütschow
Browse files

Create test data on startup for testing app

parent 4860561d
No related branches found
No related tags found
1 merge request!22Make it possible to start briar with temporary account with a bunch of testing contacts
...@@ -81,6 +81,7 @@ constructor( ...@@ -81,6 +81,7 @@ constructor(
var screenState by remember { var screenState by remember {
mutableStateOf( mutableStateOf(
if (accountManager.hasDatabaseKey()) { if (accountManager.hasDatabaseKey()) {
loadContacts()
Screen.MAIN Screen.MAIN
} else if (accountManager.accountExists()) { } else if (accountManager.accountExists()) {
Screen.LOGIN Screen.LOGIN
...@@ -101,6 +102,7 @@ constructor( ...@@ -101,6 +102,7 @@ constructor(
onSubmit = { username, password -> onSubmit = { username, password ->
accountManager.createAccount(username, password) accountManager.createAccount(username, password)
signedIn() signedIn()
loadContacts()
screenState = Screen.MAIN screenState = Screen.MAIN
} }
) )
...@@ -110,6 +112,7 @@ constructor( ...@@ -110,6 +112,7 @@ constructor(
try { try {
accountManager.signIn(it) accountManager.signIn(it)
signedIn() signedIn()
loadContacts()
screenState = Screen.MAIN screenState = Screen.MAIN
} catch (e: DecryptionException) { } catch (e: DecryptionException) {
// failure, try again // failure, try again
...@@ -135,6 +138,9 @@ constructor( ...@@ -135,6 +138,9 @@ constructor(
val dbKey = accountManager.databaseKey ?: throw AssertionError() val dbKey = accountManager.databaseKey ?: throw AssertionError()
lifecycleManager.startServices(dbKey) lifecycleManager.startServices(dbKey)
lifecycleManager.waitForStartup() lifecycleManager.waitForStartup()
}
private fun loadContacts() {
val contacts = contactManager.contacts val contacts = contactManager.contacts
for (contact in contacts) { for (contact in contacts) {
println("${contact.author.name} (${contact.alias})") println("${contact.author.name} (${contact.alias})")
......
...@@ -29,16 +29,29 @@ private class TestWithTemporaryAccount { ...@@ -29,16 +29,29 @@ private class TestWithTemporaryAccount {
println("Using data directory '$dataDir'") println("Using data directory '$dataDir'")
val app = val app =
DaggerBriarDesktopApp.builder().desktopModule( DaggerBriarDesktopTestApp.builder().desktopTestModule(
DesktopModule(dataDir.toFile()) DesktopTestModule(dataDir.toFile())
).build() ).build()
// We need to load the eager singletons directly after making the // We need to load the eager singletons directly after making the
// dependency graphs // dependency graphs
BrambleCoreEagerSingletons.Helper.injectEagerSingletons(app) BrambleCoreEagerSingletons.Helper.injectEagerSingletons(app)
BriarCoreEagerSingletons.Helper.injectEagerSingletons(app) BriarCoreEagerSingletons.Helper.injectEagerSingletons(app)
val lifecycleManager = app.getLifecycleManager()
val accountManager = app.getAccountManager()
val password = "verySecret123!" 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() app.getUI().startBriar()
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment