-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
142 additions
and
44 deletions.
There are no files selected for viewing
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
30 changes: 15 additions & 15 deletions
30
shared/src/commonTest/kotlin/com/wbrawner/twigs/shared/BudgetReducerTests.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,54 +1,54 @@ | ||
package com.wbrawner.twigs.shared | ||
|
||
import com.russhwolf.settings.Settings | ||
import com.wbrawner.twigs.shared.budget.BudgetAction | ||
import com.wbrawner.twigs.shared.budget.BudgetReducer | ||
import com.wbrawner.twigs.shared.budget.BudgetRepository | ||
import com.wbrawner.twigs.shared.user.Permission | ||
import com.wbrawner.twigs.shared.user.UserPermission | ||
import kotlinx.datetime.toInstant | ||
import kotlinx.coroutines.DelicateCoroutinesApi | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.ExperimentalCoroutinesApi | ||
import kotlinx.coroutines.newSingleThreadContext | ||
import kotlinx.coroutines.test.setMain | ||
import kotlin.test.BeforeTest | ||
import kotlin.test.DefaultAsserter.assertEquals | ||
import kotlin.test.DefaultAsserter.assertTrue | ||
import kotlin.test.Test | ||
import kotlin.test.assertFalse | ||
import kotlin.test.assertNull | ||
import kotlin.test.assertTrue | ||
|
||
class BudgetReducerTests { | ||
lateinit var reducer: BudgetReducer | ||
lateinit var dispatchedActions: MutableList<Action> | ||
lateinit var budgetRepository: FakeBudgetRepository | ||
lateinit var settings: Settings | ||
|
||
@OptIn(ExperimentalCoroutinesApi::class, DelicateCoroutinesApi::class) | ||
@BeforeTest | ||
fun setup() { | ||
Dispatchers.setMain(newSingleThreadContext("main")) | ||
dispatchedActions = mutableListOf() | ||
budgetRepository = FakeBudgetRepository() | ||
reducer = BudgetReducer(budgetRepository) | ||
settings = FakeSettings() | ||
reducer = BudgetReducer(budgetRepository, settings) | ||
reducer.dispatch = { dispatchedActions.add(it) } | ||
} | ||
|
||
@Test | ||
fun goBackWhileEditingTest() { | ||
val state = State(editingBudget = true, selectedBudget = "test") | ||
val newState = reducer.reduce(Action.Back, state) | ||
val newState = reducer.reduce(Action.Back) { state } | ||
assertFalse(newState.editingBudget) | ||
assertEquals("selectedBudget should still be set", "test", newState.selectedBudget) | ||
} | ||
|
||
@Test | ||
fun goBackWhileViewingTest() { | ||
val state = State(selectedBudget = "test") | ||
val newState = reducer.reduce(Action.Back, state) | ||
assertNull(newState.selectedBudget) | ||
} | ||
|
||
@Test | ||
fun createBudgetTest() { | ||
val state = State() | ||
val users = listOf(UserPermission("user", Permission.OWNER)) | ||
assertFalse(state.loading) | ||
val newState = reducer.reduce(BudgetAction.CreateBudget("test", "description", users), state) | ||
assertTrue(state.loading) | ||
|
||
val newState = reducer.reduce(BudgetAction.CreateBudget("test", "description", users)) { state } | ||
assertTrue(newState.loading) | ||
assertNull(newState.selectedBudget) | ||
} | ||
} |
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
94 changes: 94 additions & 0 deletions
94
shared/src/commonTest/kotlin/com/wbrawner/twigs/shared/FakeSettings.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,94 @@ | ||
package com.wbrawner.twigs.shared | ||
|
||
import com.russhwolf.settings.Settings | ||
|
||
class FakeSettings: Settings { | ||
override val keys: Set<String> | ||
get() = TODO("Not yet implemented") | ||
override val size: Int | ||
get() = TODO("Not yet implemented") | ||
|
||
override fun clear() { | ||
TODO("Not yet implemented") | ||
} | ||
|
||
override fun getBoolean(key: String, defaultValue: Boolean): Boolean { | ||
TODO("Not yet implemented") | ||
} | ||
|
||
override fun getBooleanOrNull(key: String): Boolean? { | ||
TODO("Not yet implemented") | ||
} | ||
|
||
override fun getDouble(key: String, defaultValue: Double): Double { | ||
TODO("Not yet implemented") | ||
} | ||
|
||
override fun getDoubleOrNull(key: String): Double? { | ||
TODO("Not yet implemented") | ||
} | ||
|
||
override fun getFloat(key: String, defaultValue: Float): Float { | ||
TODO("Not yet implemented") | ||
} | ||
|
||
override fun getFloatOrNull(key: String): Float? { | ||
TODO("Not yet implemented") | ||
} | ||
|
||
override fun getInt(key: String, defaultValue: Int): Int { | ||
TODO("Not yet implemented") | ||
} | ||
|
||
override fun getIntOrNull(key: String): Int? { | ||
TODO("Not yet implemented") | ||
} | ||
|
||
override fun getLong(key: String, defaultValue: Long): Long { | ||
TODO("Not yet implemented") | ||
} | ||
|
||
override fun getLongOrNull(key: String): Long? { | ||
TODO("Not yet implemented") | ||
} | ||
|
||
override fun getString(key: String, defaultValue: String): String { | ||
TODO("Not yet implemented") | ||
} | ||
|
||
override fun getStringOrNull(key: String): String? { | ||
TODO("Not yet implemented") | ||
} | ||
|
||
override fun hasKey(key: String): Boolean { | ||
TODO("Not yet implemented") | ||
} | ||
|
||
override fun putBoolean(key: String, value: Boolean) { | ||
TODO("Not yet implemented") | ||
} | ||
|
||
override fun putDouble(key: String, value: Double) { | ||
TODO("Not yet implemented") | ||
} | ||
|
||
override fun putFloat(key: String, value: Float) { | ||
TODO("Not yet implemented") | ||
} | ||
|
||
override fun putInt(key: String, value: Int) { | ||
TODO("Not yet implemented") | ||
} | ||
|
||
override fun putLong(key: String, value: Long) { | ||
TODO("Not yet implemented") | ||
} | ||
|
||
override fun putString(key: String, value: String) { | ||
TODO("Not yet implemented") | ||
} | ||
|
||
override fun remove(key: String) { | ||
TODO("Not yet implemented") | ||
} | ||
} |