-
-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✅ Add Unit Tests for BlockRepository DataStore (#577)
Co-authored-by: Leonardo Colman Lopes <[email protected]>
- Loading branch information
Showing
1 changed file
with
37 additions
and
0 deletions.
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
app/src/test/kotlin/br/com/colman/petals/use/repository/BlockRepositoryTest.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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package br.com.colman.petals.use.repository | ||
|
||
import androidx.datastore.core.DataStore | ||
import androidx.datastore.preferences.core.PreferenceDataStoreFactory | ||
import androidx.datastore.preferences.core.Preferences | ||
import io.kotest.core.spec.style.FunSpec | ||
import io.kotest.engine.spec.tempfile | ||
import io.kotest.matchers.shouldBe | ||
import kotlinx.coroutines.flow.first | ||
|
||
class BlockRepositoryTest : FunSpec({ | ||
val datastore: DataStore<Preferences> = PreferenceDataStoreFactory.create { tempfile(suffix = ".preferences_pb") } | ||
val target = BlockRepository(datastore) | ||
|
||
test("Defaults block censor true") { | ||
BlockType.entries.forEach { blockType -> | ||
val isCensored = when (blockType) { | ||
BlockType.Today -> target.isTodayCensored.first() | ||
BlockType.ThisWeek -> target.isThisWeekCensored.first() | ||
BlockType.ThisMonth -> target.isThisMonthCensored.first() | ||
BlockType.ThisYear -> target.isThisYearCensored.first() | ||
BlockType.AllTime -> target.isAllTimeCensored.first() | ||
} | ||
isCensored shouldBe true | ||
} | ||
} | ||
|
||
test("Changes today's block censure") { | ||
target.setBlockCensure(BlockType.Today, false) | ||
target.isTodayCensored.first() shouldBe false | ||
} | ||
|
||
test("Persists specified block censure") { | ||
target.setBlockCensure(BlockType.Today, false) | ||
datastore.data.first()[BlockType.Today.preferencesKey] shouldBe false | ||
} | ||
}) |