-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #207
- Loading branch information
Showing
11 changed files
with
66 additions
and
49 deletions.
There are no files selected for viewing
28 changes: 19 additions & 9 deletions
28
app/src/androidTest/java/tech/relaycorp/courier/data/preference/StoragePreferencesTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,42 @@ | ||
package tech.relaycorp.courier.data.preference | ||
|
||
import kotlinx.coroutines.test.runBlockingTest | ||
import kotlinx.coroutines.flow.first | ||
import kotlinx.coroutines.runBlocking | ||
import org.junit.After | ||
import org.junit.Ignore | ||
import org.junit.Assert.assertEquals | ||
import org.junit.Before | ||
import org.junit.Test | ||
import tech.relaycorp.courier.data.model.StorageSize | ||
import tech.relaycorp.courier.test.AppTestProvider.flowSharedPreferences | ||
import tech.relaycorp.courier.test.test | ||
import javax.inject.Provider | ||
|
||
class StoragePreferencesTest { | ||
|
||
private val preferences = StoragePreferences(Provider { flowSharedPreferences }) | ||
|
||
@Before | ||
fun setUp() { | ||
flowSharedPreferences.clear() | ||
} | ||
|
||
@After | ||
fun tearDown() { | ||
flowSharedPreferences.clear() | ||
} | ||
|
||
@Test | ||
@Ignore("Failing intermittently") // TODO: fix test | ||
fun maxStorage() = runBlockingTest { | ||
val observer = preferences.getMaxStorageSize().test(this) | ||
fun maxStorage() = runBlocking { | ||
assertEquals( | ||
StoragePreferences.DEFAULT_MAX_STORAGE_SIZE, | ||
preferences.getMaxStorageSize().first() | ||
) | ||
|
||
val newSize = StorageSize(100) | ||
preferences.setMaxStorageSize(newSize) | ||
|
||
observer | ||
.assertValues(StoragePreferences.DEFAULT_MAX_STORAGE_SIZE, newSize) | ||
.finish() | ||
assertEquals( | ||
newSize, | ||
preferences.getMaxStorageSize().first() | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,16 @@ | ||
package tech.relaycorp.courier.ui | ||
|
||
import androidx.annotation.VisibleForTesting | ||
import androidx.lifecycle.ViewModel | ||
import androidx.lifecycle.viewModelScope | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.plus | ||
|
||
abstract class BaseViewModel : ViewModel() { | ||
val ioScope = viewModelScope + Dispatchers.IO | ||
protected val scope = viewModelScope + VIEW_MODEL_DISPATCHER | ||
|
||
companion object { | ||
@VisibleForTesting | ||
var VIEW_MODEL_DISPATCHER = Dispatchers.IO | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters