-
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
1 parent
5e90d2e
commit 44f6803
Showing
6 changed files
with
93 additions
and
29 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
16 changes: 0 additions & 16 deletions
16
...entation/presentation-library-test/src/test/kotlin/presenter/LoadableItemPresenterTest.kt
This file was deleted.
Oops, something went wrong.
53 changes: 53 additions & 0 deletions
53
...ry-test/src/test/kotlin/tech/coner/trailer/presentation/library/presenter/FooPresenter.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,53 @@ | ||
package tech.coner.trailer.presentation.library.presenter | ||
|
||
import tech.coner.trailer.presentation.library.adapter.LoadableItemAdapter | ||
import tech.coner.trailer.presentation.library.model.BaseItemModel | ||
import tech.coner.trailer.presentation.library.state.LoadableItem | ||
import tech.coner.trailer.presentation.library.state.LoadableItemState | ||
import tech.coner.trailer.toolkit.konstraints.CompositeConstraint | ||
|
||
class FooPresenter : LoadableItemPresenter< | ||
Unit, | ||
FooState, | ||
Foo, | ||
Unit, | ||
FooModel | ||
>() { | ||
override val argument = Unit | ||
override val initialState = FooState(LoadableItem.Empty()) | ||
override val adapter = FooAdapter() | ||
} | ||
|
||
data class Foo(val value: Int) | ||
|
||
data class FooState(override val loadable: LoadableItem<Foo>) : LoadableItemState<Foo> | ||
|
||
class FooModel(override val original: Foo) : BaseItemModel<Foo, FooConstraint>() { | ||
override val constraints = FooConstraint() | ||
} | ||
|
||
class FooConstraint : CompositeConstraint<Foo>() { | ||
|
||
val valueIsInRange = propertyConstraint( | ||
property = Foo::value, | ||
assessFn = { | ||
when (it.value) { | ||
in 0..4 -> true | ||
else -> false | ||
} | ||
}, | ||
violationMessageFn = { "Value is out of range" } | ||
) | ||
} | ||
|
||
class FooAdapter : LoadableItemAdapter< | ||
Unit, | ||
FooState, | ||
Foo, | ||
Unit, | ||
FooModel | ||
>() { | ||
override val argumentModelAdapter = null | ||
override val partialItemAdapter = null | ||
override val itemAdapter: (Foo) -> FooModel = ::FooModel | ||
} |
21 changes: 21 additions & 0 deletions
21
...est/kotlin/tech/coner/trailer/presentation/library/presenter/LoadableItemPresenterTest.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,21 @@ | ||
package tech.coner.trailer.presentation.library.presenter | ||
|
||
import assertk.assertThat | ||
import assertk.assertions.isEqualTo | ||
import kotlinx.coroutines.flow.first | ||
import kotlinx.coroutines.test.runTest | ||
import org.junit.jupiter.api.Test | ||
import tech.coner.trailer.presentation.library.model.LoadableModel | ||
|
||
class LoadableItemPresenterTest { | ||
|
||
|
||
@Test | ||
fun itsModelFlowShouldBeAdaptedFromInitialState() = runTest { | ||
val presenter = FooPresenter() | ||
|
||
val actual = presenter.modelFlow.first() | ||
|
||
assertThat(actual).isEqualTo(LoadableModel.Empty(null)) | ||
} | ||
} |
9 changes: 0 additions & 9 deletions
9
...otlin/tech/coner/trailer/presentation/library/testsupport/LoadableItemPresenterAssertk.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,11 +1,2 @@ | ||
package tech.coner.trailer.presentation.library.testsupport | ||
|
||
import assertk.Assert | ||
import assertk.assertions.prop | ||
import tech.coner.trailer.presentation.library.model.ItemModel | ||
import tech.coner.trailer.presentation.library.presenter.LoadableItemPresenter | ||
import tech.coner.trailer.presentation.library.state.LoadableItemState | ||
|
||
|
||
fun <S : LoadableItemState<I>, I, IM : ItemModel<I>> Assert<LoadableItemPresenter<S, I, IM>>.itemModelFlow() = prop(LoadableItemPresenter<S, I, IM>::itemModelFlow) | ||
fun <S : LoadableItemState<I>, I, IM : ItemModel<I>> Assert<LoadableItemPresenter<S, I, IM>>.itemModel() = prop(LoadableItemPresenter<S, I, IM>::itemModel) |
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