Skip to content

Commit

Permalink
✅ Add Unit Tests for BlockRepository DataStore (#577)
Browse files Browse the repository at this point in the history
Co-authored-by: Leonardo Colman Lopes <[email protected]>
  • Loading branch information
gBL17 and LeoColman authored May 21, 2024
1 parent 976e472 commit d7eadb3
Showing 1 changed file with 37 additions and 0 deletions.
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
}
})

0 comments on commit d7eadb3

Please sign in to comment.