add some tests

This commit is contained in:
Phillip Thelen 2023-02-14 09:43:47 +01:00
parent 71e4c4805b
commit 6be16ea17d
2 changed files with 89 additions and 17 deletions

View file

@ -65,7 +65,7 @@
-keep class io.realm.internal.Keep -keep class io.realm.internal.Keep
-keep @io.realm.internal.Keep class * -keep @io.realm.internal.Keep class *
-dontwarn javax.** -dontwarn javax.**
-dontwarn io.realm.** -keep io.realm.**
#crashlytic #crashlytic
-keepattributes SourceFile,LineNumberTable -keepattributes SourceFile,LineNumberTable

View file

@ -9,27 +9,99 @@ import io.kotest.matchers.shouldBe
class TaskLocalRepositoryTest : WordSpec({ class TaskLocalRepositoryTest : WordSpec({
val repository = TaskLocalRepository() val repository = TaskLocalRepository()
val list = TaskList() beforeEach {
list.tasks["1"] = Task().apply { val list = TaskList()
id = "1" list.tasks["1"] = Task().apply {
type = TaskType.HABIT id = "1"
} type = TaskType.HABIT
list.tasks["2"] = Task().apply { }
id = "2" list.tasks["2"] = Task().apply {
type = TaskType.DAILY id = "2"
} type = TaskType.DAILY
list.tasks["3"] = Task().apply { isDue = true
id = "3" }
type = TaskType.DAILY list.tasks["3"] = Task().apply {
} id = "3"
list.tasks["4"] = Task().apply { type = TaskType.DAILY
id = "4" completed = true
type = TaskType.REWARD isDue = true
}
list.tasks["4"] = Task().apply {
id = "4"
type = TaskType.DAILY
completed = false
isDue = true
}
list.tasks["5"] = Task().apply {
id = "5"
type = TaskType.TODO
}
list.tasks["6"] = Task().apply {
id = "6"
type = TaskType.TODO
completed = true
}
list.tasks["7"] = Task().apply {
id = "7"
type = TaskType.REWARD
}
repository.saveTasks(list, null)
} }
"getTask" should { "getTask" should {
"return right task" { "return right task" {
repository.getTask("3").test { repository.getTask("3").test {
awaitItem()?.id shouldBe "3" awaitItem()?.id shouldBe "3"
awaitComplete()
}
}
}
"updateTask" should {
"update an existing task" {
val task = Task().apply {
id = "3"
type = TaskType.DAILY
completed = false
}
repository.updateTask(task)
repository.getTask("3").test {
awaitItem()?.completed shouldBe false
awaitComplete()
}
}
"add new item if task does not exist" {
val task = Task().apply {
id = "33"
type = TaskType.DAILY
}
repository.updateTask(task)
repository.getTaskCounts().test {
awaitItem()[TaskType.DAILY.value] shouldBe 4
}
}
}
"getTaskCounts" should {
"return task counts for all types" {
repository.getTaskCounts().test {
val counts = awaitItem()
counts[TaskType.HABIT.value] shouldBe 1
counts[TaskType.DAILY.value] shouldBe 3
counts[TaskType.TODO.value] shouldBe 2
counts[TaskType.REWARD.value] shouldBe 1
}
}
}
"getActiveTaskCounts" should {
"return only return active task counts for all types" {
repository.getActiveTaskCounts().test {
val counts = awaitItem()
counts[TaskType.HABIT.value] shouldBe 1
counts[TaskType.DAILY.value] shouldBe 2
counts[TaskType.TODO.value] shouldBe 1
counts[TaskType.REWARD.value] shouldBe 1
} }
} }
} }